/// <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 method is being called whenever a new msg received from the server /// </summary> /// <param name="sender"></param> /// <param name="info"></param> private void GetMessageFromServer(object sender, DataCommandArgs info) { var msg = CommandMessage.FromJson(info.Data); if (msg == null) { return; } // if new log is being received if (msg.CommandId == (int)CommandEnum.LogCommand) { try { // try to parse it MessageRecievedEventArgs log = new MessageRecievedEventArgs((MessageTypeEnum)Enum.Parse(typeof(MessageTypeEnum), msg.Args[0]), msg.Args[1]); Application.Current.Dispatcher.Invoke(new Action(() => { // add msg to the list _mMessages.Insert(0, log); })); } catch (Exception e) { Console.WriteLine(e.Message); } } }
public void GetMessageFromServer(object sender, DataCommandArgs info) { var msg = CommandMessage.FromJson(info.Data); if (msg == null) { return; } if (msg.CommandId == (int)CommandEnum.GetConfigCommand) // config { InitializeConfig(msg.Args); } else if (msg.CommandId == (int)CommandEnum.CloseCommand) // close { removeHandler(msg.Args[0]); } }
/// <summary> /// This method is being invoken whenever the server sends /// the TcpChannel msgs /// </summary> /// <param name="sender"></param> /// <param name="info"></param> public void GetMessageFromServer(object sender, DataCommandArgs info) { var msg = CommandMessage.FromJson(info.Data); if (msg == null) { return; } if (msg.CommandId == (int)CommandEnum.DeleteCommand) // Delete { if (msg.Args[0].Equals(SelectedItem.ImagePath) && msg.Args[1].Equals(SelectedItem.ThumbPath)) { IsRemoved = true; } } }