Пример #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
        /// <summary>
        /// c'tor instelize all members from arguments of app config
        /// </summary>
        /// <param name="args"></param>
        public ImageService(string[] args)
        {
            InitializeComponent();
            //get info fro, app config to set the varibles.
            LogList logList = LogList.Instance;

            logList.LogRecords = new List <string>();
            //get info from appconfig file to singelton appConfigSettings
            AppCongigSettings appConfig = AppCongigSettings.Instance;

            appConfig.OutPutDir  = ConfigurationManager.AppSettings["OutputDir"];
            appConfig.ThumbNail  = Int32.Parse(ConfigurationManager.AppSettings["ThumbnailSize"]);
            appConfig.SourceName = ConfigurationManager.AppSettings["SourceName"];
            appConfig.LogName    = ConfigurationManager.AppSettings["Name"];


            //create logger server, modal. controller and server.
            this.modal         = new ImageServiceModal(appConfig.OutPutDir, appConfig.ThumbNail);
            this.logging       = new LoggingService();
            this.controller    = new ImageController(this.modal, this.logging);
            this.m_imageServer = new ImageServer(this.controller, this.logging);

            if (args.Count() > 0)
            {
                appConfig.SourceName = args[0];
            }
            if (args.Count() > 1)
            {
                appConfig.LogName = args[1];
            }
            eventLog1 = new System.Diagnostics.EventLog();
            if (!System.Diagnostics.EventLog.SourceExists(appConfig.SourceName))
            {
                System.Diagnostics.EventLog.CreateEventSource(appConfig.SourceName, appConfig.LogName);
            }
            //set log and sourse names.
            eventLog1.Source = appConfig.SourceName;
            eventLog1.Log    = appConfig.LogName;
            // listen to the server updates.
            logging.MessageRecieved += OnUpDateService;
        }