HistItemType property of VaultHistoryItem

Post your questions regarding using the Vault and Fortress API in your programs.

Moderator: SourceGear

Post Reply
mmoayyed
Posts: 26
Joined: Tue Feb 26, 2008 12:43 pm

HistItemType property of VaultHistoryItem

Post by mmoayyed » Fri Feb 20, 2009 6:56 pm

Hi,

I am using the client API version 4.1.0.16216, trying to run a history request on a repository that should bring back "everything", (The top folder name is set to be "$") and there are no limits on the number of rows returned. I get back X number of results but when I look through the array of items the HistItemType on each history object only hits a few properties, mostly Created, Added and CheckedIn. I am mostly interested in MovedTo and MovedFrom and I dont seem them at all.

To test this, although I was sure we've moved around components in the repository, I manually moved file from one folder to another in the GUI client and ran the query again and it still never hit that the right case.

I also tried the HistoryQuery sample application on the site, made some modifications to make it compatible with my API version. Only change I made was in the BeginDate and EndDate and I moved the range back to 20 years ago and ran the query. Same results.

Any ideas ?

Beth
Posts: 8550
Joined: Wed Jun 21, 2006 8:24 pm
Location: SourceGear
Contact:

Re: HistItemType property of VaultHistoryItem

Post by Beth » Mon Feb 23, 2009 8:34 am

Just to make sure we are troubleshooting the right thing, can you see the moved to and from when you run a history query inside of the Vault GUI client instead of using the API? If you aren't seeing them there, then we'll troubleshoot that before looking at the API code.

Just so you know where to look for your thread, if this is only an issue in the API, then I'm going to move this over to the Development Tips section.
Beth Kieler
SourceGear Technical Support

mmoayyed
Posts: 26
Joined: Tue Feb 26, 2008 12:43 pm

Re: HistItemType property of VaultHistoryItem

Post by mmoayyed » Mon Feb 23, 2009 7:06 pm

Yes, I am using the GUI client 4.1.3 and when I try to retrieve history for a folder, I can see that a number of files have been moved to different places.
It's definitely an API problem.

shannon

Re: HistItemType property of VaultHistoryItem

Post by shannon » Tue Feb 24, 2009 1:24 pm

It would be helpful if I could see your code, can you provide a snippet?

mmoayyed
Posts: 26
Joined: Tue Feb 26, 2008 12:43 pm

Re: HistItemType property of VaultHistoryItem

Post by mmoayyed » Tue Feb 24, 2009 1:28 pm

The following lines are part of the LoadHistory() method with the following signature/parameters:
LoadHistory(myClient, "$", DateTime.Now.AddDays(-(double)8000));

This is taken from the HistoryQuery sample project posted on the forum as a sample.

Code: Select all

            
            VaultLib.VaultHistoryQueryRequest req = new VaultLib.VaultHistoryQueryRequest();
            DateTime now = DateTime.Now;
            ArrayList users = new ArrayList();
            ArrayList substrings = new ArrayList();
            ArrayList actions = new ArrayList();
            ArrayList sorts = new ArrayList();
            sorts.Add((long)VaultQueryRequestSort.DateSort);
            req.SubstringType = VaultLib.VaultQueryRequestSubstrings.DoNotFilter;
            req.IsFolder = true;
            req.Recursive = true;

            req.DateFilterType = VaultQueryRequestDateTypes.IncludePastDays;
            req.DateFilterMask = VaultQueryRequestDates.HistoryBefore | VaultQueryRequestDates.HistoryAfter;
            req.EndDate = new VaultDateTime(DateTime.Now, VaultDateTime.LocalKind);
            req.BeginDate = new VaultDateTime(dtBegin, VaultDateTime.LocalKind);
            actions.Clear();
            req.CommentFilter = VaultLib.VaultQueryRequestComments.DoNotFilter;

            req.RepID = ciUser.ActiveRepositoryID;
            req.TopName = repositoryPath;

            req.Recursive = true;
            req.Users = (VaultLib.VaultUser[])users.ToArray(typeof(VaultLib.VaultUser));
            req.Substrings = (string[])substrings.ToArray(typeof(string));

            actions.Add((long)VaultHistoryType.MovedTo);

            req.Actions = (long[])actions.ToArray(typeof(long));
            req.Sorts = (long[])sorts.ToArray(typeof(long));

            string token = String.Empty;
            int rowsRetrieved = 0;
            VaultLib.VaultHistoryItem[] items = new VaultLib.VaultHistoryItem[1];
            ciUser.Connection.HistoryBegin(req, 0, ref rowsRetrieved, ref token);
            if (rowsRetrieved > 0)
                ciUser.Connection.HistoryFetch(token, 0, rowsRetrieved - 1, ref items);
            ciUser.Connection.HistoryEnd(token);

shannon

Re: HistItemType property of VaultHistoryItem

Post by shannon » Tue Feb 24, 2009 2:12 pm

You want your DateFilterType to be set to IncludeRange, based on your other values: req.DateFilterType = VaultQueryRequestDateTypes.IncludeRange;

Can you tell me what you would select in the history query of the gui client to get the query you're trying to get with this code?

mmoayyed
Posts: 26
Joined: Tue Feb 26, 2008 12:43 pm

Re: HistItemType property of VaultHistoryItem

Post by mmoayyed » Tue Feb 24, 2009 7:09 pm

I tried the IncludeRange flag and I got this exception:

Server was unable to process request. ---> StartIndex cannot be less than zero.
Parameter name: startIndex

In the GUI client, I simply right click on $, select Show History and accept all default values in the new screen. In the History screen, i can see that many files were moved to other folders.

shannon

Re: HistItemType property of VaultHistoryItem

Post by shannon » Tue Feb 24, 2009 11:19 pm

Ok, that error might make sense....in HistoryBegin, the second parameter is the max number of items that will be returned, try changing it from 0 to something like 1000.

mmoayyed
Posts: 26
Joined: Tue Feb 26, 2008 12:43 pm

Re: HistItemType property of VaultHistoryItem

Post by mmoayyed » Wed Feb 25, 2009 10:40 am

Changed to 1000, got the same exception.

shannon

Re: HistItemType property of VaultHistoryItem

Post by shannon » Wed Feb 25, 2009 12:45 pm

Ok, I removed some lines it seemed like you weren't using and modified some values that weren't quite right. If you need to add substring or user filtering, you can do so, but I think passing empty arrays was causing a problem. Just to simplify the code, I removed the date filtering entirely since you were just going back a really long time.

Code: Select all

			VaultLib.VaultHistoryQueryRequest req = new VaultLib.VaultHistoryQueryRequest();
			DateTime now = DateTime.Now;
			ArrayList users = new ArrayList();
			ArrayList substrings = new ArrayList();
			ArrayList actions = new ArrayList();
			ArrayList sorts = new ArrayList();
			sorts.Add((long)(VaultQueryRequestSort.DateSort | VaultQueryRequestSort.DescSort));
			req.SubstringType = VaultLib.VaultQueryRequestSubstrings.DoNotFilter;
			req.IsFolder = true;
			req.Recursive = true;

			req.DateFilterType = VaultQueryRequestDateTypes.DoNotFilter;
			req.BeginDate = req.EndDate = VaultDate.EmptyDate();
			actions.Clear();
			req.CommentFilter = VaultLib.VaultQueryRequestComments.DoNotFilter;

			req.RepID = ciUser.ActiveRepositoryID;
			req.TopName = repositoryPath;
			
			VaultClientFolder vcf = ciUser.TreeCache.Repository.Root.FindFolderRecursive(repositoryPath);
			
			req.TopID = vcf.ID;

			req.Recursive = true;

			actions.Add((long)VaultRequestType.Move);

			req.Actions = (long[])actions.ToArray(typeof(long));
			req.Sorts = (long[])sorts.ToArray(typeof(long));

			string token = String.Empty;
			int rowsRetrieved = 0;
			VaultLib.VaultHistoryItem[] items = new VaultLib.VaultHistoryItem[1];
			ciUser.Connection.HistoryBegin(req, 2000, ref rowsRetrieved, ref token);
			if (rowsRetrieved > 0)
				ciUser.Connection.HistoryFetch(token, 0, rowsRetrieved - 1, ref items);
			ciUser.Connection.HistoryEnd(token);
Give that a try and see if it returns results closer to what you were expecting.

mmoayyed
Posts: 26
Joined: Tue Feb 26, 2008 12:43 pm

Re: HistItemType property of VaultHistoryItem

Post by mmoayyed » Fri Feb 27, 2009 10:31 am

Tried and this seems to work. Thanks! :)

Beth
Posts: 8550
Joined: Wed Jun 21, 2006 8:24 pm
Location: SourceGear
Contact:

Re: HistItemType property of VaultHistoryItem

Post by Beth » Fri Feb 27, 2009 3:23 pm

Thanks for the update. Happy to hear it worked for you.
Beth Kieler
SourceGear Technical Support

Post Reply