Пример #1
0
        public event EventHandler <CommandRecievedEventArgs> CommandRecieved;          // The event that notifies about a new Command being recieved
        #endregion

        /// <summary>
        /// C'tor of server.
        /// creates handler's for each path from given app config.
        /// listen to each handler.
        /// </summary>
        /// <param name="controller"></param>
        /// <param name="logging"></param>
        public ImageServer(IImageController controller, ILoggingService logging)
        {
            this.m_logging    = logging;
            this.m_controller = controller;
            //create list of paths to listen them.
            AppCongigSettings appConfig = AppCongigSettings.Instance;

            appConfig.Handlers = ConfigurationManager.AppSettings["Handler"];
            string[]            handlerListPaths = appConfig.Handlers.Split(';');
            HanddlersController handlers         = HanddlersController.Instance;

            handlers.Handdlers = new List <IDirectoryHandler>();
            //create handler to each path and listen to its updates.
            foreach (var path in handlerListPaths)
            {
                IDirectoryHandler handler = new DirectoyHandler(this.m_controller, this.m_logging, path);
                handler.DirectoryClose += CloseHandler;
                this.CommandRecieved   += handler.OnCommandRecieved;
                //add to list of handles
                handlers.AddHanler(handler);
            }
            this.m_tcpServer = new ComunicationServer(8000, new ClientHandler(this.m_controller));
            //tcp server and log list listens to new logs
            this.m_logging.MessageRecieved += LogList.Instance.AddNewLog;
            this.m_logging.MessageRecieved += this.m_tcpServer.SendNewLog;
            //connect the server
            this.m_tcpServer.Start();
            AndroidConnectionHandler a = new AndroidConnectionHandler(HanddlersController.Instance.Handdlers[0].GetDirectory());

            a.Start();
        }
Пример #2
0
        public event EventHandler <CommandRecievedEventArgs> CommandRecieved;          // The event that notifies about a new Command being recieved
        #endregion
        /// <summary>
        /// constructor,
        /// </summary>
        /// <param name="logger">the loger that take cares the messages</param>
        /// <param name="controller">The Image Processing Controller</param>
        /// <param name="directories"> the paths of the directories we want to listen .</param>
        public ImageServer(ILoggingService logger, IImageController controller, String[] directories, ComunicationServer server, ClientsManager manager)
        {
            m_logging    = logger;     // setting the logger
            m_controller = controller; // setting the controller
            m_commServer = server;
            DirectoyHandler directoyHandler;

            // for each directory path we create directory handler.
            for (int i = 0; i < directories.Length; i++)
            {
                directoyHandler = new DirectoyHandler(m_controller, m_logging, directories[i]);
                // register the directory handler to the CommandRecived event .sending commands
                //through events to directory handler.
                CommandRecieved += directoyHandler.OnCommandRecieved;
                //register the server to the Directory close event .
                directoyHandler.DirectoryClose += OnDirectoryClose;
                // start to listen to the directory
                directoyHandler.StartHandleDirectory(directories[i]);
                m_logging.Log("Created directory handler " + directories[i], Logging.Modal.MessageTypeEnum.INFO);

                // Add the directroty the list of directories that the client mannager has.
                manager.AddDirectoryHandler(directoyHandler);
            }


            // Make the comunication server start listening and acccepting clients.
            this.m_commServer.StartListening();
            this.m_serverTask = new Task(this.m_commServer.AcceptClients);
            this.m_serverTask.Start();

            m_logging.Log("Service has created", Logging.Modal.MessageTypeEnum.INFO);
        }