private VaultHistoryQueryRequest PrepareQuery(VaultClientHelper client) { VaultHistoryQueryRequest history = new VaultHistoryQueryRequest(); history.BeginDate = VaultDate.EmptyDate(); history.EndDate = VaultDate.EmptyDate(); history.DateFilterMask = VaultQueryRequestDates.DoNotFilter; history.CommentFilter = VaultQueryRequestComments.FilteredComment; history.Recursive = true; history.RepID = client.Client.ActiveRepositoryID; VaultClientFolder vcfolder = client.Client.TreeCache.Repository.Root.FindFolderRecursive("$"); history.TopName = vcfolder.FullPath; history.TopID = vcfolder.ID; history.IsFolder = true; // set the sort order history.Sorts = new long [] { (long)(VaultQueryRequestSort.NameSort | VaultQueryRequestSort.AscSort), (long)(VaultQueryRequestSort.VersionSort | VaultQueryRequestSort.AscSort), }; return(history); }
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> /// Undo checkout on the specified file. /// </summary> /// <exception>Exception</exception> private void UndoCheckout(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.UndoCheckOut(vaultClientFolder, true, LocalCopyType.Replace); Log.LogMessage(MessageImportance.Normal, string.Format(Properties.Resources.VaultUndoCheckoutSuccessful, vaultClientFolder.Name)); } if (IsVaultFile(normalizedPath)) { VaultClientFile vaultClientFile = ClientInstance.TreeCache.Repository.Root.FindFileRecursive(normalizedPath); if (!String.IsNullOrEmpty(WorkingFolder)) { ClientInstance.TreeCache.SetWorkingFolder(vaultClientFile.Parent.FullPath, WorkingFolder); } ClientInstance.UndoCheckOut(vaultClientFile, LocalCopyType.Replace); Log.LogMessage(MessageImportance.Normal, string.Format(Properties.Resources.VaultUndoCheckoutSuccessful, vaultClientFile.Name)); } if (IsVaultFolder(normalizedPath) == false && IsVaultFile(normalizedPath) == false) { throw new Exception(string.Format(Properties.Resources.VaultResourceNotFound, normalizedPath)); } }
private long GetFolderId(VaultClientHelper client, string repositoryPath) { VaultClientFolder folder = client.Root.FindFolderRecursive(repositoryPath); if (folder == null) { throw new ApplicationException("Could not find folder \"" + repositoryPath + "\""); } return(folder.ID); }
public LabelPromoter( string server, string repository, string username, string password ) { base.server = server; base.repository = repository; base.username = username; base.password = password; EstablishConnection(); root = Client.TreeCache.Repository.Root; }
/// <summary> /// Attempts to locate the Vault folder using the directory path specified. /// </summary> /// <exception>Exception</exception> private void FindFolder() { Path = VaultLib.RepositoryPath.NormalizeFolder(Path); Folder = ClientInstance.TreeCache.Repository.Root.FindFolderRecursive(Path); if (Folder == null) { throw new Exception(Properties.Resources.VaultPathValidationException); } }
public LabelPromoter(string server, string repository, string username, string password) { base.server = server; base.repository = repository; base.username = username; base.password = password; EstablishConnection(); root = Client.TreeCache.Repository.Root; }
private static void GetAllVersionedFiles(VaultClientFolder folder, HashSet <string> versionedFiles) { foreach (VaultClientFile file in folder.Files) { versionedFiles.Add(file.FullPath); } foreach (VaultClientFolder subFolder in folder.Folders) { GetAllVersionedFiles(subFolder, versionedFiles); } }
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); } }
long GetLabelId( VaultClientFolder folder, string label ) { long labelId = 0; string [] discoveredSubItemPaths = null; DateTime lastModified = VaultDate.EmptyDate(); VaultRepositoryDelta repDelta = null; VaultFileDelta fileDelta = null; long rootId = 0; try { Client.GetLabelStructureByName( label, ref labelId, folder.FullPath, string.Empty, out discoveredSubItemPaths, out lastModified, out repDelta, out fileDelta, out rootId ); } catch (Exception ) { // No label on item return -1; } return labelId; }
/// <summary> /// Retrieves the specified file. /// </summary> /// <exception>Exception</exception> private void Checkout(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.CheckOut(vaultClientFolder, true, VaultCheckOutType.CheckOut, Comment); ClientInstance.Get(vaultClientFolder, true, true, MakeWritableType.MakeAllFilesWritable, SetFileTimeType.Current, MergeType.OverwriteWorkingCopy, null); Version = Convert.ToInt32(vaultClientFolder.Version); Log.LogMessage(MessageImportance.Normal, string.Format(Properties.Resources.VaultCheckoutSuccessful), vaultClientFolder.Name); } if (IsVaultFile(normalizedPath)) { VaultClientFile vaultClientFile = ClientInstance.TreeCache.Repository.Root.FindFileRecursive(normalizedPath); if (!String.IsNullOrEmpty(WorkingFolder)) { ClientInstance.TreeCache.SetWorkingFolder(vaultClientFile.Parent.FullPath, WorkingFolder); } ClientInstance.CheckOut(vaultClientFile, VaultCheckOutType.CheckOut, Comment); ClientInstance.Get(vaultClientFile, true, MakeWritableType.MakeAllFilesWritable, SetFileTimeType.Current, MergeType.OverwriteWorkingCopy, null); Version = Convert.ToInt32(vaultClientFile.Version); Log.LogMessage(MessageImportance.Normal, string.Format(Properties.Resources.VaultCheckoutSuccessful, vaultClientFile.Name)); } if (IsVaultFolder(normalizedPath) == false && IsVaultFile(normalizedPath) == false) { throw new Exception(string.Format(Properties.Resources.VaultResourceNotFound, normalizedPath)); } }
long GetLabelId(VaultClientFolder folder, string label) { long labelId = 0; string [] discoveredSubItemPaths = null; DateTime lastModified = VaultDate.EmptyDate(); VaultRepositoryDelta repDelta = null; VaultFileDelta fileDelta = null; long rootId = 0; try { Client.GetLabelStructureByName(label, ref labelId, folder.FullPath, string.Empty, out discoveredSubItemPaths, out lastModified, out repDelta, out fileDelta, out rootId); } catch (Exception) { // No label on item return(-1); } return(labelId); }
/// <summary> /// Retrieves the specified file. /// </summary> /// <exception>Exception</exception> private void GetFile(string fileName) { if (IsVaultFolder(fileName)) { VaultClientFolder vaultClientFolder = ClientInstance.TreeCache.Repository.Root.FindFolderRecursive(fileName); if (Destination.Length == 0) { if (!String.IsNullOrEmpty(WorkingFolder)) { ClientInstance.TreeCache.SetWorkingFolder(vaultClientFolder.FullPath, WorkingFolder); } ClientInstance.Get(vaultClientFolder, true, true, MakeWritableType.MakeAllFilesWritable, SetFileTimeType.Current, MergeType.OverwriteWorkingCopy, null); } else { ClientInstance.GetToNonWorkingFolder(vaultClientFolder, true, true, true, MakeWritableType.MakeAllFilesWritable, SetFileTimeType.Current, Destination, null); } } if (IsVaultFile(fileName)) { VaultClientFile vaultClientFile = ClientInstance.TreeCache.Repository.Root.FindFileRecursive(fileName); if (Destination.Length == 0) { if (!String.IsNullOrEmpty(WorkingFolder)) { ClientInstance.TreeCache.SetWorkingFolder(vaultClientFile.Parent.FullPath, WorkingFolder); } ClientInstance.Get(vaultClientFile, true, MakeWritableType.MakeAllFilesWritable, SetFileTimeType.Current, MergeType.OverwriteWorkingCopy, null); } else { ClientInstance.GetToNonWorkingFolder(vaultClientFile, true, true, MakeWritableType.MakeAllFilesWritable, SetFileTimeType.Current, vaultClientFile.Parent.FullPath, Destination, null); } } }
protected void EstablishConnection() { if (server.StartsWith("http://") == false) { server = "http://" + server; } if (server.EndsWith("/VaultService") == false) { server += "/VaultService"; } ClientInstance myClient = new ClientInstance(); myClient.Init(VaultClientNetLib.VaultConnection.AccessLevelType.Client); myClient.Login(server, username, password); FindRepository(myClient, repository); client = myClient; root = Client.TreeCache.Repository.Root; }
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)); } }
protected void EstablishConnection() { if (server.StartsWith("http://") == false) server = "http://" + server; if (server.EndsWith("/VaultService") == false) server += "/VaultService"; ClientInstance myClient = new ClientInstance(); myClient.Init(VaultClientNetLib.VaultConnection.AccessLevelType.Client); myClient.Login(server, username, password); FindRepository(myClient, repository); client = myClient; root = Client.TreeCache.Repository.Root; }