コード例 #1
0
ファイル: ImageService.cs プロジェクト: yuvalw11/Reversi-Gui
        //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);
        }
コード例 #2
0
ファイル: ImageService.cs プロジェクト: giladmadmon/image_ex1
        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");
        }
コード例 #3
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)
 {
     // Update the service state to Start Pending.
     try
     {
         Thread.Sleep(10000);
         ServiceStatus serviceStatus = new ServiceStatus();
         serviceStatus.dwCurrentState = ServiceState.SERVICE_START_PENDING;
         serviceStatus.dwWaitHint     = 100000;
         SetServiceStatus(this.ServiceHandle, ref serviceStatus);
         eventLog1.WriteEntry("In OnStart");
         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
         IImageServiceModel serviceModel = new ImageServiceModel(outputDir, Int32.Parse(thumbnailSize));
         IImageController   m_controller = new ImageController(serviceModel);
         server = new ImageServer(m_logging, m_controller, outputDir, Int32.Parse(thumbnailSize), handler);
         m_controller.Server = server;
         //IServerConnection connection = new ServerConnection(m_controller, m_logging, 8600);
         AndroidConnection androidConnection = new AndroidConnection(m_logging, 8600);
     }
     catch (Exception e)
     {
         this.m_logging.Log(e.ToString(), MessageTypeEnum.FAIL);
     }
 }
コード例 #4
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);
        }
コード例 #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
        }
コード例 #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);
        }
コード例 #7
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();
        }
コード例 #8
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.
        }
コード例 #9
0
ファイル: ImageService.cs プロジェクト: Ofir408/MyProjects
        public ImageService()
        {
            InitializeComponent();

            // fetch source and log name from app configuration
            eventLog.Source = AppConfig.Instance.SourceName;
            eventLog.Log    = AppConfig.Instance.LogName;
            // if log doesnt exist, create it
            if (!System.Diagnostics.EventLog.SourceExists(eventLog.Source))
            {
                System.Diagnostics.EventLog.CreateEventSource(eventLog.Source, eventLog.Log);
            }


            // creates logger, imagecontroller, imageModel and ImageServer:
            logger = new LoggingModel();
            logger.MessageRecieved += LogEntry; //assign LogEntry to the logger event
            IImageController imgController = new ImageController(new ImageServiceModel(
                                                                     AppConfig.Instance.OutputDir, AppConfig.Instance.ThumbnailSize));
            List <string> paths = AppConfig.Instance.ListeningFolders;

            imgServer = new ImageServer(paths, imgController, logger);
        }
コード例 #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);
        }
コード例 #11
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();
        }
コード例 #12
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();
        }
コード例 #13
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);
        }