init
This commit is contained in:
53
Common/DTS.Common.DBSyncService/DBSyncService.cs
Normal file
53
Common/DTS.Common.DBSyncService/DBSyncService.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user