private void WaitForWinRm(WaitForStatus status, ServerConfig server) { try { var cmd = server.DeploymentUser.IsDefined() ? string.Format("id -r:{0} -u:{1} -p:\"{2}\"", server.Name, server.DeploymentUser.UserName, server.DeploymentUser.Password) : string.Format("id -r:{0}", server.Name); var path = Environment.ExpandEnvironmentVariables(@"%windir%\system32\WinRM.cmd"); var startInfo = new ProcessStartInfo(path) { Arguments = cmd, Verb = "RunAs", UseShellExecute = false, WindowStyle = ProcessWindowStyle.Hidden, RedirectStandardError = true, RedirectStandardOutput = true }; var process = Process.Start(startInfo); process.WaitForExit(); switch (status) { case WaitForStatus.Failure: if (process.ExitCode == 0) { Thread.Sleep(5000); WaitForWinRm(status, server); } break; case WaitForStatus.Success: if (process.ExitCode != 0) { Thread.Sleep(5000); WaitForWinRm(status, server); } break; } } catch { switch (status) { case WaitForStatus.Failure: return; case WaitForStatus.Success: Thread.Sleep(5000); WaitForWinRm(status, server); break; } } }
public static string GetStringValue(this WaitForStatus enumValue) { switch (enumValue) { case WaitForStatus.Green: return("green"); case WaitForStatus.Yellow: return("yellow"); case WaitForStatus.Red: return("red"); } throw new ArgumentException($"'{enumValue.ToString()}' is not a valid value for enum 'WaitForStatus'"); }
private void WaitForPing(WaitForStatus failure, ServerConfig server) { try { var pingTool = new Ping(); var reply = pingTool.Send(server.Name); switch (failure) { case WaitForStatus.Failure: if (reply.Status == IPStatus.Success) { Thread.Sleep(1000); WaitForPing(failure, server); } break; case WaitForStatus.Success: if (reply.Status != IPStatus.Success) { Thread.Sleep(1000); WaitForPing(failure, server); } break; default: throw new Exception("Status not supported."); } } catch { switch (failure) { case WaitForStatus.Failure: return; case WaitForStatus.Success: Thread.Sleep(1000); WaitForPing(failure, server); break; default: throw new Exception("Status not supported."); } } }