public void OnStart(string[] args)
{
// Ensure required components are present.
if ((object)m_parentService == null)
throw new InvalidOperationException("ParentService property of ServiceHelper component is not set");
if ((object)m_remotingServer == null)
throw new InvalidOperationException("RemotingServer property of ServiceHelper component is not set");
// Open log file if file logging is enabled.
// Make sure to do this before calling OnServiceStarting
// in case messages need to be logged by the handler.
if (m_logStatusUpdates)
m_statusLog.Open();
OnServiceStarting(args);
lock (m_clientRequestHandlers)
{
m_clientRequestHandlers.Add(new ClientRequestHandler("Clients", "Displays list of clients connected to the service", ShowClients));
m_clientRequestHandlers.Add(new ClientRequestHandler("Settings", "Displays queryable service settings from config file", ShowSettings));
m_clientRequestHandlers.Add(new ClientRequestHandler("Processes", "Displays list of service or system processes", ShowProcesses));
m_clientRequestHandlers.Add(new ClientRequestHandler("Schedules", "Displays list of process schedules defined in the service", ShowSchedules));
m_clientRequestHandlers.Add(new ClientRequestHandler("History", "Displays list of requests received from the clients", ShowRequestHistory));
m_clientRequestHandlers.Add(new ClientRequestHandler("Help", "Displays list of commands supported by the service", ShowRequestHelp, new[] { "?" }));
m_clientRequestHandlers.Add(new ClientRequestHandler("Status", "Displays the current service status", ShowServiceStatus, new[] { "stat" }));
m_clientRequestHandlers.Add(new ClientRequestHandler("Start", "Start a service or system process", StartProcess));
m_clientRequestHandlers.Add(new ClientRequestHandler("Abort", "Aborts a service or system process", AbortProcess));
m_clientRequestHandlers.Add(new ClientRequestHandler("ReloadCryptoCache", "Reloads local cryptography cache", ReloadCryptoCache));
m_clientRequestHandlers.Add(new ClientRequestHandler("UpdateSettings", "Updates service setting in the config file", UpdateSettings));
m_clientRequestHandlers.Add(new ClientRequestHandler("ReloadSettings", "Reloads services settings from the config file", ReloadSettings));
m_clientRequestHandlers.Add(new ClientRequestHandler("Reschedule", "Reschedules a process defined in the service", RescheduleProcess));
m_clientRequestHandlers.Add(new ClientRequestHandler("Unschedule", "Unschedules a process defined in the service", UnscheduleProcess));
m_clientRequestHandlers.Add(new ClientRequestHandler("SaveSchedules", "Saves process schedules to the config file", SaveSchedules));
m_clientRequestHandlers.Add(new ClientRequestHandler("LoadSchedules", "Loads process schedules from the config file", LoadSchedules));
m_clientRequestHandlers.Add(new ClientRequestHandler("Filter", "Filters status messages coming from the service", UpdateClientFilter));
// Enable file management commands if configured
if (m_supportFileManagementCommands)
{
m_clientRequestHandlers.Add(new ClientRequestHandler("Files", "Manages files on the server", ManageFiles));
m_clientRequestHandlers.Add(new ClientRequestHandler("Transfer", "Transfers files to and from the server", TransferFile));
}
m_clientRequestHandlers.Add(new ClientRequestHandler("Version", "Displays current service version", ShowVersion, new[] { "ver" }));
m_clientRequestHandlers.Add(new ClientRequestHandler("Time", "Displays current system time", ShowTime));
m_clientRequestHandlers.Add(new ClientRequestHandler("User", "Displays current user information", ShowUser, new[] { "whoami" }));
// Enable telnet support if configured
if (m_supportTelnetSessions)
m_clientRequestHandlers.Add(new ClientRequestHandler("Telnet", "Allows for a telnet session to the service server", RemoteTelnetSession, false));
// Enable health monitoring if configured
if (m_monitorServiceHealth)
{
try
{
m_performanceMonitor = new PerformanceMonitor(m_healthMonitorInterval * 1000.0D);
m_clientRequestHandlers.Add(new ClientRequestHandler("Health", "Displays a report of resource utilization for the service", ShowHealthReport));
m_clientRequestHandlers.Add(new ClientRequestHandler("ResetHealthMonitor", "Resets the system resource utilization monitor", ResetHealthMonitor));
}
catch (UnauthorizedAccessException ex)
{
string message = $"Unable to start health monitor due to exception: {ex.Message}";
LogException(new InvalidOperationException(message, ex));
UpdateStatus(UpdateType.Warning, "{0} Is the service account a member of the \"Performance Log Users\" group?", message);
}
}
}
// Add internal components as service components by default.
lock (m_serviceComponents)
{
m_serviceComponents.Add(m_processScheduler);
m_serviceComponents.Add(m_statusLog);
m_serviceComponents.Add(m_errorLogger);
m_serviceComponents.Add(m_errorLogger.ErrorLog);
m_serviceComponents.Add(m_remotingServer);
}
// Start all of the core components.
m_processScheduler.Start();
m_remotingServer.Start();
m_enabled = true;
OnServiceStarted();
}