API Question

This forum is now locked, since Gold Support is no longer offered.

Moderator: SourceGear

Locked
everettmuniz
Posts: 21
Joined: Wed Sep 27, 2006 6:51 am

API Question

Post by everettmuniz » Thu Sep 28, 2006 2:28 pm

I'm wondering if someone can give me some guidance on a couple API questions. I've searched through the forum and I wasn't able to find these questions addressed.

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; }
        }
    }
}

jclausius
Posts: 3706
Joined: Tue Dec 16, 2003 1:17 pm
Location: SourceGear
Contact:

Re: API Question

Post by jclausius » Thu Sep 28, 2006 3:10 pm

everettmuniz wrote: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.
You can accomplish this by using FindFolderRecursive and iterate through the VaultClientFolder's Files and Folders.
everettmuniz wrote: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?
It seems correct. Note, if a label has been modified through Label Promotion, it cannot be branched in the current version of Vault.
Jeff Clausius
SourceGear

Locked