示例#1
0
        private Task <bool> StartDebuggerAsync(SshDeltaCopy.Options options, DebugOptions debugOptions, bool deploy, bool debug, Func <string, Task> writeOutput, RedirectOutputOptions redirectOutputOption)
        {
            NLogService.TraceEnteringMethod(Logger);

            return(Task.Run <bool>(async() =>
            {
                var errorHelpText = new StringBuilder();
                Action <string> writeLineOutput = s => writeOutput(s + Environment.NewLine).Wait();

                try
                {
                    errorHelpText.AppendLine($"SSH Login: {options.Username}@{options.Host}:{options.Port} Directory: {options.DestinationDirectory}");

                    using (SshDeltaCopy sshDeltaCopy = new SshDeltaCopy(options))
                    {
                        sshDeltaCopy.LogOutput = writeLineOutput;

                        if (deploy)
                        {
                            Logger.Info($"StartDebuggerAsync - deploy");

                            errorHelpText.AppendLine($"SSH: Start deployment from '{options.SourceDirectory}' to '{options.DestinationDirectory}'.");
                            sshDeltaCopy.DeployDirectory(options.SourceDirectory, options.DestinationDirectory);
                            errorHelpText.AppendLine($"SSH Deployment was successful.");
                            // We are creating mdb files on local machine with pdb2mdb
                            //var createMdbCommand = sshDeltaCopy.RunSSHCommand($@"find . -regex '.*\(exe\|dll\)' -exec {debugOptions.UserSettings.SSHPdb2mdbCommand} {{}} \;", false);
                            //msgOutput(createMdbCommand.Result);
                        }

                        if (debug)
                        {
                            Logger.Info($"StartDebuggerAsync - debug");

                            await DebugAsync(debugOptions, writeOutput, redirectOutputOption, errorHelpText, writeLineOutput, sshDeltaCopy);
                        }
                    }
                }
                catch (Exception ex)
                {
                    var additionalErrorMessage = $"SSHDebugger: {ex.Message}\n\nExecuted steps:\n{errorHelpText.ToString()}";
                    await writeOutput(additionalErrorMessage);
                    throw new Exception(additionalErrorMessage, ex);
                }

                return true;
            }));
        }
        private static Task <Task> StartDebuggerAsync(SshDeltaCopy.Options options, DebugOptions debugOptions, bool deploy, bool debug, Action <string> msgOutput)
        {
            return(Task.Factory.StartNew(async() =>
            {
                try
                {
                    using (SshDeltaCopy sshDeltaCopy = new SshDeltaCopy(options))
                    {
                        sshDeltaCopy.LogOutput = msgOutput;

                        if (deploy)
                        {
                            sshDeltaCopy.DeployDirectory(options.SourceDirectory, options.DestinationDirectory);
                            // We are creating mdb files on local machine with pdb2mdb
                            //var createMdbCommand = sshDeltaCopy.RunSSHCommand($@"find . -regex '.*\(exe\|dll\)' -exec {debugOptions.UserSettings.SSHPdb2mdbCommand} {{}} \;", false);
                            //msgOutput(createMdbCommand.Result);
                        }

                        if (debug)
                        {
                            var killCommandText = $"kill $(lsof -i | grep 'mono' | grep '\\*:{debugOptions.UserSettings.SSHMonoDebugPort}' | awk '{{print $2}}')";//$"kill $(ps w | grep '[m]ono --debugger-agent=address' | awk '{{print $1}}')";
                            var killCommand = sshDeltaCopy.RunSSHCommand(killCommandText, false);
                            msgOutput(killCommand.Result);

                            // If lsof is unknown and ps aux has an bug (https://bugs.launchpad.net/linaro-oe/+bug/1192942)
                            killCommandText = $"kill $(ps w | grep '[m]ono --debugger-agent=address' | awk '{{print $1}}')";
                            var killCommand2 = sshDeltaCopy.RunSSHCommand(killCommandText, false);
                            msgOutput(killCommand2.Result);

                            var monoDebugCommand = $"mono --debugger-agent=address={IPAddress.Any}:{debugOptions.UserSettings.SSHMonoDebugPort},transport=dt_socket,server=y --debug=mdb-optimizations {debugOptions.TargetExeFileName} {debugOptions.StartArguments} &";
                            var cmd = sshDeltaCopy.CreateSSHCommand(monoDebugCommand);
                            var monoDebugCommandResult = await Task.Factory.FromAsync(cmd.BeginExecute(), result => cmd.Result);
                            msgOutput(monoDebugCommandResult);
                        }
                    }
                }
                catch (Exception ex)
                {
                    msgOutput($"Exception: {ex.Message}\n{ex.StackTrace}");
                    throw;
                }
            }));
        }
示例#3
0
 protected abstract Task DebugAsync(DebugOptions debugOptions, Func <string, Task> writeOutput, RedirectOutputOptions redirectOutputOption, StringBuilder errorHelpText, Action <string> writeLineOutput, SshDeltaCopy sshDeltaCopy);
示例#4
0
        private Task <bool> StartDebuggerAsync(SshDeltaCopy.Options options, DebugOptions debugOptions, bool deploy, bool debug, Func <string, Task> writeOutput, RedirectOutputOptions redirectOutputOption)
        {
            NLogService.TraceEnteringMethod();

            return(Task.Run <bool>(async() =>
            {
                var errorHelpText = new StringBuilder();
                Action <string> writeLineOutput = s => writeOutput(s + Environment.NewLine).Wait();

                try
                {
                    errorHelpText.AppendLine($"SSH Login: {options.Username}@{options.Host}:{options.Port} Directory: {options.DestinationDirectory}");

                    using (SshDeltaCopy sshDeltaCopy = new SshDeltaCopy(options))
                    {
                        sshDeltaCopy.LogOutput = writeLineOutput;

                        if (deploy)
                        {
                            NLogService.Logger.Info($"StartDebuggerAsync - deploy");

                            errorHelpText.AppendLine($"SSH: Start deployment from '{options.SourceDirectory}' to '{options.DestinationDirectory}'.");
                            sshDeltaCopy.DeployDirectory(options.SourceDirectory, options.DestinationDirectory);
                            errorHelpText.AppendLine($"SSH Deployment was successful.");
                            // We are creating mdb files on local machine with pdb2mdb
                            //var createMdbCommand = sshDeltaCopy.RunSSHCommand($@"find . -regex '.*\(exe\|dll\)' -exec {debugOptions.UserSettings.SSHPdb2mdbCommand} {{}} \;", false);
                            //msgOutput(createMdbCommand.Result);
                        }

                        if (debug)
                        {
                            NLogService.Logger.Info($"StartDebuggerAsync - debug");

                            errorHelpText.AppendLine($"SSH: Stop previous mono processes.");

                            var killCommandText = debugOptions.PreDebugScript;
                            var killCommand = sshDeltaCopy.RunSSHCommand(killCommandText, false);
                            writeLineOutput(killCommand.Result);

                            NLogService.Logger.Info($"Run PreDebugScript: {killCommandText}");

                            if (killCommand.ExitStatus != 0 || !string.IsNullOrWhiteSpace(killCommand.Error))
                            {
                                var error = $"SSH script error in PreDebugScript:\n{killCommand.CommandText}\n{killCommand.Error}";
                                //errorHelpText.AppendLine(error);
                                NLogService.Logger.Error(error);
                            }

                            var monoDebugCommand = debugOptions.DebugScript;

                            errorHelpText.AppendLine($"SSH: Start mono debugger");
                            errorHelpText.AppendLine(monoDebugCommand);

                            NLogService.Logger.Info($"Run DebugScript: {monoDebugCommand}");

                            // TODO if DebugScript fails no error is shown - very bad!
                            await writeOutput(errorHelpText.ToString());
                            var cmd = sshDeltaCopy.CreateSSHCommand(monoDebugCommand);
                            await RunCommandAndRedirectOutputAsync(cmd, writeOutput, redirectOutputOption);

                            if (cmd.ExitStatus != 0 || !string.IsNullOrWhiteSpace(cmd.Error))
                            {
                                var error = $"SSH script error in DebugScript:\n{cmd.CommandText}\n{cmd.Error}";
                                //errorHelpText.AppendLine(error);
                                NLogService.Logger.Error(error);

                                throw new Exception(error);
                            }

                            //var monoDebugCommandResult = await Task.Factory.FromAsync(cmd.BeginExecute(), result => cmd.Result);
                            //msgOutput(monoDebugCommandResult);
                        }
                    }
                }
                catch (Exception ex)
                {
                    var additionalErrorMessage = $"SSHDebugger: {ex.Message}\n\nExecuted steps:\n{errorHelpText.ToString()}";
                    await writeOutput(additionalErrorMessage);
                    throw new Exception(additionalErrorMessage, ex);
                }

                return true;
            }));
        }
示例#5
0
        private static Task <Task> StartDebuggerAsync(SshDeltaCopy.Options options, DebugOptions debugOptions, bool deploy, bool debug, Action <string> writeOutput, RedirectOutputOptions redirectOutputOption)
        {
            return(Task.Factory.StartNew(async() =>
            {
                var errorHelpText = new StringBuilder();
                Action <string> writeLineOutput = s => writeOutput(s + Environment.NewLine);

                try
                {
                    errorHelpText.AppendLine($"SSH Login: {options.Username}@{options.Host}:{options.Port} Directory: {options.DestinationDirectory}");

                    using (SshDeltaCopy sshDeltaCopy = new SshDeltaCopy(options))
                    {
                        sshDeltaCopy.LogOutput = writeLineOutput;

                        if (deploy)
                        {
                            errorHelpText.AppendLine($"SSH: Start deployment from '{options.SourceDirectory}' to '{options.DestinationDirectory}'.");
                            sshDeltaCopy.DeployDirectory(options.SourceDirectory, options.DestinationDirectory);
                            errorHelpText.AppendLine($"SSH Deployment was successful.");
                            // We are creating mdb files on local machine with pdb2mdb
                            //var createMdbCommand = sshDeltaCopy.RunSSHCommand($@"find . -regex '.*\(exe\|dll\)' -exec {debugOptions.UserSettings.SSHPdb2mdbCommand} {{}} \;", false);
                            //msgOutput(createMdbCommand.Result);
                        }

                        if (debug)
                        {
                            errorHelpText.AppendLine($"SSH: Stop previous mono processes.");

                            var killCommandTextOld = $"kill $(lsof -i | grep 'mono' | grep '\\*:{debugOptions.UserSettings.SSHMonoDebugPort}' | awk '{{print $2}}')";//$"kill $(ps w | grep '[m]ono --debugger-agent=address' | awk '{{print $1}}')";
                            var killCommandText = debugOptions.PreDebugScript;
                            var killCommand = sshDeltaCopy.RunSSHCommand(killCommandText, false);
                            writeLineOutput(killCommand.Result);

                            //errorHelpText.AppendLine($"SSH: Stop previous mono processes. Second try.");

                            //// If lsof is unknown and ps aux has an bug (https://bugs.launchpad.net/linaro-oe/+bug/1192942)
                            //killCommandText = $"kill $(ps w | grep '[m]ono --debugger-agent=address' | awk '{{print $1}}')";
                            //var killCommand2 = sshDeltaCopy.RunSSHCommand(killCommandText, false);
                            //writeLineOutput(killCommand2.Result);

                            var monoDebugCommandOld = $"mono --debugger-agent=address=0.0.0.0:{debugOptions.UserSettings.SSHMonoDebugPort},transport=dt_socket,server=y --debug=mdb-optimizations {debugOptions.TargetExeFileName} {debugOptions.StartArguments} &";
                            var monoDebugCommand = debugOptions.DebugScript;

                            errorHelpText.AppendLine($"SSH: Start mono debugger");
                            errorHelpText.AppendLine(monoDebugCommand);

                            var cmd = sshDeltaCopy.CreateSSHCommand(monoDebugCommand);
                            await RunCommandAndRedirectOutput(cmd, writeOutput, redirectOutputOption);

                            //var monoDebugCommandResult = await Task.Factory.FromAsync(cmd.BeginExecute(), result => cmd.Result);
                            //msgOutput(monoDebugCommandResult);
                        }
                    }
                }
                catch (Exception ex)
                {
                    var additionalErrorMessage = $"SSHDebugger: {ex.Message}\n\nExecuted steps:\n{errorHelpText.ToString()}";
                    writeOutput(additionalErrorMessage);
                    throw new Exception(additionalErrorMessage, ex);
                }
            }));
        }
 protected override Task DebugAsync(DebugOptions debugOptions, Func <string, Task> writeOutput, RedirectOutputOptions redirectOutputOption, StringBuilder errorHelpText, Action <string> writeLineOutput, SshDeltaCopy sshDeltaCopy)
 {
     // will be handled in MonoVisualStudioExtension
     return(Task.CompletedTask);
 }
示例#7
0
        protected override async Task DebugAsync(DebugOptions debugOptions, Func <string, Task> writeOutput, RedirectOutputOptions redirectOutputOption, StringBuilder errorHelpText, Action <string> writeLineOutput, SshDeltaCopy sshDeltaCopy)
        {
            errorHelpText.AppendLine($"SSH: Stop previous mono processes.");

            var killCommandText = debugOptions.PreDebugScript;
            var killCommand     = sshDeltaCopy.RunSSHCommand(killCommandText, false);

            writeLineOutput(killCommand.Result);

            Logger.Info($"Run PreDebugScript: {killCommandText}");

            if (killCommand.ExitStatus != 0 || !string.IsNullOrWhiteSpace(killCommand.Error))
            {
                var error = $"SSH script error in PreDebugScript:\n{killCommand.CommandText}\n{killCommand.Error}";
                //errorHelpText.AppendLine(error);
                Logger.Error(error);
            }

            var monoDebugCommand = debugOptions.DebugScript;

            errorHelpText.AppendLine($"SSH: Start mono debugger");
            errorHelpText.AppendLine(monoDebugCommand);

            Logger.Info($"Run DebugScript: {monoDebugCommand}");

            // TODO if DebugScript fails no error is shown - very bad!
            await writeOutput(errorHelpText.ToString());

            var cmd = sshDeltaCopy.CreateSSHCommand(monoDebugCommand);

            await RunCommandAndRedirectOutputAsync(cmd, writeOutput, redirectOutputOption);

            if (cmd.ExitStatus != 0 || !string.IsNullOrWhiteSpace(cmd.Error))
            {
                var error = $"SSH script error in DebugScript:\n{cmd.CommandText}\n{cmd.Error}";
                //errorHelpText.AppendLine(error);
                Logger.Error(error);

                throw new Exception(error);
            }

            //var monoDebugCommandResult = await Task.Factory.FromAsync(cmd.BeginExecute(), result => cmd.Result);
            //msgOutput(monoDebugCommandResult);
        }