コード例 #1
0
        protected override Result DoWork()
        {
            Status(TranslationProvider.Translate("!Starting", this.Name));
            prepareSmallgit();

            this.CaptureOutput = true;

            BinOutput output = new BinOutput();

            // Stage 1: git stash
            //          Store changes to tracked files
            Status(TranslationProvider.Translate("!Stash", this.Name));
            output = Git("stash");

            // Stage 2: git pull
            //          Download and apply any changes
            Status(TranslationProvider.Translate("!Pull", this.Name));
            output = Git("pull");

            if (output.StdOutput != "Already up-to-date.\n")
            {
                Program.SelectedSteps |= WizardSteps.View_Changelog;
                Program.ConstructSteps(Program.SelectedSteps);
            }

            // Stage 3: git stash pop
            //          Retrieve stored changes and reapply them
            Status(TranslationProvider.Translate("!Pop", this.Name));
            Git("stash pop");

            return Result.Success;
        }
コード例 #2
0
        /// <summary>
        /// Executes the specified ProcessStartInfo class, capturing output.
        /// </summary>
        /// <param name="info">ProcessStartInfo to start.</param>
        /// <returns></returns>
        protected BinOutput RunProcess(ProcessStartInfo info)
        {
            BinOutput output = new BinOutput();

            // Set standard options
            info.UseShellExecute = false;
            info.CreateNoWindow = true;
            info.RedirectStandardOutput = true;
            info.RedirectStandardError = true;

            string command = info.FileName + " " + info.Arguments + "\n";
            LibCommunications.gAddLog(command);
            #if DEBUG
            AppendText(command);
            #endif

            Process p = new Process();
            p.StartInfo = info;
            p.OutputDataReceived += delegate(object sender, DataReceivedEventArgs e)
            {
                output.StdOutput += e.Data + "\n";
                LibCommunications.gAddLog("Output data received: " + e.Data);
            };
            p.ErrorDataReceived += delegate(object sender, DataReceivedEventArgs e)
            {
                output.StdError += e.Data + "\n";
                LibCommunications.gAddLog("Error data received: " + e.Data);
            };

            p.Start();

            if (CaptureOutput)
            {
                p.BeginOutputReadLine();
                p.BeginErrorReadLine();
            }

            while (p.HasExited == false)
            {
                Thread.Sleep(1);
                checkOutput(p, false);

                // Allow cancelling of process
                if (CancelProcess == true)
                {
                    AppendText(TranslationProvider.Translate("!Terminating") + "\n");

                    try
                    {
                        p.Kill();
                    }
                    catch (Exception)
                    {
                        /* Ignore, process is already killed */
                    }
                }
            }

            checkOutput(p, true);

            return output;
        }
コード例 #3
0
        /// <summary>
        /// Run an application.
        /// </summary>
        /// <param name="working">Working directory to run in.</param>
        /// <param name="bin">Binary to execute.</param>
        /// <param name="arguments">Arguments to pass to binary.</param>
        /// <param name="callback"></param>
        /// <returns></returns>
        protected void runApp(string working, string bin, string arguments, SmallgitProcessCallback callback)
        {
            ProcessStartInfo info = new ProcessStartInfo(this.home + "\\bin\\" + bin, arguments);
            info.WorkingDirectory = working;
            info.EnvironmentVariables["PATH"] = this.home + "\\bin";
            info.EnvironmentVariables["HOME"] = this.home + "\\smallgit";

            info.RedirectStandardError = true;
            info.RedirectStandardOutput = true;
            info.UseShellExecute = false;
            info.CreateNoWindow = true;

            BinOutput output = new BinOutput();
            Process process = new Process();
            process.EnableRaisingEvents = true;
            process.StartInfo = info;
            process.Exited += delegate(object sender, EventArgs e)
            {
                callback(process.ExitCode, output);
            };
            process.OutputDataReceived += delegate(object sendingProcess, DataReceivedEventArgs outLine)
            {
                output.stdout += outLine.Data;
            };
            process.ErrorDataReceived += delegate(object sendingProcess, DataReceivedEventArgs outLine)
            {
                output.stderr += outLine.Data;
            };
            process.Start();
        }