Пример #1
0
        public void TryKillProcessAndChildrenRecursively(Process process)
        {
            var messages = new List <string>();
            var result   = ShellExecutor.ExecuteCommand(
                "/bin/bash",
                $"-c \"kill -TERM {process.Id}\"",
                Environment.CurrentDirectory,
                m => { },
                m => { },
                m => messages.Add(m)
                );

            if (result != 0)
            {
                throw new ShellExecutionException(result, messages);
            }

            //process.Kill() doesnt seem to work in netcore 2.2 there have been some improvments in netcore 3.0 as well as also allowing to kill child processes
            //https://github.com/dotnet/corefx/pull/34147
            //In netcore 2.2 if the process is terminated we still get stuck on process.WaitForExit(); we need to manually check to see if the process has exited and then close it.
            if (process.HasExited)
            {
                process.Close();
            }
        }
Пример #2
0
        private void event_BalloonClicked(object sender, DDBalloonClickedEventArgs e)
        {
            var s = Properties.Settings.Default;

            if (!string.IsNullOrEmpty(s.DialCmd_File))
            {
                var phonenumber = Filters.DigitsOnly(e.BalloonInfo.CallerIdNumber);
                var command     = new ShellCommand(s.DialCmd_File, s.DialCmd_Args);
                command.WorkingDirectory = s.DialCmd_WorkDir;

                ShellExecutor.ExecuteCommand(command, new[] {
                    new KeyValuePair <string, string>("%PHONENUMBER%", phonenumber)
                });
            }
        }
        static int Execute(
            string command,
            string arguments,
            string workingDirectory,
            out StringBuilder debugMessages,
            out StringBuilder infoMessages,
            out StringBuilder errorMessages,
            NetworkCredential?networkCredential,
            IDictionary <string, string>?customEnvironmentVariables,
            CancellationToken cancel
            )
        {
            var debug    = new StringBuilder();
            var info     = new StringBuilder();
            var error    = new StringBuilder();
            var exitCode = ShellExecutor.ExecuteCommand(
                command,
                arguments,
                workingDirectory,
                x =>
            {
                Console.WriteLine($"{DateTime.UtcNow} DBG: {x}");
                debug.Append(x);
            },
                x =>
            {
                Console.WriteLine($"{DateTime.UtcNow} INF: {x}");
                info.Append(x);
            },
                x =>
            {
                Console.WriteLine($"{DateTime.UtcNow} ERR: {x}");
                error.Append(x);
            },
                networkCredential,
                customEnvironmentVariables,
                cancel);

            debugMessages = debug;
            infoMessages  = info;
            errorMessages = error;

            return(exitCode);
        }
Пример #4
0
        private void event_WebInterface(object sender, EventArgs e)
        {
            string url;

            if (sender == _fop2webinterface)
            {
                url = Properties.Settings.Default.FOP2Url;
            }
            else
            {
                url = Properties.Settings.Default.FOP2UserPortal;
            }

            var command = new ShellCommand(url);

            ShellExecutor.ExecuteCommand(command, new[] {
                new KeyValuePair <string, string>("%CONTEXT%", _client.Context),
                new KeyValuePair <string, string>("%USER%", _client.Username),
                new KeyValuePair <string, string>("%PASS%", _client.Password),
            });
        }
Пример #5
0
        public static void OctoVersionDiscoverLocalGitBranch(out string branch, Action <LoggerConfiguration> additionLogs)
        {
            var(_, configuration) = ConfigurationBootstrapper.BootstrapWithoutValidation <AppSettings>();
            LogBootstrapper.Bootstrap(configuration, additionLogs);

            var stdout = new List <string>();
            var stderr = new List <string>();

            var exitCode = ShellExecutor.ExecuteCommand(
                "git",
                "rev-parse --abbrev-ref HEAD",
                Environment.CurrentDirectory,
                log => { },
                log => { stdout.Add(log); },
                log => { stdout.Add(log); }
                );

            if (exitCode != 0)
            {
                throw new Exception("Calling git binary to determine local branch failed.")
                      .WithData(nameof(stdout), stdout)
                      .WithData(nameof(stderr), stderr);
            }

            var bareBranch = stdout.FirstOrDefault() ?? throw new Exception("Failed to determine local branch.")
                                   .WithData(nameof(stdout), stdout)
                                   .WithData(nameof(stderr), stderr);

            branch = $"refs/heads/{bareBranch}";

            var environmentVariableName = $"{ConfigurationBootstrapper.EnvironmentVariablePrefix}{nameof(AppSettings.CurrentBranch)}";

            Environment.SetEnvironmentVariable(environmentVariableName, branch);

            Log.Warning("The current Git branch has been automatically determined to be {branch}.", branch);
            Log.Warning($"It is STRONGLY RECOMMENDED to NOT rely on automatic branch detection on your build agents. It will fail in unexpected ways for tags, pull requests, commit hashes etc. Please set the {environmentVariableName} variable deterministically instead");
        }
Пример #6
0
 private void fop2WebInterfaceToolStripMenuItem_Click(object sender, EventArgs e)
 {
     ShellExecutor.ExecuteCommand(new ShellCommand(this.GetFOP2WebInterfaceURL()));
 }