Esempio n. 1
0
        /// <summary>
        /// the constructor get Icontroller and Ilogging, take the two paths to directories
        /// that we need to listen from the APP config,
        /// create handlers for the directrories and notify the logging.
        /// </summary>
        /// <param name="controller">the controller that we paa to the handler</param>
        /// <param name="logging">the logging incharge to notify the user about the process</param>
        public ImageServer(IImageController controller, ILoggingService logging, int imagesCounter)
        {
            this.imagesCounter = imagesCounter;
            this.handlers      = new Dictionary <string, IDirectoryHandler>();
            this.m_controller  = controller;
            this.m_logging     = logging;

            string[] directories = (ConfigurationManager.AppSettings.Get("Handler").Split(';'));
            this.m_tcpServer = new TcpServer();
            this.m_tcpServer.DataReceived += ExecuteTcpServer;
            foreach (string path in directories)
            {
                try
                {
                    IDirectoryHandler handler = new DirectoyHandler(m_logging, m_controller, m_tcpServer);
                    CommandRecieved += handler.OnCommandRecieved;
                    CloseService    += handler.onCloseService;
                    handler.StartHandleDirectory(path);
                    this.m_logging.Log("Handler created for " + path, Logging.Modal.MessageTypeEnum.INFO);
                    this.handlers[path] = handler;
                }
                catch (Exception e)
                {
                    this.m_logging.Log("Error creating handler for the directory: " + path + " " + e.ToString(), Logging.Modal.MessageTypeEnum.INFO);
                }
            }

            this.m_tcpServer.Start();
        }
Esempio n. 2
0
 /// <summary>
 /// constructor
 /// </summary>
 /// <param name="controller">image controller</param>
 /// <param name="loggingService">logger</param>
 public ImageServer(IImageController controller, ILoggingService loggingService)
 {
     this.m_controller = controller;
     this.m_logging    = loggingService;
     directories       = (ConfigurationManager.AppSettings.Get("Handler").Split(';'));
     foreach (string directory in directories)
     {
         try
         {
             IDirectoryHandler handler = new DirectoyHandler(m_controller, m_logging, directory);
             CloseService           += handler.OnCloseSevice;
             CommandRecieved        += handler.OnCommandRecieved;
             handler.DirectoryClose += (s, e) =>
             {
                 CloseService    -= handler.OnCloseSevice;
                 CommandRecieved -= handler.OnCommandRecieved;
             };
             handler.StartHandleDirectory(directory);
             m_logging.Log("Handler created for " + directory, Logging.Modal.MessageTypeEnum.INFO);
         }
         catch (Exception e)
         {
             m_logging.Log("faild to create handler for: " + directory, Logging.Modal.MessageTypeEnum.FAIL);
         }
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Creates a handler for the input directory.
        /// </summary>
        /// <param name="pathToDir">A path for a dir which requires handling</param>
        /// <param name="modalParameters">An IModalParameters object</param>
        private void CreateHandlerByDirectory(string pathToDir, IModalParameters modalParameters)
        {
            IDirectoryHandler dirHandler = new DirectoyHandler(modalParameters, LoggingService);

            SubscribeHandlerEvents(dirHandler);
            dirHandler.StartHandleDirectory(pathToDir);
        }
Esempio n. 4
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();
        }
Esempio n. 5
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);
        }
Esempio n. 6
0
        /// <summary>
        /// constructor.
        /// </summary>
        /// <param name="controller">controller</param>
        /// <param name="logging"> logger</param>
        public ImageServer(IImageController controller, ILoggingService logging)
        {
            try {
                this.m_controller = controller;
                this.m_logging    = logging;

                //establish a tcp connection
                IPEndPoint ep = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 8000);
                this.tcpListener = new TcpListener(ep);
                this.tcpListener.Start();
                this.handlers = new Dictionary <string, IDirectoryHandler>();
            } catch (Exception e) { this.m_logging.Log("Couldn't establish tcp server: " + e.ToString(), MessageTypeEnum.FAIL); }

            this.m_logging.Log("Tcp server established: ", MessageTypeEnum.INFO);
            this.clientsList = new List <TcpClient>();
            LogCollectionSingleton.Instance.LogsCollection.CollectionChanged += ImageServer_LogCollectionChanged;
            folders = ConfigurationManager.AppSettings["Handler"].Split(';');
            //creates handler for each given folder
            foreach (string folder in folders)
            {
                try
                {
                    IDirectoryHandler handler = new DirectoyHandler(this.m_controller, this.m_logging, folder);
                    createHandler(folder);
                }catch (Exception exception)
                {
                    this.m_logging.Log("failed to listen to the folder: " + folder + exception, MessageTypeEnum.FAIL);
                }
            }
            AcceptClients();
        }
Esempio n. 7
0
        /// <summary>
        /// Creates the directory handler that listens for images to be added (and eventually adds them).
        /// Param: the path
        /// </summary>
        public void CreateHandler(string path)
        {
            IDirectoryHandler h = new DirectoyHandler(m_controller, m_logging, path);

            CommandRecieved  += h.OnCommandRecieved;
            h.DirectoryClose += OnCloseServer;
        }
Esempio n. 8
0
        /// <summary>
        /// Closing the server - handler will call this function to tell server it closed.
        /// </summary>
        /// <param name="sender"> Handler as sender. </param>
        /// <param name="e"> Information on the handler - dir and a message. </param>
        public void OnCloseServer(object sender, DirectoryCloseEventArgs e)
        {
            DirectoyHandler dh = (DirectoyHandler)sender;

            CommandRecieved   -= dh.OnCommandRecieved;
            dh.DirectoryClose -= OnCloseServer;
            CloseCommand      -= dh.OnClose;
        }
Esempio n. 9
0
        private void CreateHandler(string path)
        {
            IDirectoryHandler handler = new DirectoyHandler(m_logging, m_controller, path);

            CommandRecieved        += handler.OnCommandRecieved;
            handler.DirectoryClose += this.onClose;
            this.m_logging.Log("Created handler for: " + path, Logging.Modal.MessageTypeEnum.INFO);
        }
Esempio n. 10
0
        /// <summary>
        /// Creating a handler for a directory path
        /// </summary>
        /// <param name="path"> directory path </param>
        public void CreateHandler(string path)
        {
            IDirectoryHandler handler = new DirectoyHandler(m_controller, m_logging);

            handler.StartHandleDirectory(path);
            CommandRecieved        += handler.OnCommandRecieved;
            handler.DirectoryClose += OnCloseHandler;
        }
Esempio n. 11
0
        /// <summary>
        /// sets a handler to the directory given in path parameter.
        /// the event handler of the handler registers to the server's commands event.
        /// </summary>
        /// <param name="path">path to a directory</param>
        public void ListenToDirectory(string path)
        {
            IDirectoryHandler handler = new DirectoyHandler(m_controller, m_logging);

            this.CommandRecieved   += handler.OnCommandRecieved;
            handler.DirectoryClose += HandlerIsBeingClosed;
            handler.StartHandleDirectory(path);
        }
Esempio n. 12
0
        /*********************************************************************/

        public void createHandler(string directory, int handler_num)
        {
            IDirectoryHandler h = new DirectoyHandler(directory, controller, logging);

            handlers.Add(handler_num, h);
            CommandRecieved  += h.OnCommandRecieved;
            h.DirectoryClose += onCloseServer;
        }
Esempio n. 13
0
        public void CreateHandler(string path)
        {
            DirectoyHandler dh = new DirectoyHandler(_controller, _loggingService, path);

            dh.HandleDirectory(path);
            CommandRecieved        += dh.OnCommandRecieved;
            DirectoryHandlerClosed += dh.OnDirectoryHandlerClosed;
        }
Esempio n. 14
0
        /// <summary>
        /// The Function Starts the Directory Service Until Directed Otherwise
        /// </summary>
        #endregion
        public void StartDirectoryHandler(string path)
        {
            IDirectoryHandler directory = new DirectoyHandler(m_controller, m_logging); // Creating the Directory Handler for the Dir

            directory.DirectoryClose += OnDirectoryClose;                               // Adding the Event Handler for when the Directory is closed
            CommandRecieved          += directory.OnCommandRecieved;                    // Subsribing to the Command Recieve Event
            directory.StartHandleDirectory(path);                                       // Start Handling the Folder
        }
Esempio n. 15
0
 private void CreateHandlers(string[] foldersToWatch)
 {
     foreach (string folder in foldersToWatch)
     {
         DirectoyHandler handler = new DirectoyHandler(Logging, Controller);
         CommandReceived += handler.OnCommandReceived; // When ImageServer sends a command the event will trigger each handler's OnCommandReceived
         handler.StartHandleDirectory(folder);
     }
 }
Esempio n. 16
0
        /// <summary>
        /// this method create handle.
        /// </summary>
        /// <param name="pathDirectory">path to the directory</param>
        public void CreateHandler(string pathDirectory)
        {
            IDirectoryHandler handler = new DirectoyHandler(pathDirectory, m_controller, m_logging);

            CommandRecieved        += handler.OnCommandRecieved;
            handler.DirectoryClose += RemoveHandler;
            handler.StartHandleDirectory(pathDirectory);
            handlersList.Add(pathDirectory);
        }
Esempio n. 17
0
        /// <summary>
        /// Creates handler for a given directory path
        /// </summary>
        /// <param name="directory"></param>
        private void CreateHandler(string directory)
        {
            IDirectoryHandler handler = new DirectoyHandler(m_controller, m_logger);

            handler.StartHandleDirectory(directory);
            handler.DirectoryClose += onDirectoryError;
            m_logger.Log(DateTime.Now.ToString() + " deployed handler in directory " + directory, MessageTypeEnum.INFO);
            CommandRecieved += handler.OnCommandRecieved;
        }
Esempio n. 18
0
        /// <summary>
        /// Creates the handler.
        /// </summary>
        /// <param name="dirPath">The dir path.</param>
        public void CreateHandler(string dirPath)
        {
            // debug.write("dirPath\n");
            IDirectoryHandler dirHandler = new DirectoyHandler(dirPath, m_logging, m_controller);

            CommandRecieved           += dirHandler.OnCommandRecieved;
            dirHandler.DirectoryClose += CloseHandler;
            Handlers.Add(dirPath, dirHandler);
        }
Esempio n. 19
0
        /// <summary>
        /// Creates a new directory handler for the directory of the given path.
        /// </summary>
        /// <param name="path">The path of the directory to be handled.</param>
        private void CreateDirectoryHandler(string path)
        {
            IDirectoryHandler directoryHandler = new DirectoyHandler(m_controller, m_logging);

            m_logging.Log("A directory handler was created for the directory in path: " + path, MessageTypeEnum.INFO);
            CommandRecieved += directoryHandler.OnCommandRecieved;
            directoryHandler.DirectoryClose += OnDirectoryClose;
            directoryHandler.StartHandleDirectory(path);
        }
        /**
         * the function create handler to specific path
         */
        public void createHandler(string path)
        {
            IDirectoryHandler h = new DirectoyHandler(path, m_controller, m_logging);

            CommandRecieved      += h.OnCommandRecieved;//directory
            this.CloseTheService += h.OnCloseService;
            h.DirectoryClose     += closeServer;
            m_logging.Log("Created handler: " + path, MessageTypeEnum.INFO);
            h.StartHandleDirectory();
        }
Esempio n. 21
0
        /// <summary>
        /// CreateHandler :
        /// creates the handler for a given directory's path.
        /// </summary>
        /// <param name="dirPath"></param>
        public void CreateHandler(string dirPath)
        {
            m_logging.Log("In create handler", MessageTypeEnum.INFO);
            IDirectoryHandler dirHandler = new DirectoyHandler(dirPath, m_logging, m_controller);

            CommandRecieved += dirHandler.OnCommandRecieved;
            CloseEvent      += dirHandler.CloseHandler;
            dirHandler.StartHandleDirectory(dirPath);
            this.m_logging.Log("Created handler for: " + dirPath, MessageTypeEnum.INFO);
        }
Esempio n. 22
0
        /// <summary>
        /// createHandler.
        /// creates handler given a folder
        /// </summary>
        /// <param name="folder">folder to be handled</param>
        private void createHandler(string folder)
        {
            IDirectoryHandler handler = new DirectoyHandler(this.m_controller, this.m_logging, folder);

            this.handlers.Add(folder, handler);
            this.CommandRecieved   += handler.OnCommandRecieved;
            handler.DirectoryClose += removeHandler;
            handler.StartHandleDirectory(folder);
            this.m_logging.Log("start watch the directory: " + folder, MessageTypeEnum.INFO);
        }
Esempio n. 23
0
        /// <summary>
        /// by a given path -create a handler for it
        /// </summary>
        /// <param name="path">path of direcory to handle</param>
        public void CreateHandler(string path)
        {
            IDirectoryHandler h = new DirectoyHandler(this.m_controller, this.m_logging, path);

            //subscribe the relevant functions to events
            CommandRecieved  += h.OnCommandRecieved;
            h.DirectoryClose += ClosingServer;
            //after creating the handler - start actually handling it
            h.StartHandleDirectory(path);
        }
Esempio n. 24
0
        /// <summary>
        /// creates a new handler for a given directory
        /// </summary>
        /// <param name= directory> the path to the directory we want to monitor </param>
        private void CreateHandler(string directory)
        {
            // create handler for given directory
            IDirectoryHandler directoryHandler = new DirectoyHandler(this.controller, this.logging);

            handlerList.Add(directoryHandler);
            directoryHandler.DirectoryClose += new EventHandler <DirectoryCloseEventArgs>(CloseHandler);
            this.CommandRecieved            += directoryHandler.OnCommandRecieved;
            directoryHandler.StartHandleDirectory(directory);
        }
Esempio n. 25
0
        /// <summary>
        /// CreateHandler function.
        /// </summary>
        /// <param name="path">the path the handler is on charge</param>
        private void CreateHandler(string path)
        {
            IDirectoryHandler handler = new DirectoyHandler(m_logging, m_controller, path);

            Handlers[path]    = handler;
            CommandRecieved  += handler.OnCommandRecieved;
            this.CloseServer += handler.OnCloseHandler;
            handler.StartHandleDirectory(path);
            this.m_logging.Log("Handler was created for directory: " + path, MessageTypeEnum.INFO);
        }
Esempio n. 26
0
        /// <summary>
        /// Adds a directory at the given path.
        /// </summary>
        /// <param name="path">The directory's path.</param>
        public void AddDirectory(string path)
        {
            IDirectoryHandler Handler = new DirectoyHandler(m_logging, m_controller);

            if (Handler.StartHandleDirectory(path))
            {
                CommandRecieved += Handler.OnCommandRecieved;
                //Handler.LogChanged += com_server.ClHandler.OnLogChange; //TODO: ... something
                Handler.CommandDone += com_server.ClHandler.CommandDone;
            }
        }
Esempio n. 27
0
 public void InitDirectoryHandlers(string[] pathsToWatch)
 {
     for (int i = 0; i < pathsToWatch.Length; i++)
     {
         IDirectoryHandler directoryHandler = new DirectoyHandler(this.m_controller, this.m_logging);
         directoryHandler.StartHandleDirectory(pathsToWatch[i]);
         //adding handler and path to directory into dictionary
         this.m_deirectoryPathsToHandlers.Add(pathsToWatch[i], directoryHandler);
         this.CommandRecieved            += directoryHandler.OnCommandRecieved;
         directoryHandler.DirectoryClose += this.RemoveDirectoryHandler;
     }
 }
Esempio n. 28
0
        /// <summary>
        /// creating handler for a specific directory
        /// </summary>
        /// <param name="path">The directory path</param>
        private void CreateHandler(string path)
        {
            //creating the handler
            IDirectoryHandler handler = new DirectoyHandler(m_logging, m_controller);

            HandlerPerPath[path] = handler;
            CommandRecieved     += handler.OnCommandRecieved;
            //register the handler to CloseServer event
            this.CloseServer += handler.StopHandler;
            handler.StartHandleDirectory(path);
            this.m_logging.Log("Handler was created for directory: " + path, MessageTypeEnum.INFO);
        }
Esempio n. 29
0
        /// <summary>Creates dir handler</summary>
        /// <param name="dirPath">The directory handler</param>
        private void createDirHandler(string dirPath)
        {
            //Creates a new directory handler using the logger, controller and directory path.
            IDirectoryHandler directoryDandler = new DirectoyHandler(m_logging, m_controller, dirPath);

            //Adds the handler to the command and the closeserver listener
            CommandRecieved  += directoryDandler.OnCommandRecieved;
            this.CloseServer += directoryDandler.OnCloseHandler;
            //Requires the handle to begin to handle the directory
            directoryDandler.StartHandleDirectory(dirPath);
            this.m_logging.Log("New Directory Handler: " + dirPath, Logging.Modal.MessageTypeEnum.INFO);
        }
Esempio n. 30
0
        /// <summary>
        /// ImageServer is the server that in charge on all the Handlers.
        /// </summary>
        /// <param name="controller"></param>
        /// <param name="logging"></param>
        public ImageServer(IImageController controller, ILoggingService logging, int port)
        {
            this.port = port;
            //function to remove handler
            this.handle += this.handling;
            //function to inform our list of handlers that a handler was removed:
            this.handle += HandlerSingleton.Instance.GetDelegate();


            // intilaize Server's controller and logger.
            this.m_controller = controller;
            this.m_logging    = logging;


            //we will do the mobile server communication as a task in order to prevent damage
            //to the reset of the functionality of the code.
            new Task(() =>
            {
                MobileServer serv = new MobileServer(this, this.m_controller, this.m_logging, 8234);
                serv.Start();
            }).Start();



            this.ch = new ClientHandler(new ExecuteCommands(this.m_logging), this.handle);
            // get all directories path

            string[] paths = ConfigurationManager.AppSettings.Get("Handler").Split(';');
            foreach (string path in paths)
            {
                // handler creation
                IDirectoryHandler directoryHandler = new DirectoyHandler(this.m_logging, this.m_controller, path);
                CommandRecieved   += directoryHandler.OnCommandRecieved;
                this.server_close += directoryHandler.closeHandler;
                directoryHandler.StartHandleDirectory(path);
                //adding the handler to our dictary so we can close it when we are told to by the GUI
                dic.Add(path, directoryHandler);
                HandlerSingleton.addItem(path);
                this.m_logging.Log("Create handler for path - " + path, Logging.Modal.MessageTypeEnum.INFO);
            }


            //after looping through the folders:


            this.m_logging.Log("starting to listen", Logging.Modal.MessageTypeEnum.INFO);



            Start();
        }