Пример #1
0
        protected override void OnStart(string[] args)
        {
            // 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);

            eventLog1.WriteEntry("In OnStart");

            // 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);


            //creating the server.
            int    thumbnailSize = int.Parse(AppConfigReader.Instance.GetValueByKey("ThumbnailSize"));
            string outputDir     = AppConfigReader.Instance.GetValueByKey("OutputDir");

            string handler = AppConfigReader.Instance.GetValueByKey("Handler");

            string[] handlerDirs = { handler };
            if (handler.Contains(";"))
            {
                handlerDirs = AppConfigReader.Instance.GetValueByKey("Handler").Split(';');
            }

            LoggingService logger = new LoggingService();

            logger.MessageRecieved += LogWriteEntry;

            Logger logs = new Logger();

            logger.MessageRecieved += logs.addLog;

            ImageController imageController = new ImageController(new ImageServiceModal(outputDir, thumbnailSize), logs);
            List <string>   dirsList        = new List <string>(handlerDirs);
            ImageServer     server          = new ImageServer(imageController, logger, dirsList);

            server.CreateHandlers();

            CloseService += delegate
            {
                server.OnCloseServer(this, EventArgs.Empty);
            };
            imageController.setHandlers(server.getHandlers());

            ClientHandler ch = new ClientHandler();

            ch.executeCommand += imageController.ExecuteCommand;
            TCPServer tcpserver = new TCPServer("127.0.0.1", 8000, ch);

            tcpserver.Start();

            logger.Log("Server started", MessageTypeEnum.INFO);
        }