/// <summary> /// Called when a command was received from windows' service system. /// </summary> /// <param name="command">The received command.</param> /// <param name="commandSpecificEventType">Type of the command specific event. See description of dwEventType at https://msdn.microsoft.com/en-us/library/windows/desktop/ms685996(v=vs.85).aspx </param> public void OnCommand(ServiceControlCommand command, uint commandSpecificEventType) { switch (command) { case ServiceControlCommand.Stop: PerformAction(ServiceState.StopPending , ServiceState.Stopped , serviceImplementation.Stop , ServiceAcceptedControlCommandsFlags.None); break; case ServiceControlCommand.Pause: PerformAction(ServiceState.PausePending , ServiceState.Paused , serviceImplementation.Pause , ServiceAcceptedControlCommandsFlags.PauseContinueStop); break; case ServiceControlCommand.Continue: PerformAction(ServiceState.ContinuePending , ServiceState.Running , serviceImplementation.Continue , ServiceAcceptedControlCommandsFlags.PauseContinueStop); break; } }
/// <summary> /// Called when a command was received from windows' service system. /// </summary> /// <param name="command">The received command.</param> /// <param name="commandSpecificEventType">Type of the command specific event. See description of dwEventType at https://msdn.microsoft.com/en-us/library/windows/desktop/ms683241(v=vs.85).aspx</param> public void OnCommand(ServiceControlCommand command, uint commandSpecificEventType) { if (command == ServiceControlCommand.Stop) { statusReportCallback(ServiceState.StopPending, ServiceAcceptedControlCommandsFlags.None, win32ExitCode: 0, waitHint: 3000); var win32ExitCode = 0; try { serviceImplementation.Stop(); } catch { win32ExitCode = -1; } statusReportCallback(ServiceState.Stopped, ServiceAcceptedControlCommandsFlags.None, win32ExitCode, waitHint: 0); } else if (command == ServiceControlCommand.Shutdown) { try { statusReportCallback(ServiceState.StopPending, ServiceAcceptedControlCommandsFlags.None, win32ExitCode: 0, waitHint: 3000); //this is probably too much, see note down below serviceImplementation.Shutdown(); } catch { } finally { statusReportCallback(ServiceState.Stopped, ServiceAcceptedControlCommandsFlags.None, win32ExitCode: 0, waitHint: 0); } } }
/// <summary> /// Called when a command was received from windows' service system. /// </summary> /// <param name="command">The received command.</param> /// <param name="commandSpecificEventType">Type of the command specific event. See description of dwEventType at https://msdn.microsoft.com/en-us/library/windows/desktop/ms683241(v=vs.85).aspx</param> public static void OnCommand(ServiceControlCommand command, uint commandSpecificEventType) { if (command == ServiceControlCommand.Stop) { StatusReportCallback(ServiceState.StopPending, ServiceAcceptedControlCommandsFlags.None, win32ExitCode: 0, waitHint: 3000); var win32ExitCode = 0; try { // Stop Services flecoqui Options opt = new Options(); opt.TraceLevel = Options.LogLevel.Verbose; opt.TraceFile = "C:\\temp\\ttt.log"; TimeSpan t = new TimeSpan(0, 0, 0, 10, 0); opt.LogInformation("Stopping service, timeout ms: " + t.TotalMilliseconds.ToString()); bool result = StopServices(t); } catch { win32ExitCode = -1; } StatusReportCallback(ServiceState.Stopped, ServiceAcceptedControlCommandsFlags.None, win32ExitCode, waitHint: 0); } }
private void HandleServiceControlCommand(ServiceControlCommand command, uint eventType, IntPtr eventData, IntPtr eventContext) { try { stateMachine.OnCommand(command, eventType); } catch { ReportServiceStatus(ServiceState.Stopped, ServiceAcceptedControlCommandsFlags.None, win32ExitCode: -1, waitHint: 0); } }
public void ItShallIgnoreUnsupportedCommands(ServiceControlCommand unsupportedCommand) { // Given GivenTheServiceHasBeenStarted(); // When sut.OnCommand(unsupportedCommand, 0); // Then no other calls than the startup calls must have been made A.CallTo(statusReportCallback).MustHaveHappened(Repeated.NoMoreThan.Once); A.CallTo(serviceImplmentation).MustHaveHappened(Repeated.NoMoreThan.Once); }
private void HandleServiceControlCommand(ServiceControlCommand command, uint eventType, IntPtr eventData, IntPtr eventContext) { try { Log.Informational("Service command received: " + command.ToString()); switch (command) { case ServiceControlCommand.Stop: this.StopService(false); break; case ServiceControlCommand.Continue: case ServiceControlCommand.DeviceEvent: case ServiceControlCommand.HardwareProfileChange: case ServiceControlCommand.Interrogate: case ServiceControlCommand.NetBindAdd: case ServiceControlCommand.NetBindDisable: case ServiceControlCommand.NetBindEnable: case ServiceControlCommand.NetBindRemoved: case ServiceControlCommand.Paramchange: case ServiceControlCommand.Pause: case ServiceControlCommand.PowerEvent: case ServiceControlCommand.SessionChange: case ServiceControlCommand.Shutdown: // TODO: Implement break; default: if ((int)command >= 128) { try { Gateway.ExecuteServiceCommand((int)command); } catch (Exception ex) { Log.Critical(ex); } } break; } } catch (Exception ex) { Log.Critical(ex); ReportServiceStatus(ServiceState.Stopped, ServiceAcceptedControlCommandsFlags.None, win32ExitCode: 1, waitHint: 0); } }
/// <summary> /// Called when a command was received from windows' service system. /// </summary> /// <param name="command">The received command.</param> /// <param name="commandSpecificEventType">Type of the command specific event. See description of dwEventType at https://msdn.microsoft.com/en-us/library/windows/desktop/ms683241(v=vs.85).aspx</param> public void OnCommand(ServiceControlCommand command, uint commandSpecificEventType) { if (command == ServiceControlCommand.Stop) { statusReportCallback(ServiceState.StopPending, ServiceAcceptedControlCommandsFlags.None, win32ExitCode: 0, waitHint: 3000); var win32ExitCode = 0; try { serviceImplementation.Stop(); } catch { win32ExitCode = -1; } statusReportCallback(ServiceState.Stopped, ServiceAcceptedControlCommandsFlags.None, win32ExitCode, waitHint: 0); } }
private void WhenTheOSSendsControlCommand(ServiceControlCommand controlCommand, uint commandSpecificEventType) { serviceControlHandler(controlCommand, commandSpecificEventType, IntPtr.Zero, serviceControlContext); }
public void OnCommand(ServiceControlCommand command, uint commandSpecificEventType) { switch (command) { case ServiceControlCommand.Stop: { _statusReportCallback(ServiceState.StopPending, ServiceAcceptedControlCommandsFlags.None, win32ExitCode: 0, waitHint: 60000); var win32ExitCode = 0; try { _serviceImplementation.Stop(); } catch { win32ExitCode = -1; } finally { _statusReportCallback(ServiceState.Stopped, ServiceAcceptedControlCommandsFlags.None, win32ExitCode, waitHint: 0); } break; } case ServiceControlCommand.Pause: { _statusReportCallback(ServiceState.PausePending, ServiceAcceptedControlCommandsFlags.None, win32ExitCode: 0, waitHint: 20000); var win32ExitCode = 0; try { _serviceImplementation.OnPause(); } catch { win32ExitCode = -1; } _statusReportCallback(ServiceState.Paused, ServiceAcceptedControlCommandsFlags.PauseContinue | ServiceAcceptedControlCommandsFlags.Stop, win32ExitCode, waitHint: 0); break; } case ServiceControlCommand.Continue: { _statusReportCallback(ServiceState.ContinuePending, ServiceAcceptedControlCommandsFlags.None, win32ExitCode: 0, waitHint: 20000); var win32ExitCode = 0; try { _serviceImplementation.OnContinue(); } catch { win32ExitCode = -1; } if (_serviceImplementation.CanPauseAndContinue) { _statusReportCallback(ServiceState.Running, ServiceAcceptedControlCommandsFlags.Stop | ServiceAcceptedControlCommandsFlags.PauseContinue, win32ExitCode, waitHint: 0); } else { _statusReportCallback(ServiceState.Running, ServiceAcceptedControlCommandsFlags.Stop, win32ExitCode, waitHint: 0); } break; } } }