/// <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()); }
/// <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()); }
/// <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); }
/// <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(); }