Exemple #1
0
        /// <summary>
        /// start function of the service:
        /// -    creats output directory
        /// -    creats server, modal, conntroler and logger.
        /// </summary>
        /// <param name="args">arguments</param>
        protected override void OnStart(string[] args)
        {
            this.m_logging = new LoggingService();
            this.m_logging.AddEvent(OnMsg);
            m_logging.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();
            timer.Enabled = true;
            // 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);

            string outputFolder  = CreateOutputDirFolder();
            int    thumbnailSize = int.Parse(ConfigurationManager.AppSettings["ThumbnailSize"]);

            this.m_modal      = new ImageServiceModal(outputFolder, thumbnailSize);
            this.m_controller = new ImageController(this.m_modal);

            Console.WriteLine("creating Server");
            this.m_imageServer = new ImageServer(this.m_controller, this.m_logging);
            this.m_imageServer.Start();
        }
Exemple #2
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);
        }
        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");
        }
        public ImageService(string[] args)
        {
            InitializeComponent();
            string eventSourceName = ConfigurationManager.AppSettings.Get("SourceName");
            string logName         = ConfigurationManager.AppSettings.Get("LogName");

            eventLog1 = new System.Diagnostics.EventLog();
            if (!System.Diagnostics.EventLog.SourceExists(eventSourceName))
            {
                System.Diagnostics.EventLog.CreateEventSource(eventSourceName, logName);
            }
            eventLog1.Source = eventSourceName;
            eventLog1.Log    = logName;

            //initialize the members
            this.modal = new ImageServiceModal()
            {
                OutputFolder  = ConfigurationManager.AppSettings.Get("OutputDir"),
                thumbnailSize = Int32.Parse(ConfigurationManager.AppSettings.Get("ThumbnailSize"))
            };
            this.controller = new ImageController(this.modal);
            this.logging    = new LoggingService();
            this.logging.MessageRecieved += this.WriteMessage;
            string[] directories = (ConfigurationManager.AppSettings.Get("Handler").Split(';'));
            this.imageServer = new ImageServer(this.controller, this.logging, directories, directories.Length);
        }
Exemple #5
0
        /// <summary>
        /// ImageService Constructor.
        /// </summary>
        /// <param name="args"></param>
        public ImageService(string[] args)
        {
            // init components (eventLog)
            InitializeComponent();
            AppConfigParser appConfigParser = new AppConfigParser();


            if (!EventLog.SourceExists(appConfigParser.LogName))
            {
                EventLog.CreateEventSource(
                    appConfigParser.SourceName, appConfigParser.LogName);
            }
            // assign parameters to log after init
            eventLog.Source = appConfigParser.SourceName;
            eventLog.Log    = appConfigParser.LogName;

            // init image model
            IImageServiceModel imageServiceModel = new ImageServiceModel(appConfigParser.OutputDirectory, appConfigParser.ThumbnailSize);

            // init loggingModel
            ILoggingService loggingModel = new LoggingService();

            // subscribe our main Service to the LoggingService
            loggingModel.MessageRecieved += OnMsg;

            this.imageServer = new ImageServer(loggingModel, imageServiceModel);

            // add directory handler for each directory from AppConfig
            foreach (string directoryPath in appConfigParser.Handler)
            {
                this.imageServer.AddDirectoryHandler(directoryPath);
            }
        }
Exemple #6
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
        }
Exemple #7
0
        /// <summary>
        /// Create an ImageServer object instance.
        /// </summary>
        private void CreateServer()
        {
            IImageServerParameters serverParameters = _configuration;
            IModalParameters       modalParameters  = _configuration;

            _server = new ImageServer(modalParameters, serverParameters);
        }
        /// <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");
        }
Exemple #9
0
        /// <summary>
        /// starts service and creates the main objects of the exercise
        /// </summary>
        /// <param name="args"> for starting service. </param>
        protected override void OnStart(string[] args)
        {
            // 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"]);

            logger = new LoggingService();
            modal  = new ImageServiceModal(outputFolder, 120);

            controller    = new ImageController(modal);
            m_imageServer = new ImageServer(logger, controller);
            m_imageServer.createHandlers();
            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();
            timer.Enabled = true;

            // Update the service state to Running.
            serviceStatus.dwCurrentState = ServiceState.SERVICE_RUNNING;
            SetServiceStatus(this.ServiceHandle, ref serviceStatus);
        }
Exemple #10
0
 /// <summary>
 /// Service constructor
 /// </summary>
 public ImageService()
 {
     try
     {
         //read params from app config
         eventLog1        = new System.Diagnostics.EventLog();
         eventLog1.Source = ConfigurationManager.AppSettings.Get("SourceName");
         eventLog1.Log    = ConfigurationManager.AppSettings.Get("LogName");
         //initialize members
         this.logging = new LoggingService(this.eventLog1);
         this.logging.MessageRecieved += WriteMessage;
         string output    = ConfigurationManager.AppSettings.Get("OutputDir");
         int    thumbSize = Int32.Parse(ConfigurationManager.AppSettings.Get("ThumbnailSize"));
         this.modal             = new ImageServiceModal(output, thumbSize);
         this.controller        = new ImageController(this.modal, this.logging);
         this.m_imageServer     = new ImageServer(controller, logging);
         this.controller.Server = m_imageServer;
         int            port    = 8000;
         IClientHandler handler = new ClientHandler(controller, logging);
         ServiceServer = new ServiceServer(logging, handler, port);
         ImageServer.UpdateOnRemovingHandler += ServiceServer.Update;
         this.logging.UpdateLogItems         += ServiceServer.Update;
         ServiceServer.StartServer();
         //TCP server starting
         ITCPClientHandler tcpHandler = new TCPClientHandler(controller, logging);
         ITCPServer        tcpServer  = new TCPServer(7000, logging, tcpHandler);
         tcpServer.StartServer();
     }
     catch (Exception e)
     {
         this.eventLog1.WriteEntry(e.Message, EventLogEntryType.Error);
     }
 }
Exemple #11
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);
        }
        /// <summary>
        /// The function initializing the members of the service
        /// </summary>
        private void MembersInitialize()
        {
            logging = new LoggingService();
            logging.MessageRecieved += OnMessage;

            m_imageServer = new ImageServer(logging);
        }
Exemple #13
0
        public ImageService(string[] args)
        {
            InitializeComponent();
            this.logCollectionSingleton = LogCollectionSingleton.Instance;
            eventLog1 = new System.Diagnostics.EventLog();
            //app config values
            string eventSourceName = ConfigurationManager.AppSettings.Get("SourceName");
            string logName         = ConfigurationManager.AppSettings.Get("LogName");

            if (!System.Diagnostics.EventLog.SourceExists(eventSourceName))
            {
                System.Diagnostics.EventLog.CreateEventSource(eventSourceName, logName);
            }
            eventLog1.Source = eventSourceName;
            eventLog1.Log    = logName;
            this.logger      = new LoggingService();
            //register this messageRecived function to the MessageRecieved event in the logger
            this.logger.MessageRecieved += MessageRecievedOperation;
            this.model = new ImageServiceModal()
            {
                OutputFolder  = ConfigurationManager.AppSettings.Get("OutputDir"),
                ThumbnailSize = Int32.Parse(ConfigurationManager.AppSettings.Get("ThumbnailSize"))
            };
            this.controller             = new ImageController(this.model);
            this.m_imageServer          = new ImageServer(this.controller, this.logger);
            this.controller.ImageServer = this.m_imageServer;
            this.m_appServer            = new AppServer(this.controller, this.logger);
        }
Exemple #14
0
        /// <summary>
        /// A function that is trigged when the service is started.
        /// First it logs the fact that is it starting up the service and also changes its status to SERVICE_START_PENDING
        /// After that, it logs the fact that the service was started and changes its status to SERVICE_RUNNING.
        /// </summary>
        /// <param name="args">The arguements given to the service on startup.</param>
        protected override void OnStart(string[] args)
        {
            eventLog1.WriteEntry("Starting ImageService.");
            // 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);
            //START IT UP HERE
            Logging = new LoggingService();
            Logging.MessageRecieved += C_MessageRecieved;
            Communication.Server ComServer = Communication.Server.GetServer();
            Server = new ImageServer(Logging);
            String[] Handelers = ConfigurationManager.AppSettings["Handler"].Split(';');
            for (int i = 0; i < Handelers.Count(); i++)
            {
                Server.AddDirectory(Handelers[i]);
            }
            // Update the service state to Running.
            ServiceStatus.dwCurrentState = ServiceState.SERVICE_RUNNING;
            SetServiceStatus(this.ServiceHandle, ref ServiceStatus);
            IPEndPoint ep = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 8000);

            ComServer.ServerStart(ep);
            eventLog1.WriteEntry("Started ImageService.");
        }
        /// <summary>
        /// getting the settings from the app config and Initializing the service
        /// </summary>
        /// <param name="args">arguments</param>
        public ImageService(string[] args)
        {
            InitializeComponent();
            string handler       = ConfigurationManager.AppSettings.Get("Handler");
            string outputDir     = ConfigurationManager.AppSettings.Get("OutputDir");
            string thumbnailSize = ConfigurationManager.AppSettings.Get("ThumbnailSize");

            string eventSourceName = ConfigurationManager.AppSettings.Get("SourceName");
            string logName         = ConfigurationManager.AppSettings.Get("LogName");

            eventLog1 = new System.Diagnostics.EventLog();
            if (!System.Diagnostics.EventLog.SourceExists(eventSourceName))
            {
                System.Diagnostics.EventLog.CreateEventSource(eventSourceName, logName);
            }
            eventLog1.Source = eventSourceName;
            eventLog1.Log    = logName;

            logging = new LoggingService();
            logging.MessageRecieved += OnMsg;
            modal       = new ImageServiceModal(outputDir, int.Parse(thumbnailSize));
            controller  = new ImageController(modal, logging);
            imageServer = new ImageServer(controller, logging, handler);
            //clientHandler = new HandleGuiClient(controller, logging, imageServer);
            clientHandler = new HandleAndroidClient(controller, logging, imageServer);
            serverChannel = new TcpServerChannel(8000, logging, clientHandler);
            clientHandler.NotifyClients += serverChannel.NotifyClients;
        }
Exemple #16
0
        protected override void OnStart(string[] args)
        {
            string outputDir     = ConfigurationManager.AppSettings.Get("OutputDir");
            int    thumbnailSize = Int32.Parse(ConfigurationManager.AppSettings.Get("ThumbnailSize"));

            modal  = new ImageServiceModal(outputDir, thumbnailSize);
            logger = new LoggingService();
            logger.MessageRecieved += OnMessage;
            controller              = new ImageController(modal, logger);
            this.logger.Log("On Start", MessageTypeEnum.INFO);
            server = new ImageServer(controller, logger);

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

            // Update the service state to Running.
            serviceStatus.dwCurrentState = ServiceState.SERVICE_RUNNING;
            SetServiceStatus(this.ServiceHandle, ref serviceStatus);
        }
Exemple #17
0
        /// <summary>
        /// The method ovverides the onStart method from serviceBase to start the service.
        /// </summary>
        /// <param name="args"></param> Args for the service.
        protected override void OnStart(string[] args)
        {
            eventLog1.WriteEntry("In OnStart");
            try
            {
                logger      = new LoggingService();
                model       = new ImageServiceModel();
                controller  = new ImageController(model);
                imageServer = new ImageServer(logger, controller);

                logger.MessageReceived += onMessageReceived;
                CreateHandlers();
                //imageServer.Start();

                // 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);
            }
            catch (Exception e)
            {
                eventLog1.WriteEntry(e.StackTrace);
            }
        }
Exemple #18
0
        /// <summary>
        /// starts service
        /// </summary>
        /// <param name="args"> for starting service. </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);

            logging.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);

            modal                    = new ImageServiceModal();
            controller               = new ImageController(modal, logging);
            m_imageServer            = new ImageServer(logging, modal, controller);
            logging.MessageRecieved += m_imageServer.UpdateLog;
        }
 /// <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);
     }
 }
Exemple #20
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 Logger object used in the system
            ILoggsRecorder logger = new LoggingService();

            logger.MessageRecieved += this.WriteToEventLogger;
            logger.Log("In ImageService created the logging service", MessageTypeEnum.INFO);

            //creating the modal with app config paramaters
            logger.Log("In ImageService starting to create the Modal, Controller and Server", MessageTypeEnum.INFO);
            logger.Log("Here is a warning message1", MessageTypeEnum.WARNING);
            var    appSettings = ConfigurationManager.AppSettings;
            string outputDir   = appSettings["OutputDir"];

            string[] dirsToBeHandled = appSettings["Handler"].Split(';');
            int      thumbnailSize;

            //if conversion failed, put default value
            if (!Int32.TryParse(appSettings["ThumbnailSize"], out thumbnailSize))
            {
                thumbnailSize = 120;
            }

            IImageModal modal      = new ImageModal(logger, outputDir, thumbnailSize);
            IController controller = new Controller.Controller(modal, logger);

            IServerChannel serverChannel      = new TcpServerChannel(8080);
            IServerChannel photoServerChannel = new TcpPhotoChannel(8000);

            serverChannel.Start();
            server = new ImageServer(controller, logger, serverChannel, photoServerChannel, dirsToBeHandled);
            logger.MessageRecieved += serverChannel.NotifyServerOfMessage;
            controller.SetDHManager(server);
            logger.Log("Here is a warning message2", MessageTypeEnum.WARNING);
            logger.Log("In ImageService finished creating the Modal, Controller and Server", MessageTypeEnum.INFO);
            logger.Log("Here is a fail message, for display only", MessageTypeEnum.FAIL);
            logger.Log("Another fail message, for display only", MessageTypeEnum.FAIL);
        }
 /**
  * initialize all classes.
  */
 public void initilaizeClasses()
 {
     modal = new ImageServiceModal(this.outputDir, this.thumbnailSize);
     eventLog1.WriteEntry("initilaizeClasses: " + this.outputDir);
     controller    = new ImageController(modal);
     m_imageServer = new ImageServer(this.controller, this.logging);
     m_imageServer.Start();
     logging.MessageRecieved += Logging_MessageRecieved;// (this,eventArgs) ;
 }
Exemple #22
0
        protected override void OnStart(string[] args)
        {
            string[] paths         = ConfigurationManager.AppSettings["Handler"].Split(';');
            string   outputDir     = ConfigurationManager.AppSettings["OutputDir"];
            string   sourceName    = ConfigurationManager.AppSettings["SourceName"];
            string   logName       = ConfigurationManager.AppSettings["LogName"];
            int      thumbnailSize = int.Parse(ConfigurationManager.AppSettings["ThumbnailSize"]);


            List <string> pathsList = new List <string>();

            foreach (string path in paths)
            {
                if (Directory.Exists(path))
                {
                    pathsList.Add(path);
                }
                else
                {
                    eventLogger.WriteEntry(DateTime.Now.ToString() + " " + path + ": Invalid Path To Directory");
                }
            }

            paths = pathsList.ToArray <string>();

            eventLogger = new System.Diagnostics.EventLog();
            if (!System.Diagnostics.EventLog.SourceExists(sourceName))
            {
                System.Diagnostics.EventLog.CreateEventSource(
                    sourceName, logName);
            }
            eventLogger.Source = sourceName;
            eventLogger.Log    = logName;

            eventLogger.WriteEntry(DateTime.Now.ToString() + " Service Started");


            // initialize logging
            logging = new LoggingModel();
            logging.MessageRecieved += OnMessageRecieved;
            // initialize servers controllers and modals
            imageModel        = new ImageServiceModel(outputDir, thumbnailSize);
            controller        = new ImageController(imageModel, logging);
            m_imageServer     = new ImageServer(paths, imageModel, logging, controller);
            controller.Server = m_imageServer;
            srv      = new TcpServer("127.0.0.1", 8000, (IClientHandler)controller, logging);
            receiver = new ImageReceiver(8001, m_imageServer, logging);
            ImageServer.NotifyHandlerRemoved += srv.Notify;
            this.logging.NotifyLogChanged    += srv.Notify;

            // start handeling clients
            receiver.Start();
            srv.Start();
        }
Exemple #23
0
 /**
  * initialize all classes.
  */
 public void initilaizeClasses()
 {
     modal = new ImageServiceModal(this.outputDir, this.thumbnailSize);
     eventLog1.WriteEntry("initilaizeClasses: " + this.outputDir);
     controller    = new ImageController(modal, logging);
     m_imageServer = new ImageServer(this.controller, this.logging, PORT_NUM);
     m_imageServer.Start();
     //logging.MessageRecieved += Logging_MessageRecieved;// (this,eventArgs) ;
     UpdateLogMessage += m_imageServer.sendClients;
     //logging.MessageRecieved += logging.newLog;
 }
        /// <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);
        }
        /// <summary>
        /// Image service constructor.
        /// </summary>
        /// <param name="args"></param>
        public ImageService(string[] args)
        {
            try
            {
                InitializeComponent();
                //Get settings from app.config.
                ServiceSettings serviceSettings = ServiceSettings.GetServiceSettings();
                //Set service settings.
                string eventSourceName = serviceSettings.SourceName;
                //Set log name.
                string logName = serviceSettings.LogName;
                if (args.Count() > 0)
                {
                    eventSourceName = args[0];
                }
                if (args.Count() > 1)
                {
                    logName = args[1];
                }
                //Create event logger.
                eventLog1 = new System.Diagnostics.EventLog();
                if (!System.Diagnostics.EventLog.SourceExists(eventSourceName))
                {
                    System.Diagnostics.EventLog.CreateEventSource(eventSourceName, logName);
                }
                eventLog1.Source = eventSourceName;
                eventLog1.Log    = logName;

                //Create image service modal.
                m_imageServiceModal = new ImageServiceModal(serviceSettings.OutputDir, serviceSettings.ThumbnailSize);
                //Create logging service.
                m_loggingService = new LoggingService();
                m_loggingService.MessageRecieved += WriteToLog;
                //Create controller.
                m_controller = new ImageController(m_imageServiceModal);
                //Create image server.
                m_imageServer = new ImageServer(m_controller, m_loggingService, serviceSettings.Handlers);
                m_loggingService.Log("Image service created", MessageTypeEnum.INFO);

                HandleAndroidClient handleAndroidRequest = new HandleAndroidClient(m_loggingService, m_imageServiceModal, serviceSettings.Handlers[0]);
                m_tcpServer = new TCPServerChannel(1102, m_loggingService, handleAndroidRequest);

                //handleGuiRequest.NotifyClients += m_tcpServer.NotifyClientsOnChange;
                m_loggingService.NotifyClients += m_tcpServer.NotifyClientsOnChange;

                m_tcpServer.Start();
            }
            catch (Exception e)
            {
                m_loggingService.Log("Failed creating image service, exception: " + e.Message, MessageTypeEnum.FAIL);
            }
        }
Exemple #26
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="logging">logging</param>
 /// <param name="imageServer">Image server.</param>
 public HandleGuiRequest(ILoggingService logging, ImageServer imageServer)
 {
     //Create dictionary from enum int to ICommand
     commands = new Dictionary <int, ICommand>()
     {
         { (int)CommandEnum.GetConfigCommand, new GetConfigCommand() },
         { (int)CommandEnum.CloseHandler, new CloseHandlerCommand(imageServer, this) },
         { (int)CommandEnum.LogCommand, new LogCommand(logging) },
         { (int)CommandEnum.EchoCommand, new EchoCommand() }
     };
     m_logging  = logging;
     m_stopTask = false;
 }
Exemple #27
0
        /// <summary>
        /// Constructor for ImageService.
        /// </summary>
        /// <param name="args"> Arguments. </param>
        public ImageService(string[] args)
        {
            InitializeComponent();
            string eventSourceName = ConfigurationManager.AppSettings.Get("SourceName");
            string logName         = ConfigurationManager.AppSettings.Get("LogName");
            string outputDir       = ConfigurationManager.AppSettings.Get("OutputDir");
            string handler         = ConfigurationManager.AppSettings.Get("Handler");
            int    ThumbnailSize   = int.Parse(ConfigurationManager.AppSettings.Get("ThumbnailSize"));

            if (args.Count() > 0)
            {
                eventSourceName = args[0];
            }
            if (args.Count() > 1)
            {
                logName = args[1];
            }
            if (eventSourceName == null)
            {
                eventSourceName = "MySource";
            }
            if (logName == null)
            {
                logName = "MyNewLog";
            }

            eventLog1 = new System.Diagnostics.EventLog();
            try {
                if (!System.Diagnostics.EventLog.SourceExists(eventSourceName))
                {
                    System.Diagnostics.EventLog.CreateEventSource(eventSourceName, logName);
                }
            } catch (Exception e)
            {
                return;
            }

            eventLog1.Source         = eventSourceName;
            eventLog1.Log            = logName;
            logging                  = new LoggingService();
            logging.MessageRecieved += MessageTypes;

            // create image service model
            modal = new ImageServiceModal(outputDir, ThumbnailSize);

            // create image controller
            controller    = new ImageController(modal);
            m_imageServer = new ImageServer(controller, logging);
            m_imageServer.CreateHandler(handler);
        }
Exemple #28
0
        /// <summary>
        /// Service constructor
        /// </summary>
        public ImageService()
        {
            /*
             * InitializeComponent();
             * eventLog1 = new System.Diagnostics.EventLog();
             * eventLog1.Source = "ImageServiceSource";
             * eventLog1.Log = "ImageServiceLog";
             * this.logging = new LoggingService(eventLog1);
             * this.logging.MessageRecieved += WriteToEntry;
             */


            try
            {
                InitializeComponent();
                //read params from app config
                string eventSourceName = ConfigurationManager.AppSettings.Get("SourceName");
                string logName         = ConfigurationManager.AppSettings.Get("LogName");
                eventLog1 = new System.Diagnostics.EventLog();
                if (!System.Diagnostics.EventLog.SourceExists(eventSourceName))
                {
                    System.Diagnostics.EventLog.CreateEventSource(eventSourceName, logName);
                }
                eventLog1.Source = eventSourceName;
                eventLog1.Log    = logName;
                //initialize members
                this.logging = new LoggingService(this.eventLog1);
                this.logging.MessageRecieved += WriteMessage;

                string OutputFolder  = ConfigurationManager.AppSettings.Get("OutputDir");
                int    ThumbnailSize = Int32.Parse(ConfigurationManager.AppSettings.Get("ThumbnailSize"));

                this.modal = new ImageServiceModal(OutputFolder, ThumbnailSize);

                this.controller        = new ImageController(this.modal, this.logging);
                this.m_imageServer     = new ImageServer(controller, logging);
                this.controller.Server = m_imageServer;
                IClientHandler ch = new ClientHandler(controller, logging);
                imageServiceSrv = new ServiceServer(8000, logging, ch);
                ImageServer.NotifyAllHandlerRemoved += imageServiceSrv.Update;
                this.logging.UpdateLogEntries       += imageServiceSrv.Update;
                imageServiceSrv.Start();
            }
            catch (Exception e)
            {
                this.eventLog1.WriteEntry(e.ToString(), EventLogEntryType.Error);
            }
        }
        /************************************************************************
         * The Input: -.
         * The Output: -.
         * The Function operation: The function reads from the appConfig and initiallizes
         * and creates members.
         *************************************************************************/
        private void InitializeService()
        {
            //Reading appConfig.
            string[] handlerPaths  = ConfigurationManager.AppSettings["Handler"].Split(';');
            string   outputDir     = ConfigurationManager.AppSettings["OutputDir"];
            int      thumbnailSize = Int32.Parse(ConfigurationManager.AppSettings["ThumbnailSize"]);

            //Initializing and creating the members.
            this.model               = new ImageServiceModel(outputDir, thumbnailSize);
            this.logging             = new LoggingService();
            this.controller          = new ImageController(this.model);
            logging.MessageReceived += OnLog;
            this.m_imageServer       = new ImageServer(this.controller, this.logging, handlerPaths);
            //Updating the entry.
            eventLog1.WriteEntry("End Of Initialization");
        }
        /// <summary>
        /// cons't
        /// </summary>
        /// <param name="logModal">ILoggingModal</param>
        /// <param name="server"> ImageServer</param>
        public ServerController(ILoggingModel logModal, ImageServer server)
        {
            //Dictionary: key - CommandState , value - command to execute
            this.commands   = new Dictionary <int, ICommand>();
            this.m_logModal = logModal;
            this.sever      = server;

            //Get App Config command
            commands[(int)CommandStateEnum.GET_APP_CONFIG] = new GetAppConfigCommand();

            //Get All Log command
            commands[(int)CommandStateEnum.GET_ALL_LOG] = new GetLogCommand(this.m_logModal);

            //Close Handler command
            commands[(int)CommandStateEnum.CLOSE_HANDLER] = new CloseHandleCommand(this.sever);
        }