How to do an auto commit on changed files
Moderator: SourceGear
How to do an auto commit on changed files
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.
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.
Re: How to do an auto commit on changed files
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.)
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.)
Re: How to do an auto commit on changed files
I've tried using that but it didn't return anything.
The result of the changeColl.Count is 0.
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)
Re: How to do an auto commit on changed files
Log into the gui client with the same user on that machine. Is there anything in the pending change set?
Re: How to do an auto commit on changed files
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?
Re: How to do an auto commit on changed files
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:
So, will you be pending adds with the gui client or do you need help doing that in your code?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.)
Re: How to do an auto commit on changed files
I need to do it via code. How can I check if a file needs to be added or not?
Re: How to do an auto commit on changed files
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.
Re: How to do an auto commit on changed files
Thanks! How do I do the actual adding?
Re: How to do an auto commit on changed files
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).
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).
Re: How to do an auto commit on changed files
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:
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).
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)
Re: How to do an auto commit on changed files
Do you have a stack trace and message for the exception?
Re: How to do an auto commit on changed files
The message is simply: "Commit failed"
Here's the stack trace:
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
Re: How to do an auto commit on changed files
Can you check the client and server logs for errors?
the server log : sgvault.log in %windir%\temp\sgvault
client log: VaultGUIClient in %TEMP%
the server log : sgvault.log in %windir%\temp\sgvault
client log: VaultGUIClient in %TEMP%
Re: How to do an auto commit on changed files
The client log:
I can't however reach the server log file at the moment.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()