Exemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ImageService"/> class.
        /// </summary>
        /// <param name="args">The arguments.</param>
        public ImageService(string[] args)
        {
            InitializeComponent();
            string eventSourceName = "MySource1";
            string logName         = "MyLogFile1";

            if (args.Count() > 0)
            {
                eventSourceName = args[0];
            }
            if (args.Count() > 1)
            {
                logName = args[1];
            }
            eventLog1 = new System.Diagnostics.EventLog();
            if (!System.Diagnostics.EventLog.SourceExists(eventSourceName))
            {
                System.Diagnostics.EventLog.CreateEventSource(eventSourceName, logName);
            }
            eventLog1.Source = ConfigurationManager.AppSettings.Get("SourceName");
            eventLog1.Log    = ConfigurationManager.AppSettings.Get("LogName");
            EventHandler <MessageRecievedEventArgs> MessageRecieved = new EventHandler <MessageRecievedEventArgs>(onMsg);

            this.logging = new LoggingService(MessageRecieved);
            IImageController controller = new ImageController(new ImageServiceModal(this.logging), this.logging);

            this.server = new ImageServer(controller, this.logging);
            controller.setServer(server);
            ClientHandler clientHandler = new ClientHandler(controller, logging);
            TcpServer     tcpServer     = new TcpServer(logging, clientHandler, 8000);

            LoggingService.NotifyLogEntry    += tcpServer.NotifyAllClients;
            ImageServer.NotifyHandlerRemoved += tcpServer.NotifyAllClients;
            ImageServer.NotifyCloseGui       += tcpServer.NotifyAllClients;
            ImageServer.NotifyCloseGui       += tcpServer.CallRemoveClient;
            tcpServer.Start();
        }
Exemplo n.º 2
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);
        }