From 0b489cc927a93f9307b866086d632f90783cf010 Mon Sep 17 00:00:00 2001 From: Eric Fontana Date: Wed, 16 Jul 2014 12:43:17 -0400 Subject: [PATCH] Added RedisOutput and TcpListener --- TimberWinR.ServiceHost/Program.cs | 71 +- .../TimberWinR.ServiceHost.csproj | 6 + TimberWinR/Class1.cs | 12 - TimberWinR/Inputs/InputListener.cs | 25 + TimberWinR/Inputs/TcpInputListener.cs | 90 + TimberWinR/Inputs/TextLine.cs | 19 + TimberWinR/Manager.cs | 64 + TimberWinR/Outputs/OutputSender.cs | 28 + TimberWinR/Outputs/Redis.cs | 143 + TimberWinR/TimberWinR.csproj | 15 +- TimberWinR/packages.config | 2 +- .../csredis.1.4.7.1/csredis.1.4.7.1.nupkg | Bin 0 -> 46345 bytes .../csredis.1.4.7.1/lib/net40/csredis.XML | 2515 +++++++++++++++++ .../csredis.1.4.7.1/lib/net40/csredis.dll | Bin 0 -> 80896 bytes 14 files changed, 2945 insertions(+), 45 deletions(-) delete mode 100644 TimberWinR/Class1.cs create mode 100644 TimberWinR/Inputs/InputListener.cs create mode 100644 TimberWinR/Inputs/TcpInputListener.cs create mode 100644 TimberWinR/Inputs/TextLine.cs create mode 100644 TimberWinR/Manager.cs create mode 100644 TimberWinR/Outputs/OutputSender.cs create mode 100644 TimberWinR/Outputs/Redis.cs create mode 100644 packages/csredis.1.4.7.1/csredis.1.4.7.1.nupkg create mode 100644 packages/csredis.1.4.7.1/lib/net40/csredis.XML create mode 100644 packages/csredis.1.4.7.1/lib/net40/csredis.dll 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 + +