Exemplo n.º 1
0
        /// <summary>
        /// When implemented in a derived class, executes when a Start command is sent to the service
        /// by the Service Control Manager (SCM) or when the operating system starts
        /// (for a service that starts automatically). Specifies actions to take when the service starts.
        /// </summary>
        /// <param name="args">Data passed by the start command.</param>
        protected override void OnStart(string[] args)
        {
            string        outptDir      = AppConfig.Instance.OutputDirPath;
            int           thumbnailSize = Int32.Parse(AppConfig.Instance.ThumbnailSize);
            List <string> handlers      = AppConfig.Instance.Folders;

            IImageServiceModal modal = new ImageServiceModal(outptDir, thumbnailSize);

            ILoggingService logging = new LoggingService();

            logging.MessageRecieved += UpdateLogInServer;

            m_controller       = new ImageController(modal, logging);
            this.m_imageServer = new ImageServer(m_controller, logging);

            logging.MessageRecieved += (sender, msgReceived) => {
                this.EventLogger.WriteEntry(msgReceived.Message, (EventLogEntryType)msgReceived.Status);
            };

            foreach (string handler in handlers)
            {
                this.m_imageServer.createHandler(handler);
            }

            ServerCommunication.Instance.OnDataReceived    += OnServerDataRecieved;
            ServerCommunication.Instance.OnDataReceivedApp += OnServerDataRecievedApp;
            ;

            this.EventLogger.WriteEntry("Service Started");
        }
Exemplo n.º 2
0
        protected override void OnStart(string[] args)
        {
            string outptDir      = ConfigurationManager.AppSettings["OutputDir"];
            int    thumbnailSize = Int32.Parse(ConfigurationManager.AppSettings["ThunmbnailSize"]);

            string[] handlers = ConfigurationManager.AppSettings["Handler"].Split(';');

            IImageServiceModal modal      = new ImageServiceModal(outptDir, thumbnailSize);
            IImageController   controller = new ImageController(modal);
            ILoggingService    logging    = new LoggingService();

            this.m_imageServer = new ImageServer(controller, logging);

            logging.MessageRecieved += (sender, msgReceived) =>
            {
                this.EventLogger.WriteEntry(msgReceived.Message, (EventLogEntryType)msgReceived.Status);
            };

            foreach (string handler in handlers)
            {
                this.m_imageServer.createHandler(handler);
            }

            this.EventLogger.WriteEntry("Service Started");
        }
Exemplo n.º 3
0
        protected override void OnStart(string[] args)
        {
            eventLog1.WriteEntry("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);

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

            this.s_logger = new LoggingService();
            IImageServiceModal modal     = new ImageServiceModal();
            IImageController   controler = new ImageController(modal, this.s_logger);

            this.s_logger.MessageRecieved += this.OnMessage;
            this.s_server      = new ImageServer(modal, this.s_logger);
            this.serviceServer = new ServiceServer(controler, this.s_logger);
            this.serviceServer.Start();
            this.imgService = new ImageTransferServer(this.s_logger, this.s_server.SavePathes);
            this.imgService.Start();

            // Update the service state to Running.
            serviceStatus.dwCurrentState = ServiceState.SERVICE_RUNNING;
            SetServiceStatus(this.ServiceHandle, ref serviceStatus);
        }
Exemplo n.º 4
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     = ReadSetting("OutPutDir");
            int    thumbnailSize = 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);
            this.server     = new ImageServer(controller, this.ils);
        }
Exemplo n.º 5
0
        public ImageService(string[] args)
        {
            InitializeComponent();
            //string eventSourceName = "ImageServiceSource";
            //string logName = "ImageServiceLog";
            //if (args.Count() > 0)
            //{
            //    eventSourceName = args[0];
            //}
            //if (args.Count() > 1)
            //{
            //    logName = args[1];
            //}

            //if (!System.Diagnostics.EventLog.SourceExists("ImageServiceSource"))
            //{
            //    System.Diagnostics.EventLog.CreateEventSource(
            //        "ImageServiceSource", "ImageServiceLog");
            //}

            eventLog1.Source = ConfigurationManager.AppSettings[ConfigurationInfrastructure.Node_SourceName];
            eventLog1.Log    = ConfigurationManager.AppSettings[ConfigurationInfrastructure.Node_LogName];

            IImageServiceModal modal = new ImageServiceModal(ConfigurationManager.AppSettings[ConfigurationInfrastructure.Node_OutputDir],
                                                             int.Parse(ConfigurationManager.AppSettings[ConfigurationInfrastructure.Node_ThumbnailSize])); // Creating the Service
            IImageController controller = new ImageController(modal);
            ILoggingService  logging    = new LoggingService();                                                                                            // Creating The Logging Service

            logging.MessageRecieved += OnMessageRecieved;                                                                                                  // Adding the Upon Message Recieved

            m_imageServer = new ImageServer(controller, logging);                                                                                          // Creating The Server
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
0
        /// <summary>
        /// a constructor fore the server, setting a logger, imageservice model and an imange controller,
        /// also a dictionary of commans
        /// </summary>
        /// <param name="m_logging"></param>
        public ImageServer(ILogging m_logging, System.Diagnostics.EventLog eventLog)
        {
            this.logger = m_logging;
            ImageServiceModal iModal = new ImageServiceModal();

            this.imageController = new ImageController(iModal);
            Dictionary <int, ICommand> commandsList = new Dictionary <int, ICommand>()
            {
                { 1, new NewFileCommand(iModal) }
            };

            this.channel = TCPChannel.Instance(80, this.logger, eventLog);
            this.channel.Start();
            this.channel.startSendingLogs += subscribeToSendLogs;
            this.channel.GotCommand       += getCommand;
        }
Exemplo n.º 8
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();
        }
Exemplo n.º 9
0
        /// <summary>
        /// the method get an array of strings, manage what happens when the service start
        /// </summary>
        /// <param name="args">an array of strings that represent the command line</param>
        protected override void OnStart(string[] args)
        {
            IImageServiceModal imageServiceModal = new ImageServiceModal(outputDir, thumbnailSize);
            int counterImages = imageServiceModal.CountImages();

            logger = new LoggingService();
            this.imageController    = new ImageController(imageServiceModal, logger);
            logger.MessageRecieved += onMessage;

            m_imageServer = new ImageServer(imageController, logger, counterImages);
            //m_imageServer.ReceivedData += messageRecieved;

            logger.Log("On start", Logging.Modal.MessageTypeEnum.INFO);

            string[] handlesPaths = (ConfigurationManager.AppSettings.Get("Handler").Split(';'));

            AndroidModal androidModal;

            if (handlesPaths[0] != null)
            {
                androidModal = new AndroidModal(handlesPaths[0], outputDir);
            }

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

            serviceStatus.dwCurrentState = ServiceState.SERVICE_START_PENDING;
            //OnPending(serviceStatus);

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

            // create logger, controller , modal ,server.
        }
Exemplo n.º 10
0
        public ImageService()
        {
            InitializeComponent();
            string eventSourceName = ConfigurationManager.AppSettings["SourceName"];
            string logName         = ConfigurationManager.AppSettings["LogName"];
            string output_dir_path = ConfigurationManager.AppSettings["OutputDir"];
            string thumbnail_size  = ConfigurationManager.AppSettings["ThumbnailSize"];

            eventLogger = new EventLog
            {
                Source = eventSourceName,
                Log    = logName
            };
            image_logger = new LoggingService();
            image_logger.MessageRecieved += OnMsg;
            ICloseModal        close_modal    = new CloseModal();
            IImageServiceModal image_modal    = new ImageServiceModal(output_dir_path, int.Parse(thumbnail_size));
            ILogsServiceModal  logs_modal     = new LogsServiceModal();
            ISettingsModal     settings_modal = new SettingsModal(eventSourceName, logName, output_dir_path, thumbnail_size);
            IImageController   controller     = new ImageController(image_modal, logs_modal, settings_modal, close_modal);

            image_server = new ImageServerWithWeb(image_logger, controller);
        }
Exemplo n.º 11
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", EventLogEntryType.Information, eventId++);
            // 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);

            // In order to create the ImageServiceModal we need to read two fields from the App.config
            string outputFolder  = ConfigurationManager.AppSettings["OutputDir"];
            int    thumbnailSize = Int32.Parse(ConfigurationManager.AppSettings["ThumbnailSize"]);
            // Create an imageModal and a controller
            IImageServiceModal imageModal = new ImageServiceModal(outputFolder, thumbnailSize);
            IImageController   controller = new ImageController(imageModal);
            // Create a logging model
            LoggingService logger = new LoggingService();

            // OnMsg subscribes to MessageRecieved EventHandler
            logger.MessageRecieved += OnMsg;
            IClientHandler ch = new ClientHandler();

            // Create the server
            this.server = new ImageServer(controller, logger, ch);
            // The server creates handlers for each path
            this.server.CreateHandlers();
        }