Get Valid Labels Example

Examples of programs integrating with Vault and Fortress API. Also, information on integrating with NAnt, CruiseControl.Net and other third-party tools

Moderator: SourceGear

Post Reply
ejhansen71
Posts: 60
Joined: Thu Nov 13, 2014 10:12 am
Location: Lake in the Hills, IL

Get Valid Labels Example

Post by ejhansen71 » Mon Dec 08, 2014 12:51 pm

Can you provide an example of the usage of ClientInstance.BeginLabelQuery?
I want to list all of the Lables under Project $/EJH_Test

void ClientInstance.BeginLabelQuery(string strItemPath, long nObjID, bool bGetRecursive, bool bGetInherited, bool bGetFileItems, bool bGetFolderItems, int nRowLimit, out int nRowsRetrievedInherited, out int nRowsRetreivedRecursive, out string strQryToken)

Here's what I have:
public static void ValidLabels()
{
string url = "https://vault/VaultService";
string username = "name";
string password = "password";
string repository = "Chicago";

// Return Labels from Project
string objectPath = "$/EJH_Test";
ClientInstance getInstance = new ClientInstance();

getInstance.BeginLabelQuery(objectPath? , ???, true,true,true,true, 50, 50, 50, ???);
}
Thanks!

Eric

ejhansen71
Posts: 60
Joined: Thu Nov 13, 2014 10:12 am
Location: Lake in the Hills, IL

Re: Get Valid Labels Example

Post by ejhansen71 » Mon Dec 08, 2014 3:16 pm

I guess I'm also looking for an updated API help file. The one included does not cover most methods available.
Thanks!

Eric

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

Re: Get Valid Labels Example

Post by Beth » Mon Dec 08, 2014 5:45 pm

Here's what you'll need for the beginlabelquery.

.BeginLabelQuery(string strItemPath, long nObjID, bool bGetRecursive, bool bGetInherited, bool bGetFileItems, bool bGetFolderItems, int nRowLimit, out int nRowsRetrievedInherited, out int nRowsRetreivedRecursive, out string strQryToken)

- strItemPath = $/EJH_Test

- nObjID = Object's ID of the file or folder $/EJH_Test

A Client Instance has a Repository. Within the Repository, there is a
root folder. You can query that root folder for an object to get the ID:
ClientInstance.Repository.Root.FindTreeObjectRecursive("$/EJH_Test")

Then use the ID of the VaultClientTreeObject. Note,
FindTreeObjectRecursive() results may be null, a VaultClientFile or a
VaultClientFolder.

- bGetRecursive - flag to search for ALL of the labels applied to lower
objects found in the repository path. Should most likely be false.

- bGetInherited - flag to indicate to retrieve labels that were applied to
a parent. For example, if the query were to look up lables of
$/A/B/C/D/E/F/ and this flag was set to true, it would find a 'parent'
label applied at $/A/B/C/D/ (assuming D/E/F/ is a sub-folder of that label)

- nRowLimit - a ceiling for the number of labels to retrieve.

- nRowsRetrievedInherited - number of 'main' label items that could be
retrieved.

- nRowsRetreivedRecursive - number of 'recursive' labels that could be
retrieved.

- strQryToken - a token used to pass to the GetLabel*() methods and
EndLabelQuery() to either retrieve label results and 'close' the query
once the results are no longer needed.

I have a feature request logged to get the new methods documented.

F: 17982
Beth Kieler
SourceGear Technical Support

ejhansen71
Posts: 60
Joined: Thu Nov 13, 2014 10:12 am
Location: Lake in the Hills, IL

Re: Get Valid Labels Example

Post by ejhansen71 » Tue Dec 09, 2014 11:02 am

Thanks Beth. For posterity, here is the code I used to query a label:
public static void ValidLabels()
{
string url = "https://vault.xxx.com/VaultService";
string username = "username";
string password = "password";
string repository = "RepositoryName";

// Set the login options and login/connect to a repository.
ServerOperations.client.LoginOptions.URL = url;
ServerOperations.client.LoginOptions.User = username;
ServerOperations.client.LoginOptions.Password = password;
ServerOperations.client.LoginOptions.Repository = repository;
ServerOperations.Login();

ServerOperations.client.AutoCommit = true;

// Project Object holding the labels
string objectPath = "$/EJH_Test";

//strQueryToken to hold result of BeginLabelQuery
string labels = "";

//VaultLabelItemX Array to hold result of GetLabelQuerytItems
VaultLabelItemX[] vltItems = new VaultLabelItemX[] { };

//Not sure if I have to initialize - but I did
vltItems.Initialize();

int iNumOfRecords = 100;

// First get the id of the objectPath - why you need both id and name is a mystery but you do
VaultClientTreeObject vctoObjectPathID = ServerOperations.client.ClientInstance.Repository.Root.FindTreeObjectRecursive("$/EJH_Test");

//Convert VaultClientTreeObject to long
long iObjNum = Convert.ToInt32(vctoObjectPathID.ID.ToString());
Console.WriteLine(iObjNum);

//Start Query BeginLabelQuery(string strItemPath, long nObjID, bool bGetRecursive, bool bGetInherited, bool bGetFileItems,
//bool bGetFolderItems, int nRowLimit, out int nRowsRetrievedInherited, out int nRowsRetreivedRecursive, out string strQryToken)
ServerOperations.client.ClientInstance.BeginLabelQuery(objectPath, iObjNum, true, false, false, false, iNumOfRecords, out iNumOfRecords, out iNumOfRecords, out labels);

//Take strQueryToken and load up your aultLabelItemX Array
ServerOperations.client.ClientInstance.GetLabelQueryItems_Main(labels, 0, 100, out vltItems);

//Count the number of labels returned
Console.WriteLine(vltItems.Length);
//Get the first member of the aultLabelItemX Array
foreach (VaultLabelItemX vlixFirstItem in vltItems)
{
// Finally, write your label and label id to the console. Use the Read() function to force the console to stay open until you hit enter.
Console.Write(vlixFirstItem.LabelID + ", ");
Console.WriteLine(vlixFirstItem.Label);
}
Console.Read();
ServerOperations.client.ClientInstance.EndLabelQuery(labels);
}
Last edited by ejhansen71 on Tue Dec 09, 2014 11:25 am, edited 1 time in total.
Thanks!

Eric

ejhansen71
Posts: 60
Joined: Thu Nov 13, 2014 10:12 am
Location: Lake in the Hills, IL

Re: Get Valid Labels Example

Post by ejhansen71 » Tue Dec 09, 2014 11:23 am

The above code gets just the labels under the main branch $/EJH_Test. Replace part of the code with this below to get all of the labels under $/EJH_Test recursively:
//Take strQueryToken and load up your aultLabelItemX Array
ServerOperations.client.ClientInstance.GetLabelQueryItems_Recursive(labels, 0, 100, out vltItems);

//Count the number of labels returned
Console.WriteLine(vltItems.Length);
//Get the first member of the aultLabelItemX Array
foreach (VaultLabelItemX vlixFirstItem in vltItems)
{
// Finally, write your label and label id to the console. Use the Read() function to force the console to stay open until you hit enter.
Console.Write(vlixFirstItem.LabelID + ", ");
Console.WriteLine(vlixFirstItem.Label);
}
Console.Read();
ServerOperations.client.ClientInstance.EndLabelQuery(labels);
}
Thanks!

Eric

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

Re: Get Valid Labels Example

Post by Beth » Wed Dec 10, 2014 9:28 am

Just an FYI..

In Vault 8 you will have a few additional options for working with labels. We have added the command FindLabels to our Vault command-line client and the function ServerOperation.ProcessCommandFindLabels() to the Vault 8 API.
Beth Kieler
SourceGear Technical Support

jvollaro
Posts: 1
Joined: Tue Jan 20, 2015 10:20 am

Re: Get Valid Labels Example

Post by jvollaro » Wed Mar 04, 2015 2:23 pm

Beth wrote:Just an FYI..

In Vault 8 you will have a few additional options for working with labels. We have added the command FindLabels to our Vault command-line client and the function ServerOperation.ProcessCommandFindLabels() to the Vault 8 API.
Is there an examle C# code which uses the new ServerOperation.ProcessCommandFindLabels()?

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

Re: Get Valid Labels Example

Post by Beth » Fri Mar 06, 2015 5:04 pm

I don't think we have an example for that one written yet. I'll see if someone can get you an example.

If you look in the .chm file that is included with the API download, it should be documented there.
Beth Kieler
SourceGear Technical Support

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

Re: Get Valid Labels Example

Post by Beth » Tue Mar 10, 2015 2:25 pm

Here's how we use it in our command-line client.

Code: Select all

string strSearchString = (string)curArg.items[0];
string strReposPath = RepositoryPath.NormalizeFolder((string)curArg.items[1]);

// only wildcard is supported at this time.
VaultFindInFilesDefine.PatternMatch pm = (_args.patternMatch != VaultFindInFilesDefine.PatternMatch.Undefined) ? _args.patternMatch : VaultFindInFilesDefine.PatternMatch.Wildcard;

VaultLabelItemX[] arLabelItems = null;
int nRetCode = ServerOperations.ProcessCommandFindLabels(strSearchString, strReposPath, _args.Recursive, _args.HistoryRowLimit, _args.MatchCase, _args.MatchWord, pm, out arLabelItems);

XmlHelper.XmlOutput(_xml, nRetCode, arLabelItems);
Inside the API download is a folder holding code for the command-line client. The example I posted came from VaultCmdLineClient.cs.
Beth Kieler
SourceGear Technical Support

Post Reply