Exemplo n.º 1
0
 /// <summary>
 /// reads setting data from server, and sets them to the prop's
 /// </summary>
 /// <param name="obj"></param>
 /// <param name="e"></param>
 public void SetSettingsData(object obj, ServerDataReciecedEventArgs e)
 {
     if (e.DataType.Equals("Settings")) // if reads "settings" as pre-command from server, we now need to read settings
     {
         JObject  settingsObj = JObject.Parse(e.Date);
         string   handlers    = (string)settingsObj["Handler"];
         string[] handlerList = handlers.Split(';');
         foreach (string handler in handlerList)
         {
             this.AddToList(this, new PropertyChangedEventArgs(handler));
         }
         this.thumbnailSize = "" + (int)settingsObj["thumbNail"];
         this.logName       = (string)settingsObj["logName"];
         this.srcName       = (string)settingsObj["sourceName"];
         this.outputDic     = (string)settingsObj["OutPutDir"];
     }
     // if not Log or Close cmd & not settings.. - Handlers cmd
     else if (e.DataType.Equals("Log") && e.Date.StartsWith("0:close handler:"))
     {
         string             starts = e.Date.Substring(16); // reads handlres...
         HandlerDirectories dir    = null;
         foreach (HandlerDirectories dirr in this.HandlerDirsList)
         {
             if (dirr.Path.Equals(starts))
             {
                 dir = dirr;
             }
         }
         if (dir != null)
         {
             this.HandlerDirsList.Remove(dir);
             this.removeEnabled = false;
         }
     }
 }
Exemplo n.º 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());
        }
Exemplo n.º 3
0
        /// <summary>
        /// AppCongigSettings-recived operation from new client to send him current settings.
        /// </summary>
        /// <param name="args">args for the command</param>
        /// <param name="result">reference to result flag to update</param>
        /// <returns>an app config settings in json format)</returns>
        public string Execute(string[] args, out bool result)
        {
            result = true;
            ServerDataReciecedEventArgs a = new ServerDataReciecedEventArgs("Settings", AppCongigSettings.Instance.ToJSON());

            return(a.ToJSON());
        }
Exemplo n.º 4
0
        /// <summary>
        /// get json format to logs list
        /// </summary>
        /// <param name="args">args for the command</param>
        /// <param name="result">reference to result flag to update</param>
        /// <returns>an *error message* / image path (if you use it it will open the image)</returns>
        public string Execute(string[] args, out bool result)
        {
            result = true;
            ServerDataReciecedEventArgs a = new ServerDataReciecedEventArgs("LogList", log.GetLogList());
            string logs = a.ToJSON();

            return(logs);
        }
Exemplo n.º 5
0
 /// <summary>
 /// reads setting data from server, and sets them to the prop's
 /// </summary>
 /// <param name="obj"></param>
 /// <param name="e"></param>
 public void SetSettingsData(object obj, ServerDataReciecedEventArgs e)
 {
     if (e.DataType.Equals("Settings")) // if reads "settings" as pre-command from server, we now need to read settings
     {
         JObject  settingsObj = JObject.Parse(e.Date);
         string   handlers    = (string)settingsObj["Handler"];
         string[] handlerList = handlers.Split(';');
         // clear the list and get new handlers
         this.Handlers.Clear();
         foreach (string handler in handlerList)
         {
             if ((!this.Handlers.Contains(handler)) && (handler != null) && (handler != ""))
             {
                 this.Handlers.Add(handler);
             }
         }
         this.thumbnailSize = "" + (int)settingsObj["thumbNail"];
         this.logName       = (string)settingsObj["logName"];
         this.srcName       = (string)settingsObj["sourceName"];
         this.outputDir     = (string)settingsObj["OutPutDir"];
         lock (Client.Instance.objc)                 // Grab the phone when I have something ready for the worker
         {
             Monitor.PulseAll(Client.Instance.objc); // Signal worker there is work to do
         }
     }
     // if not Log or Close cmd & not settings.. - Handlers cmd
     else if (e.DataType.Equals("Log") && e.Date.StartsWith("1:close handler:"))
     {
         string starts = e.Date.Substring(16); // reads handlres...
         String dir    = null;
         foreach (string dirr in this.Handlers)
         {
             if (dirr.Equals(starts))
             {
                 dir = dirr;
                 break;
             }
         }
         if (dir != null)
         {
             this.Handlers.Remove(dir);
         }
         lock (Client.Instance.objc)                 // Grab the phone when I have something ready for the worker
         {
             Monitor.PulseAll(Client.Instance.objc); // Signal worker there is work to do
         }
     }
     else if (e.DataType.Equals("Log") && e.Date.StartsWith("1:Server being closed"))
     {
         // clear the list beacuse server disconnected
         this.Handlers.Clear();
     }
 }
Exemplo n.º 6
0
        /// <summary>
        /// connect server with port and ip and start listening for new clients
        ///for each client, create delegete that will be listening for incomme logs.
        /// </summary>
        public void Start()
        {
            IPEndPoint ep = new IPEndPoint(IPAddress.Parse("127.0.0.1"), port);

            listener = new TcpListener(ep);
            listener.Start();
            //start listen to clients
            Task task = new Task(() => {
                while (true)
                {
                    try
                    {
                        TcpClient client = listener.AcceptTcpClient();
                        ch.HandleClient(client);
                        //create delegete that will listent to new info from server to client and send.
                        EventHandler <MessageRecievedEventArgs> clientLogListener = null;
                        clientLogListener = delegate(object sender, MessageRecievedEventArgs e)
                        {
                            //send to client orders
                            try
                            {
                                NetworkStream stream = client.GetStream();
                                BinaryWriter writer  = new BinaryWriter(stream);
                                {
                                    ServerDataReciecedEventArgs message = new ServerDataReciecedEventArgs("Log", (int)e.Status + ":" + e.Message);
                                    writer.Write(message.ToJSON());
                                }
                                //if send-error:stop listen
                            } catch (Exception)
                            {
                                GUICommandRecieved -= clientLogListener;
                                client.Close();
                            }
                        };
                        GUICommandRecieved += clientLogListener;
                    }
                    catch (SocketException)//for any problem meanse server disconnected
                    {
                        break;
                    }
                }
            });

            task.Start();
        }
Exemplo n.º 7
0
 /// <summary>
 /// The function being called when new data recived. it check what data type it is
 /// if its a log list or only one log, add to the list. any other case ignore.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 public void ReadFromServer(object sender, ServerDataReciecedEventArgs e)
 {
     //if only one log recived
     if (e.DataType.Equals("Log") && (!(e.Date.StartsWith("0:close handler:"))))
     {
         string[] logRecord = e.Date.Split(':');
         NewLogNotify(this, new LogRecord((MessageTypeEnum)int.Parse(logRecord[0]), e.Date));
     }
     //if log list(!) recived. recived in string, each log sperated by ";"
     else if (e.DataType.Equals("LogList"))
     {
         //make an array from the logs and add them.
         string[] logList = e.Date.Split(';');
         foreach (string log in logList)
         {
             string[] logRecord = log.Split(':');
             NewLogNotify(this, new LogRecord((MessageTypeEnum)int.Parse(logRecord[0]), log)); // reads each log separately
         }
     }
 }
Exemplo n.º 8
0
        /// <summary>
        /// this methode create a task witch always listen to new messages from server.
        /// when new message recived it notify all methodes(settings and logs)
        /// </summary>
        public void StartListenToServer()
        {
            Task task = new Task(() =>
            {
                while (this.listenToServer) //if no connection to server-stop
                {                           //the try catch is if server disconnected
                    try
                    {
                        string data = basicClient.ReadDataFromServer();
                        ServerMassages(this, ServerDataReciecedEventArgs.FromJSON(data));
                    }
                    catch (Exception)
                    {
                        ServerMassages(this, new ServerDataReciecedEventArgs("Log", "2:Disconnected from server-bye"));
                        Disconnect();
                        break;
                    }
                }
            });

            task.Start();
        }
Exemplo n.º 9
0
 /// <summary>
 /// The function being called when new data recived. it check what data type it is
 /// if its a log list or only one log, add to the list. any other case ignore.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 public void ReadFromServer(object sender, ServerDataReciecedEventArgs e)
 {
     //if only one log recived
     if (e.DataType.Equals("Log") && (!(e.Date.StartsWith("0:close handler:"))))
     {
         string[] logRecord = e.Date.Split(':');
         this.logList.Add(new Log
         {
             Type = (MessageTypeEnum)int.Parse(logRecord[0]),
             Data = e.Date
         });
         lock (Client.Instance.objc)
         {
             Monitor.PulseAll(Client.Instance.objc); // Signal
         }
     }
     //if log list(!) recived. recived in string, each log sperated by ";"
     else if (e.DataType.Equals("LogList"))
     {
         //make an array from the logs and add them.
         string[] logList = e.Date.Split(';');
         foreach (string log in logList)
         {
             string[] logRecord = log.Split(':');
             this.logList.Add(new Log
             {
                 Type = (MessageTypeEnum)int.Parse(logRecord[0]),
                 Data = log
             });
         }
         lock (Client.Instance.objc)
         {
             Monitor.PulseAll(Client.Instance.objc); // Signal
         }
     }
 }
Exemplo n.º 10
0
 /// <summary>
 /// sends message "remove handler" to server
 /// </summary>
 /// <param name="obj"></param>
 /// <param name="e"></param>
 public void RemoveHandler(object obj, ServerDataReciecedEventArgs e)
 {
     GuiClient.Instance.SendMessage("" + (int)CommandEnum.CloseCommand + ":" + e.Date);
 }
Exemplo n.º 11
0
 /// <summary>
 ///  Triggers ReadSettingsFromServer the event each time new message recevied from server
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 public void ReadFromServer(object sender, ServerDataReciecedEventArgs e)
 {
     ReadSettingsFromServer(this, e);
 }