Ejemplo n.º 1
0
        //this function is called when the service begins.
        protected override void OnStart(string[] args)
        {
            eventLog1.WriteEntry("In OnStart");
            //creating logging service to send messages to the log
            this.ils = new LoggingService();
            //every time the logger receives a message MessageRecieved is invoked and onmsg function in this class is called
            this.ils.MessageRecieved += this.OnMsg;
            string outputDir     = ReadAppConfig.ReadSetting("OutPutDir");
            int    thumbnailSize = ReadAppConfig.ReadThumbnailSize("ThumbnailSize");

            if (thumbnailSize == -1) //in case of failed conversion to an int
            {
                thumbnailSize = 120;
                eventLog1.WriteEntry("warning: parsing failed, sets thumbnailsize to 120");
            }
            else
            {
                eventLog1.WriteEntry("Thumbnail size has been read successfuly");
            }
            //creating image model (thumbail size should be taken from app.config file)
            this.modal = new ImageServiceModal(outputDir, thumbnailSize);
            eventLog1.WriteEntry("output dir is: " + outputDir);
            //creating the controller and the server.
            this.controller    = new ImageController(modal, ils);
            this.server        = new ImageServer(this.controller, this.ils);
            this.server.Close += OnServerClose;
            this.controller.addServer(this.server);
            this.cServer              = new ComunicationServer(8000, this.controller);
            this.ils.MessageRecieved += delegate(object sender, MessageRecievedEventArgs e)
            {
                string[] logArgs = { e.Status.ToString(), e.Message };
                this.cServer.SendCommandToAllClients((int)CommandsEnum.LogCommand, logArgs);
            };

            this.cServer.Start();
            ITCPHandler tcpClientHandler = new TCPHandler(controller, ils);
            ITCPServer  tcpServer        = new TCPServer(8001, ils, tcpClientHandler);

            tcpServer.Start();
            this.imageServer = new TCPServer(8001, ils, new TCPHandler(this.controller, ils));
            this.imageServer.Start();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// This function is called when the service starts.
        /// The functions initialized the sercice components and starts listning to the folders.
        /// </summary>
        /// <param name="args"></param>
        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);

            // What the function really does
            string sourceDirectoriesKey = "Handler";
            string outPutDirKey         = "OutputDir";
            string logSourceNameKey     = "SourceName";
            string logNameKey           = "LogName";
            string thumbnailSizeKey     = "ThumbnailSize";

            // Define the evant log, messages from this application will be writeen to.
            eventLog1 = new System.Diagnostics.EventLog();
            if (!System.Diagnostics.EventLog.SourceExists(this.getAppConfigValue(logSourceNameKey)))
            {
                System.Diagnostics.EventLog.CreateEventSource(
                    this.getAppConfigValue(logSourceNameKey), this.getAppConfigValue(logNameKey));
            }
            eventLog1.Source = this.getAppConfigValue(logSourceNameKey);
            eventLog1.Log    = this.getAppConfigValue(logNameKey);

            // Defime the service's timer
            this.timer          = new System.Timers.Timer();
            this.timer.Interval = 60000; // 60 seconds
            this.timer.Elapsed += new System.Timers.ElapsedEventHandler(this.OnTimer);

            // Define the logger
            this.logging = new LoggingService();
            // Regidter the the logging model event o when a part of the program
            // send a request to the logging model in order to write a log.
            // the funtion writeLog will be invoked and it will write the massage to the event viewer.
            this.logging.MessageRecieved += this.writeLog;

            // Define the logging buffer helps to send logs to the clients
            LogingBuffer logsBuffer = new LogingBuffer();

            this.logging.MessageRecieved += logsBuffer.AddLog;

            // Define the ImageModel
            int size = int.Parse(this.getAppConfigValue(thumbnailSizeKey));

            this.modal = new ImageServiceModal(this.getAppConfigValue(outPutDirKey), size);

            // Define the controler
            this.controller = new ImageController(this.modal, logsBuffer, logging);

            // Define the ClientsManagget that will manage the coimunication with the diffrent clients.
            ClientsManager managger = new ClientsManager(this.controller, this.logging);

            // Define the cominication server
            this.comServer = new ComunicationServer("127.0.0.1", 8000, managger, this.logging);

            // Define the server
            string directories = this.getAppConfigValue(sourceDirectoriesKey);

            string[] directoryArray = directories.Split(';');
            this.m_imageServer = new ImageServer(this.logging, this.controller, directoryArray, comServer, managger);

            eventLog1.WriteEntry("In OnStart");
            this.timer.Start();

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