Exemplo n.º 1
0
        public string GetFile(string fileRepositoryPath, long version, TemporaryDirectory tempDir)
        {
            try
            {
                // Find the file by path in our current tree cache.
                VaultClientFile foundFile;
                if (!CanGetFile(fileRepositoryPath, version, out foundFile))
                {
                    return(String.Empty);
                }

                // This is important: do not modify the VaultClientFile reference returned by FindFileRecursive,
                // as you will modify your tree cache (which will be saved to disk).  Make a copy of the
                // object and modify that one.
                VaultClientFile copy = new VaultClientFile(foundFile);

                // Modify the copy to represent the requested file version.
                // Files added in this feature will have an initial version of 0, which doesn't actually exist in the
                // Vault repository.  When we are asked to retrieve such a file, we bump the version number up to 1.
                copy.Version = Math.Max(1, version);

                // Get the file.
                Client.GetByDisplayVersionToNonWorkingFolder(copy, MakeWritableType.MakeAllFilesWritable, SetFileTimeType.Current, copy.Parent.FullPath, tempDir.DirectoryPath, null);

                return(Path.Combine(tempDir.DirectoryPath, copy.Name));
            }
            catch (Exception e)
            {
                // Intentionally squashed.
                Trace.WriteLine(e);
                return(String.Empty);
            }
        }
Exemplo n.º 2
0
        private int FindVersionWithLabel( ClientInstance client, VaultClientFile file, string label )
        {
            string token;
            int inheritedRowCount;
            int recursiveRowCount;
            client.BeginLabelQuery( file.FullPath, file.ID, false, true, true, true, VaultClientHelper.MaxQuerySize, out inheritedRowCount, out recursiveRowCount, out token );

            if( inheritedRowCount < 1 )
            {
                client.EndLabelQuery( token );
                return -1;
            }

            VaultLabelItemX[] items;
            client.GetLabelQueryItems_Main( token, 0, inheritedRowCount, out items );

            client.EndLabelQuery( token );

            foreach( VaultLabelItemX x in items )
            {
                if( x.Label == label )
                {
                    return (int) x.Version;
                }
            }

            return -1;
        }
Exemplo n.º 3
0
        public string GetFile( string fileRepositoryPath, long version, TemporaryDirectory tempDir )
        {
            try
            {
                // Find the file by path in our current tree cache.
                VaultClientFile foundFile;
                if( !CanGetFile( fileRepositoryPath, version, out foundFile ) )
                {
                    return String.Empty;
                }

                // This is important: do not modify the VaultClientFile reference returned by FindFileRecursive,
                // as you will modify your tree cache (which will be saved to disk).  Make a copy of the
                // object and modify that one.
                VaultClientFile copy = new VaultClientFile( foundFile );

                // Modify the copy to represent the requested file version.
                // Files added in this feature will have an initial version of 0, which doesn't actually exist in the
                // Vault repository.  When we are asked to retrieve such a file, we bump the version number up to 1.
                copy.Version = Math.Max(1, version);

                // Get the file.
                Client.GetByDisplayVersionToNonWorkingFolder( copy, MakeWritableType.MakeAllFilesWritable, SetFileTimeType.Current, copy.Parent.FullPath, tempDir.DirectoryPath, null );

                return Path.Combine( tempDir.DirectoryPath, copy.Name );
            }
            catch( Exception e )
            {
                // Intentionally squashed.
                Trace.WriteLine( e );
                return String.Empty;
            }
        }
        private int FindVersionWithLabel(ClientInstance client, VaultClientFile file, string label)
        {
            string token;
            int    inheritedRowCount;
            int    recursiveRowCount;

            client.BeginLabelQuery(file.FullPath, file.ID, false, true, true, true, VaultClientHelper.MaxQuerySize, out inheritedRowCount, out recursiveRowCount, out token);

            if (inheritedRowCount < 1)
            {
                client.EndLabelQuery(token);
                return(-1);
            }

            VaultLabelItemX[] items;
            client.GetLabelQueryItems_Main(token, 0, inheritedRowCount, out items);

            client.EndLabelQuery(token);

            foreach (VaultLabelItemX x in items)
            {
                if (x.Label == label)
                {
                    return((int)x.Version);
                }
            }

            return(-1);
        }
Exemplo n.º 5
0
        /// <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));
            }
        }
Exemplo n.º 6
0
        long findVersionWithLabel(VaultClientFile file, string label)
        {
            string token;
            int    inheritedRowCount;
            int    recursiveRowCount;
            int    maxQuerySize = 5000;

            Client.BeginLabelQuery(file.FullPath, file.ID, false, true, true, true, maxQuerySize, out inheritedRowCount, out recursiveRowCount, out token);

            if (inheritedRowCount < 1)
            {
                Client.EndLabelQuery(token);
                return(-1);
            }

            VaultLabelItemX [] items;
            Client.GetLabelQueryItems_Main(token, 0, inheritedRowCount, out items);

            Client.EndLabelQuery(token);

            foreach (VaultLabelItemX x in items)
            {
                if (x.Label == label)
                {
                    return(x.Version);
                }
            }

            return(-1);
        }
Exemplo n.º 7
0
        public bool CanGetFile(string fileRepositoryPath, long version, out VaultClientFile clientFile)
        {
            clientFile = Client.TreeCache.Repository.Root.FindFileRecursive(fileRepositoryPath);

            if (clientFile == null)
            {
                Trace.WriteLine("Couldn't find file {0} in the tree.", fileRepositoryPath);
                return(false);
            }

            return(true);
        }
Exemplo n.º 8
0
        public bool CanGetFile( string fileRepositoryPath, long version, out VaultClientFile clientFile )
        {
            clientFile = Client.TreeCache.Repository.Root.FindFileRecursive( fileRepositoryPath );

            if( clientFile == null )
            {
                Trace.WriteLine( "Couldn't find file {0} in the tree.", fileRepositoryPath );
                return false;
            }

            return true;
        }
        public void Add(VaultClientHelper client, VaultHistoryItemBase historyItem)
        {
            VaultClientFile file = client.Root.FindFileRecursive(historyItem.ID);

            if (file == null)
            {
                return;
            }

            string fullPath = file.FullPath;

            Add(fullPath, fullPath, historyItem.Version, file.Version, historyItem.TxDate, historyItem.UserName, historyItem.Comment);
        }
Exemplo n.º 10
0
        /// <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));
            }
        }
Exemplo n.º 11
0
        /// <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);
                }
            }
        }
Exemplo n.º 12
0
        public void PromoteLabelVersion(string filePath, string label, long newVersion)
        {
            VaultClientFile file = root.FindFileRecursive(filePath);

            file.Version = newVersion;

            VaultLabelPromotionItem item = new VaultLabelPromotionItem();

            item.ChangeType = VaultLabelPromotionChangeType.Modify;
            item.ItemName   = file.Name;
            item.ItemPath   = file.FullPath;
            item.Version    = file.Version;
            item.ID         = file.ID;

            long labelId = GetLabelId(root, label);

            item.Version = newVersion;
            SynchObVerId(item);

            long currentLabeledVersion = findVersionWithLabel(file, label);

            // Move
            if (currentLabeledVersion != -1)
            {
                item.ChangeType = VaultLabelPromotionChangeType.Modify;
            }
            else // Add
            {
                item.ChangeType = VaultLabelPromotionChangeType.Add;
            }

            VaultLabelPromotionItem [] items = new VaultLabelPromotionItem [] { item };

            DateTime lastDate   = VaultDate.EmptyDate();
            int      nIdxFailed = 0;
            string   conflict   = null;

            int    promoteResult = Client.PromoteLabelItems(root.FullPath, labelId, label, ref lastDate, items, out nIdxFailed, out conflict);
            string resultString  = VaultConnection.GetSoapExceptionMessage(promoteResult);
        }
Exemplo n.º 13
0
        /// <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));
            }
        }
Exemplo n.º 14
0
        long findVersionWithLabel( VaultClientFile file, string label )
        {
            string token;
            int inheritedRowCount;
            int recursiveRowCount;
            int maxQuerySize = 5000;
            Client.BeginLabelQuery( file.FullPath, file.ID, false, true, true, true, maxQuerySize, out inheritedRowCount, out recursiveRowCount, out token );

            if( inheritedRowCount < 1 )
            {
                Client.EndLabelQuery( token );
                return -1;
            }

            VaultLabelItemX [] items;
            Client.GetLabelQueryItems_Main( token, 0, inheritedRowCount, out items );

            Client.EndLabelQuery( token );

            foreach( VaultLabelItemX x in items )
            {
                if( x.Label == label )
                {
                    return x.Version;
                }
            }

            return -1;
        }