/// <summary>
        /// Checks the file out.
        /// </summary>
        /// <param name="filePath">The file path.</param>
        /// <exception cref="System.Exception">
        /// Unable to check out file
        /// or
        /// File is read only, please checkout the file before running
        /// </exception>
        public void Checkout(string filePath)
        {
            if (!File.GetAttributes(filePath).HasFlag(FileAttributes.ReadOnly))
            {
                return;
            }

            string output;

            try
            {
                var info = new ProcessExecutorInfo($"\"{TfPath}\"", $"checkout {WrapPathInQuotes(filePath)}")
                {
                    WorkingDirectory = Directory.GetParent(filePath).FullName
                };

                output = ProcessExecutor.ExecuteCmd(info);
            }
            catch (Exception ex)
            {
                throw new Exception("Unable to check out file " + filePath + Environment.NewLine + ex);
            }

            if (File.GetAttributes(filePath).HasFlag(FileAttributes.ReadOnly))
            {
                throw new Exception("File \"" + filePath + "\" is read only even though it should have been checked out, please checkout the file before running.  Output: " + output);
            }
        }
예제 #2
0
        /// <summary>
        /// Gets the specified files from the server, potentially overwriting it, even if it's checked out.
        /// </summary>
        /// <param name="overwrite">if set to <c>true</c> [overwrite].</param>
        /// <param name="fileNames">The file names.</param>
        /// <exception cref="System.Exception">Unable to determin if file is different than contents for the file  + sourcePath + Environment.NewLine + ex</exception>
        public string Get(bool overwrite, params string[] fileNames)
        {
            if (fileNames == null || fileNames.Length == 0)
            {
                return("No Files Given");
            }

            var fileNameBatches = fileNames.BatchLessThanMaxLength(MaxCommandLength,
                                                                   "Filename \"{0}\" is longer than the max length {1}.",
                                                                   3 // 1 for each quote, and one more for the space between.
                                                                   );

            var output = new StringBuilder();

            foreach (var batch in fileNameBatches)
            {
                try
                {
                    var files = string.Join(" ", batch.Select(WrapPathInQuotes));
                    var info  = CreateProcessExecutorInfo("get", null, files + (overwrite ? " /overwrite": ""), Directory.GetParent(fileNames.First()).FullName);
                    output.AppendLine(ProcessExecutor.ExecuteCmd(info));
                }
                catch (Exception ex)
                {
                    throw new Exception("Unable to get files " + string.Join(", ", batch) + Environment.NewLine + ex);
                }
            }
            return(output.ToString());
        }
예제 #3
0
 private void ExecutePostSolutionRestoreCommands()
 {
     foreach (var cmd in PostSolutionRestoreCommands)
     {
         Logger.AddDetail($"Executing Command: \"{cmd.FileName}\" {cmd.Arguments}");
         var result = ProcessExecutor.ExecuteCmd(cmd);
         Logger.AddDetail(result);
         PostSolutionRestoreCommandResults.Add(result);
     }
 }
예제 #4
0
        protected void ExecuteNuGetRestoreForSolution()
        {
            var cmd = new ProcessExecutorInfo(NuGetPath, $"restore \"{SolutionPath}\" -NonInteractive");

            Logger.Show("Restoring Nuget for the solution.");
            Logger.AddDetail(cmd.FileName + " " + cmd.Arguments);
            var results = ProcessExecutor.ExecuteCmd(cmd);

            Logger.Show(results);
            UpdateProjectsPostSolutionRestore();
        }
예제 #5
0
 /// <summary>
 /// Adds the file.
 /// </summary>
 /// <param name="filePath">The file path.</param>
 /// <exception cref="System.Exception">Unable to Add the file {filePath}</exception>
 public void Add(string filePath)
 {
     try
     {
         var info = CreateProcessExecutorInfo("add", filePath);
         ProcessExecutor.ExecuteCmd(info);
     }
     catch (Exception ex)
     {
         throw new Exception("Unable to Add the file " + filePath + Environment.NewLine + ex);
     }
 }
예제 #6
0
        /// <summary>
        /// Un-does the specified file path.
        /// </summary>
        /// <param name="filePath">The file path.</param>
        /// <exception cref="System.Exception">Unable to Undo Checkout If Unchanged for file  + filePath + Environment.NewLine + ex</exception>
        public void Undo(string filePath)
        {
            try
            {
                var info = CreateProcessExecutorInfo("undo", filePath, "/noprompt");

                ProcessExecutor.ExecuteCmd(info);
            }
            catch (Exception ex)
            {
                throw new Exception("Unable to Undo Checkout for file " + filePath + Environment.NewLine + ex);
            }
        }
예제 #7
0
        /// <summary>
        /// Determines whether the specified files are different.
        /// </summary>
        /// <param name="sourcePath">The source path.</param>
        /// <param name="diffPath">The difference path.</param>
        /// <returns></returns>
        public bool AreDifferent(string sourcePath, string diffPath)
        {
            try
            {
                var info   = CreateProcessExecutorInfo("Diff", sourcePath, WrapPathInQuotes(diffPath) + " /format:Brief");
                var output = ProcessExecutor.ExecuteCmd(info);

                return(output.Contains("files differ"));
            }
            catch (Exception ex)
            {
                throw new Exception($"Unable to determine if \"{sourcePath}\" is different than \"{diffPath}" + sourcePath + Environment.NewLine + ex);
            }
        }
        /// <summary>
        /// Adds the file.
        /// </summary>
        /// <param name="filePath">The file path.</param>
        public void Add(string filePath)
        {
            try
            {
                var info = new ProcessExecutorInfo($"\"{TfPath}\"", $"add {WrapPathInQuotes(filePath)}")
                {
                    WorkingDirectory = Directory.GetParent(filePath).FullName
                };

                ProcessExecutor.ExecuteCmd(info);
            }
            catch (Exception ex)
            {
                throw new Exception("Unable to Add the file " + filePath + Environment.NewLine + ex);
            }
        }
        /// <summary>
        /// Un-does the specified file path.
        /// </summary>
        /// <param name="filePath">The file path.</param>
        /// <exception cref="System.Exception">Unable to Undo Checkout If Unchanged for file  + filePath + Environment.NewLine + ex</exception>
        public void Undo(string filePath)
        {
            try
            {
                var info = new ProcessExecutorInfo($"\"{TfPath}\"", $"undo {WrapPathInQuotes(filePath)} /noprompt")
                {
                    WorkingDirectory = Directory.GetParent(filePath).FullName
                };

                ProcessExecutor.ExecuteCmd(info);
            }
            catch (Exception ex)
            {
                throw new Exception("Unable to Undo Checkout for file " + filePath + Environment.NewLine + ex);
            }
        }
예제 #10
0
        /// <summary>
        /// Returns true if the file was unchanged and an undo operation was performed
        /// </summary>
        /// <param name="filePath"></param>
        /// <returns></returns>
        public bool UndoCheckoutIfUnchanged(string filePath)
        {
            try
            {
                var info   = CreateProcessExecutorInfo("Diff", filePath, "/format:Brief");
                var output = ProcessExecutor.ExecuteCmd(info);

                if (output.Contains("files differ"))
                {
                    return(false);
                }

                Undo(filePath);
                return(true);
            }
            catch (Exception ex)
            {
                throw new Exception("Unable to Undo Checkout If Unchanged for file " + filePath + Environment.NewLine + ex);
            }
        }
예제 #11
0
        /// <summary>
        /// Checks the file(s) out.
        /// </summary>
        /// <param name="fileNames">The file names.</param>
        /// <returns></returns>
        /// <exception cref="System.Exception">Unable to check out file
        /// or
        /// File is read only, please checkout the file before running</exception>
        public string Checkout(params string[] fileNames)
        {
            if (fileNames == null || fileNames.Length == 0)
            {
                return("No Files Given");
            }

            var fileNamesToCheckoutBatches = fileNames.Where(f => File.GetAttributes(f).HasFlag(FileAttributes.ReadOnly))
                                             .BatchLessThanMaxLength(MaxCommandLength,
                                                                     "Filename \"{0}\" is longer than the max length {1}.",
                                                                     3          // 1 for each quote, and one more for the space between.
                                                                     );

            var output = new StringBuilder();

            foreach (var batch in fileNamesToCheckoutBatches)
            {
                try
                {
                    var files = string.Join(" ", batch.Select(WrapPathInQuotes));
                    var info  = CreateProcessExecutorInfo("checkout", null, files, Directory.GetParent(fileNames.First()).FullName);
                    output.AppendLine(ProcessExecutor.ExecuteCmd(info));
                }
                catch (Exception ex)
                {
                    throw new Exception("Unable to check out files " + string.Join(", ", batch) + Environment.NewLine + ex);
                }
            }

            foreach (var file in fileNamesToCheckoutBatches.SelectMany(v => v))
            {
                if (File.GetAttributes(file).HasFlag(FileAttributes.ReadOnly))
                {
                    throw new Exception("File \"" + file + "\" is read only even though it should have been checked out, please checkout the file before running.  Output: " + output);
                }
            }
            return(output.ToString());
        }
        /// <summary>
        /// Returns true if the file was unchanged and an undo operation was performed
        /// </summary>
        /// <param name="filePath"></param>
        /// <returns></returns>
        public bool UndoCheckoutIfUnchanged(string filePath)
        {
            try
            {
                var info = new ProcessExecutorInfo($"\"{TfPath}\"", $"Diff {WrapPathInQuotes(filePath)}")
                {
                    WorkingDirectory = Directory.GetParent(filePath).FullName
                };

                var output = ProcessExecutor.ExecuteCmd(info);

                if (output.Trim() != "edit: " + filePath.Trim())
                {
                    return(false);
                }

                Undo(filePath);
                return(true);
            }
            catch (Exception ex)
            {
                throw new Exception("Unable to Undo Checkout If Unchanged for file " + filePath + Environment.NewLine + ex);
            }
        }