Example #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();
        }
Example #2
0
        /// <summary>
        /// close recevied from client. we delete the handler by the given path and
        /// notify logger(withch will notify other clients)
        /// </summary>
        /// <param name="args">args for the command</param>
        /// <param name="result">reference to result flag to update</param>
        /// <returns>an *error message* / folder pathbeing closed</returns>
        public string Execute(string[] args, out bool result)
        {
            // The String Will Return the New Path if result = true, and will return the error message otherwise
            result = true;
            HanddlersController handlersList     = HanddlersController.Instance;
            MessageTypeEnum     resultOfDeleting = MessageTypeEnum.FAIL;
            string status = handlersList.DeleteHandller(args[1] + ":" + args[2]);

            //if(status != )
            m_service.Log("close handler:" + args[1] + ":" + args[2], MessageTypeEnum.WARNING);
            AppCongigSettings settings = AppCongigSettings.Instance;

            settings.Handlers = settings.Handlers.Replace(args[1] + ":" + args[2] + ";", "");
            if (handlersList.Handdlers.Count() == 0)
            {
                settings.Handlers = "";
            }
            if (status.Equals("deleted"))
            {
                resultOfDeleting = MessageTypeEnum.INFO;
            }
            ServerDataReciecedEventArgs a = new ServerDataReciecedEventArgs("Log", (int)resultOfDeleting + ":your reqest was:" + status);

            return(a.ToJSON());
        }