MiddlewareService.cs 1.53 KB
Newer Older
Vaclav Svaton's avatar
Vaclav Svaton committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
using System;
using System.ServiceProcess;
using HaaSMiddleware.BackgroundThread;
using HaaSMiddleware.ServiceTier.EtchProxy;
using log4net.Config;
using log4net;
using Org.Apache.Etch.Bindings.Csharp.Support;
using Org.Apache.Etch.Bindings.Csharp.Util;
using org.apache.etch.EtchServiceTier;

namespace HaaSMiddleware.MiddlewareService
{
	public partial class MiddlewareService : ServiceBase
	{
		private readonly MiddlewareBackgroundTaskRunner timer;
		private readonly ServerFactory listener;
		private ILog log;

        private const string URI = "tls://dhirelease.it4i.cz:4001?TlsConnection.certName=dhirelease.it4i.cz&Packetizer.maxPktSize=0";
		//private const string URI = "tls://haasdhi.it4i.cz:4001?TlsConnection.certName=haasdhi.it4i.cz&Packetizer.maxPktSize=0";
		//private const string URI = "tcp://localhost:4001";
		
		public MiddlewareService()
		{
			// Logging setup
			XmlConfigurator.Configure();
			this.log = LogManager.GetLogger("MiddlewareService Main");
			InitializeComponent();
			this.timer = new MiddlewareBackgroundTaskRunner();
			this.listener = EtchServiceTierHelper.NewListener(URI, null, new ServiceTierServerFactory());
		}

		protected override void OnStart(string[] args)
		{
			log.Info("Service starting...");
			// Timer start
			timer.Start();
			// Etch setup
			// Start the Listener
			listener.TransportControl(TransportConsts.START_AND_WAIT_UP, 4000);
			log.Info("Service started and listening.");
		}

		protected override void OnStop()
		{
			// Stop timer
			timer.Stop();
			log.Info("Service stopped.");
		}
	}
}