[API] ClientInstance.GetWorkingFolder returns null

If you are having a problem using Vault, post a message here.

Moderator: SourceGear

Post Reply
oleksa
Posts: 10
Joined: Wed Jul 26, 2006 8:33 am

[API] ClientInstance.GetWorkingFolder returns null

Post by oleksa » Fri Aug 04, 2006 2:17 am

Hello.
I would like to get working folder path for instance of VaultClientFile.
I got VaultClientFileColl using ClientInstance.GetFileAndFolderListsByRegex and for each item I'd like to get folder path on local computer.

But

Code: Select all

wf = ci.GetWorkingFolder(vcf);
always returns null :( (vcf it is instance of VaultClientFile from VaultClientFileColl) In the Vault client working folder was set
I'd tried

Code: Select all

wf = ci.GetWorkingFolder(vcf.Parent);
I've run example SourceGear Vault Client API and its method CheckForWorkingFolder(VaultClientTreeObject obj, bool isCheckout) works fine - the same code (

Code: Select all

wf = _ci.GetWorkingFolder((VaultClientFolder)obj);
) returns instance of WorkingFolder class for the same repository path.

Help me please - what's wrong could be with GetWorkingFolder function? Should I post my code entirely?

Thank you.

jclausius
Posts: 3706
Joined: Tue Dec 16, 2003 1:17 pm
Location: SourceGear
Contact:

Post by jclausius » Fri Aug 04, 2006 8:26 am

The GetWorkingFolder will return a working folder that is specifically assigned to that object. It will not return a working folder if it is inherited. I believe you would need to walk the parent path to find the nearest working folder.

Do you just want the path of the working folder? If so, you could try using ci.TreeCache.GetBestWorkingFolder()
Jeff Clausius
SourceGear

oleksa
Posts: 10
Joined: Wed Jul 26, 2006 8:33 am

Post by oleksa » Fri Aug 04, 2006 8:58 am

I need path that was assigned by "Set working folder" popup menu on repository tree node in the standart Vault client.

I.e.
1. I open Vault GUI client
2. I select $/Test node in the folders tree (e.g. there is file1.txt and file2.txt)
3. I right-click on $/Test node and select Set working folder item
4. I write c:\temp\test and press Enter
6. I execute Get latest version for $/Test. All files from $/Test are copied to the c:\temp\test
5. I close Vault GUI client

Is it possible to get string 'c:\temp\test' for instance of VaultClientFolder using Vault Client API from my application?

Code: Select all

ClientInstance ci;
// ci was connected before, default repository was set
System.Collections.ArrayList regexList = new System.Collections.ArrayList();

VaultClientFolderColl vcFolders;
VaultClientFileColl vcFiles;

regexList.Add(new Regex("test1\\.txt"));
ci.Refresh();
ci.GetFileAndFolderListsByRegex(ci.TreeCache.Repository.Root, regexList, true, out vcFiles, out vcFolders);
// I got here instance VaultClientFile for "test1.txt" in the vcFiles
if (vcFiles.Count == 1)
{
	VaultClientFile vcf = vcFiles[0] as VaultClientFile;
	string localFolder;
	localFolder = ci.TreeCache.GetBestWorkingFolder(vcf.Parent);
	//localFolder is null here
	// I expect that it will contain c:\temp\test

	localFolder = ci.TreeCache.GetWorkingFolder(vcf.Parent);
	//localFolder is null here
	// I expect that it will contain c:\temp\test

	VaultClientFolder localFolder = ci.TreeCache.GetBestWorkingFolder(vcf.Parent);
	WorkingFolder wf = null;
	vcfolder = vcf.Parent;
	while ((localFolder == null || wf == null) && vcfolder != null)
	{
		localFolder = ci.TreeCache.GetWorkingFolder(vcfolder.Parent.FullPath);
		wf = ci.GetWorkingFolder(vcfolder.Parent);
		vcfolder = vcfolder.Parent;
	}
	//I enumerate all folders up to root but locaFolder and wf are null :(
}

oleksa
Posts: 10
Joined: Wed Jul 26, 2006 8:33 am

Post by oleksa » Mon Aug 14, 2006 2:07 am

The problem was that I've initialized ClientInstance with VaultConnection.AccessLevelType.PluginWebService not VaultConnection.AccessLevelType.Client.

so here is sample code

Code: Select all

ClientInstance ci;
ci = new ClientInstance();
//ci.Init(VaultConnection.AccessLevelType.PluginWebService);
ci.Init(VaultConnection.AccessLevelType.Client);
ci.UseFileSystemWatchers = false;
string url = string.Empty, user = string.Empty, password = string.Empty, repository = string.Empty;
RetrieveSession(ref url, ref user, ref password, ref repository);
ci.Login(url, user, password);
// get repository name
[...]
ci.Refresh();
VaultClientFolder vcf = ci.TreeCache.Repository.Root.FindFolderRecursive("$/Test");
WorkingFolder wf = ci.GetWorkingFolder(vcf);
if (wf != null)
	Trace.WriteLine(wf.GetLocalFolderPath());
// I got c:\temp\test here. I'm happy

jclausius
Posts: 3706
Joined: Tue Dec 16, 2003 1:17 pm
Location: SourceGear
Contact:

Post by jclausius » Mon Aug 14, 2006 8:19 am

That would explain things. Plugin Web Service client instance is not really meant for any end-user coding.
Jeff Clausius
SourceGear

Post Reply