Question 1
I need a bit of guidance on how I would list all folders at a given path. Ultimately, I'd like to create an XML document with the folder names but if someone could offer the correct way to get the list I can handle the XML document creation. The folders I want to list represent branches in case that matters.
Question 2
I'm interested in a NAnt task that can branch by a label. I looked at the code for the tasks vaultgetbylabel and vaultbranch and came up with the following. Is this a valid way to branch by label?
Code: Select all
using System;
using NAnt.Core;
using NAnt.Contrib.Tasks.SourceGearVault;
using NAnt.Core.Attributes;
using VaultClientNetLib;
using VaultClientOperationsLib;
namespace GBS.NAnt.VaultTasks
{
[TaskName("vaultbranchbylabel")]
public class VaultBranchByLabel : VaultBase
{
private ChangeSetItemColl _changeSetItems;
private string _comment;
private string _destinationPath;
private string _label;
private string _repository;
private string _sourcePath;
public VaultBranchByLabel()
{
_repository = "";
_comment = "";
_changeSetItems = new ChangeSetItemColl();
_sourcePath = "";
_label = "";
_destinationPath = "";
}
protected override void ExecuteTask()
{
long lLabelId = 0;
long lRootId = 0;
VaultClientTreeObject oLabelStructure = null;
string[] sSubItemPathArray = null;
base.AccessLevel = VaultConnection.AccessLevelType.Client;
base.Login();
try
{
base.SelectRepository(_repository);
if (!base.IsVaultFolder(_sourcePath) || base.IsVaultFile(_sourcePath))
{
throw new BuildException("Unsupported usage of the Vault branch command. Source is a file or is missing.", this.Location);
}
VaultClientFolder oSourceFolder = base.ClientInstance.TreeCache.Repository.Root.FindFolderRecursive(_sourcePath);
base.ClientInstance.GetByLabel_GetStructure(
oSourceFolder.FullPath,
_label,
ref lLabelId,
null,
out sSubItemPathArray,
out oLabelStructure,
out lRootId);
ChangeSetItem_CopyBranch oNewBranch = new ChangeSetItem_CopyBranch(
DateTime.Now,
_comment,
string.Empty,
oSourceFolder.FullPath,
_destinationPath,
oLabelStructure.ObjVerID
);
oNewBranch.Comment = _comment;
this._changeSetItems.Add(oNewBranch);
if (!base.ClientInstance.Commit(_changeSetItems))
{
throw new BuildException("Commitment of change set failed!", this.Location);
}
base.VaultLog("Files added to Vault repository successfully.");
}
finally
{
base.Logout();
}
}
[TaskAttribute("comment", Required=false)]
public string Comment
{
get { return _comment; }
set { _comment = value; }
}
[TaskAttribute("destinationpath", Required=true)]
public string DestinationPath
{
get { return _destinationPath; }
set { _destinationPath = value; }
}
[TaskAttribute("labelstring", Required=true)]
public string Label
{
get { return _label; }
set { _label = value; }
}
[TaskAttribute("repository", Required=true)]
public string Repository
{
get { return _repository; }
set { _repository = value; }
}
[TaskAttribute("sourcepath", Required=true)]
public string SourcePath
{
get { return _sourcePath; }
set { _sourcePath = value; }
}
}
}