public void IncomingMessage(Message msg) { if (!string.IsNullOrEmpty(msg.Body)) { //Console.WriteLine("msg body: {0}", msg.Body); try { TMsgWrapper msgObj = JsonConvert.DeserializeObject <TMsgWrapper>(msg.Body); logger.Debug("Recieved message - " + msg.Body); if (msgObj != null) { //if (_form != null) _form?.IncomingEMRALDMsg(msg.From, msgObj); //process the message with EMRALD _evCallBackFunc?.Invoke(ResAndNameFromConnection(msg.From), msgObj); } else { _form?.IncomingOtherMsg(ResAndNameFromConnection(msg.From), msg.Body); } } catch (Exception e) { _form?.IncomingOtherMsg(ResAndNameFromConnection(msg.From), msg.Body); logger.Error(e.Message); System.Threading.Thread.Sleep(500); //give time for error to write to log throw new Exception(e.Message); } } }
private void btnSendMsg_Click_1(object sender, EventArgs e) { if (cbRegisteredClients.SelectedIndex >= 0) { //see if json is valid string schemaStr = System.IO.File.ReadAllText("MessageProtocol.JSON"); JSchema schemaChk = JSchema.Parse(schemaStr); try { JToken json = JToken.Parse(rtbJSONMsg.Text); IList <ValidationError> errors; bool valid = json.IsValid(schemaChk, out errors); if (!valid) { rtbJSONErrors.Visible = true; rtbJSONErrors.Clear(); foreach (var error in errors) { rtbJSONErrors.AppendText(error.Message + Environment.NewLine); foreach (var child in error.ChildErrors) { rtbJSONErrors.AppendText("Error - Line : " + child.LineNumber + " Pos : " + child.LinePosition + " - " + child.Message + Environment.NewLine); } } } else { TMsgWrapper msg = JsonConvert.DeserializeObject <TMsgWrapper>(rtbJSONMsg.Text); if (msg != null) { rtbJSONErrors.Visible = false; AssignServer(); //make sure it has been assigned _server.SendMessage(msg, (string)cbRegisteredClients.Items[cbRegisteredClients.SelectedIndex]); } else { rtbJSONErrors.Visible = true; rtbJSONErrors.Text = "Error creating message from JSON text."; } } } catch (Exception er) { rtbJSONErrors.Visible = true; if (er is JsonReaderException) { rtbJSONErrors.Text = "Error - Line : " + ((JsonReaderException)er).LineNumber + " Pos : " + ((JsonReaderException)er).LinePosition + Environment.NewLine; } else { rtbJSONErrors.Text = "Text is not a valid JSON Message Object :" + Environment.NewLine; } rtbJSONErrors.AppendText(er.Message); } } else { MessageBox.Show("You must select a client to send it to. Left of the Send Bttn."); } }
public void IncomingMessage(Message msg) { if (!string.IsNullOrEmpty(msg.Body)) { TMsgWrapper msgObj = JsonConvert.DeserializeObject <TMsgWrapper>(msg.Body); if (msgObj != null) { if (m_form != null) { if (msg.From == null) { m_form.IncomingEMRALDMsg("Server", msgObj); } else { m_form.IncomingEMRALDMsg(msg.From, msgObj); } } //todo - process the message with EMRALD } else { m_form.IncomingOtherMsg(msg.From, msg.Body); } } }
private void btnGenMsg_Click(object sender, EventArgs e) { TimeSpan time = TimeSpan.FromSeconds(0); try { time = TimeSpan.Parse(tbTimeSpan.Text); } catch { }; TMsgWrapper msgObj = new TMsgWrapper(MessageType.mtSimEvent, tbDispName.Text, TimeSpan.FromSeconds(0), tbMsgDesc.Text); msgObj.simEvents.Add(new SimEvent((SimEventType)cbMsgType.SelectedIndex, time)); switch (tabCtrlMsgTypes.SelectedIndex) { case 0: //Item Data msgObj.simEvents[0].itemData = new ItemData(tbItemDataName.Text, tbItemDataValue.Text); break; case 1: //Status msgObj.simEvents[0].status = (StatusType)cbStatusMsgType.SelectedIndex; break; } if (msgObj != null) { rtbJSONMsg.Text = JsonConvert.SerializeObject(msgObj, Formatting.Indented); } }
public void IncomingEMRALDMsg(string sender, TMsgWrapper msg) { MethodInvoker methodInvokerDelegate = delegate() { //rtfReceived.Text = msg; rtfReceived.AppendText("From : " + sender + Environment.NewLine); rtfReceived.AppendText("JSON String: \n"); rtfReceived.AppendText(JsonConvert.SerializeObject(msg, Formatting.Indented)); }; InvokeUIUpdate(methodInvokerDelegate); }
//private void rbCompModFV_CheckedChanged(object sender, EventArgs e) //{ // this.grpboxCompMod1.Enabled = rbCompModFV.Checked; // if(rbCompModFV.Checked) // { // rbCompModInfo.Checked = false; // } // else // { // tbCompModField.Clear(); // tbCompModValue.Clear(); // } //} //private void rbCompModInfo_CheckedChanged(object sender, EventArgs e) //{ // this.grpboxCompMod2.Enabled = rbCompModInfo.Checked; // if (rbCompModInfo.Checked) // { // rbCompModFV.Checked = false; // } // else // { // rtbCompMsgInfo.Clear(); // } //} private void btnGenMsg_Click(object sender, EventArgs e) { TimeSpan time = TimeSpan.FromSeconds(0); try { time = TimeSpan.Parse(lblSimTime.Text); } catch { }; TMsgWrapper msgObj = new TMsgWrapper(MessageType.mtSimAction, tbDispName.Text, time, tbMsgDesc.Text); TimeSpan actTime = TimeSpan.FromSeconds(0); try { if (pnlTimePicking.Visible) { actTime = TimeSpan.Parse(tbTimeSpan.Text); } } catch { MessageBox.Show("Not a valid time for the action."); return; }; switch ((SimActionType)cbMsgType.SelectedIndex) { case SimActionType.atCompModify: msgObj.simAction = new SimAction(SimActionType.atCompModify, actTime, new ItemData(tbItemDataName.Text, tbItemDataValue.Text)); break; case SimActionType.atOpenSim: TimeSpan endTime = TimeSpan.FromSeconds(0); try { endTime = TimeSpan.Parse(tbEndTime.Text); } catch { } msgObj.simAction = new SimAction(new SimInfo(tbModelRef.Text, endTime, tbConfigData.Text)); break; case SimActionType.atTimer: case SimActionType.atRestartAtTime: msgObj.simAction = new SimAction((SimActionType)cbMsgType.SelectedIndex, actTime); break; default: msgObj.simAction = new SimAction((SimActionType)cbMsgType.SelectedIndex); break; } if (msgObj != null) { rtbJSONMsg.Text = JsonConvert.SerializeObject(msgObj, Formatting.Indented); } }
public bool SendMessage(TMsgWrapper msg, string toJid = "") { // Convert the SampleMessage to a JSON string string jsonStr = JsonConvert.SerializeObject(msg); // if (toJid == "" || m_RosterItems.ContainsKey(toJid)) { m_xmppNsgClient.SendMessage(jsonStr, m_nextMsgId.ToString(), toJid); m_nextMsgId++; return(true); } else { return(false); } }
public bool SendMessage(TMsgWrapper msg, string resAndClient) { string key = resAndClient; if (_resourceLookup.ContainsKey(key)) { Jid userJid = _resourceLookup[key]; // Convert the SampleMessage to a JSON string string jsonStr = JsonConvert.SerializeObject(msg); logger.Debug("Sending message - " + jsonStr); _xmppMsgServer.SendMessage(jsonStr, "S-" + _nextMsgId.ToString(), userJid); _nextMsgId++; return(true); } else { string err = "error, could not find attached simulation for " + resAndClient; logger.Error(err); throw new Exception(err); } }
public void IncomingEMRALDMsg(string sender, TMsgWrapper msg) { MethodInvoker methodInvokerDelegate = delegate() { rtfReceived.AppendText("From : " + sender + Environment.NewLine); rtfReceived.AppendText("JSON String: \n"); rtfReceived.AppendText(JsonConvert.SerializeObject(msg, Formatting.Indented)); List <TMsgWrapper> msgList; if (_validMessages.TryGetValue(sender, out msgList)) { msgList.Add(msg); } else { msgList = new List <TMsgWrapper>(); _validMessages.Add(sender, msgList); msgList.Add(msg); } }; InvokeUIUpdate(methodInvokerDelegate); }