How to do an auto commit on changed files

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

Moderator: SourceGear

joacim
Posts: 21
Joined: Wed Jan 28, 2009 6:04 am
Location: Interactive Medica

How to do an auto commit on changed files

Post by joacim » Wed Jan 28, 2009 8:51 am

Hi,

I've searched this forum but I simply can't find any examples that fits my need. What I want to do is to build a client application that will run every night and make sure that all files in a particular folder (and its subfolders) is checked into Vault. So basically I want an example that would enumerate all files and sub folders and see if they have changed (or new files/folders have been added) and in that case commit them (create) to Vault.

I do understand how I can log into Vault using ServerOperations.client.LoginOptions and also how I can set the working folder using ServerOperations.SetWorkingFolder, but I simply don't understand how to build the change set and commit it.

Any help would be much appreciated.

shannon

Re: How to do an auto commit on changed files

Post by shannon » Wed Jan 28, 2009 9:51 am

To commit any files that have changed, you just need to get the changeset and call commit. To get the changeset, call ServerOperations.ProcessCommandListChangeSet(new string[] {<path to search recursively>}). Pass the ChangeSetItemColl that is returned to ServerOperations.ProcessCommandCommit

If the files/folders that have been added have actually been pended as an add to Vault (i.e. they are visible in the pending change set), the commands above will commit them with the other changes. If not, you'll have to walk the tree and add them yourself before getting the changeset and calling commit. (Let me know if this is what you need to do and I'll provide more help.)

joacim
Posts: 21
Joined: Wed Jan 28, 2009 6:04 am
Location: Interactive Medica

Re: How to do an auto commit on changed files

Post by joacim » Wed Jan 28, 2009 9:59 am

I've tried using that but it didn't return anything.

Code: Select all

'code to set LoginOptions and call the Login() method goes here...
ServerOperations.SetWorkingFolder("$/TestAutoCheckIn", "c:\vaultTest", False)
Dim changeColl As ChangeSetItemColl = ServerOperations.ProcessCommandListChangeSet(New String() {"c:\vaultTest"})
Console.Write(changeColl.Count.ToString) 
The result of the changeColl.Count is 0.

shannon

Re: How to do an auto commit on changed files

Post by shannon » Wed Jan 28, 2009 10:00 am

Log into the gui client with the same user on that machine. Is there anything in the pending change set?

joacim
Posts: 21
Joined: Wed Jan 28, 2009 6:04 am
Location: Interactive Medica

Re: How to do an auto commit on changed files

Post by joacim » Wed Jan 28, 2009 10:12 am

No there is nothing in the pending change set. To clarify: the $/TestAutoCheckIn folder in Vault is empty, but I've added files to the local folder c:\vaultTest, shouldn't these come up in the change set after I've set the working folder or must I do something else?

shannon

Re: How to do an auto commit on changed files

Post by shannon » Wed Jan 28, 2009 10:27 am

No, you have to pend an add for those files before they'll show up in the pending change set. That's what this part of my response is about:
If the files/folders that have been added have actually been pended as an add to Vault (i.e. they are visible in the pending change set), the commands above will commit them with the other changes. If not, you'll have to walk the tree and add them yourself before getting the changeset and calling commit. (Let me know if this is what you need to do and I'll provide more help.)
So, will you be pending adds with the gui client or do you need help doing that in your code?

joacim
Posts: 21
Joined: Wed Jan 28, 2009 6:04 am
Location: Interactive Medica

Re: How to do an auto commit on changed files

Post by joacim » Wed Jan 28, 2009 12:32 pm

I need to do it via code. How can I check if a file needs to be added or not?

shannon

Re: How to do an auto commit on changed files

Post by shannon » Wed Jan 28, 2009 1:22 pm

There are several functions for finding Vault objects in the RepositoryUtil class. Try RepositoryUtil.PathExists, it will return true if that file or folder exists in the repository - it can take either a repository path or a disk path.

joacim
Posts: 21
Joined: Wed Jan 28, 2009 6:04 am
Location: Interactive Medica

Re: How to do an auto commit on changed files

Post by joacim » Wed Jan 28, 2009 1:45 pm

Thanks! How do I do the actual adding?

shannon

Re: How to do an auto commit on changed files

Post by shannon » Wed Jan 28, 2009 1:55 pm

Use ServerOperations.ProcessCommandAdd. The first parameter is the destination (either repository path or local path) - I think in your case, the source folder and destination folder are the same. The second parameter is an array of one or more local paths of files or folders to be added.

If the autocommit option is on, it will commit these items immediately, otherwise, it will just add them to the pending changes (and you can commit them after that).

joacim
Posts: 21
Joined: Wed Jan 28, 2009 6:04 am
Location: Interactive Medica

Re: How to do an auto commit on changed files

Post by joacim » Wed Jan 28, 2009 2:46 pm

Thank you so very much, it seems to work except for the most importent part: I get an exception when I try to call the ProcessCommandCommit method. I'm a bit unsure which of the overloads I need to use. My code is as follows:

Code: Select all

    ServerOperations.SetWorkingFolder("$/TestAutoCheckIn", "c:\vaultTest", False)
    AddNewFilesAndFolders("c:\vaultTest")
    Dim changeColl As ChangeSetItemColl = ServerOperations.ProcessCommandListChangeSet(New String() {"c:\vaultTest"})
    ServerOperations.ProcessCommandCommit(changeColl, UnchangedHandler.Checkin, False, LocalCopyType.Leave, False)
The AddNewFilesAndFolders simply checks all files and subfolder if they exist or not and calls ProcessCommandAdd on each of them (if RepositoryUtil.PathExists returns false).

shannon

Re: How to do an auto commit on changed files

Post by shannon » Wed Jan 28, 2009 2:52 pm

Do you have a stack trace and message for the exception?

joacim
Posts: 21
Joined: Wed Jan 28, 2009 6:04 am
Location: Interactive Medica

Re: How to do an auto commit on changed files

Post by joacim » Wed Jan 28, 2009 3:17 pm

The message is simply: "Commit failed"
Here's the stack trace:
at VaultClientIntegrationLib.ServerOperations.ProcessCommandCommit(ChangeSetItemColl csic, UnchangedHandler unchanged, Boolean keepCheckedOut, LocalCopyType localCopy, Boolean removeLocalCopy, Boolean resolveMerge, ChangeSetItemColl& csicRemove)
at VaultClientIntegrationLib.ServerOperations.ProcessCommandCommit(ChangeSetItemColl csic, UnchangedHandler unchanged, Boolean keepCheckedOut, LocalCopyType localCopy, Boolean removeLocalCopy, ChangeSetItemColl& csicRemove)
at VaultClientIntegrationLib.ServerOperations.ProcessCommandCommit(ChangeSetItemColl csic, UnchangedHandler unchanged, Boolean keepCheckedOut, LocalCopyType localCopy, Boolean removeLocalCopy)
at VaultTest.Form1.Button1_Click(Object sender, EventArgs e) in C:\Users\Joacim\AppData\Local\Temporary Projects\VaultTest\Form1.vb:line 23

shannon

Re: How to do an auto commit on changed files

Post by shannon » Wed Jan 28, 2009 3:26 pm

Can you check the client and server logs for errors?

the server log : sgvault.log in %windir%\temp\sgvault
client log: VaultGUIClient in %TEMP%

joacim
Posts: 21
Joined: Wed Jan 28, 2009 6:04 am
Location: Interactive Medica

Re: How to do an auto commit on changed files

Post by joacim » Wed Jan 28, 2009 3:41 pm

The client log:
2009-01-28 15:00:25 <generic>: [GUIClientWorkerThread:7892] While trying to move state folder C:\Users\Joacim\AppData\Local\SourceGear\Vault_1\Client\7B78657A-7B76-43F6-A0E6-3066F8FD241D\joacima\_sgvault\-834296285 to C:\Users\Joacim\AppData\Local\SourceGear\Vault_1\Client\7B78657A-7B76-43F6-A0E6-3066F8FD241D\joacima\_sgvault\1259464332 [System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Users\Joacim\AppData\Local\SourceGear\Vault_1\Client\7B78657A-7B76-43F6-A0E6-3066F8FD241D\joacima\_sgvault\-834296285'.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.Directory.Move(String sourceDirName, String destDirName)
at VaultClientOperationsLib.WorkingFolder.RecursiveMoveFolder(WorkingFolder oldWorkingFolder, String newDiskFolderPath, ClientInstance ci, Boolean copy)]Could not find a part of the path 'C:\Users\Joacim\AppData\Local\SourceGear\Vault_1\Client\7B78657A-7B76-43F6-A0E6-3066F8FD241D\joacima\_sgvault\-834296285'.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.Directory.Move(String sourceDirName, String destDirName)
at VaultClientOperationsLib.WorkingFolder.RecursiveMoveFolder(WorkingFolder oldWorkingFolder, String newDiskFolderPath, ClientInstance ci, Boolean copy)

Stack Trace:
at VaultClientOperationsLib.WorkingFolder.RecursiveMoveFolder(WorkingFolder oldWorkingFolder, String newDiskFolderPath, ClientInstance ci, Boolean copy)
at VaultClientOperationsLib.WorkingFolder.Move(String newDiskFolderPath)
at VaultClientOperationsLib.ChangeSetItem_Rename.DoWorkingFolderRename(TreeCache treeCache, String sourcePath, String destPath, Boolean undo)
at VaultClientOperationsLib.ChangeSetItem_Rename.PerformInWorkingFolder(TreeCache treeCache, Boolean undo)
at VaultClientOperationsLib.TreeCache.UpdateRepositoryWithPendingChange(ChangeSetItemPerformPending csiPP, Boolean updateWorkingFolder, Boolean undo, Boolean isRefresh, ChangeSetItemColl csisToRemove)
at VaultClientOperationsLib.TreeCache.UpdateRepositoryWithPendingChanges(ChangeSetItemColl items, Boolean updateWorkingFolder, Boolean undo, Boolean isRefresh)
at VaultClientOperationsLib.TreeCache.ChangeSetItems_AppendRange(ChangeSetItemColl items)
at VaultClientOperationsLib.ClientInstance.InternalChangeSet_Append(ChangeSetItemColl items)
at VaultClientPresentationLib.GUIClientInstance.Rename(RepositoryExplorerSelection selection)
at VaultClientPresentationLib.GUIClientThread.ProcessCommand(GUIClientThreadCommand command, GUIClientThreadCommandResult& outputResult)
at VaultClientPresentationLib.GUIClientThread.Start()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
I can't however reach the server log file at the moment.

Post Reply