C# API: Return List<string> of files from a selected Label

If you are having a problem using Vault, post a message here.

Moderator: SourceGear

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

C# API: Return List<string> of files from a selected Label

Post by ejhansen71 » Mon Feb 02, 2015 2:52 pm

Hi -

I am attempting to return a list of files associated with a given label. I have successfully returned all Labels associated with a project (e.g. $/Projects) using some sample classes in the following post:
http://support.sourcegear.com/viewtopic ... 31&t=11600

In those sample classes, there is a method that downloads objects related to a label to a folder, but I don't want to do that. All I want is a List<string> of files associated with a label.

We are currently using v6.1. At some point we will be moving to v8...but I need it to work on v6.1 for now.

Can you help?
Thanks!

Eric

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

Re: C# API: Return List<string> of files from a selected Lab

Post by Beth » Tue Feb 03, 2015 1:50 pm

Still working out a response to this.
Beth Kieler
SourceGear Technical Support

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

Re: C# API: Return List<string> of files from a selected Lab

Post by ejhansen71 » Fri Feb 06, 2015 2:46 pm

Any update?
Thanks!

Eric

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

Re: C# API: Return List<string> of files from a selected Lab

Post by Beth » Fri Feb 06, 2015 6:04 pm

In Vault 6, you will use the ClientInstance.GetByLabel_GetStructure() method. I believe the last parameter is an out parameter that will return a data structure representing the contents of the label.
Beth Kieler
SourceGear Technical Support

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

Re: C# API: Return List<string> of files from a selected Lab

Post by ejhansen71 » Mon Feb 09, 2015 2:44 pm

Beth - Thank you for looking into this for me. I was hoping you could help me implement this. There are 2 versions of this

public bool GetByLabel_GetStructure(string currentPathToLabelItem, string labelName, ref long labelID, string labelSubItemPath, out string[] discoveredSubItemPaths, out VaultClientOperationsLib.VaultClientTreeObject labelStructure, out long rootID)
Member of VaultClientOperationsLib.ClientInstance

public bool GetByLabel_GetStructure(string currentPathToLabelItem, string labelName, ref long labelID, string labelSubItemPath, out string[] discoveredSubItemPaths, out string[] discoveredObjSubItemPaths, out VaultClientOperationsLib.VaultClientTreeObject labelStructure, out long rootID)
Member of VaultClientOperationsLib.ClientInstance

Assuming I will use the first one, I get:
public bool GetByLabel_GetStructure(
string currentPathToLabelItem <== Self explanitory, path to the label items
, string labelName <== Self explanitory, label name
, ref long labelID <== ???
, string labelSubItemPath <== ???
, out string[] discoveredSubItemPaths <== ???
, out VaultClientOperationsLib.VaultClientTreeObject labelStructure <== This is an abstract class. How would I implement this?
, out long rootID <== What is this for?
)
I have these questions as the API does not explain it.

So I have ${PATHtoFiles}, ${LABEL}. How do I use the above to get the files?

Thank you!
Thanks!

Eric

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

Re: C# API: Return List<string> of files from a selected Lab

Post by Beth » Mon Feb 09, 2015 4:52 pm

You will want to use the first method you posted. You will supply currentPathToLabelItem and labelName.

The labelID should be a var to a long initialized to some value less than 1. labelSubItemPath can be null.

discoveredSubItemPaths should be string[] initialized to null.

labelStructure should be a VaultClientOperationsLib.VaultClientTreeObject initialized to null.

rootID should be a long initialized to a value < 1.

Then make the API call to the Server. Upon successful return, you will look at the labelStructure variable. It will be a VaultClientFolder if the label structure was invoked on a folder, and a VaultClientFile if invoked on a file.

For a VaultClientFolder, you will need to traverse the tree through code looking at the VaultClientFolder.Files and VaultClientFolder.Folders member variables.
Beth Kieler
SourceGear Technical Support

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

Re: C# API: Return List<string> of files from a selected Lab

Post by ejhansen71 » Wed Feb 11, 2015 3:41 pm

Okay. Using:
public bool GetByLabel_GetStructure(string currentPathToLabelItem, string labelName, ref long labelID, string labelSubItemPath, out string[] discoveredSubItemPaths, out VaultClientOperationsLib.VaultClientTreeObject labelStructure, out long rootID)
Member of VaultClientOperationsLib.ClientInstance

For testing I used the following fields from an object:
public string currentPathToLabelItem = null;
public string labelName = null;
public long labelID = -1;
public string labelSubItemPath = null;
public string[] discoveredSubItemPaths = null;
public VaultClientTreeObject labelStructure = null;
public long rootID = -1;

Then called this method:
public static void GetFilenames( VaultTicket vltk )
{

try
{
ServerOperations.client.ClientInstance.GetByLabel_GetStructure("$/ntzload", "20150210_ntzload_1", ref vltk.labelID, vltk.labelSubItemPath, out vltk.discoveredSubItemPaths, out vltk.labelStructure, out vltk.rootID);
}
catch (Exception e)
{
Console.WriteLine(e.StackTrace);
}

}

Which resulted in this error:
VaultServiceAPILib.VaultSoapException: 1009 : FailPermissionDenied

at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
at VaultClientNetLib.ClientService.VaultService.GetLabelStructure(Int32 nRepID, String strItemPath, Int64& nLabelID, String& strLabel, String strLabelSubPath, String[]& arLabelPaths, String[]& arObjLabelPaths, Int64& nRootID, VaultDateTime& dtLastModified, VaultRepositoryDelta& rd, VaultFileDelta& fd)
at VaultClientNetLib.VaultConnection.GetLabelStructureByID(Int32 repID, Int64 labelID, String currentPathToLabelItem, String labelSubItemPath, String[]& discoveredSubItemPaths, String[]& discoveredObjSubItemPaths, VaultDateTime& dtLastModified, VaultRepositoryDelta& repositoryDelta, VaultFileDelta& fileDelta, Int64& rootID)
at VaultClientOperationsLib.ClientInstance.GetLabelStructureByID(Int64 labelID, String currentPathToLabelItem, String labelSubItemPath, String[]& discoveredSubItemPaths, String[]& discoveredObjSubItemPaths, VaultDateTime& dtLastModified, VaultRepositoryDelta& repositoryDelta, VaultFileDelta& fileDelta, Int64& rootID)
at VaultClientOperationsLib.ClientInstance.GetByLabel_GetStructure(String currentPathToLabelItem, String labelName, Int64& labelID, String labelSubItemPath, String[]& discoveredSubItemPaths, String[]& discoveredObjSubItemPaths, VaultClientTreeObject& labelStructure, Int64& rootID)
at VaultClientOperationsLib.ClientInstance.GetByLabel_GetStructure(String currentPathToLabelItem, String labelName, Int64& labelID, String labelSubItemPath, String[]& discoveredSubItemPaths, VaultClientTreeObject& labelStructure, Int64& rootID)
at IssueNet_Vault.VaultAccess.GetFilenames(VaultTicket vltk) in c:\Users\ehansen\VSProjects\IssueNet_Vault\IssueNet_Vault\VaultAccess.cs:line 219

When I try to use the API to re-login, I'm told I am already logged in. Any Ideas?

I tried a few other things and got:
VaultServiceAPILib.VaultSoapException: 1206 : FailObjPathInvalid
at VaultService.VaultService.GetLabelStructure(Int32 nRepID, String strItemPath, Int64& nLabelID, String& strLabel, String strLabelSubPath, String[]& arLabelPaths, String[]& arObjLabelPaths, Int64& nRootID, VaultDateTime& dtLastModified, VaultRepositoryDelta& rd, VaultFileDelta& fd)
at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
at VaultClientNetLib.ClientService.VaultService.GetLabelStructure(Int32 nRepID, String strItemPath, Int64& nLabelID, String& strLabel, String strLabelSubPath, String[]& arLabelPaths, String[]& arObjLabelPaths, Int64& nRootID, VaultDateTime& dtLastModified, VaultRepositoryDelta& rd, VaultFileDelta& fd)
at VaultClientNetLib.VaultConnection.GetLabelStructureByID(Int32 repID, Int64 labelID, String currentPathToLabelItem, String labelSubItemPath, String[]& discoveredSubItemPaths, String[]& discoveredObjSubItemPaths, VaultDateTime& dtLastModified, VaultRepositoryDelta& repositoryDelta, VaultFileDelta& fileDelta, Int64& rootID)
at VaultClientOperationsLib.ClientInstance.GetLabelStructureByID(Int64 labelID, String currentPathToLabelItem, String labelSubItemPath, String[]& discoveredSubItemPaths, String[]& discoveredObjSubItemPaths, VaultDateTime& dtLastModified, VaultRepositoryDelta& repositoryDelta, VaultFileDelta& fileDelta, Int64& rootID)
at VaultClientOperationsLib.ClientInstance.GetByLabel_GetStructure(String currentPathToLabelItem, String labelName, Int64& labelID, String labelSubItemPath, String[]& discoveredSubItemPaths, String[]& discoveredObjSubItemPaths, VaultClientTreeObject& labelStructure, Int64& rootID)
at VaultClientOperationsLib.ClientInstance.GetByLabel_GetStructure(String currentPathToLabelItem, String labelName, Int64& labelID, String labelSubItemPath, String[]& discoveredSubItemPaths, VaultClientTreeObject& labelStructure, Int64& rootID)
at IssueNet_Vault.VaultAccess.GetFilenames(VaultTicket vltk) in c:\Users\ehansen\VSProjects\IssueNet_Vault\IssueNet_Vault\VaultAccess.cs:line 227
Thanks!

Eric

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

Re: C# API: Return List<string> of files from a selected Lab

Post by Beth » Wed Feb 11, 2015 5:13 pm

Which user is being used for logging in?

Is what you showed me line 219?
Beth Kieler
SourceGear Technical Support

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

Re: C# API: Return List<string> of files from a selected Lab

Post by ejhansen71 » Tue Feb 17, 2015 12:25 pm

I figured out the User issue. Here is the current Error:
The thread 0x1ad4 has exited with code 259 (0x103).
A first chance exception of type 'System.Exception' occurred in VaultClientOperationsLib.dll
The server did not return a repository delta or file delta for item $/arrow
at VaultClientOperationsLib.ClientInstance.GetByLabel_GetStructure(String currentPathToLabelItem, String labelName, Int64& labelID, String labelSubItemPath, String[]& discoveredSubItemPaths, String[]& discoveredObjSubItemPaths, VaultClientTreeObject& labelStructure, Int64& rootID)
at VaultClientOperationsLib.ClientInstance.GetByLabel_GetStructure(String currentPathToLabelItem, String labelName, Int64& labelID, String labelSubItemPath, String[]& discoveredSubItemPaths, VaultClientTreeObject& labelStructure, Int64& rootID)
at IssueNet_Vault.VaultAccess.GetFilenames(VaultTicket vltk)

I am calling this mathod:
public static void GetFilenames(VaultTicket vltk)
{
try
{
SetRepository("Arrow");
ServerOperations.client.ClientInstance.GetByLabel_GetStructure("$/arrow", "eric_testing_20150209_1", ref vltk._MinusOne, vltk._LabelSubItemPath, out vltk._DiscoveredSubItemPaths, out vltk._LabelStructure, out vltk._RootID);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.WriteLine(e.StackTrace);
}
Console.WriteLine(vltk._DiscoveredSubItemPaths);
//Console.WriteLine(vltk._LabelStructure.ToString());
}

Which calls this one to set the Repository:
public static void SetRepository (string repo)
{
try
{
ServerOperations.SetRepository(repo);
}
catch (System.ArgumentNullException e)
{
e.StackTrace.ToString();
}
_Repository = repo;
}

The user has full rights to all projects and repositories.
The Repository is Arrow
The Path is $/arrow
The Label is eric_testing_20150209_1
THe Longs are ser to a public variable of -1
The other collections are public variables set to a value of null
vltk is the object that holds this information.

What am I doing wrong?
Thanks!

Eric

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

Re: C# API: Return List<string> of files from a selected Lab

Post by Beth » Thu Feb 19, 2015 1:27 pm

Give this a try instead:

public void ClientInstance.GetLabelStructureByName
(
string labelName, /* the label's name */
ref long labelID, /* a long (use 0)*/
string currentPathToLabelItem, /* the repo path to the item */
string labelSubItemPath, /* try null */
out string[] discoveredSubItemPaths, /* var */
out VaultDateTime dtLastModified, /* var */
out VaultRepositoryDelta repositoryDelta, /* var */
out VaultFileDelta fileDelta, /* var */
out long rootID /* var */
)


C# example:

long labelID = 0L, rootID = 0L; // try 0 instead
VaultRepositoryDelta rd = null;
VaultFileDelta fd = null;
VaultDateTime lastMod;
string labelSubItemPath = null;
string[] discoveredSubItemPaths = null, discoveredObjSubItemPaths = null;

try
{

ServerOperations.client.ClientInstance.GetLabelStructureByName("eric_testing_20150209_1", ref labelID, "$/arrow", labelSubItemPath, out discoveredSubItemPaths, out discoveredObjSubItemPaths, out lastMod, out rd, out fd, out rootID);

}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.WriteLine(e.StackTrace);
}

try
{
if (rd != null)
{
VaultClientFolder folder = new VaultClientFolder();
folder.Update(rd.Root, rd.Root.Name, null, null, null);

// walk folder using 'folder.Folders' and 'folder.Files'
}
else if (fd != null)
{
VaultClientFile file = new VaultClientFile(fd, null);
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.WriteLine(e.StackTrace);
}
Beth Kieler
SourceGear Technical Support

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

Re: C# API: Return List<string> of files from a selected Lab

Post by ejhansen71 » Tue Mar 10, 2015 12:58 pm

Beth,

We are cooking with gas here. The logic you have above works...but only for the files attached to the label at the root level.

LAbel: TEST
Included Files:
$/arrow/a.pl
$/arrow/b.sh
$/arrow/c.sas
$/arrow/projecta/d.sh
$/arrow/projectb/e.sas

When using the code above, I get the first 3 returned DIRECTLY under $/arrow - however, the other 2 under $/arrow/projecta and $/arrow/projectb do not get included.

I saw your note that says: "Walk the folders..." - I don't know how you do that. Is there a recursive flag? Any suggestions?

Thanks!

ERic
Thanks!

Eric

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

Re: C# API: Return List<string> of files from a selected Lab

Post by ejhansen71 » Mon Mar 23, 2015 10:25 am

Beth -

We upgraded to 8.0.1. Using c#, how can we get a list of files (with their modification dates if possible) associated with a label. The files can be in any folder and so we need to have this done recursively.

Thanks -

Eric
Thanks!

Eric

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

Re: C# API: Return List<string> of files from a selected Lab

Post by Beth » Mon Mar 23, 2015 10:38 am

The post on February 19 will list the files.

To walk the folders look at the 'folder' variable. It will have a Files and Folders element. Go to each sub item to see the tree.

For example

VaultClientFolder folder = ...

Stack<VaultClientFolder> stack = new Stack<VaultClientFolder>(); stack.Push(folder);

while (stack.Count > 0)
{
VaultClientFolder f = stack.Pop();
Console.WriteLine(string.Format("At {0}{1}", f.FullPath, Environment.NewLine));

// print out the files
if (f.Files != null)
{
foreach (VaultClientFile file in f.Files)
{
Console.WriteLine(string.Format("File at {0}{1}", file.FullPath, Environment.NewLine));
}
}

// add the sub folders
if (f.Folders != null) { foreach (VaultClientFolder fSub in
f.Folders) { stack.Push(fSub); }
}
Beth Kieler
SourceGear Technical Support

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

Re: C# API: Return List<string> of files from a selected Lab

Post by ejhansen71 » Mon Mar 23, 2015 12:17 pm

Beth -

The code you provided works perfectly. Thank you so much!

Eric
Thanks!

Eric

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

Re: C# API: Return List<string> of files from a selected Lab

Post by Beth » Mon Mar 23, 2015 1:42 pm

You're welcome.
Beth Kieler
SourceGear Technical Support

Post Reply