/// <summary> /// This function is being called when a client wrote a new msg /// It transfer the object into CommandMessage and execute the /// right command /// </summary> /// <param name="sender"></param> /// <param name="info"></param> private void GetMessageFromUser(object sender, DataCommandArgs info) { var msg = CommandMessage.FromJson(info.Data); if (msg == null) { _mLogging.Log("Can't convert " + info.Data + " to JSON", MessageTypeEnum.FAIL); return; } _mLogging.Log("Got msg from user, Command ID: " + msg.CommandId, MessageTypeEnum.INFO); bool result; // close command if (msg.CommandId == (int)CommandEnum.CloseCommand) { CommandRecieved?.Invoke(this, new CommandRecievedEventArgs((int)CommandEnum.CloseCommand, null, msg.Args[0])); // send the msg to all the clients serverChannel.SendToAll(msg.ToJson()); } else if (msg.CommandId == (int)CommandEnum.DeleteCommand) { DeleteImages(msg.Args); } else { string answer = _mController.ExecuteCommand(msg.CommandId, null, out result); serverChannel.SendToAll(answer); } }
/// <summary> /// This function is being called whenever a new log is being written, /// This function is responsible of senting the new log to all the clients /// </summary> /// <param name="sender"></param> /// <param name="msg"></param> public void SendLog(Object sender, MessageRecievedEventArgs msg) { string[] info = { msg.Status.ToString(), msg.Message }; CommandMessage msgC = new CommandMessage((int)CommandEnum.LogCommand, info); serverChannel.SendToAll(msgC.ToJson()); System.Threading.Thread.Sleep(100); }