ClientInstance.PromoteLabelItems error

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

Moderator: SourceGear

Locked
anite
Posts: 2
Joined: Sun Nov 27, 2005 5:47 pm

ClientInstance.PromoteLabelItems error

Post by anite » Sun Nov 27, 2005 6:02 pm

Hi, I'm trying to programmatically promote a file to a later version within a label. When I call ClientInstance.PromoteLabelItems, I get a return code of 1206 (FailObjPathInvalid). Can someone shed some light on this?
I've included the code below. The label name is 3.37.0.0 and was created in the $/Source/Common folder. If I look at the version of the file returned by FindFileRecursive, the version is the newest version which I want to promote up to.
Thanks

long labelId = 0;
string[] discoveredSubItemPaths;
DateTime lastModified;
VaultRepositoryDelta repositoryDelta;
VaultFileDelta fileDelta;
long rootID;

clientInstance.GetLabelStructureByName("3.37.0.0",
ref labelId, "$/Source/Common",
string.Empty,
out discoveredSubItemPaths,
out lastModified,
out repositoryDelta,
out fileDelta,
out rootID);

VaultClientFile clientFile = clientInstance.TreeCache.Repository.Root.FindFileRecursive("$/Source/Common/Infrastructure/Common/Versioning.cs");

DateTime lastChange = DateTime.MinValue;
int indexFailed = -1;
string rootPathConflict;

VaultLib.VaultLabelPromotionItem promotionItem = new VaultLabelPromotionItem();
promotionItem.ChangeType = (int)VaultLib.VaultLabelPromotionChangeType.Modify;
promotionItem.ID = clientFile.ID;
promotionItem.ObjVerID = clientFile.ObjVerID;
promotionItem.ItemName = clientFile.Name;
promotionItem.ItemPath = clientFile.FullPath;
promotionItem.Version = clientFile.Version;

VaultLabelPromotionItem[] promotionItems = new VaultLib.VaultLabelPromotionItem[1];
promotionItems[0] = promotionItem;

int ret = clientInstance.PromoteLabelItems("$/Source/Common",
labelId,
"3.37.0.0",
ref lastChange,
promotionItems,
out indexFailed,
out rootPathConflict);

jeremy_sg
Posts: 1821
Joined: Thu Dec 18, 2003 11:39 am
Location: Sourcegear
Contact:

Post by jeremy_sg » Mon Nov 28, 2005 11:07 am

Try changing

promotionItem.ItemPath = clientFile.FullPath

to

promotionItem.ItemPath = clientFile.FullPath.Remove(0, clientFile.Parent.FullPath.Length);

ItemPath is treated as being rooted at the top of the label (Infrastructure/Common/Versioning.cs in this case).

anite
Posts: 2
Joined: Sun Nov 27, 2005 5:47 pm

Post by anite » Mon Nov 28, 2005 7:24 pm

Hi, thanks for your tip. The code change that you suggested doesn't work because it returns an item path of /Versioning.cs which results in a malformed path error, but I took what you said about the item path being rooted at the top of the label and what does work is if the item path specified is Common/Infrastructure/Common/Versioning.cs. So I modified my code to get the item path to be:

string itemPath = clientFile.Name;
VaultClientFolder folder = clientFile.Parent;
do
{
itemPath = folder.Name + "/" + itemPath;
folder = folder.Parent;
}
while (folder.FullPath.CompareTo(this.LabelPath) != 0);
promotionItem.ItemPath = folder.Name + "/" + itemPath;

It works but it's not pretty and probably will break if inconsistent label paths and item paths are specified. Do you have a better way to get this path?

While we're on the topic, I'm writing this code because within our nant build I'd like to promote items to a specified label so that the label contains correct versions of source as well as built binaries. I couldn't find an existing nant task for promotion. Are there any plans for this?

Thanks for your help.

jeremy_sg
Posts: 1821
Joined: Thu Dec 18, 2003 11:39 am
Location: Sourcegear
Contact:

Post by jeremy_sg » Tue Nov 29, 2005 8:06 am

Sorry that I didn't catch that.

You could just do

promotionItem.ItemPath = clientFile.FullPath.Remove(0,"$/Source/Common".Length);

We're planning changes to the nant tasks in the near future. I'll make sure that we address label promotion. You are welcome to check in your label promotion task in to vaultpub.sourcegear.com

Locked