private void BuildChangeSetOfCheckedOutFiles(VaultClientFolder folder, out ChangeSetItemColl changeSet) { if (ClientInstance.WorkingFolderOptions.RequireCheckOutBeforeCheckIn == false) { // Do a scan to update the change set list ClientInstance.UpdateKnownChanges_All(false); } // The new list of change set items changeSet = new ChangeSetItemColl(); // Get the internal change set ChangeSetItemColl csic = ClientInstance.InternalChangeSet_GetItems(true); if ((csic != null) && (csic.Count > 0)) { // From the full change list, build a new list including only those in the requested folder foreach (ChangeSetItem internalChange in csic) { if (internalChange.DisplayRepositoryPath.IndexOf(folder.FullPath) == 0) { changeSet.Add(internalChange); } } } }
/// <summary> /// Add a file to the change set collection. /// </summary> /// <param name="fileName">Full path and filename of the file to add.</param> /// <exception>Exception</exception> private void AddFileToCollection(string fileName) { string repositoryPath = Folder.FullPath + "/" + System.IO.Path.GetFileName(fileName); if (File.Exists(fileName)) { ChangeSetItem_AddFile changeSetItem = new ChangeSetItem_AddFile(DateTime.Now, Comment, String.Empty, fileName, repositoryPath); _changeSetCollection.Add(changeSetItem); Log.LogMessage(MessageImportance.Normal, string.Format(Properties.Resources.VaultFileAddedToChangeSet, fileName)); } else if (Directory.Exists(fileName)) { ChangeSetItem_AddFolder changeSetItem = new ChangeSetItem_AddFolder(DateTime.Now, Comment, String.Empty, fileName, repositoryPath); _changeSetCollection.Add(changeSetItem); Log.LogMessage(MessageImportance.Normal, string.Format(Properties.Resources.VaultFolderAddedToChangeSet, fileName)); } else { throw new Exception(Properties.Resources.VaultAddFilesException); } }
private static ChangeSetItemColl RemoveDuplicatesFromChangeSet(ChangeSetItemColl input) { Console.WriteLine("Removing duplicates"); var result = new ChangeSetItemColl(); var dict = new Dictionary <string, ChangeSetItemType>(); foreach (ChangeSetItem item in input) { if (dict.TryGetValue(item.DisplayRepositoryPath, out var status)) { if (status != item.Type) { throw new Exception($"{item.DisplayRepositoryPath} has multiple statuses: {status} and {item.Type}"); } Console.WriteLine($"***** ignoring duplicate {item.DisplayRepositoryPath} - {item.Type}"); continue; } dict[item.DisplayRepositoryPath] = item.Type; result.Add(item); } return(result); }
/// <summary> /// Checks the specified file or folder into the repository. /// </summary> /// <exception>Exception</exception> private void Checkin(string fileName) { string normalizedPath = RepositoryPath.NormalizeFolder(fileName); if (IsVaultFolder(normalizedPath)) { VaultClientFolder vaultClientFolder = ClientInstance.TreeCache.Repository.Root.FindFolderRecursive(normalizedPath); if (!String.IsNullOrEmpty(WorkingFolder)) { ClientInstance.TreeCache.SetWorkingFolder(vaultClientFolder.FullPath, WorkingFolder); } ClientInstance.Refresh(); ChangeSetItemColl changeSet; BuildChangeSetOfCheckedOutFiles(vaultClientFolder, out changeSet); if (!ClientInstance.Commit(changeSet)) { string errMsg = VaultConnection.GetSoapExceptionMessage(changeSet[0].Request.Response.Status); throw new Exception(string.Format(Properties.Resources.VaultCheckinFolderException, normalizedPath, errMsg)); } else { Version = Convert.ToInt32(vaultClientFolder.Version); Log.LogMessage(MessageImportance.Normal, string.Format(Properties.Resources.VaultCheckinSuccessful), vaultClientFolder.Name); } } else if (IsVaultFile(normalizedPath)) { string previousWorkingFolder = ""; string repositoryFolderPath = ""; string tmpdiskPath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), string.Format("msbuild_checkinfor_{0}", System.IO.Path.GetFileName(normalizedPath))); VaultClientFile vaultClientFile = ClientInstance.TreeCache.Repository.Root.FindFileRecursive(normalizedPath); if (!String.IsNullOrEmpty(WorkingFolder)) { ClientInstance.TreeCache.SetWorkingFolder(vaultClientFile.Parent.FullPath, WorkingFolder); } string diskFilename = System.IO.Path.Combine(ClientInstance.GetWorkingFolder(vaultClientFile).GetLocalFolderPath(), normalizedPath.Substring(normalizedPath.LastIndexOf(VaultDefine.PathSeparator) + 1)); bool bChangeWorkingFolder = false; if (!Misc.stringIsBlank(_diskFile) && _diskFile != diskFilename) { bChangeWorkingFolder = true; if (!File.Exists(_diskFile)) { throw new Exception(string.Format(Properties.Resources.VaultDiskFileDoesNotExist, _diskFile)); } // They've specified a different disk file (no working folder) repositoryFolderPath = vaultClientFile.Parent.FullPath; previousWorkingFolder = ClientInstance.TreeCache.GetWorkingFolder(repositoryFolderPath); if (Directory.Exists(tmpdiskPath) == false) { Directory.CreateDirectory(tmpdiskPath); } // Set a different working folder to avoid interference with the real working folder ClientInstance.TreeCache.SetWorkingFolder(repositoryFolderPath, tmpdiskPath); diskFilename = System.IO.Path.Combine(tmpdiskPath, vaultClientFile.Name); Log.LogMessage(MessageImportance.Normal, string.Format(Properties.Resources.VaultSetNewWorkingFolder, repositoryFolderPath, tmpdiskPath, previousWorkingFolder)); ClientInstance.CheckOut(vaultClientFile, 2, "Temp checkout for MSBuild Vault task."); ClientInstance.Get(vaultClientFile, true, MakeWritableType.MakeAllFilesWritable, SetFileTimeType.Current, MergeType.OverwriteWorkingCopy, null); if (File.Exists(diskFilename)) { File.SetAttributes(diskFilename, FileAttributes.Normal); File.Delete(diskFilename); } File.Copy(_diskFile, diskFilename); ClientInstance.Refresh(); } try { ChangeSetItemColl requestedChange = new ChangeSetItemColl(); requestedChange.Add(new ChangeSetItem_Modified(DateTime.Now, _comment, "", vaultClientFile.ID, vaultClientFile.ObjVerID, diskFilename, normalizedPath, false, vaultClientFile.EOL)); if (!ClientInstance.Commit(requestedChange)) { string errMsg = VaultConnection.GetSoapExceptionMessage(requestedChange[0].Request.Response.Status); throw new Exception(string.Format(Properties.Resources.VaultCheckinFileException, normalizedPath, errMsg)); } else { Version = Convert.ToInt32(vaultClientFile.Version); Log.LogMessage(MessageImportance.Normal, string.Format(Properties.Resources.VaultCheckinSuccessful, vaultClientFile.Name)); } } finally { if (bChangeWorkingFolder) { if (Misc.stringIsBlank(previousWorkingFolder)) { Log.LogMessage(MessageImportance.Normal, string.Format(Properties.Resources.VaultWorkingFolderCleared, repositoryFolderPath)); ClientInstance.TreeCache.RemoveWorkingFolder(repositoryFolderPath); } else { Log.LogMessage(MessageImportance.Normal, string.Format(Properties.Resources.VaultWorkingFolderRestored, repositoryFolderPath, previousWorkingFolder)); ClientInstance.TreeCache.SetWorkingFolder(repositoryFolderPath, previousWorkingFolder); } } if (Directory.Exists(tmpdiskPath)) { Misc.DeleteDirectoryRecursivelyIncludingReadOnly(tmpdiskPath); } } } else { throw new Exception(string.Format(Properties.Resources.VaultCheckinFileNotFoundException, normalizedPath)); } }