/// <summary> /// Prints the given exception using the Console Manager. /// </summary> /// <param name="ex">The ex.</param> private static void PrintException(Exception ex) { ConsoleManager.ErrorWriteLine("Deployment failed."); ConsoleManager.ErrorWriteLine(" Error - " + ex.GetType().Name); ConsoleManager.ErrorWriteLine(" " + ex.Message); ConsoleManager.ErrorWriteLine(" " + ex.StackTrace); }
private static SshCommand ExecuteCommand(SshClient client, string commandText) { ConsoleManager.WriteLine("SSH TX:"); ConsoleManager.WriteLine(commandText, ConsoleColor.Green); using (var command = client.CreateCommand(commandText)) { var result = command.Execute(); ConsoleManager.WriteLine("SSH RX:"); if (command.ExitStatus != 0) { ConsoleManager.ErrorWriteLine("Error " + command.ExitStatus); ConsoleManager.ErrorWriteLine(command.Error); } if (string.IsNullOrWhiteSpace(result) == false) { ConsoleManager.WriteLine(result, ConsoleColor.Yellow); } return(command); } }
/// <summary> /// Deletes the linux directory recursively. /// </summary> /// <param name="client">The client.</param> /// <param name="path">The path.</param> private static void DeleteLinuxDirectoryRecursive(SftpClient client, string path) { var files = client.ListDirectory(path); foreach (var file in files) { if (file.Name.Equals(LinuxCurrentDirectory) || file.Name.Equals(LinuxParentDirectory)) { continue; } if (file.IsDirectory) { DeleteLinuxDirectoryRecursive(client, file.FullName); } try { client.Delete(file.FullName); } catch { ConsoleManager.ErrorWriteLine("WARNING: Failed to delete file or folder '" + file.FullName + "'"); } } }
static void Main(string[] args) { #region Handle Single Instance Application bool isNewMutex; AppMutex = new Mutex(true, MutexName, out isNewMutex); if (isNewMutex == false) { AppMutex = null; Environment.ExitCode = CommandLine.Parser.DefaultExitCodeFail; return; } #endregion Console.WriteLine("SSH Deployment Tool [Version " + typeof(Unosquare.Labs.SshDeploy.Program).Assembly.GetName().Version.ToString() + "]"); Console.WriteLine("(c) 2015 Unosquare SA de CV. All Rights Reserved."); var invokedVerbName = string.Empty; CliVerbOptionsBase invokedVerbOptions = null; var options = new CliOptions(); var parseResult = CommandLine.Parser.Default.ParseArguments(args, options, (verb, verbOptions) => { invokedVerbName = verb; invokedVerbOptions = verbOptions as CliVerbOptionsBase; if (invokedVerbOptions != null) { ConsoleManager.Verbose = invokedVerbOptions.Verbose != 0; } }); if (parseResult == false) { Environment.ExitCode = CommandLine.Parser.DefaultExitCodeFail; return; } try { switch (invokedVerbName) { case CliOptions.RunVerb: { var verbOptions = invokedVerbOptions as RunVerbOptions; DeploymentManager.ExecuteRunVerb(verbOptions); break; } case CliOptions.ShellVerb: { var verbOptions = invokedVerbOptions as ShellVerbOptions; DeploymentManager.ExecuteShellVerb(verbOptions); break; } case CliOptions.MonitorVerb: { var verbOptions = invokedVerbOptions as MonitorVerbOptions; DeploymentManager.ExecuteMonitorVerb(verbOptions); break; } } } catch (Exception ex) { ConsoleManager.ErrorWriteLine("Error - " + ex.GetType().Name); ConsoleManager.ErrorWriteLine(ex.Message); ConsoleManager.ErrorWriteLine(ex.StackTrace); Environment.ExitCode = CommandLine.Parser.DefaultExitCodeFail; } if (Environment.ExitCode != 0) { ConsoleManager.ErrorWriteLine("Completed with errors. Exit Code " + Environment.ExitCode.ToString()); } else { ConsoleManager.WriteLine("Completed."); } }