How do I add new file to Vault repository using the API?

Post your questions regarding using the Vault and Fortress API in your programs.

Moderator: SourceGear

Post Reply
sambati
Posts: 4
Joined: Tue Apr 24, 2007 10:07 am

How do I add new file to Vault repository using the API?

Post by sambati » Tue Apr 24, 2007 10:12 am

How do I add new file to Vault repository using the API?

client.Repository.Root.Files.Add

or

Dim oItem As ChangeSetItem_AddFile = New ChangeSetItem_AddFile(System.DateTime.Now, "My Comments", "My Properties", PhysicalLocalPath, VaultPath)

is not helping me much. It will be great if you can point me to a good example.

Thanks

Srini

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

Post by jclausius » Tue Apr 24, 2007 12:42 pm

Once you've created a Change Set Item Collection with actual change set items, all you need to do is call Commit().

For more examples, download, build and step through the code for the Command Line Client in the Vault Client API. In particular, step through the handlers for "vault.exe ADD" and "vault COMMIT".
Jeff Clausius
SourceGear

mmoayyed
Posts: 26
Joined: Tue Feb 26, 2008 12:43 pm

How to add a file to repository ???

Post by mmoayyed » Thu Feb 28, 2008 2:00 pm

Here's the sample code I use:

col = new ChangeSetItemColl();
filePath = @"C:\dev1.txt";
project = "$/";

changeFile = new ChangeSetItem_AddFile(new VaultDateTime(), comment, String.Empty, filePath, project);

col.Add(changeFile);

res = moClient.Commit(col, "Changeset comments");

res is ALWAYS false.

Any ideas ?

mmoayyed
Posts: 26
Joined: Tue Feb 26, 2008 12:43 pm

Post by mmoayyed » Thu Feb 28, 2008 2:03 pm

Actually, if there was a way that I could know WHY the commit operation failed that would be great. A true/false value doesn't exactly describe the problem. Are there any logs somewhere on the server that I am not aware of ?

mmoayyed
Posts: 26
Joined: Tue Feb 26, 2008 12:43 pm

Post by mmoayyed » Thu Feb 28, 2008 2:06 pm

Forgot to mention that I am using the Client API 4.0.5

mmoayyed
Posts: 26
Joined: Tue Feb 26, 2008 12:43 pm

Post by mmoayyed » Thu Feb 28, 2008 2:13 pm

I tried calling different Commit() functions, adding different files to different branches and I also tried switch to different repositories. All failed. The result value is still FALSE.

shannon

Post by shannon » Thu Feb 28, 2008 2:38 pm

Have you looked at the examples here: http://support.sourcegear.com/viewtopic.php?t=8020 ?

mmoayyed
Posts: 26
Joined: Tue Feb 26, 2008 12:43 pm

Post by mmoayyed » Thu Feb 28, 2008 2:41 pm

sure, but the examples use the integration library and the ServerOperations class. I am actually just using the <PORN SPAM> API since our application was written entirely based on that. Plus, I think the integration lib is just a wrapper around the <PORN SPAM> API and so they're calling the methods that I am. I am more interested to know what and how different we're calling the same functions. If we're both calling the same stuff, how can that lib work and not the way I am doing it ?

shannon

Post by shannon » Thu Feb 28, 2008 3:00 pm

try checking the server log : sgvault.log in %windir%\temp\sgvault
or client logs are in %TEMP%

mmoayyed
Posts: 26
Joined: Tue Feb 26, 2008 12:43 pm

Post by mmoayyed » Sat Mar 01, 2008 11:50 pm

Thanks for your help. For logs on the client side, do you happen to know what they're called or perhaps if there's a pattern ? my %TEMP% directory is huge and I only found 3 .log files which had nothing to do with SGV it seems.

I am planning to install the new client API 4.1.0.16216 and see if that makes any difference at all. If not, I will also try the integration lib. I will get back to you soon.

Thanks again.

shannon

Post by shannon » Mon Mar 03, 2008 10:00 am

The log files are .txt files, but one of my coworkers suggested using the message events.

Are you subscribing to the message events in your code? Try writing them to the console or a file (or whatever display you have).

//During clientinstance login:

if ( ClientInstance != null )
{
ClientInstance.EventEngine.addListener(client, typeof(MessageEvent));
ClientInstance.EventEngine.addListener(client, typeof(BulkMessageEvent));
}

//Then define these two handlers
public void HandleEvent(MessageEvent e)
{
}

/// <summary>
/// BulkMessageEvent handler. Writes the message if Verbose is true or the message level is error.
/// </summary>
/// <param name="e"></param>
public void HandleEvent(BulkMessageEvent e)
{
}

mmoayyed
Posts: 26
Joined: Tue Feb 26, 2008 12:43 pm

Post by mmoayyed » Tue Mar 04, 2008 11:36 am

Thanks. I subscribed to the message engine and here are the messages that I go back from: HandleEvent(MessageEvent e)

VaultClientOperationsLib.ProgressMessageBeforeTransactionBegin
VaultClientOperationsLib.ProgressMessageTransactionBegin
VaultClientOperationsLib.ProgressMessageTransactionItemFailed
VaultClientOperationsLib.ProgressMessageTransactionFailed

So I looked at the log file on the server and I found out that that I have a message for: AddFile: $/Aspen2000 returned: FailObjAlreadyExists

The file I am trying to add is: C:\dev1.txt and the folder that it's going to is $/Aspen2000

What's strange is that when I bring up the client to actually find this file, it isnt there. Do I need to refresh something or perhaps clear out the server cache somehow to make the file show up ?

mmoayyed
Posts: 26
Joined: Tue Feb 26, 2008 12:43 pm

Post by mmoayyed » Tue Mar 04, 2008 11:41 am

I also renamed and tried to add a completely new file that I am positive does not exist in vault. I got the same error back which said file object already exists. Any ideas ?

I am going to try the integration lib and see if it does anything different for me.

shannon

Post by shannon » Tue Mar 04, 2008 12:07 pm

I think your repository path is wrong. It looks like it expects you to be passing $/Aspen2000/dev1.txt but you are passing $/Aspen2000. So it is trying to add dev1.txt as Aspen2000 but already finding an object with that name.

Post Reply