Added RedisOutput and TcpListener
This commit is contained in:
@@ -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<TimberWinRService>(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();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The Main body of the Service Worker Thread
|
||||
/// </summary>
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user