Get Valid Labels Example
Moderator: SourceGear
-
- Posts: 61
- Joined: Thu Nov 13, 2014 10:12 am
- Location: Lake in the Hills, IL
Get Valid Labels Example
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, ???);
}
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
Eric
-
- Posts: 61
- Joined: Thu Nov 13, 2014 10:12 am
- Location: Lake in the Hills, IL
Re: Get Valid Labels Example
I guess I'm also looking for an updated API help file. The one included does not cover most methods available.
Thanks!
Eric
Eric
Re: Get Valid Labels Example
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
.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
SourceGear Technical Support
-
- Posts: 61
- Joined: Thu Nov 13, 2014 10:12 am
- Location: Lake in the Hills, IL
Re: Get Valid Labels Example
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);
}
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
Eric
-
- Posts: 61
- Joined: Thu Nov 13, 2014 10:12 am
- Location: Lake in the Hills, IL
Re: Get Valid Labels Example
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);
}
//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
Eric
Re: Get Valid Labels Example
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.
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
SourceGear Technical Support
Re: Get Valid Labels Example
Is there an examle C# code which uses the new ServerOperation.ProcessCommandFindLabels()?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.
Re: Get Valid Labels Example
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.
If you look in the .chm file that is included with the API download, it should be documented there.
Beth Kieler
SourceGear Technical Support
SourceGear Technical Support
Re: Get Valid Labels Example
Here's how we use it in our command-line client.
Inside the API download is a folder holding code for the command-line client. The example I posted came from VaultCmdLineClient.cs.
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);
Beth Kieler
SourceGear Technical Support
SourceGear Technical Support