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); } } } }
private ChangeSetItemColl DetectChanges() { Console.WriteLine("Detecting changes"); var changes = new ChangeSetItemColl(); var folder = ServerOperations.ProcessCommandListFolder(_repoFolder, true); HandleModifiesAndDeletes(folder, changes, true); HandleAdds(folder, changes); return(changes); }
private void HandleModifiesAndDeletes(VaultClientFolder folder, ChangeSetItemColl changes, bool isRepoRoot) { var diskPath = MakeDiskPath(folder.FullPath); if (!isRepoRoot && !Directory.Exists(diskPath)) { changes.AddRange(ServerOperations.ProcessCommandDelete(new[] { folder.FullPath })); return; } HandleFiles(folder.Files, changes); foreach (VaultClientFolder subFolder in folder.Folders) { HandleModifiesAndDeletes(subFolder, changes, false); } }
private static void HandleFiles(VaultClientFileColl fileColl, ChangeSetItemColl changes) { var diskPaths = fileColl.Cast <VaultClientFile>().Select(x => x.FullPath).ToList(); var statuses = ServerOperations.ProcessCommandStatus(diskPaths.ToArray()); var pathAndStatus = diskPaths.Zip(statuses, Tuple.Create); foreach (var(path, status) in pathAndStatus) { switch (status) { case WorkingFolderFileStatus.None: case WorkingFolderFileStatus.Edited: break; case WorkingFolderFileStatus.Missing: changes.AddRange(ServerOperations.ProcessCommandDelete(new[] { path })); Console.WriteLine($"Deleted {path} as it was {status}"); break; case WorkingFolderFileStatus.Renegade: ServerOperations.ProcessCommandCheckout(new[] { path }, false, false, new GetOptions()); Console.WriteLine($"Checked out {path} as it was {status}"); break; case WorkingFolderFileStatus.Merged: case WorkingFolderFileStatus.NeedsMerge: case WorkingFolderFileStatus.Unknown: case WorkingFolderFileStatus.MoreRecent: case WorkingFolderFileStatus.Old: Console.WriteLine($"Unhandled {path} with {status}"); break; default: throw new ArgumentOutOfRangeException(); } } }
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); }
private void HandleAdds(VaultClientFolder folder, ChangeSetItemColl changes) { var versionedFiles = new HashSet <string>(); GetAllVersionedFiles(folder, versionedFiles); var versionedDiskPaths = versionedFiles.Select(MakeDiskPath).ToList(); var filesToAdd = new HashSet <string>(Directory.GetFiles(_workingFolder, "*", SearchOption.AllDirectories)); filesToAdd.ExceptWith(versionedDiskPaths); var dirToFiles = new Dictionary <string, HashSet <string> >(); foreach (var file in filesToAdd) { var dir = Path.GetDirectoryName(file); dir = dir.Substring(Math.Min(_workingFolder.Length + 1, dir.Length)); if (!dirToFiles.TryGetValue(dir, out var files)) { files = new HashSet <string>(); dirToFiles[dir] = files; } files.Add(file); } foreach (var pair in dirToFiles) { var dir = pair.Key; var files = pair.Value; var repoFolder = string.IsNullOrEmpty(dir) ? _repoFolder : $"{_repoFolder}/{dir}"; repoFolder = repoFolder.Replace('\\', '/'); changes.AddRange(ServerOperations.ProcessCommandAdd(repoFolder, files.ToArray())); } }
/// <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)); } }
/// <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)); } }
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); } } } }