Пример #1
0
        private void RemoveBufferedMessages(cBufferedMessage.eMessageType MessageType)
        {
            Cursor.Current = Cursors.WaitCursor;
            Application.DoEvents();

            ListView_BufferedMessages.StopSorting();
            ListView_BufferedMessages.BeginUpdate();
            for (int iIndex = ListView_BufferedMessages.Items.Count - 1; iIndex >= 0; iIndex--)
            {
                cBufferedMessage BufferedMessage = (cBufferedMessage)ListView_BufferedMessages.Items[iIndex].Tag;
                if (BufferedMessage.MessageType == MessageType)
                {
                    ListView_BufferedMessages.Items.RemoveAt(iIndex);
                }
            }
            RSMPGS.ProcessImage.BufferedMessages.RemoveAll(bbuf => bbuf.MessageType == MessageType);

            /*
             *
             * List<cBufferedMessage> BufferedMessagesToSend =
             * foreach (cBufferedMessage BufferedMessage in BufferedMessagesToSend)
             * {
             * ListView_BufferedMessages.Items.Remove(BufferedMessage.lvItem);
             * }
             * RSMPGS.ProcessImage.BufferedMessages.RemoveAll(bbuf => bbuf.MessageType == MessageType);
             */
            ListView_BufferedMessages.EndUpdate();
            ListView_BufferedMessages.ResumeSorting();

            textBox_BufferedMessages.Text = RSMPGS.ProcessImage.BufferedMessages.Count.ToString();

            Cursor.Current = Cursors.Default;
        }
Пример #2
0
        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;
        }