Calling VaultHistoryItem.GetActionString()

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

Moderator: SourceGear

Post Reply
bodgerx
Posts: 13
Joined: Wed Nov 11, 2009 7:16 am

Calling VaultHistoryItem.GetActionString()

Post by bodgerx » Mon Nov 16, 2009 10:24 am

I'm trying to loop through a list of history items to find a labelled version using the API and sample code wrappers (ServerOperations).

I can sucessfully retrive checked-in items, but for some reason, never labels.

I assumed that by calling GetActionString() on a VaultHistoryItem object, but it never returns anything - not even 'Checked In' on a standard item.

e.g.:

public static bool IsHigherLiveVersion(VaultHistoryItem ItemToCompare, VaultHistoryItem[] theList)
{
foreach(VaultHistoryItem curItem in theList)
{
if ((curItem.Name == ItemToCompare.Name) && (curItem.GetActionString().Contains("Released Live")))
{
if (curItem.Version > ItemToCompare.Version)
return true;
}
}

return false;
}

shannon

Re: Calling VaultHistoryItem.GetActionString()

Post by shannon » Tue Nov 17, 2009 8:22 am

The history query doesn't retrieve label actions recursively...if you ran your query on $, but were looking for a label on a child item, you'd never find it. Without seeing the code you used to get the history items, that's the only guess I can make.

However, if you're only looking for labels, I might have an easier path for you. There isn't a wrapper method, but I can walk you through using a label query instead of a history query. If you really need to use the history for whatever reason, I'll need to see more of your code to get a handle on what is going wrong. Let me know which option you'd like to go with.

bodgerx
Posts: 13
Joined: Wed Nov 11, 2009 7:16 am

Re: Calling VaultHistoryItem.GetActionString()

Post by bodgerx » Tue Nov 17, 2009 9:44 am

My apologies, I didn't give you the full picture.

This is the initial code (that calls the method "IsHigherLiveVersion()"):

Code: Select all

   

            VaultClientFolder folder = new VaultClientFolder();
            folder = RepositoryUtil.FindVaultFolderAtReposOrLocalPath(tbVaultPath.Text);

            DateSortOption myDateSort = new DateSortOption();

            VaultHistoryItem[] vHist = ServerOperations.ProcessCommandHistory(tbVaultPath.Text,
                                                   chkRecursive.Checked,
                                                   myDateSort,
                                                   "",
                                                   "",
                                                   "",
                                                   "",
                                                   "",
                                                   "",
                                                   _minVersion,
                                                   _maxVersion,
                                                   _maxRows);


            StringBuilder sOutput = new StringBuilder("<table border='4px'><tr><td>File</td><td>Latest Version No.</td></tr>");
            
            foreach (VaultHistoryItem currHist in vHist)
            {
                if (!IsHigherLiveVersion(currHist, vHist) && currHist.Type != 1) //If there is no higher version and the type is not a folder
                {
                     
                    sOutput.Append("<tr><td>" + currHist.Name + "</td><td> "
                                              + currHist.Version.ToString() + "</td></tr>");
                }
            }

vHist gets passed to IsHighLiveVersion, which then calls GetActionString() on that instance.

Thanks.

shannon

Re: Calling VaultHistoryItem.GetActionString()

Post by shannon » Tue Nov 17, 2009 10:25 am

The code you have is only going to return labels for the item at this path: tbVaultPath.Text

Could that be part of the problem you're having?

bodgerx
Posts: 13
Joined: Wed Nov 11, 2009 7:16 am

Re: Calling VaultHistoryItem.GetActionString()

Post by bodgerx » Tue Nov 17, 2009 10:55 am

Yes, that is intentional - I want everything at that path (e.g. a folder and its contents) - and I want to check the labels on files under there, as well as the action (check-in) etc.

Is this not the way to achieve this?

shannon

Re: Calling VaultHistoryItem.GetActionString()

Post by shannon » Tue Nov 17, 2009 11:02 am

The history query only does a non-recursive label search, regardless of whether you request a recursive query, so you'll only get labels for the root item. (You can see this behavior when you perform a history query in the gui client.)

bodgerx
Posts: 13
Joined: Wed Nov 11, 2009 7:16 am

Re: Calling VaultHistoryItem.GetActionString()

Post by bodgerx » Wed Nov 18, 2009 3:45 am

It seems strange that this method should act recursively on everything but labels.

What would be the reccomended method to use to do a recursive label search?

Thanks.

shannon

Re: Calling VaultHistoryItem.GetActionString()

Post by shannon » Wed Nov 18, 2009 8:33 am

My guess is that this was done for performance reasons, but that's just a guess.

Regardless, I think the label query function should do what you need. As I said before, there isn't a wrapper function, but it isn't very hard to use.

Code: Select all

long objId = RepositoryUtil.FindVaultTreeObjectAtReposOrLocalPath(tbVaultPath.Text).ID;
string qryToken;
long rowsRetMain;
long rowsRetRecur;

ServerOperations.client.ClientInstance.BeginLabelQuery(
    tbVaultPath.Text,
    objId,
    true, // get recursive
    true, // get inherited
    true, // get file items
    true, // get folder items
    1000,
    out rowsRetMain,
    out rowsRetRecur,
    out qryToken);
VaultLabelItemX[] labelItems;
ServerOperations.client.ClientInstance.GetLabelQueryItems_Recursive(
    qryToken, 0, (int) rowsRetRecur, out labelItems);
ServerOperations.client.ClientInstance.EndLabelQuery(qryToken);
You may need to alter your comparison code since you won't be comparing two VaultHistoryItem objects anymore, but I think the information you need should still be present. VaultLabelItemX and VaultHistoryItem are both based off VaultHistoryItemBase.
Give that a try and let me know if you need more help.

bodgerx
Posts: 13
Joined: Wed Nov 11, 2009 7:16 am

Re: Calling VaultHistoryItem.GetActionString()

Post by bodgerx » Wed Nov 18, 2009 9:35 am

That looks good, thank you for your help. I will give it a go.

bodgerx
Posts: 13
Joined: Wed Nov 11, 2009 7:16 am

Re: Calling VaultHistoryItem.GetActionString()

Post by bodgerx » Thu Nov 19, 2009 5:52 am

I've tried it using the following code:

Code: Select all

              long objId = RepositoryUtil.FindVaultTreeObjectAtReposOrLocalPath(tbVaultPath.Text).ID;
                string qryToken;
                long rowsRetMain;
                long rowsRetRecur;

                ServerOperations.client.ClientInstance.BeginLabelQuery(tbVaultPath.Text,
                                                                       objId,
                                                                       true, // get recursive
                                                                       true, // get inherited
                                                                       true, // get file items
                                                                       false, // get folder items
                                                                       1000,
                                                                       out rowsRetMain,
                                                                       out rowsRetRecur,
                                                                       out qryToken);
                VaultLabelItemX[] labelItems;

                ServerOperations.client.ClientInstance.GetLabelQueryItems_Recursive(qryToken, 
                                                                                    0, 
                                                                                    (int)rowsRetRecur, 
                                                                                    out labelItems);

                foreach (VaultLabelItemX currItem in labelItems)
                {  //output here
                }
It seems to return the latest version labels only. Which is exactly what I wanted actually, but how would I get it to return ALL labels for all versions?

shannon

Re: Calling VaultHistoryItem.GetActionString()

Post by shannon » Thu Nov 19, 2009 8:54 am

I think that code should be returning everything....is it possible you need to increase max rows? It's set to only return the first 1000 right now.

bodgerx
Posts: 13
Joined: Wed Nov 11, 2009 7:16 am

Re: Calling VaultHistoryItem.GetActionString()

Post by bodgerx » Mon Nov 23, 2009 8:37 am

My bad - it was returning all the labels - I wasn't scrolling through the full list the VS debugger.

Thanks for you help - I have now deployed my app to our dev team and they are using it.

shannon

Re: Calling VaultHistoryItem.GetActionString()

Post by shannon » Mon Nov 23, 2009 9:04 am

Great, thanks for the update. Let us know if you have any more questions.

Post Reply