diff --git a/TimberWinR.ServiceHost/Program.cs b/TimberWinR.ServiceHost/Program.cs index e3880ff..be15a7b 100644 --- a/TimberWinR.ServiceHost/Program.cs +++ b/TimberWinR.ServiceHost/Program.cs @@ -1,10 +1,17 @@ using System; using System.Collections.Generic; using System.Linq; + using System.Text; using System.Threading; using System.Threading.Tasks; +using TimberWinR.Outputs; +using TimberWinR.ServiceHost; +using TimberWinR.Inputs; + using Topshelf; +using Topshelf.HostConfigurators; +using Topshelf.ServiceConfigurators; namespace TimberWinR.ServiceHost { @@ -12,17 +19,25 @@ namespace TimberWinR.ServiceHost { private static void Main(string[] args) { + Arguments arguments = new Arguments(); + HostFactory.Run(hostConfigurator => - { + { + string cmdLine = Environment.CommandLine; + hostConfigurator.Service(serviceConfigurator => { - serviceConfigurator.ConstructUsing(() => new TimberWinRService()); + serviceConfigurator.ConstructUsing(() => new TimberWinRService(arguments)); serviceConfigurator.WhenStarted(myService => myService.Start()); serviceConfigurator.WhenStopped(myService => myService.Stop()); }); - hostConfigurator.RunAsLocalSystem(); + hostConfigurator.AddCommandLineDefinition("configFile", c => arguments.ConfigFile = c); + hostConfigurator.ApplyCommandLine(); + hostConfigurator.RunAsLocalSystem(); + hostConfigurator.StartAutomatically(); + hostConfigurator.EnableShutdown(); hostConfigurator.SetDisplayName("TimberWinR"); hostConfigurator.SetDescription("TimberWinR using Topshelf"); hostConfigurator.SetServiceName("TimberWinR"); @@ -30,58 +45,60 @@ namespace TimberWinR.ServiceHost } } + internal class Arguments + { + public string ConfigFile { get; set; } + + public Arguments() + { + ConfigFile = string.Empty; + } + } + + internal class TimberWinRService { readonly CancellationTokenSource _cancellationTokenSource; readonly CancellationToken _cancellationToken; - readonly Task _task; + readonly Task _serviceTask; + + private readonly TcpInputListener _nlogListener; - public TimberWinRService() + public TimberWinRService(Arguments args) { _cancellationTokenSource = new CancellationTokenSource(); _cancellationToken = _cancellationTokenSource.Token; - _task = new Task(RunService, _cancellationToken); - + _serviceTask = new Task(RunService, _cancellationToken); + + _nlogListener = new TcpInputListener(_cancellationToken, 5140); + var outputRedis = new RedisOutput(new string[] { "tstlexiceapp006.vistaprint.svc", "tstlexiceapp007.vistaprint.svc" }, _cancellationToken); + outputRedis.Connect(_nlogListener); } public void Start() { - _task.Start(); + _serviceTask.Start(); } public void Stop() { _cancellationTokenSource.Cancel(); + _nlogListener.Shutdown(); } - + /// /// The Main body of the Service Worker Thread /// private void RunService() { + TimberWinR.Manager manager = new TimberWinR.Manager(); + while (!_cancellationTokenSource.IsCancellationRequested) { Console.WriteLine("I am working"); - - Console.WriteLine(" Step 1"); - System.Threading.Thread.Sleep(1000); - - Console.WriteLine(" Step 2"); - System.Threading.Thread.Sleep(1000); - - Console.WriteLine(" Step 3"); - System.Threading.Thread.Sleep(1000); - - Console.WriteLine(" Step 4"); - System.Threading.Thread.Sleep(1000); - - Console.WriteLine(" Step 5"); - System.Threading.Thread.Sleep(1000); - + System.Threading.Thread.Sleep(1000); } - } - } } diff --git a/TimberWinR.ServiceHost/TimberWinR.ServiceHost.csproj b/TimberWinR.ServiceHost/TimberWinR.ServiceHost.csproj index 2484e91..ef66fe9 100644 --- a/TimberWinR.ServiceHost/TimberWinR.ServiceHost.csproj +++ b/TimberWinR.ServiceHost/TimberWinR.ServiceHost.csproj @@ -51,6 +51,12 @@ + + + {4ef96a08-21db-4178-be44-70dae594632c} + TimberWinR + +