Need some help with the API.

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

Moderator: SourceGear

Post Reply
dschrenk
Posts: 10
Joined: Fri Feb 24, 2006 11:53 am

Need some help with the API.

Post by dschrenk » Fri Feb 24, 2006 12:10 pm

Im creating an app in VS.NET (C#) that uses Vault Client API to manage ours server environments from Vault. I am new to the Vault API and thought I was moving along pretty good untill I ran into a problem getting a file from vault.

I've tried a number of things, and now I'm at a loss of what to do next.

Here's the code:

Code: Select all


string _file = test.txt;
string prevPath = mlClient.TreeCache.GetWorkingFolder($/mySite);
string diskPath = "\\server\client_sync";
string fullPath = diskPath + "\\" + _file;

VaultClientFolder searchFolder = mlClient.Repository.Root.FindFolderRecursive(_vaultPath);
VaultClientFile _vcFile = new VaultClientFile();
SearchForFile(searchFolder, _file, ref _vcFile);

// set working folder
mlClient.TreeCache.SetWorkingFolder(_vaultPath, diskPath);
mlClient.WorkingFolderOptions.MakeBackups = true;
mlClient.WorkingFolderOptions.MakeWritableAfterCommit = _makeWritable;

//Get file from Vault
mlClient.Get(_vcFile ,true, MakeWritableType.MakeAllFilesWritable, SetFileTimeType.Current, MergeType.Unspecified, null);

Here's the error I get back:

Message: Exception of type VaultClientOperationsLib.GetLatestVersionFailedException was thrown.
Source: VaultClientOperationsLib
Stack: at VaultClientOperationsLib.ClientInstance.ProcessGetFileRequests(GetFileInfo[] infos, MakeWritableType makeWritable, SetFileTimeType setFileTime, MergeType merge, Boolean updateHiddenFilesOnly, String ancestorFullPath, Boolean flat, String ancestorDiskPath, OverwritePrompt PromptData, Boolean isLabelGet, String currentPathToLabelItem, Int64 labelID, Boolean isRetry, Boolean isGetByDisplayVersion)
at VaultClientOperationsLib.ClientInstance.Get(VaultClientFile[] files, Boolean forceLatest, MakeWritableType makeWritable, SetFileTimeType setFileTime, MergeType merge, OverwritePrompt PromptData)
at VaultClientOperationsLib.ClientInstance.Get(VaultClientFile file, Boolean forceLatest, MakeWritableType makeWritable, SetFileTimeType setFileTime, MergeType merge, OverwritePrompt PromptData)


Can someone help?
I'm using Vaut v3.1.7.3719.


Thanks,
David

dan
Posts: 2448
Joined: Wed Dec 17, 2003 5:03 pm
Location: SourceGear
Contact:

Post by dan » Fri Feb 24, 2006 1:24 pm

Some things to check:

1. Does the working folder exist on disk?

2. Is _vcFile a valid file and not null? (Note that you can use mlClient.Repository.Root.FileRecursive to find the file).

3. I'm not sure if MergeType.Unspecified is valid or not. You may need to pass in one of the actual values.

Note that our command line client source is available in the client API installer. It should also have example of the Get command.

dschrenk
Posts: 10
Joined: Fri Feb 24, 2006 11:53 am

Post by dschrenk » Mon Feb 27, 2006 8:45 am

Thanks for getting back. Here are the responces to your tips:

1. The folder does exist but is a UNC path, does that make a difference?


2. The SearchForFile() function uses FileRecursive to sets VaultClientFile _vcFile, and is a valid file.

Code: Select all

public static void SearchForFile(VaultClientFolder folder, string fileName, ref VaultClientFile _vcFile) {
	// search for foldername
	if (folder.Files != null) {
		foreach (VaultClientFile subfile in folder.Files) {
			if (subfile.Name == fileName) {
				_vcFile = subfile;
				break;
			}
		}
	}
}
I also gave mlClient.Repository.Root.FindFileRecursive() a try and still have the same outcome.

3. I have tried all of the possible VaultClientOperationsLib.MergeType's:
  • OverwriteWorkingCopy
    Unspecified
    MergeLater
    AttemptAutomaticMerge
And I have taken a look at the Command Line client and the syntax matches. I just cant find whats going wrong.

-D

dan
Posts: 2448
Joined: Wed Dec 17, 2003 5:03 pm
Location: SourceGear
Contact:

Post by dan » Mon Feb 27, 2006 11:09 am

Try using a non-UNC path, and see if it works (also, see if the SetWorkingFolder actually works on a UNC path)

If it still isn't working, I'd take a copy of the CLC code and see if that works, and if it does, start adding your code bit by bit until it breaks, which should locate what the issue is.

dschrenk
Posts: 10
Joined: Fri Feb 24, 2006 11:53 am

Post by dschrenk » Wed Mar 01, 2006 8:55 am

ok... I broke it down to 5 lines:

Code: Select all

string diskPath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "mb_sync");
VaultClientFile _vcFile = new VaultClientFile();
_vcFile = mlClient.Repository.Root.FindFileRecursive(_vaultPath + _file);
mlClient.TreeCache.SetWorkingFolder(_vaultPath, diskPath);
mlClient.Get(_vcFile, true, MakeWritableType.MakeAllFilesWritable, SetFileTimeType.Current, MergeType.OverwriteWorkingCopy, null);
And im still getting the same VaultClientOperationsLib.GetLatestVersionFailedException.

What am I doing wrong!??! :?

-d

dan
Posts: 2448
Joined: Wed Dec 17, 2003 5:03 pm
Location: SourceGear
Contact:

Post by dan » Wed Mar 01, 2006 9:21 am

Try explicitly creating the working folder before doing the Get and see if that helps.

dschrenk
Posts: 10
Joined: Fri Feb 24, 2006 11:53 am

Post by dschrenk » Wed Mar 01, 2006 10:18 am

How so? Ive tried setting it to a temp dir.

Code: Select all

string diskPath = "c:\\temp";
Is there any other way to set a working folder?

-d

dan
Posts: 2448
Joined: Wed Dec 17, 2003 5:03 pm
Location: SourceGear
Contact:

Post by dan » Wed Mar 01, 2006 10:54 am

Just noticed that you are sending a Vault file path into the SetWorkingFolder function. Make it the parent folder instead and see if that works.

If not, take out the setworkingfolder call entirely and set a working folder through the GUI client to the same folder, just to see if the problem is the working folder.

dschrenk
Posts: 10
Joined: Fri Feb 24, 2006 11:53 am

Post by dschrenk » Wed Mar 01, 2006 11:55 am

I think I just found the error. There is no working path set even after I set it through the GUI. If I try to set it, it doesnt seem to take it.

How do I set it?

dan
Posts: 2448
Joined: Wed Dec 17, 2003 5:03 pm
Location: SourceGear
Contact:

Post by dan » Wed Mar 01, 2006 1:32 pm

Do you get any error in the messages pane or in a dialog?

You can turn on client logging (see the knowlege base on this forum) to see if it displays any useful error messages.

dschrenk
Posts: 10
Joined: Fri Feb 24, 2006 11:53 am

Post by dschrenk » Thu Mar 02, 2006 8:31 am

ok... I double checked my code and it is getting set, and still getting the same exception. Working folder is getting set.

The errors I get are through the GetLatestVersionFailedException in .NET, so I have no messages panes or in a dialog boxes to receive the error.

I continue to get the same error:
Message: Exception of type VaultClientOperationsLib.GetLatestVersionFailedException was thrown.
Source: VaultClientOperationsLib
Stack: at VaultClientOperationsLib.ClientInstance.ProcessGetFileRequests(GetFileInfo[] infos, MakeWritableType makeWritable, SetFileTimeType setFileTime, MergeType merge, Boolean updateHiddenFilesOnly, String ancestorFullPath, Boolean flat, String ancestorDiskPath, OverwritePrompt PromptData, Boolean isLabelGet, String currentPathToLabelItem, Int64 labelID, Boolean isRetry, Boolean isGetByDisplayVersion)
at VaultClientOperationsLib.ClientInstance.Get(VaultClientFile[] files, Boolean forceLatest, MakeWritableType makeWritable, SetFileTimeType setFileTime, MergeType merge, OverwritePrompt PromptData)
at VaultClientOperationsLib.ClientInstance.Get(VaultClientFile file, Boolean forceLatest, MakeWritableType makeWritable, SetFileTimeType setFileTime, MergeType merge, OverwritePrompt PromptData)


And client logging seems like it would only be good for using the GUI Client.

dan
Posts: 2448
Joined: Wed Dec 17, 2003 5:03 pm
Location: SourceGear
Contact:

Post by dan » Thu Mar 02, 2006 9:15 am

You should be able to use the logging, if you create a file name of [yourexe.exe].config, and put it in the same folder as your exe.

I'm not quite sure what to tell you on this issue. Again, I would try using the command line client source first and adding your code until it breaks, which should localize where the problem is.

Post Reply