Exemplo n.º 1
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);
            }
        }
Exemplo n.º 2
0
        // Here You will Use the App Config!
        /// <summary>
        ///Start the server
        ///Param: string[] args - the command line arguments
        /// </summary>
        protected override void OnStart(string[] args)
        {
            eventLog1.WriteEntry(ServiceState.SERVICE_RUNNING.ToString());
            // Update the service state to Start Pending.
            ServiceStatus serviceStatus = new ServiceStatus();

            logging = new LoggingModal();
            logging.MessageRecieved += OnMsg;
            model         = new ImageServiceModel(ConfigurationManager.AppSettings["OutputDir"], Int32.Parse(ConfigurationManager.AppSettings["ThumbnailSize"]));
            controller    = new ImageController(model);
            m_imageServer = new ImageServer(controller, logging);

            CreateHandlers();

            serviceStatus.dwCurrentState = ServiceState.SERVICE_START_PENDING;
            serviceStatus.dwWaitHint     = 100000;

            // Update the service state to Running.
            serviceStatus.dwCurrentState = ServiceState.SERVICE_RUNNING;

            var server = new Thread(m_imageServer.StartServer);

            server.IsBackground = false;
            server.Start();
        }
Exemplo n.º 3
0
 public ImageController(IImageServiceModel model)
 {
     m_model  = model; // Storing the Model Of The System
     commands = new Dictionary <int, ICommand>
     {
         { (int)CommandEnum.NewFileCommand, new NewFileCommand(m_model) }
     };
 }
Exemplo n.º 4
0
 public ImageController(IImageServiceModel iModal)
 {
     /// Creates an enum-ICommand dictionary.
     commands = new Dictionary <CommandEnum, ICommand>()
     {
         { CommandEnum.NewFileCommand, new NewFileCommand(iModal) }
     };
 }
Exemplo n.º 5
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="Model"></param>
 public ImageController(IImageServiceModel Model)
 {
     this.imageServiceModel = Model;                    // Storing the Model Of The System
     commands = new Dictionary <int, ICommand>()
     {
         { (int)CommandCategoryEnum.AddFile, new NewFileCommand(this.imageServiceModel) }
         // For Now will contain NEW_FILE_COMMAND
     };
 }
Exemplo n.º 6
0
 /// <summary>
 /// ImageController Constructor
 /// </summary>
 /// <param name="image_model">the image model</param>
 public ImageController(IImageServiceModel image_model)
 {
     img_model     = image_model;
     commands_list = new Dictionary <int, ICommand>()
     {
         { (int)CommandEnum.NewFileCommand, new NewFileCommand(img_model) },
         { (int)CommandEnum.GetConfigCommand, new GetConfigCommand(img_model) }
     };
 }
Exemplo n.º 7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ImageController"/> class.
 /// </summary>
 /// <param name="model">The model.</param>
 public ImageController(IImageServiceModel model)
 {
     m_model  = model; //storing the model of the system
     commands = new Dictionary <int, ICommand>()
     {
         { (int)CommandEnum.NewFileCommand, new NewFileCommand(m_model) },
         { (int)CommandEnum.GetConfigCommand, new GetConfigCommand(m_model) }
     };
 }
Exemplo n.º 8
0
 public ImageServer(string[] paths, IImageServiceModel imageModel, ILoggingModel log, IImageController controller)
 {
     m_logger     = log;
     m_controller = controller;
     pathList     = new List <string>(paths);
     foreach (string path in paths)
     {
         CreateHandler(path);
     }
 }
Exemplo n.º 9
0
 /// <summary>
 /// The constructor
 /// </summary>
 /// <param name="Model"> The class that responsible to manage the files </param>
 public ImageController(IImageServiceModel Model)
 {
     m_Model  = Model;                   // Storing the Model Of The System
     commands = new Dictionary <int, ICommand>()
     {
         { (int)CommandEnum.NewFileCommand, new NewFileCommand(Model) },
         { (int)CommandEnum.GetConfigCommand, new GetConfigCommand() },
         { (int)CommandEnum.LogCommand, new LogCommand() }
     };
 }
Exemplo n.º 10
0
 /// <summary>
 /// Creates the ImageController.
 /// Param: IImagerServiceModel.
 /// Creates the command - the NewFileCommand.
 /// </summary>
 public ImageController(IImageServiceModel model)
 {
     m_model  = model;                   // Storing the Modal Of The System
     commands = new Dictionary <int, ICommand>
     {
         { 0, new NewFileCommand(m_model) },
         { 1, new GetConfigCommand() },
         { 2, new LogCommand() }
     };
 }
Exemplo n.º 11
0
        public ImageController(IImageServiceModel model)
        {
            // Storing the Model Of The System

            m_model  = model;
            commands = new Dictionary <int, ICommand> {
                // For Now will contain just NEW_FILE_COMMAND
                { 1, new NewFileCommand(m_model) }
            };
        }
Exemplo n.º 12
0
 public ImageController(IImageServiceModel i_Model, ILoggingService i_Logger)
 {
     m_Logger   = i_Logger;
     m_Model    = i_Model;
     m_Commands = new Dictionary <int, ICommand>()
     {
         { 1, new NewFileCommand(m_Model, m_Logger) },
         { 2, new GetSettingsCommand(m_Model, m_Logger) }
     };
 }
Exemplo n.º 13
0
        public ImageController(IImageServiceModel Model, ILoggingModel log)
        {
            m_Model  = Model;            // Storing the Model Of The System
            m_log    = log;
            commands = new Dictionary <int, ICommand>();

            commands.Add((int)CommandEnum.NewFileCommand, new NewFileCommand(m_Model));
            commands.Add((int)CommandEnum.LogHistoryCommand, new LogHistoryCommand(m_log));
            commands.Add((int)CommandEnum.CloseCommand, new CloseCommand());
        }
Exemplo n.º 14
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();
        }
Exemplo n.º 15
0
        private Dictionary <CommandEnum, ICommand> commands;   // The Commads Dictionary
        #endregion

        /// <summary>
        /// The ImageController constructor.
        /// </summary>
        /// <param name="imageModel"></param> The image model.
        public ImageController(IImageServiceModel imageModel)
        {
            model    = imageModel;
            commands = new Dictionary <CommandEnum, ICommand>()
            {
                { CommandEnum.NewFileCommand, new NewFileCommand(model) },
                { CommandEnum.GetConfigCommand, new GetCongigCommand() },
                { CommandEnum.RemoveHandlerCommand, new RemoveHandlerCommand() },
                { CommandEnum.GetAllLogsCommand, new GetAllLogsCommand() },
                { CommandEnum.GetStudentsInfo, new GetStudentsInfoCommand() },
                { CommandEnum.GetNumImages, new NumImagesCommand(model) },
                { CommandEnum.NewImageCommand, new NewImageCommand(model) }
                //  {CommandEnum.LogCommand, new LogCommand() }
            };
        }
Exemplo n.º 16
0
        /// <summary>
        /// Constructor of The controller
        /// </summary>
        /// <param name="list">
        /// a reference to list of all the active clients
        /// </param>
        public ImageController(ref List <IDirectoryHandler> list)
        {
            string outputDir     = ConfigurationManager.AppSettings["OutputDir"];
            int    thumbnailSize = Int32.Parse(ConfigurationManager.AppSettings["ThumbnailSize"]);

            m_model  = new ImageServiceModel(outputDir, thumbnailSize); // Storing the Model Of The System
            commands = new Dictionary <int, ICommand>
            {
                { (int)CommandEnum.NewFileCommand, new NewFileCommand(m_model) },
                { (int)CommandEnum.GetConfigCommand, new ImageService.Commands.GetConfigCommand(ref list) },
                { (int)CommandEnum.LogCommand, new ImageService.Commands.LogCommand() },
                { (int)CommandEnum.CloseCommand, new CloseCommand() }
            };
            ((CloseCommand)commands[(int)CommandEnum.CloseCommand]).CloseCommandEvent += SendCommand;
        }
Exemplo n.º 17
0
        /************************************************************************
         * 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.MessageRecieved += OnLog;
            this.m_imageServer       = new ImageServer(this.controller, this.logging, handlerPaths);
            //Updating the entry.
            eventLog1.WriteEntry("End Of Initialization");
        }
Exemplo n.º 18
0
        protected override void OnStart(string[] args)
        {
            m_Logger.Log("Starting service.", MessageTypeEnum.INFO);
            // 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);

            // Creating service components.
            m_Logger.Log("Creating service components.", MessageTypeEnum.INFO);
            m_Model                      = new ImageServiceModel(m_Logger);
            m_Controller                 = new ImageController(m_Model, m_Logger);
            m_ImageServer                = new ImageServer(m_Controller, m_Logger);
            m_Server                     = new NetworkServer(PORT, m_Controller, m_Logger);
            m_Server.ClientConnected    += addClient;
            m_Server.clientDisconnected += removeClient;

            // Create output and thumbnails directories.
            bool   result     = false;
            string outputPath = ImageService.ReadSetting("OutputDir", out result);

            if (false == result)
            {
                m_Logger.Log($"OutputDir attribute cannot be found in appConfig.\nSetting default value.", MessageTypeEnum.INFO);
                outputPath = @"C:\Output";
            }

            this.CreateOutputFolder(outputPath);
            string thumbnailsPath = $@"{outputPath}\Thumbnails";

            this.CreateOutputFolder(thumbnailsPath);

            // Initiate server listenning (Run as task in order to guarentee OnStart method finish).
            Task serverStartTask = new Task(() =>
            {
                m_Server.Start();
            });

            serverStartTask.Start();
        }
Exemplo n.º 19
0
 /// <summary>
 /// Constructor of ImageServer
 /// </summary>
 /// <param name="controller"> The controller of the service </param>
 /// <param name="logging"> The class that hold the event handler to notify on new message to the event log </param>
 /// <param name="pathHandlers"> the path of the directories that need to create for them handlers</param>
 public ImageServer(ILoggingService logging)
 {
     m_appParsing              = AppParsing.Instance;
     m_modelImage              = new ImageServiceModel(m_appParsing.OutputDir, m_appParsing.ThumbnailSize);
     m_controller              = new ImageController(m_modelImage);
     m_tcpServer               = new TCPServiceServer(m_appParsing.Port, m_appParsing.IP);
     m_tcpServer.DataReceived += DataReceviedServer;
     m_tcpServer.Start();
     m_logging = logging;
     m_logging.MessageRecieved += NewLogEntry;
     foreach (string pathHandler in m_appParsing.PathHandlers)
     {
         CreateHandler(pathHandler);
         logging.Log($"Handler for {pathHandler} was created", MessageTypeEnum.INFO);
     }
     m_commands = new List <int>()
     {
         ((int)CommandEnum.GetConfigCommand),
         ((int)CommandEnum.LogCommand)
     };
 }
Exemplo n.º 20
0
        protected override void OnStart(string[] args)
        {
            #region Other

            eventLog.WriteEntry("In OnStart", EventLogEntryType.Information);

            // Updates the service state to Start Pending.
            ServiceStatus serviceStatus = new ServiceStatus
            {
                dwCurrentState = ServiceState.ServiceStartPending,
                dwWaitHint     = 100000
            };

            SetServiceStatus(ServiceHandle, ref serviceStatus);

            // Updates the service state to Running.
            serviceStatus.dwCurrentState = ServiceState.ServiceRunning;
            SetServiceStatus(ServiceHandle, ref serviceStatus);
            _loggingService = new LoggingService();
            _loggingService.MessageRecieved += OnMessegeRecieved;

            #endregion

            _controller  = new ImageController();
            _imageServer = new ImageServer(_controller, _loggingService);
            _imageServer.DirectoryHandlerClosed += OnDirectoryHandlerClosed;

            InitializeSettingsInfo();

            _model = new ImageServiceModel(_settingsInfo.OutputDirectory, _settingsInfo.ThumbnailSize);

            // Creates TCP server
            _tcpServer = new TcpServer(8000, _loggingService, new TcpClientHandlerFactory(_controller));
            _tcpServer.NewClientConnected += OnNewClientConnected;
            eventLog.EntryWritten         += _tcpServer.OnLogEntryWritten;

            _controller.AddCommand(CommandEnum.NewFileCommand, new NewFileCommand(_model));
            _controller.AddCommand(CommandEnum.CloseDirectoryHandlerCommand,
                                   new CloseDirectoryHandlerCommand(_imageServer));
        }
Exemplo n.º 21
0
 public NewFileCommand(IImageServiceModel Model)
 {
     this.imageServiceModel = Model;            // Storing the Model
 }
Exemplo n.º 22
0
 /// <summary>
 /// Creates the NewFileCommand.
 /// Param: the IImageServiceModel
 /// </summary>
 public NewFileCommand(IImageServiceModel model)
 {
     m_model = model;            // Storing the Modal
 }
Exemplo n.º 23
0
 /// <summary>
 /// NewFileCommand Constructor
 /// </summary>
 /// <param name="imgModel">Our model</param>
 public NewFileCommand(IImageServiceModel imgModel)
 {
     this.imgModel = imgModel;
 }
Exemplo n.º 24
0
 public GetSettingsCommand(IImageServiceModel i_Model, ILoggingService i_Logger)
 {
     m_Model  = i_Model;
     m_Logger = i_Logger;
 }
Exemplo n.º 25
0
 public NewFileCommand(IImageServiceModel modal)
 {
     imageModal = modal;
 }
Exemplo n.º 26
0
 public NumImagesCommand(IImageServiceModel imageModel)
 {
     model = imageModel;
 }
Exemplo n.º 27
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CloseCommand"/> class.
 /// </summary>
 /// <param name="model">The model.</param>
 /// <param name="server">The server.</param>
 public CloseCommand(IImageServiceModel model, ImageServer server)
 {
     this.model  = model;
     this.server = server;
 }
Exemplo n.º 28
0
 public NewFileCommand(IImageServiceModel i_Model, ILoggingService i_Logger)
 {
     m_Logger = i_Logger;
     m_Model  = i_Model;
 }
Exemplo n.º 29
0
        private IImageServiceModel model;       // The Image Model

        /// <summary>
        /// The NewfileCommand's constructor.
        /// </summary>
        /// <param name="imageModel">The image model.</param>
        /// The image model.
        public NewFileCommand(IImageServiceModel imageModel)
        {
            model = imageModel;
        }
Exemplo n.º 30
0
 /// <summary>
 /// CloseCommand Constructor
 /// </summary>
 /// <param name="imgModel">Our model</param>
 /// <param name="imgServer">Our server</param>
 public CloseCommand(IImageServiceModel imgModel, ImageServer imgServer)
 {
     this.imgModel  = imgModel;
     this.imgServer = imgServer;
 }