예제 #1
0
 /// <summary>
 /// request a new instance of the class.
 /// </summary>
 /// <return> returns the instance of the object (singleton) </return>
 public static LogHistory CreateLogHistory()
 {
     // if not already created
     if (logHistory == null)
     {
         logHistory = new LogHistory();
     }
     // otherwise create new instance
     return(logHistory);
 }
예제 #2
0
        /// <summary>
        /// the function that runs when the service starts
        /// </summary>
        protected override void OnStart(string[] args)
        {
            // service info class (singelton)
            ServiceInfo info = ServiceInfo.CreateServiceInfo();

            // log history class (singelton)
            history = LogHistory.CreateLogHistory();
            // create the service model
            IImageServiceModal model = new ImageServiceModal(info.OutputDir, info.ThumbnailSize);
            // create the services servers
            ImageController controller = new ImageController(model);

            // create image server
            server = new ImageServer(controller, logger);
            // create tcp server
            //tcpServer = new TcpServer(controller, logger);
            // create TcpApplicationServer
            tcpApplicationServer = new TcpApplicationServer(logger);
            // start the tcp server
            string[] str = { };
            //tcpServer.Start(str);
            // start the image server
            server.Start(info.Handlers.ToArray());
            // start the application server
            tcpApplicationServer.Start(str);
            controller.HandlerClosedEvent += server.CloseHandler;
            //logger.NotifyClients += tcpServer.NotifyClients;
            //server.NotifyClients += tcpServer.NotifyClients;
            //tcpServer.CommandRecieved += server.NewCommand;
            logger.MessageRecieved += ImageServiceMessage;
            logger.MessageRecieved += history.UpdateLog;
            //logger.MessageRecieved += tcpServer.NewLog;


            // Update the service state to Start Pending.
            ServiceStatus serviceStatus = new ServiceStatus();

            serviceStatus.dwCurrentState = ServiceState.SERVICE_START_PENDING;
            serviceStatus.dwWaitHint     = 100000;
            SetServiceStatus(this.ServiceHandle, ref serviceStatus);

            logger.Log("In OnStart", MessageTypeEnum.INFO);
            // Set up a timer to trigger every minute.
            System.Timers.Timer timer = new System.Timers.Timer();
            timer.Interval = 60000; // 60 seconds
            timer.Elapsed += new System.Timers.ElapsedEventHandler(this.OnTimer);
            timer.Start();

            // Update the service state to Running.
            serviceStatus.dwCurrentState = ServiceState.SERVICE_RUNNING;
            SetServiceStatus(this.ServiceHandle, ref serviceStatus);
        }
예제 #3
0
        /// <summary>
        /// the function that runs when the service stops
        /// </summary>
        protected override void OnStop()
        {
            // write to the log
            logger.Log("In onStop", MessageTypeEnum.INFO);
            LogHistory logHistory = LogHistory.CreateLogHistory();

            // close the image server
            server.Stop();
            // close the tcp server
            //tcpServer.Stop();
            // close the application server
            tcpApplicationServer.Stop();
            logger.MessageRecieved -= ImageServiceMessage;
            //logger.NotifyClients -= tcpServer.NotifyClients;
            logger.MessageRecieved -= logHistory.UpdateLog;
            logger.MessageRecieved -= history.UpdateLog;
            //logger.MessageRecieved += tcpServer.NewLog;
            //server.NotifyClients -= tcpServer.NotifyClients;
            logHistory.ResetLog();
            logger.Log("In onStop", MessageTypeEnum.INFO);
        }