protected override Result RunCore(Argument[] args) { var descriptions = ServiceStatusProvider.DescribeWindowsStatuses(); var waitForDescription = descriptions[_waitFor]; string serviceName = CafeServerWindowsServiceOptions.ServiceName; var fullPath = _fileSystem.FindInstallationDirectoryInPathContaining(ServiceStatusProvider .ServiceControllerExecutable, @"C:\windows\System32"); Presenter.ShowMessage($"Executing command to {_command} the service {serviceName}", Logger); _processExecutor.ExecuteAndWaitForExit( Path.Combine(fullPath, ServiceStatusProvider.ServiceControllerExecutable), $"{_command} {serviceName}", LogInformation, LogError); Presenter.ShowMessage($"Waiting for {serviceName} to be {waitForDescription}", Logger); var status = _serviceStatusWaiter.WaitFor(_waitFor); var statusDescription = descriptions[status]; Presenter.ShowMessage($"Service {serviceName} status is now {statusDescription}", Logger); return(status == _waitFor ? Result.Successful() : Result.Failure( $"Expecting {_command} command to put the service in '{waitForDescription}' status but instead it is in '{statusDescription}' status.")); }
public ServiceStatusWaiter(string taskDescription, IAutoResetEvent autoResetEvent, ITimerFactory timerFactory, ServiceStatusProvider serviceStatusProvider) : base(taskDescription, autoResetEvent, timerFactory) { _serviceStatusProvider = serviceStatusProvider; }
public CafeWindowsServiceStatusOption(ProcessExecutor processExecutor, IFileSystem fileSystem) : base("gets the status of the cafe windows service") { _serviceStatusProvider = new ServiceStatusProvider(processExecutor, fileSystem); }