Ejemplo n.º 1
0
        private ILoggingService logger;              // delete
        public ImageController(IImageServiceModal modal, LogingBuffer logsBuffer, ILoggingService logger)
        {
            m_modal            = modal;         // Storing the Modal Of The System
            this.loggingBuffer = logsBuffer;
            this.logger        = logger;
            ConfigurationModal config = new ConfigurationModal();

            commands = new Dictionary <int, ICommand>()
            {
                // For Now will contain NEW_FILE_COMMAND
                { (int)CommandEnum.NewFileCommand, new NewFileCommand(m_modal) },
                { (int)CommandEnum.LogCommand, new GetLogsCommand(logsBuffer, this.logger) },
                { (int)CommandEnum.GetConfigCommand, new GetConfigCommand(config) },
                { (int)CommandEnum.RemoveDirectoryFromConfigurationCommand, new RemoveDirectoryFromConfigurationCommand(config) }
            };
        }
Ejemplo n.º 2
0
 /// <summary>
 /// A constractor of the get logs command.
 /// </summary>
 /// <param name="buffer"> The logging buffer the command will get the logs from</param>
 /// <param name="logging"></param>
 public GetLogsCommand(LogingBuffer buffer, ILoggingService logging)
 {
     this.logger     = logging;
     this.logsBuffer = buffer;
 }
Ejemplo n.º 3
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);
        }