public void HandleClientMessage(Connection cnn, Chetch.Messaging.Message message) { //record this LogMessage(CMDataSource.MessageDirection.INBOUND, message); switch (message.Type) { case MessageType.SHUTDOWN: break; case MessageType.STATUS_RESPONSE: if (message.HasValue("ServerID")) { //send status request to all connected clients var clients = message.GetList <String>("Connections"); System.Diagnostics.Trace.WriteLine(String.Format("Server status response shows {0} client connections ...", clients.Count)); foreach (var cs in clients) { var data = cs.Split(' '); var clientName = data[1]; if (clientName != null && clientName != String.Empty) { CurrentClient.RequestClientConnectionStatus(clientName); System.Diagnostics.Trace.WriteLine("Requesting status of " + clientName); //System.Threading.Thread.Sleep(100); } } } break; default: break; } //ehd switch }
private void SendClientCommand(String target, String command, List <Object> commandArgs) { ClientConnection client = appCtx.CurrentClient; System.Diagnostics.Trace.WriteLine("Sending " + command + " to " + target); MessageSent = client.SendCommand(target, command, commandArgs); UpdateMessageSentDetails(); }
private void LogMessage(CMDataSource.MessageDirection direction, Chetch.Messaging.Message message) { if (message.Type == Chetch.Messaging.MessageType.TRACE) { CurrentDataSource?.AddTraceData(message); } else { CurrentDataSource?.AddMessageData(direction, message); } }
public MessageData(MessageDirection direction, Chetch.Messaging.Message message) { ID = message.ID; Direction = direction; Type = message.Type; Target = message.Target; Sender = message.Sender; Summary = message.Value; Message = message; Timestamp = DateTime.Now.Ticks; }
private void HandleMessage(Object sender, ListChangedEventArgs e) { switch (e.ListChangedType) { case ListChangedType.ItemAdded: //showing response IList <CMDataSource.MessageData> l = (IList <CMDataSource.MessageData>)sender; var md = l[e.NewIndex]; if (MessageSent != null && md.Message.ResponseID == MessageSent.ID) { PopulateMessageDetails(md); MessageSent = null; } if (ServerCommandSent != null && md.Message.ResponseID == ServerCommandSent.ID) { String text = md.Message.ToStringHeader() + Environment.NewLine + md.Message.ToStringValues(true); PopulateTextBox(tbServerCommandResponse, text); ServerCommandSent = null; } break; } }
private void SendServerCommand() { try { var client = appCtx.CurrentClient; if (cmbServerCommands.SelectedIndex == -1) { throw new Exception("Please select a command"); } var s = cmbServerCommands.SelectedItem; Server.CommandName scmd = (Server.CommandName)Enum.Parse(typeof(Server.CommandName), s.ToString()); List <Object> args = new List <object>(); switch (scmd) { case Server.CommandName.CLOSE_CONNECTION: if (listViewServerConnections.SelectedItems.Count > 0) { args.Add(listViewServerConnections.SelectedItems[0].Name); } else { throw new Exception("Please select a connection"); } break; default: args = tbServerCommandLine.Text.Split(' ').ToList <Object>(); break; } ServerCommandSent = client.SendServerCommand(scmd, args); } catch (Exception e) { HandleException(e); } }
private void ModifyMessage(Connection cnn, Chetch.Messaging.Message message) { LogMessage(CMDataSource.MessageDirection.OUTBOUND, message); }
private void SendMessage(String sendType = null) { System.Diagnostics.Debug.Print("Send message"); try { if (sendType == null) { if (cmbSendType.SelectedItem != null) { sendType = cmbSendType.SelectedItem.ToString(); } } if (sendType == null || sendType == String.Empty) { throw new Exception("No send type provided"); } String target = null; if (listViewClients.SelectedItems != null && listViewClients.SelectedItems.Count > 0) { target = listViewClients.SelectedItems[0].Name; } ClientConnection client = appCtx.CurrentClient; String commandLine = tbCommandLine.Text; List <String> clArgs = commandLine.Split(' ').ToList(); if (client == null) { throw new Exception("No client from which to send"); } switch (sendType.Trim().ToUpper()) { case "PING": MessageSent = client.SendPing(target); break; case "STATUS REQUEST": if (target == null) { MessageSent = client.RequestServerStatus(); } else { MessageSent = client.RequestClientConnectionStatus(target); } break; case "SUBSCRIBE": if (target == null) { throw new Exception("Please select client to subscribe to"); } else { MessageSent = client.Subscribe(target); } break; case "UNSUBSCRIBE": if (target == null) { throw new Exception("Please select client to unsubscribe from"); } else { MessageSent = client.Unsubscribe(target); } break; case "COMMAND": if (target != null) { var cmd = clArgs[0]; var cmdArgs = clArgs.Count > 1 ? clArgs.GetRange(1, clArgs.Count - 1).ToList <Object>() : null; int repeat = 1; int delay = 0; String rd = tbRepeatDelay.Text; if (rd != null && rd != String.Empty) { String[] ar = rd.Split(':'); repeat = ar.Length > 0 ? System.Convert.ToInt32(ar[0]) : 1; delay = ar.Length > 1 ? System.Convert.ToInt32(ar[1]) : 0; } ThreadExecutionManager.Execute <List <Object> >("ccmdCMM", repeat, delay, SendClientCommand, target, cmd, cmdArgs); } else { throw new Exception("Use server tab to send commands to server"); } break; default: throw new Exception("Send type " + sendType + " not recognised"); } UpdateMessageSentDetails(); } catch (Exception e) { HandleException(e); } }