/************************************************************************
         * The Input: ImageController a LoggingService and the way to a handler.
         * The Output: -
         * The Function operation: The function builds a server.
         *************************************************************************/
        public ImageServer(IImageController controller, ILoggingService logging, string[] handlersPath)
        {
            m_controller = controller;
            m_logging    = logging;
            m_logging.MessageReceived += OnLogMessageReceived;

            RemoveHandlerCommand removeHandlerCommand = new RemoveHandlerCommand();

            removeHandlerCommand.RemoveHandler += OnRemoveHandler;

            controller.AddCommand(CommandEnum.RemoveHandlerCommand, removeHandlerCommand);

            commands = new Dictionary <string, CommandEnum>()
            {
                { "Close Handler", CommandEnum.CloseCommand }
            };

            serverChannel = new TCPConnectionServer(new ClientHandler(m_controller, m_logging));

            serverChannel.Start();


            handlers          = new List <IDirectoryHandler>();
            this.handlersPath = handlersPath;
            //Creating handlers.
            for (int i = 0; i < handlersPath.Length; i++)
            {
                handlers.Add(new DirectoryHandler(this.m_controller, this.m_logging));
                handlers[i].StartHandleDirectory(handlersPath[i]);
                CommandReceived            += handlers[i].OnCommandRecieved;
                handlers[i].DirectoryClose += OnHandlerClose;
                // Logging each handler into the entry.
                m_logging.Log("Directory Handler created at path:" + handlersPath[i], Logging.Modal.MessageTypeEnum.INFO);
            }
        }
Exemplo n.º 2
0
        public event EventHandler <CommandReceivedEventArgs> CommandReceived;          // The event that notifies about a new Command being recieved
        #endregion

        /// <summary>
        /// The ImageServer's constructor.
        /// </summary>
        /// <param name="imageLogger">The image logger</param>
        /// <param name="imageController">The image controller</param>
        public ImageServer(ILoggingService imageLogger, IImageController imageController)
        {
            controller              = imageController;
            logger                  = imageLogger;
            logger.MessageReceived += OnLogMessageReceived;
            RemoveHandlerCommand removeHandlerCommand = new RemoveHandlerCommand();

            removeHandlerCommand.RemoveHandler += OnRemoveHandler;
            controller.AddCommand(CommandEnum.RemoveHandlerCommand, removeHandlerCommand);
            commands = new Dictionary <string, CommandEnum>()
            {
                { "Close Handler", CommandEnum.CloseCommand }
            };
            //serverChannel = new TCPServerChannel(new ClientHandler(controller, logger));
            imageServer = new TCPImageServer(new ImageHandler(controller, logger));
            //serverChannel.Start();
            imageServer.Start();
            //CreateHandlers();
            // serverChannel.OnMessageToServer += OnMessageToServerReceived;
            //maybe outer task it instead of inner task
        }