private void CreateDebugOptions(out UserSettings settings, out DebugOptions debugOptions, out SshDeltaCopy.Options options) { ThreadHelper.ThrowIfNotOnUIThread(); var allDeviceSettings = UserSettingsManager.Instance.Load(); settings = allDeviceSettings.CurrentUserSettings; if (settings.UseDeployPathFromProjectFileIfExists) { try { _monoExtension.OverwriteWithProjectSettingsFromStartupProject(ref settings); } catch (Exception ex) { Logger.Error(ex); } } debugOptions = _monoExtension.CreateDebugOptions(settings); options = new SshDeltaCopy.Options() { Host = settings.SSHHostIP, Port = settings.SSHPort, Username = settings.SSHUsername, Password = settings.SSHPassword, PrivateKeyFile = settings.SSHPrivateKeyFile, SourceDirectory = debugOptions.OutputDirectory, DestinationDirectory = settings.SSHDeployPath, RemoveOldFiles = true, PrintTimings = true, RemoveTempDeleteListFile = true, }; }
private void CreateDebugOptions(out UserSettings settings, out DebugOptions debugOptions, out SshDeltaCopy.Options options) { ThreadHelper.ThrowIfNotOnUIThread(); var allDeviceSettings = UserSettingsManager.Instance.Load(); settings = allDeviceSettings.CurrentUserSettings; if (settings.UseDeployPathFromProjectFileIfExists) { try { var localProjectConfig = _monoExtension.GetProjectSettingsFromStartupProject(); if (localProjectConfig.HasValue) { if (!string.IsNullOrWhiteSpace(localProjectConfig.Value.SSHDeployPath)) { Logger.Info($"SSHDeployPath = {settings.SSHDeployPath} was overwritten with local *.VSMonoDebugger.config: {localProjectConfig.Value.SSHDeployPath}"); settings.SSHDeployPath = localProjectConfig.Value.SSHDeployPath; } if (!string.IsNullOrWhiteSpace(localProjectConfig.Value.WindowsDeployPath)) { Logger.Info($"WindowsDeployPath = {settings.WindowsDeployPath} was overwritten with local *.VSMonoDebugger.config: {localProjectConfig.Value.WindowsDeployPath}"); settings.WindowsDeployPath = localProjectConfig.Value.WindowsDeployPath; } } } catch (Exception ex) { Logger.Error(ex); } } debugOptions = _monoExtension.CreateDebugOptions(settings); options = new SshDeltaCopy.Options() { Host = settings.SSHHostIP, Port = settings.SSHPort, Username = settings.SSHUsername, Password = settings.SSHPassword, PrivateKeyFile = settings.SSHPrivateKeyFile, SourceDirectory = debugOptions.OutputDirectory, DestinationDirectory = settings.SSHDeployPath, RemoveOldFiles = true, PrintTimings = true, RemoveTempDeleteListFile = true, }; }
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; } })); }
private static void CreateDebugOptions(out UserSettings settings, out DebugOptions debugOptions, out SshDeltaCopy.Options options) { var allDeviceSettings = UserSettingsManager.Instance.Load(); settings = allDeviceSettings.CurrentUserSettings; debugOptions = _monoExtension.CreateDebugOptions(settings, true); options = new SshDeltaCopy.Options() { Host = settings.SSHHostIP, Port = settings.SSHPort, Username = settings.SSHUsername, Password = settings.SSHPassword, PrivateKeyFile = settings.SSHPrivateKeyFile, SourceDirectory = debugOptions.OutputDirectory, DestinationDirectory = settings.SSHDeployPath, RemoveOldFiles = true, PrintTimings = true, RemoveTempDeleteListFile = true, }; }
public SSHDebuggerBase(SshDeltaCopy.Options options) { _sshOptions = options; }
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; })); }
public static Task <Task> DebugAsync(SshDeltaCopy.Options options, DebugOptions debugOptions, Func <string, Task> writeOutput, RedirectOutputOptions redirectOutputOption = RedirectOutputOptions.None) { writeOutput("Start DeployAndDebug over SSH ..."); return(StartDebuggerAsync(options, debugOptions, false, true, writeOutput, redirectOutputOption)); }
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); } })); }
public static Task <Task> DebugAsync(SshDeltaCopy.Options options, DebugOptions debugOptions, Action <string> msgOutput) { msgOutput("Start DeployAndDebug over SSH ..."); return(StartDebuggerAsync(options, debugOptions, false, true, msgOutput)); }
private async Task <bool> DeployAndRunCommandOverSSH(bool deploy, bool startDebugger) { // TODO error handling // TODO show ssh output stream // TODO stop monoRemoteSshDebugTask properly try { if (!deploy && !startDebugger) { return(true); } var allDeviceSettings = UserSettingsManager.Instance.Load(); var settings = allDeviceSettings.CurrentUserSettings; if (deploy) { await _monoExtension.BuildSolutionAsync(); } var debugOptions = _monoExtension.CreateDebugOptions(settings, true); var options = new SshDeltaCopy.Options() { Host = settings.SSHHostIP, Port = settings.SSHPort, Username = settings.SSHUsername, Password = settings.SSHPassword, SourceDirectory = debugOptions.OutputDirectory, DestinationDirectory = settings.SSHDeployPath, RemoveOldFiles = true, PrintTimings = true, RemoveTempDeleteListFile = true, }; if (deploy) { await _monoExtension.ConvertPdb2Mdb(options.SourceDirectory, HostOutputWindowEx.WriteLineLaunchError); } System.Threading.Tasks.Task monoRemoteSshDebugTask; if (startDebugger) { if (deploy) { monoRemoteSshDebugTask = await SSHDebugger.DeployAndDebugAsync(options, debugOptions, HostOutputWindowEx.WriteLaunchError, settings.RedirectOutputOption); } else { monoRemoteSshDebugTask = await SSHDebugger.DebugAsync(options, debugOptions, HostOutputWindowEx.WriteLaunchError, settings.RedirectOutputOption); } _monoExtension.AttachDebuggerToRunningProcess(debugOptions); } else { monoRemoteSshDebugTask = await SSHDebugger.DeployAsync(options, debugOptions, HostOutputWindowEx.WriteLaunchError, settings.RedirectOutputOption); } await monoRemoteSshDebugTask; return(true); } catch (Exception ex) { HostOutputWindowEx.WriteLineLaunchError(ex.Message); NLogService.Logger.Error(ex); // TODO MessageBox MessageBox.Show(ex.Message, "MonoRemoteDebugger", MessageBoxButton.OK, MessageBoxImage.Error); } return(false); }
public SSHDebuggerDotnet(SshDeltaCopy.Options options) : base(options) { }
public SSHDebuggerMono(SshDeltaCopy.Options options) : base(options) { }