Calling VaultHistoryItem.GetActionString()
Moderator: SourceGear
Calling VaultHistoryItem.GetActionString()
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;
}
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;
}
Re: Calling VaultHistoryItem.GetActionString()
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.
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.
Re: Calling VaultHistoryItem.GetActionString()
My apologies, I didn't give you the full picture.
This is the initial code (that calls the method "IsHigherLiveVersion()"):
vHist gets passed to IsHighLiveVersion, which then calls GetActionString() on that instance.
Thanks.
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.
Re: Calling VaultHistoryItem.GetActionString()
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?
Could that be part of the problem you're having?
Re: Calling VaultHistoryItem.GetActionString()
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?
Is this not the way to achieve this?
Re: Calling VaultHistoryItem.GetActionString()
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.)
Re: Calling VaultHistoryItem.GetActionString()
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.
What would be the reccomended method to use to do a recursive label search?
Thanks.
Re: Calling VaultHistoryItem.GetActionString()
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.
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.
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);
Give that a try and let me know if you need more help.
Re: Calling VaultHistoryItem.GetActionString()
That looks good, thank you for your help. I will give it a go.
Re: Calling VaultHistoryItem.GetActionString()
I've tried it using the following code:
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?
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
}
Re: Calling VaultHistoryItem.GetActionString()
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.
Re: Calling VaultHistoryItem.GetActionString()
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.
Thanks for you help - I have now deployed my app to our dev team and they are using it.
Re: Calling VaultHistoryItem.GetActionString()
Great, thanks for the update. Let us know if you have any more questions.