/// <summary> /// Prints the deployment number the Monitor is currently in. /// </summary> /// <param name="deploymentNumber">The deployment number.</param> private static void PrintDeploymentNumber(int deploymentNumber) { ConsoleManager.WriteLine(" Starting deployment ID " + deploymentNumber + " - " + DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString(), ConsoleColor.Green); }
/// <summary> /// Starts the user interaction. /// </summary> /// <param name="fsMonitor">The fs monitor.</param> /// <param name="sshClient">The SSH client.</param> /// <param name="sftpClient">The SFTP client.</param> /// <param name="shellStream">The shell stream.</param> /// <param name="verbOptions">The verb options.</param> private static void StartUserInteraction(FileSystemMonitor fsMonitor, SshClient sshClient, SftpClient sftpClient, ShellStream shellStream, MonitorVerbOptions verbOptions) { ForwardShellStreamInput = false; while (true) { var readKey = Console.ReadKey(true); if (readKey.Key == ConsoleKey.F1) { ForwardShellStreamInput = !ForwardShellStreamInput; if (ForwardShellStreamInput) { ConsoleManager.WriteLine(" >> Entered console input forwarding.", ConsoleColor.Green); ForwardShellStreamOutput = true; } else { ConsoleManager.WriteLine(" >> Left console input forwarding.", ConsoleColor.Red); } continue; } if (ForwardShellStreamInput) { if (readKey.Key == ConsoleKey.Enter) { shellStream.WriteLine(string.Empty); } else { shellStream.WriteByte((byte)readKey.KeyChar); } shellStream.Flush(); continue; } if (readKey.Key == ConsoleKey.Q) { break; } if (readKey.Key == ConsoleKey.C) { ConsoleManager.Clear(); continue; } if (readKey.Key == ConsoleKey.N) { CreateNewDeployment(sshClient, sftpClient, shellStream, verbOptions); continue; } if (readKey.Key == ConsoleKey.E) { RunSshClientCommand(sshClient, verbOptions); continue; } if (readKey.Key == ConsoleKey.S) { RunShellStreamCommand(shellStream, verbOptions); continue; } if (readKey.Key != ConsoleKey.H) { ConsoleManager.WriteLine("Unrecognized command '" + readKey.KeyChar + "' -- Press 'H' to get a list of available commands.", ConsoleColor.Red); } if (readKey.Key == ConsoleKey.H) { var helpColor = ConsoleColor.Cyan; ConsoleManager.WriteLine("Console help", helpColor); ConsoleManager.WriteLine(" H Prints this screen", helpColor); ConsoleManager.WriteLine(" Q Quits this application", helpColor); ConsoleManager.WriteLine(" C Clears the screen", helpColor); ConsoleManager.WriteLine(" N Force a deployment cycle", helpColor); ConsoleManager.WriteLine(" E Run the Pre-deployment command", helpColor); ConsoleManager.WriteLine(" S Run the Post-deployment command", helpColor); ConsoleManager.WriteLine(" F1 Toggle shell-interactive mode", helpColor); ConsoleManager.WriteLine(string.Empty); continue; } } }
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."); } }