mirror of
https://github.com/ckaczor/WeatherService.git
synced 2026-01-13 17:23:11 -05:00
Initial commit
This commit is contained in:
61
Program.cs
Normal file
61
Program.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using Common.Debug;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.ServiceProcess;
|
||||
using WeatherService.Framework;
|
||||
|
||||
namespace WeatherService
|
||||
{
|
||||
static class Program
|
||||
{
|
||||
public static Session Session { get; set;}
|
||||
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Tracer.Initialize(@"C:\WeatherCenter\Logs", "WeatherService", Process.GetCurrentProcess().Id.ToString(), Environment.UserInteractive);
|
||||
|
||||
if (args.Contains("-install", StringComparer.InvariantCultureIgnoreCase))
|
||||
{
|
||||
Tracer.WriteLine("Starting install...");
|
||||
|
||||
try
|
||||
{
|
||||
WindowsServiceInstaller.RuntimeInstall<ServiceImplementation>();
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Tracer.WriteException("Service install", exception);
|
||||
}
|
||||
|
||||
Tracer.WriteLine("Install complete");
|
||||
}
|
||||
else if (args.Contains("-uninstall", StringComparer.InvariantCultureIgnoreCase))
|
||||
{
|
||||
Tracer.WriteLine("Starting uninstall...");
|
||||
|
||||
try
|
||||
{
|
||||
WindowsServiceInstaller.RuntimeUnInstall<ServiceImplementation>();
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Tracer.WriteException("Service uninstall", exception);
|
||||
}
|
||||
|
||||
Tracer.WriteLine("Uninstall complete");
|
||||
}
|
||||
else
|
||||
{
|
||||
Tracer.WriteLine("Starting service");
|
||||
|
||||
var implementation = new ServiceImplementation();
|
||||
|
||||
if (Environment.UserInteractive)
|
||||
ConsoleHarness.Run(args, implementation);
|
||||
else
|
||||
ServiceBase.Run(new WindowsServiceHarness(implementation));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user