54 lines
1.9 KiB
C#
54 lines
1.9 KiB
C#
|
|
using System.Diagnostics;
|
|||
|
|
using System.ServiceProcess;
|
|||
|
|
using System.Timers;
|
|||
|
|
using DTS.Common.DBSyncService.Properties;
|
|||
|
|
|
|||
|
|
// ReSharper disable InconsistentNaming
|
|||
|
|
|
|||
|
|
namespace DTS.Common.DBSyncService
|
|||
|
|
{
|
|||
|
|
public partial class DBSyncService : ServiceBase
|
|||
|
|
{
|
|||
|
|
public DBSyncService()
|
|||
|
|
{
|
|||
|
|
InitializeComponent();
|
|||
|
|
if (!EventLog.SourceExists(Settings.Default.ServiceName)) { EventLog.CreateEventSource(Settings.Default.ServiceName, Settings.Default.Service); }
|
|||
|
|
eventLog.Source = Settings.Default.ServiceName;
|
|||
|
|
eventLog.Log = Settings.Default.Service;
|
|||
|
|
if (!Settings.Default.Monitoring) return;
|
|||
|
|
var timer = new Timer { Interval = Settings.Default.Interval }; // default - 60 seconds
|
|||
|
|
timer.Elapsed += OnTimer;
|
|||
|
|
timer.Start();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void OnTimer(object sender, ElapsedEventArgs args)
|
|||
|
|
{
|
|||
|
|
// TODO: Insert monitoring activities here.
|
|||
|
|
eventLog.WriteEntry("Monitoring the System", EventLogEntryType.Information);
|
|||
|
|
}
|
|||
|
|
protected override void OnStart(string[] args)
|
|||
|
|
{
|
|||
|
|
eventLog.WriteEntry(Settings.Default.ServiceName + " started", EventLogEntryType.Information);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
protected override void OnStop()
|
|||
|
|
{
|
|||
|
|
eventLog.WriteEntry(Settings.Default.ServiceName + " stopped", EventLogEntryType.Information);
|
|||
|
|
}
|
|||
|
|
public enum CustomCommands { SyncDb = 128, Command2 = 129, Command3 = 130 }
|
|||
|
|
protected override void OnCustomCommand(int command)
|
|||
|
|
{
|
|||
|
|
base.OnCustomCommand(command);
|
|||
|
|
switch (command)
|
|||
|
|
{
|
|||
|
|
case (int)CustomCommands.SyncDb:
|
|||
|
|
break;
|
|||
|
|
case (int)CustomCommands.Command2:
|
|||
|
|
break;
|
|||
|
|
case (int)CustomCommands.Command3:
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|