using System;
#if !NET461
namespace Swan.Services
{
///
/// Mimic a Windows ServiceBase class. Useful to keep compatibility with applications
/// running as services in OS different to Windows.
///
[Obsolete("This abstract class will be removed in version 3.0")]
public abstract class ServiceBase
{
///
/// Gets or sets a value indicating whether the service can be stopped once it has started.
///
///
/// true if this instance can stop; otherwise, false.
///
public bool CanStop { get; set; } = true;
///
/// Gets or sets a value indicating whether the service should be notified when the system is shutting down.
///
///
/// true if this instance can shutdown; otherwise, false.
///
public bool CanShutdown { get; set; }
///
/// Gets or sets a value indicating whether the service can be paused and resumed.
///
///
/// true if this instance can pause and continue; otherwise, false.
///
public bool CanPauseAndContinue { get; set; }
///
/// Gets or sets the exit code.
///
///
/// The exit code.
///
public int ExitCode { get; set; }
///
/// Indicates whether to report Start, Stop, Pause, and Continue commands in the event log.
///
///
/// true if [automatic log]; otherwise, false.
///
public bool AutoLog { get; set; }
///
/// Gets or sets the name of the service.
///
///
/// The name of the service.
///
public string ServiceName { get; set; }
///
/// Stops the executing service.
///
public void Stop()
{
if (!CanStop) return;
CanStop = false;
OnStop();
}
///
/// When implemented in a derived class, executes when a Start command is sent to the service by the Service Control Manager (SCM)
/// or when the operating system starts (for a service that starts automatically). Specifies actions to take when the service starts.
///
/// The arguments.
protected virtual void OnStart(string[] args)
{
// do nothing
}
///
/// When implemented in a derived class, executes when a Stop command is sent to the service by the Service Control Manager (SCM).
/// Specifies actions to take when a service stops running.
///
protected virtual void OnStop()
{
// do nothing
}
}
}
#endif