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); }
/// <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); } } }
/// <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(); }
/// <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); }
/// <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 }
/// <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; }
/// <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); }
/// <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; }
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); } }
/// <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); }
/// <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(); }
/// <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); }
/// <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); }
/// <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); }
/// <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); }
/// <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); }
/// <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; } }
/// <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); }
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; } }
/// <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); }
/// <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(); }
/// <summary> /// This function reads all the paths from the Config file, /// and creates a handler for each path. /// </summary> public void readPath() { string paths = ConfigurationManager.AppSettings["Handler"]; string[] pathArray = paths.Split(';'); for (int i = 0; i < pathArray.Length; i++) { IDirectoyHandler handle = new DirectoyHandler(this.m_controller, this.m_logging); CommandRecieved += handle.OnCommandRecieved; handle.DirectoryClose += OnDirctoryClose; handle.StartHandleDirectory(pathArray[i]); appConfigManager.Instance.clickRemove += handle.OnRemove; } }
/// <summary> /// CreateHandler function. /// create a handler that listen to event of command of newFile /// and an event of of closing server, start to handle the directory /// and update the logger. /// </summary> /// <param name="path"> path of wanted directory</param> public void CreateHandler(string path) { try { IDirectoryHandler handler = new DirectoyHandler(this.m_controller, this.m_logging); this.CommandRecieved += handler.OnCommandRecieved; this.ServerClose += handler.OnStopHandle; handler.StartHandleDirectory(path); } catch (Exception e) { this.m_logging.Log(e.ToString(), Logging.Modal.MessageTypeEnum.FAIL); return; } this.m_logging.Log("Handler" + path + "was created successfully", Logging.Modal.MessageTypeEnum.INFO); }
/// <summary> /// creating a new handler. /// </summary> /// <param name="directory"> the directory the handler listens to </param> public void createHandler(string directory) { if (Directory.Exists(directory)) { IDirectoryHandler dirHandler = new DirectoyHandler(m_controller, m_logging); CommandRecieved += dirHandler.OnCommandRecieved; dirHandler.DirectoryClose += CloseHandler; dirHandler.StartHandleDirectory(directory.Trim()); } else { m_logging.Log("Directory \"" + directory + "\" does not exist!", Logging.Modal.MessageTypeEnum.FAIL); } }
/// <summary> /// Creates handler for each specified path in the App.config /// </summary> public void CreateHandlers() { string paths = ConfigurationManager.AppSettings["Handler"]; string[] listOfPaths = paths.Split(';'); foreach (string path in listOfPaths) { IDirectoryHandler handler = new DirectoyHandler(path, this.m_controller, this.m_logging); // handler.OnCommandRecieved subscribes to CommandRecieved EventHandler CommandRecieved += handler.OnCommandRecieved; // OnCloseServer subscribes to DirectoryClose EventHandler handler.DirectoryClose += OnCloseServer; // Creates FileSystemEventHandler to track after any creation of a file or directory in the specified path handler.StartHandleDirectory(path); this.listOfHandlers.Add(handler); } this.Start(); }
/// <summary> /// Create new handler for the given path. /// </summary> /// <param name="directory"> The folder that the new handler will listen to. </param> /// <returns> The new handler. If the handler's creation failed - return null. </returns> public DirectoyHandler CreateHandler(String directory) { DirectoyHandler h = new DirectoyHandler(directory, m_controller, m_logging); if (h.StartHandleDirectory(directory)) { CommandRecieved += h.OnCommandRecieved; h.DirectoryClose += OnCloseServer; CloseCommand += h.OnClose; m_logging.Log("starting handler for directory: " + directory, MessageTypeEnum.INFO); return(h); } else { return(null); } }
public ImageServer(IImageController i_Controller, ILoggingService i_Logger) { m_Logger = i_Logger; m_Controller = i_Controller; m_DirectoriesHandlers = new List <DirectoyHandler>(); bool result = false; string watchedDirectories = ImageService.ReadSetting("Handler", out result); string[] directories = watchedDirectories.Split(';'); foreach (string path in directories) { DirectoyHandler directoryHandler = new DirectoyHandler(path, m_Controller, this, m_Logger); m_DirectoriesHandlers.Add(directoryHandler); directoryHandler.StartHandleDirectory(); } m_Logger.Log("Image Server Created.", MessageTypeEnum.INFO); }
/// <summary> /// Create new handlers for the given paths. /// </summary> public void createHandlers() { //Read from App.config string paths = ConfigurationManager.AppSettings["Handler"]; string[] listOfPaths = paths.Split(';'); foreach (string path in listOfPaths) { IDirectoryHandler handler = new DirectoyHandler(path, this.m_controller, this.m_logging); CommandRecieved += handler.OnCommandRecieved; handler.DirectoryClose += OnCloseServer; CloseService += handler.OnCloseService; handler.StartHandleDirectory(path); this.listOfHandlers.Add(handler); m_logging.Log("Created Handler for path: " + path + ".", Logging.Modal.MessageTypeEnum.INFO); } }
/// <summary> /// Constructor /// </summary> /// <param name="controller">Image controller.</param> /// <param name="logging">Logging</param> /// <param name="handlersPathes">Handlera pathes.</param> public ImageServer(IImageController controller, ILoggingService logging, string[] handlersPathes) { Controller = controller; Logging = logging; m_handlers = new List <IDirectoryHandler>(); //For each path in handlers pathes. foreach (var path in handlersPathes) { //Write to log. m_logging.Log("Creating handler for: " + path, MessageTypeEnum.INFO); //Create handler. IDirectoryHandler handler = new DirectoyHandler(m_controller, m_logging, path); m_handlers.Add(handler); //Add events. CommandRecieved += handler.OnCommandRecieved; CloseServer += handler.CloseHandler; //Start handle directory. handler.StartHandleDirectory(path); } }