コード例 #1
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));
            }
        }
コード例 #2
0
ファイル: VaultBase.cs プロジェクト: sainabob/teamlab.v7.5
        /// <summary>
        /// Help function used to simplify many of the tasks.  It simply checks to see if the supplied
        /// string is a valid Vault file or not.
        /// </summary>
        /// <param name="fileName">Name of the file you wish to check for the existence of.</param>
        /// <returns>True if the file exists, false otherwise.</returns>
        public bool IsVaultFile(string fileName)
        {
            VaultClientFile vaultClientFile;

            string normalizedPath = RepositoryPath.NormalizeFolder(fileName);

            vaultClientFile = ClientInstance.TreeCache.Repository.Root.FindFileRecursive(normalizedPath);

            if (vaultClientFile == null)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
コード例 #3
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));
            }
        }
コード例 #4
0
ファイル: VaultBase.cs プロジェクト: sainabob/teamlab.v7.5
        /// <summary>
        /// Helper function used to simplify many of the tasks.  It simply checks to see if the supplied
        /// string is a valid Vault folder or not.
        /// </summary>
        /// <param name="folderName">Name of the folder you wish to check for the existence of.</param>
        /// <returns>True if a folder exists, false otherwise.</returns>
        public bool IsVaultFolder(string folderName)
        {
            VaultClientFolder vaultClientFolder;

            string normalizedPath = RepositoryPath.NormalizeFolder(folderName);

            if (ClientInstance.TreeCache != null)
            {
                vaultClientFolder = ClientInstance.TreeCache.Repository.Root.FindFolderRecursive(normalizedPath);
            }
            else
            {
                throw new Exception(Resources.VaultTreeCacheFailure);
            }
            if (vaultClientFolder == null)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
コード例 #5
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));
            }
        }
コード例 #6
0
        public void Parse(string[] args)
        {
            for (int i = 0; i < args.Length; i++)
            {
                string s = args[i];
                if ((s == null) || (s.Length == 0))
                {
                    // do not process bogus args.
                    continue;
                }

                if ((s == VaultCmdLineClientDefines.StdInParam) &&
                    (_cmd == Command.BATCH))
                {
                    items.Add(s);
                    continue;
                }

                if (s[0] == '-')
                {
                    Option option = VaultCmdLineClient.LookupOptionByString(s.Substring(1));
                    switch (option)
                    {
                    case Option.BACKUP:
                    {
                        if (TestForArgument(i, args.Length, s))
                        {
                            string sOpt = args[++i];

                            switch (sOpt.ToLower())
                            {
                            case "yes":
                            case "true":
                                this.MakeBackup = BackupOption.yes;
                                break;

                            case "no":
                            case "false":
                                this.MakeBackup = BackupOption.no;
                                break;

                            default:
                                if (!Error)
                                {
                                    Error        = true;
                                    ErrorMessage = string.Format("Invalid value for -backup: {0}.  Use \"yes\" or \"no\".", sOpt);
                                }
                                break;
                            }
                        }

                        break;
                    }

                    case Option.BEGINDATE:
                    {
                        if (TestForArgument(i, args.Length, s))
                        {
                            string sDate = args[++i];
                            try
                            {
                                this.HistoryBeginDate = DateTime.Parse(sDate);
                            }
                            catch (Exception eBegDate)
                            {
                                Error        = true;
                                ErrorMessage = string.Format("{0} could not be converted to a valid date: {1}", option, eBegDate.Message);
                            }
                        }

                        break;
                    }

                    case Option.BEGINVERSION:
                    {
                        if (TestForArgument(i, args.Length, s))
                        {
                            string sVersion = args[++i];
                            try
                            {
                                this.VersionHistoryBeginVersion = long.Parse(sVersion);
                            }
                            catch (Exception e)
                            {
                                Error        = true;
                                ErrorMessage = string.Format("{0} could not be converted to a valid numeric version number: {1}", option, e.Message);
                            }
                        }
                        break;
                    }

                    case Option.BEGINLABEL:
                    {
                        if (TestForArgument(i, args.Length, s))
                        {
                            HistoryBeginLabel = args[++i];
                        }
                        break;
                    }

                    case Option.COMMENT:
                    {
                        if (TestForArgument(i, args.Length, s))
                        {
                            _comment = args[++i];
                        }
                        break;
                    }

                    case Option.COMMIT:
                    {
                        AutoCommit = true;
                        break;
                    }

                    case Option.COMPARETO:
                    {
                        if (TestForArgument(i, args.Length, s))
                        {
                            _strDiffCompareTo = args[++i];
                        }
                        break;
                    }

                    case Option.DATESORT:
                        if (TestForArgument(i, args.Length, s))
                        {
                            DateSort = VaultCmdLineClient.LookupDateSortOptionByString(args[++i]);
                        }
                        break;

                    case Option.DESTFOLDER:
                    {
                        if (TestForArgument(i, args.Length, s))
                        {
                            DestPath = args[++i];
                        }
                        break;
                    }

                    case Option.LABELWORKINGFOLDER:
                    {
                        if (TestForArgument(i, args.Length, s))
                        {
                            LabelWorkingFolder = args[++i];
                        }
                        break;
                    }

                    case Option.DESTPATH:
                    {
                        if (TestForArgument(i, args.Length, s))
                        {
                            DestPath = args[++i];
                        }
                        break;
                    }

                    case Option.ENDDATE:
                    {
                        if (TestForArgument(i, args.Length, s))
                        {
                            string sDate = args[++i];
                            try
                            {
                                this.HistoryEndDate = DateTime.Parse(sDate);
                            }
                            catch (Exception eEndDate)
                            {
                                Error        = true;
                                ErrorMessage = string.Format("{0} could not be converted to a valid date: {1}", option, eEndDate.Message);
                            }
                        }
                        break;
                    }

                    case Option.ENDLABEL:
                    {
                        if (TestForArgument(i, args.Length, s))
                        {
                            HistoryEndLabel = args[++i];
                        }
                        break;
                    }

                    case Option.EXCLUDEACTIONS:
                    {
                        if (TestForArgument(i, args.Length, s))
                        {
                            HistoryExcludedActions = args[++i];
                        }
                        break;
                    }

                    case Option.EXCLUDEUSERS:
                    {
                        if (TestForArgument(i, args.Length, s))
                        {
                            HistoryExcludedUsers = args[++i];
                        }
                        break;
                    }

                    case Option.EXCLUSIVE:
                    {
                        CheckOutExclusive = true;
                        break;
                    }

                    case Option.SERVER:
                    case Option.HOST:
                    {
                        if (TestForArgument(i, args.Length, s))
                        {
                            _host = args[++i];
                        }
                        break;
                    }

                    case Option.KEEPCHECKEDOUT:
                    {
                        _bKeepCheckedOut = true;
                        break;
                    }

                    case Option.LEAVEFILE:
                    {
                        LocalCopy = LocalCopyType.Leave;
                        break;
                    }

                    case Option.MAKEWRITABLE:
                    {
                        MakeWritable = MakeWritableType.MakeAllFilesWritable;
                        break;
                    }

                    case Option.MAKEREADONLY:
                    {
                        MakeWritable = MakeWritableType.MakeAllFilesReadOnly;
                        break;
                    }

                    case Option.MERGE:
                    {
                        if (TestForArgument(i, args.Length, s))
                        {
                            string      strOpt = args[++i];
                            MergeOption mo     = VaultCmdLineClient.LookupMergeOptionByString(strOpt);
                            switch (mo)
                            {
                            case MergeOption.auto:
                            case MergeOption.automatic:
                            case MergeOption.automerge:
                                Merge = MergeType.AttemptAutomaticMerge;
                                break;

                            case MergeOption.later:
                            case MergeOption.mergelater:
                            case MergeOption.no_overwrite:
                                Merge = MergeType.MergeLater;
                                break;

                            case MergeOption.overwrite:
                                Merge = MergeType.OverwriteWorkingCopy;
                                break;

                            default:
                                if (Error == false)
                                {
                                    Error        = true;
                                    ErrorMessage = string.Format("Invalid value for -{0}: {1}", Option.MERGE, strOpt);
                                }
                                break;
                            }
                        }

                        break;
                    }

                    case Option.NOCLOAKS:
                    {
                        this.RespectCloaks = false;
                        break;
                    }

                    case Option.NORECURSIVE:
                    {
                        this.Recursive = false;
                        break;
                    }

                    case Option.NOSSL:
                    {
                        _ssl = false;
                        break;
                    }

                    case Option.OUT:
                    {
                        if (TestForArgument(i, args.Length, s))
                        {
                            string sName = args[++i];
                            this.OutFile = sName;
                        }
                        break;
                    }

                    case Option.PASSWORD:
                    {
                        if (TestForArgument(i, args.Length, s))
                        {
                            _password = args[++i];
                        }
                        break;
                    }

                    case Option.PERFORMDELETIONS:
                    {
                        if (TestForArgument(i, args.Length, s))
                        {
                            PerformDeletions = VaultCmdLineClient.LookupPerformDeletionsOptionByString(args[++i]);
                        }
                        break;
                    }


                    case Option.PROXYSERVER:
                    {
                        if (TestForArgument(i, args.Length, s))
                        {
                            _proxyServer = args[++i];
                        }
                        break;
                    }

                    case Option.PROXYPORT:
                    {
                        if (TestForArgument(i, args.Length, s))
                        {
                            _proxyPort = args[++i];
                        }
                        break;
                    }

                    case Option.PROXYUSER:
                    {
                        if (TestForArgument(i, args.Length, s))
                        {
                            _proxyUser = args[++i];
                        }
                        break;
                    }

                    case Option.PROXYPASSWORD:
                    {
                        if (TestForArgument(i, args.Length, s))
                        {
                            _proxyPassword = args[++i];
                        }
                        break;
                    }

                    case Option.PROXYDOMAIN:
                    {
                        if (TestForArgument(i, args.Length, s))
                        {
                            _proxyDomain = args[++i];
                        }
                        break;
                    }

                    case Option.REPOSITORY:
                    {
                        if (TestForArgument(i, args.Length, s))
                        {
                            _repository = args[++i];
                        }
                        break;
                    }

                    case Option.REQUIRECHECKOUT:
                    {
                        RequireCheckOut = true;
                        break;
                    }

                    case Option.REVERTFILE:
                    {
                        LocalCopy = LocalCopyType.Replace;
                        break;
                    }

                    case Option.ROWLIMIT:
                    {
                        if (TestForArgument(i, args.Length, s))
                        {
                            string sInt = args[++i];
                            try
                            {
                                HistoryRowLimit = Int32.Parse(sInt);
                            }
                            catch (Exception)
                            {
                            }
                        }
                        break;
                    }

                    case Option.SETFILETIME:
                    {
                        if (TestForArgument(i, args.Length, s))
                        {
                            string         strOpt = args[++i];
                            FileTimeOption fto    = VaultCmdLineClient.LookupFileTimeOptionByString(strOpt);

                            switch (fto)
                            {
                            case FileTimeOption.current:
                                this.SetFileTime = SetFileTimeType.Current;
                                break;

                            case FileTimeOption.checkin:
                                this.SetFileTime = SetFileTimeType.CheckIn;
                                break;

                            case FileTimeOption.modification:
                            case FileTimeOption.modified:
                                this.SetFileTime = SetFileTimeType.Modification;
                                break;

                            default:
                                if (!Error)
                                {
                                    Error        = true;
                                    ErrorMessage = string.Format("Invalid value for -setfiletime: {0}", strOpt);
                                }
                                break;
                            }
                        }
                        break;
                    }

                    case Option.SSL:
                    {
                        _ssl = true;
                        break;
                    }

                    case Option.UNCHANGED:
                    {
                        if (TestForArgument(i, args.Length, s))
                        {
                            string sOpt = args[++i];

                            switch (sOpt.ToLower())
                            {
                            case "leavecheckedout":
                                this.Unchanged = UnchangedHandler.LeaveCheckedOut;
                                break;

                            case "undocheckout":
                                this.Unchanged = UnchangedHandler.UndoCheckout;
                                break;

                            case "checkin":
                                this.Unchanged = UnchangedHandler.Checkin;
                                break;

                            default:
                                if (!Error)
                                {
                                    Error        = true;
                                    ErrorMessage = string.Format("Invalid value for -unchanged: {0}", sOpt);
                                }
                                break;
                            }
                        }

                        break;
                    }

                    case Option.URL:
                    {
                        if (TestForArgument(i, args.Length, s))
                        {
                            _url = args[++i];
                        }
                        break;
                    }

                    case Option.USERNAME:
                    case Option.USER:
                    {
                        if (TestForArgument(i, args.Length, s))
                        {
                            _user = args[++i];
                        }
                        break;
                    }

                    case Option.VAULTDIFF:
                    {
                        if (TestForArgument(i, args.Length, s))
                        {
                            _strDiffBin = args[++i];
                        }
                        break;
                    }

                    case Option.VAULTDIFF_OPTIONS:
                    {
                        if (TestForArgument(i, args.Length, s))
                        {
                            _strDiffArgs = args[++i];
                        }
                        break;
                    }

                    case Option.WILDCARD:
                    {
                        if (TestForArgument(i, args.Length, s))
                        {
                            Wildcard = args[++i];
                        }
                        break;
                    }

                    case Option.VERBOSE:
                    {
                        Verbose = true;
                        break;
                    }

                    case Option.YESIAMSURE:
                    {
                        _yesiamsure = true;
                        break;
                    }

                    default:
                    {
                        if (!Error)
                        {
                            Error        = true;
                            ErrorMessage = string.Format("unknown option: {0} - run 'vault.exe HELP' for help", s);
                        }
                        break;
                    }
                    }
                }
                else
                {
                    if (!checkForCommand(s))
                    {
                        if (
                            (s[0] == VaultDefine.RootName[0]) &&
                            (s.EndsWith(VaultDefine.PathSeparator.ToString()))
                            )
                        {
                            s = RepositoryPath.NormalizeFolder(s);
                        }
                        else if (s == VaultDefine.RootName)
                        {
                            s = RepositoryPath.NormalizeFolder(s);
                        }

                        items.Add(s);
                    }
                }
            }
        }