API GetByDisplayVersion doesn't work with older versions?

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

Moderator: SourceGear

Post Reply
montek
Posts: 107
Joined: Mon Jan 05, 2004 8:46 am

API GetByDisplayVersion doesn't work with older versions?

Post by montek » Thu May 13, 2004 3:50 pm

I'm trying to write my own method to get a specific (display) version of a file. The code below works fine if the version I want is NEWER than the current baseline; however, if it's OLDER, it just seems to slip on through, without any errors, but doesn't actually get anything at all. Any ideas?

Code: Select all

public void getVersion(string path, long version) { 
   VaultClientFile file = null; 

   file = client.TreeCache.Repository.Root.FindFileRecursive(path); 
   if (file != null) { 
      file.Version = version; 
       
      VaultClientFile[] files = new VaultClientFile[1]; // Because GetByDisplayVersion only takes an array. 
      files[0] = file; 
       
      client.GetByDisplayVersion(files, MakeWritableType.MakeAllFilesReadOnly, SetFileTimeType.CheckIn, MergeType.OverwriteWorkingCopy, null); 
   } else 
       throw new Exception(string.Format("getVersion(): {0} does not exist", path)); 
} 

montek
Posts: 107
Joined: Mon Jan 05, 2004 8:46 am

Re: API GetByDisplayVersion doesn't work with older versions

Post by montek » Wed May 19, 2004 5:48 am

bump. Any ideas?

sterwill
Posts: 256
Joined: Thu Nov 06, 2003 10:01 am
Location: SourceGear

Post by sterwill » Wed May 19, 2004 2:33 pm

Modifying the file returned by client.TreeCache.Repository.Root.FindFileRecursive() is a bad idea. You will definitely corrupt your tree structure information this way, since the modified TreeCache will be saved to disk. To correct the corruption, remove your saved repository structure files (Vault will get the complete structure again on the next login). Do this before continuing to test your client application, or debugging will be nearly impossible. See this KB article for details (remove CacheMember_Repository and CacheMember_LastStructureGetTime).

Instead of modifying the VaultClientFile you get back from FindFileRecursive, make a copy (use VaultClientFile's copy constructor).

Also, GetByDisplayVersion has some undocumented requirements of the VaultClientFile objects you pass it. The ObjVerID property of the file must be set to 0 for the Version (display version) property to be used.
Shaw Terwilliger
SourceGear LLC
`echo sterwill5sourcegear6com | tr 56 @.`

montek
Posts: 107
Joined: Mon Jan 05, 2004 8:46 am

Post by montek » Fri May 28, 2004 5:58 am

Thank you very much. I was able to get this to work with the following code (in case anyone else needs/wants it).

Code: Select all

public void getVersion(string path, long version) {
			VaultClientFile file = null;

			file = new VaultClientFile(client.TreeCache.Repository.Root.FindFileRecursive(path));
			if (file != null) {
				file.ObjVerID = 0; // You must do this for GetByDisplayVersion to work properly and not corrupt the treeCache.
				file.Version = version;
				
				VaultClientFile[] files = new VaultClientFile[1]; // Because GetByDisplayVersion only takes arrays.
				files[0] = file;
				
				client.GetByDisplayVersion(files, MakeWritableType.MakeAllFilesReadOnly, SetFileTimeType.CheckIn, MergeType.OverwriteWorkingCopy, null);
			} else 
				throw new Exception(string.Format("getVersion(): {0} does not exist", path));
		}

Post Reply