Ejemplo n.º 1
0
        /// <summary>
        /// When we start the service this method is called.
        /// </summary>
        /// <param name="args">Arguments</param>
        protected override void OnStart(string[] args)
        {
            //Log for start
            eventLog1.WriteEntry("In OnStart", EventLogEntryType.Information, this.eventId);
            this.logs.AddLog(new Log((int)MessageTypeEnum.INFO, "In OnStart"));
            // 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);


            // Update the service state to Running.
            serviceStatus.dwCurrentState = ServiceState.SERVICE_RUNNING;
            SetServiceStatus(this.ServiceHandle, ref serviceStatus);

            //The logging service we made
            logging = new LoggingService();
            //Creating the log collection
            LogCollection logs = new LogCollection();

            //  tcpServer = TcpServer.GetInstance(8000, new AndroidHandler());
            androidServer = TcpServer.GetInstance(9222, new AndroidHandler());
            // Adding functions to the event when we get new log
            logging.MessageRecieved += OnMsg;
            //    logging.MessageRecieved += logs.AddLog;
            logging.MessageRecieved += SendLogToClients;

            //Creating our all system members - the model server and controller
            this.modal = new ImageServiceModal();
            //We will create the controller
            this.controller = new ImageController(this.modal);

            //  tcpServer.ExcecuteCommand += controller.ExecuteCommand;
            //The server is in task because we want it background
            //   Task t = new Task(tcpServer.Start);
            Task t = new Task(androidServer.Start);

            t.Start();
            this.m_imageServer = new ImageServer(this.controller, this.logging);
            Configure configs = Configure.GetInstance();

            handlers = new Dictionary <string, IDirectoryHandler>();
            //Creating the handlers to each folder than configured in the app config.
            foreach (string handler in configs.AllHandlers)
            {
                IDirectoryHandler h = m_imageServer.createHandler(handler);

                if (h != null)
                {
                    Console.WriteLine("Adding the handler " + handler);
                    handlers.Add(handler, h);
                }
            }
            //Adding to the controller the command of close command
            controller.AddCommand += AddCloseCommand;
            controller.AddCommand += AddLogCommand;
            controller.AddAditionalCommands((int)CommandEnum.CloseCommand);
            //Adding the log comand
            controller.AddAditionalCommands((int)CommandEnum.LogCommand);
        }