public RSMP_Messages.StatusUpdate CreateAndSendStatusUpdateMessage(cRoadSideObject RoadSideObject, List <RSMP_Messages.Status_VTQ> sS, bool bCreateMessageOnly, out string sSendBuffer) { sSendBuffer = ""; RSMP_Messages.StatusUpdate StatusUpdateMessage = new RSMP_Messages.StatusUpdate(); StatusUpdateMessage.mType = "rSMsg"; StatusUpdateMessage.type = "StatusUpdate"; StatusUpdateMessage.mId = System.Guid.NewGuid().ToString(); StatusUpdateMessage.ntsOId = RoadSideObject.sNTSObjectId; StatusUpdateMessage.xNId = RoadSideObject.sExternalNTSId; StatusUpdateMessage.cId = RoadSideObject.sComponentId; StatusUpdateMessage.sTs = CreateISO8601UTCTimeStamp(); StatusUpdateMessage.sS = sS; sSendBuffer = JSonSerializer.SerializeObject(StatusUpdateMessage); if (bCreateMessageOnly) { return(StatusUpdateMessage); } if (RSMPGS.JSon.SendJSonPacket(StatusUpdateMessage.type, StatusUpdateMessage.mId, sSendBuffer, true)) { if (RSMPGS.MainForm.checkBox_ViewOnlyFailedPackets.Checked == false) { RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Info, "Sent Status Update message, Type: " + StatusUpdateMessage.type + ", MsgId: " + StatusUpdateMessage.mId); } } else { if (cHelper.IsSettingChecked("BufferAndSendStatusUpdatesWhenConnect")) { cBufferedMessage BufferedMessage = new cBufferedMessage(cBufferedMessage.eMessageType.Status, StatusUpdateMessage.type, StatusUpdateMessage.mId, sSendBuffer); RSMPGS.MainForm.AddBufferedMessageToListAndListView(BufferedMessage); RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Warning, "Buffered Status Update message, Type: " + StatusUpdateMessage.type + ", MsgId: " + StatusUpdateMessage.mId); } } return(StatusUpdateMessage); }
private void button_BufferedMessages_CreateRandom_Click(object sender, EventArgs e) { if (comboBox_BufferedMessages_CreateRandom_Type.SelectedIndex < 0) { return; } int iMessageCount; if (Int32.TryParse(textBox_CreateRandomMessages_Count.Text, out iMessageCount) == false || iMessageCount > 30000) { MessageBox.Show("Invalid number or too many messages (>30000)", "Create buffered messages", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (iMessageCount <= 0) { return; } Cursor.Current = Cursors.WaitCursor; Application.DoEvents(); List <cAlarmObject> AlarmObjects = new List <cAlarmObject>(); List <cStatusReturnValue> StatusReturnValues = new List <cStatusReturnValue>(); List <cStatusReturnValue> ValidStatusReturnValues = new List <cStatusReturnValue>(); List <cRoadSideObject> AggregatedStatusRoadSideObjects = new List <nsRSMPGS.cRoadSideObject>(); foreach (cRoadSideObject RoadSideObject in RSMPGS.ProcessImage.RoadSideObjects.Values) { AlarmObjects.AddRange(RoadSideObject.AlarmObjects); foreach (cStatusObject StatusObject in RoadSideObject.StatusObjects) { StatusReturnValues.AddRange(StatusObject.StatusReturnValues); ValidStatusReturnValues.AddRange(StatusObject.StatusReturnValues.FindAll(srv => srv.Value.Quality == cValue.eQuality.recent)); } if (RoadSideObject.bIsComponentGroup) { AggregatedStatusRoadSideObjects.Add(RoadSideObject); } } Random rnd = new Random(); ListView_BufferedMessages.StopSorting(); ListView_BufferedMessages.BeginUpdate(); // RSMPGS.ProcessImage.AggregatedStatusObjects string sSendBuffer; for (int iIndex = 0; iIndex < iMessageCount; iIndex++) { switch (comboBox_BufferedMessages_CreateRandom_Type.SelectedIndex) { case 0: if (AlarmObjects.Count > 0) { cAlarmObject AlarmObject = AlarmObjects[rnd.Next(0, AlarmObjects.Count - 1)]; cJSon.AlarmSpecialisation alarmSpecialisation = new cJSon.AlarmSpecialisation[] { cJSon.AlarmSpecialisation.Acknowledge, cJSon.AlarmSpecialisation.Issue, cJSon.AlarmSpecialisation.Suspend }[rnd.Next(0, 2)]; RSMP_Messages.AlarmHeaderAndBody alarmHeaderAndBody = RSMPGS.JSon.CreateAndSendAlarmMessage(AlarmObject, alarmSpecialisation, true, out sSendBuffer); cBufferedMessage BufferedMessage = new cBufferedMessage(cBufferedMessage.eMessageType.Alarm, alarmHeaderAndBody.type, alarmHeaderAndBody.mId, sSendBuffer); AddBufferedMessageToListAndListView(BufferedMessage); } break; case 1: if (AggregatedStatusRoadSideObjects.Count > 0) { cRoadSideObject RoadSideObject = AggregatedStatusRoadSideObjects[rnd.Next(0, AggregatedStatusRoadSideObjects.Count - 1)]; RSMP_Messages.AggregatedStatus aggregatedStatus = RSMPGS.JSon.CreateAndSendAggregatedStatusMessage(RoadSideObject, true, out sSendBuffer); cBufferedMessage BufferedMessage = new cBufferedMessage(cBufferedMessage.eMessageType.AggregatedStatus, aggregatedStatus.type, aggregatedStatus.mId, sSendBuffer); AddBufferedMessageToListAndListView(BufferedMessage); } break; case 2: if (StatusReturnValues.Count > 0) { cStatusReturnValue StatusReturnValue = StatusReturnValues[rnd.Next(0, StatusReturnValues.Count - 1)]; List <RSMP_Messages.Status_VTQ> sS = new List <RSMP_Messages.Status_VTQ>(); RSMP_Messages.Status_VTQ s = new RSMP_Messages.Status_VTQ(); s.sCI = StatusReturnValue.StatusObject.sStatusCodeId; s.n = StatusReturnValue.sName; s.q = StatusReturnValue.Value.Quality.ToString(); s.s = StatusReturnValue.Value.Quality == cValue.eQuality.unknown ? null : StatusReturnValue.Value.GetValue(); sS.Add(s); RSMP_Messages.StatusUpdate statusUpdate = RSMPGS.JSon.CreateAndSendStatusUpdateMessage(StatusReturnValue.StatusObject.RoadSideObject, sS, true, out sSendBuffer); cBufferedMessage BufferedMessage = new cBufferedMessage(cBufferedMessage.eMessageType.Status, statusUpdate.type, statusUpdate.mId, sSendBuffer); AddBufferedMessageToListAndListView(BufferedMessage); } break; case 3: if (ValidStatusReturnValues.Count > 0) { cStatusReturnValue StatusReturnValue = ValidStatusReturnValues[rnd.Next(0, ValidStatusReturnValues.Count - 1)]; List <RSMP_Messages.Status_VTQ> sS = new List <RSMP_Messages.Status_VTQ>(); RSMP_Messages.Status_VTQ s = new RSMP_Messages.Status_VTQ(); s.sCI = StatusReturnValue.StatusObject.sStatusCodeId; s.n = StatusReturnValue.sName; s.q = StatusReturnValue.Value.Quality.ToString(); s.s = StatusReturnValue.Value.Quality == cValue.eQuality.unknown ? null : StatusReturnValue.Value.GetValue(); sS.Add(s); RSMP_Messages.StatusUpdate statusUpdate = RSMPGS.JSon.CreateAndSendStatusUpdateMessage(StatusReturnValue.StatusObject.RoadSideObject, sS, true, out sSendBuffer); cBufferedMessage BufferedMessage = new cBufferedMessage(cBufferedMessage.eMessageType.Status, statusUpdate.type, statusUpdate.mId, sSendBuffer); AddBufferedMessageToListAndListView(BufferedMessage); } break; } //cBufferedMessage //AddBufferedMessageToListAndListView(cBufferedMessage BufferedMessage) } ListView_BufferedMessages.EndUpdate(); ListView_BufferedMessages.ResumeSorting(); Cursor.Current = Cursors.Default; }