public void UpdateAlarmListView(ListViewItem lvItem)
        {
            cAlarmObject AlarmObject = (cAlarmObject)lvItem.Tag;

            // alarmCodeId;description;externalAlarmCodeId;externalNtSAlarmCodeId;priority;category;name;type;value;Kommentar
            lvItem.Text = AlarmObject.StatusAsText();
            int iSubItemIndex = 1;

            //lvItem.SubItems[iSubItemIndex++].Text = AlarmObject.AlarmEvents.Count() > 0 ? AlarmObject.AlarmEvents.Count().ToString() : "";
            lvItem.SubItems[iSubItemIndex++].Text = AlarmObject.AlarmCount > 0 ? AlarmObject.AlarmCount.ToString() : "";
            lvItem.SubItems[iSubItemIndex++].Text = AlarmObject.sAlarmCodeId;
            lvItem.SubItems[iSubItemIndex++].Text = AlarmObject.sDescription;
            lvItem.SubItems[iSubItemIndex++].Text = AlarmObject.sExternalAlarmCodeId;
            lvItem.SubItems[iSubItemIndex++].Text = AlarmObject.sExternalNTSAlarmCodeId;
            lvItem.SubItems[iSubItemIndex++].Text = AlarmObject.sPriority;
            lvItem.SubItems[iSubItemIndex++].Text = AlarmObject.sCategory;

            foreach (cAlarmReturnValue AlarmReturnValue in AlarmObject.AlarmReturnValues)
            {
                lvItem.SubItems[iSubItemIndex++].Text = AlarmReturnValue.sName;
                lvItem.SubItems[iSubItemIndex++].Text = AlarmReturnValue.Value.GetValueType();
                lvItem.SubItems[iSubItemIndex++].Text = AlarmReturnValue.Value.GetValue();
                lvItem.SubItems[iSubItemIndex++].Text = AlarmReturnValue.sComment.Replace("\n", " / ");
            }
        }
Exemple #2
0
        public void AddAlarmEventToList(cAlarmObject AlarmObject, cAlarmEvent AlarmEvent)
        {
            if (bIsUpdatingAlarmEventList == false)
            {
                listView_AlarmEvents.StopSorting();
                listView_AlarmEvents.BeginUpdate();
                bIsUpdatingAlarmEventList = true;
            }

            ListViewItem lvItem = new ListViewItem(AlarmEvent.sTimeStamp);

            lvItem.SubItems.Add(AlarmObject.RoadSideObject.sComponentId + " / " + AlarmObject.RoadSideObject.sObject);
            lvItem.SubItems.Add(AlarmEvent.sMessageId);
            lvItem.SubItems.Add(AlarmEvent.sAlarmCodeId);
            lvItem.SubItems.Add(AlarmEvent.sDirection);
            lvItem.SubItems.Add(AlarmEvent.sEvent);

            foreach (cAlarmEventReturnValue AlarmReturnValues in AlarmEvent.AlarmEventReturnValues)
            {
                lvItem.SubItems.Add(AlarmReturnValues.sName);
                lvItem.SubItems.Add(AlarmReturnValues.sValue);
            }

            listView_AlarmEvents.Items.Add(lvItem);
        }
 public void CloneFromAlarmObject(cAlarmObject AlarmObjectToCopy)
 {
     RoadSideObject          = AlarmObjectToCopy.RoadSideObject;
     bActive                 = AlarmObjectToCopy.bActive;
     bSuspended              = AlarmObjectToCopy.bSuspended;
     bAcknowledged           = AlarmObjectToCopy.bAcknowledged;
     sObjectType             = AlarmObjectToCopy.sObjectType;
     sSpecificObject         = AlarmObjectToCopy.sSpecificObject;
     sAlarmCodeId            = AlarmObjectToCopy.sAlarmCodeId;
     sDescription            = AlarmObjectToCopy.sDescription;
     sExternalAlarmCodeId    = AlarmObjectToCopy.sExternalAlarmCodeId;
     sExternalNTSAlarmCodeId = AlarmObjectToCopy.sExternalNTSAlarmCodeId;
     sPriority               = AlarmObjectToCopy.sPriority;
     sCategory               = AlarmObjectToCopy.sCategory;
     AlarmReturnValues.Clear();
     foreach (cAlarmReturnValue AlarmReturnValue in AlarmObjectToCopy.AlarmReturnValues)
     {
         cAlarmReturnValue NewAlarmReturnValue = new cAlarmReturnValue();
         NewAlarmReturnValue.sName    = AlarmReturnValue.sName;
         NewAlarmReturnValue.sComment = AlarmReturnValue.sComment;
         NewAlarmReturnValue.Value    = new cValue(AlarmReturnValue.Value.ValueTypeObject, true);
         AlarmReturnValues.Add(NewAlarmReturnValue);
     }
     // We don't copy alarm events
 }
Exemple #4
0
        private void contextMenuStrip_Alarm_Opening(object sender, CancelEventArgs e)
        {
            ListViewItem lvItem = (listView_Alarms.SelectedItems.Count > 0) ? listView_Alarms.SelectedItems[0] : null;

            if (lvItem != null && RSMPGS.RSMPConnection.ConnectionStatus() == cTcpSocket.ConnectionStatus_Connected)
            {
                cAlarmObject AlarmObject = (cAlarmObject)lvItem.Tag;

                if (!AlarmObject.bActive && AlarmObject.bAcknowledged &&
                    RSMPGS.RSMPConnection.ConnectionStatus() == cTcpSocket.ConnectionStatus_Connected)
                {
                    ToolStripMenuItem_Acknowledge.Enabled = false;
                }
                else
                {
                    ToolStripMenuItem_Acknowledge.Enabled = true;
                }
                ToolStripMenuItem_Suspend.Enabled = true;
                ToolStripMenuItem_Suspend.Checked = AlarmObject.bSuspended == true;
                toolStripMenuItem_Alarm_RequestCurrentState.Enabled = (RSMPGS.JSon.NegotiatedRSMPVersion >= cJSon.RSMPVersion.RSMP_3_1_5) ? true : false;
            }
            else
            {
                ToolStripMenuItem_Acknowledge.Enabled = false;
                ToolStripMenuItem_Suspend.Enabled     = false;
                toolStripMenuItem_Alarm_RequestCurrentState.Enabled = false;
            }
        }
Exemple #5
0
 public void UpdateAlarmListView(cAlarmObject AlarmObject)
 {
     foreach (ListViewItem lvItem in listView_Alarms.Items)
     {
         if (lvItem.Tag == AlarmObject)
         {
             UpdateAlarmListView(lvItem);
             break;
         }
     }
 }
        public void CreateAndSendAlarmMessage(cAlarmObject AlarmObject, AlarmSpecialisation alarmSpecialisation)
        {
            RSMP_Messages.AlarmHeader AlarmHeader;
            cAlarmEvent AlarmEvent = null;
            string      sSendBuffer;

            try
            {
                AlarmHeader = new RSMP_Messages.AlarmHeader();

                AlarmHeader.mType = "rSMsg";
                AlarmHeader.type  = "Alarm";
                AlarmHeader.mId   = System.Guid.NewGuid().ToString();

                AlarmHeader.ntsOId = AlarmObject.RoadSideObject.sNTSObjectId;
                AlarmHeader.xNId   = AlarmObject.RoadSideObject.sExternalNTSId;
                AlarmHeader.cId    = AlarmObject.RoadSideObject.sComponentId;
                AlarmHeader.aCId   = AlarmObject.sAlarmCodeId;
                AlarmHeader.xACId  = AlarmObject.sExternalAlarmCodeId;
                AlarmHeader.xNACId = AlarmObject.sExternalNTSAlarmCodeId;

                AlarmHeader.aSp = alarmSpecialisation.ToString();

                sSendBuffer = JSonSerializer.SerializeObject(AlarmHeader);

                AlarmEvent              = new cAlarmEvent();
                AlarmEvent.AlarmObject  = AlarmObject;
                AlarmEvent.sDirection   = "Sent";
                AlarmEvent.sTimeStamp   = CreateLocalTimeStamp();
                AlarmEvent.sMessageId   = AlarmHeader.mId;
                AlarmEvent.sAlarmCodeId = AlarmHeader.aCId;
                AlarmEvent.sEvent       = AlarmHeader.aSp;

                RSMPGS.MainForm.AddAlarmEventToAlarmObjectAndToList(AlarmObject, AlarmEvent);
                RSMPGS.MainForm.UpdateAlarmListView(AlarmObject);

                /*
                 * if (RSMPGS_Main.bWriteEventsContinous)
                 * {
                 * RSMPGS.SysLog.EventLog("Alarm;{0}\tMId: {1}\tComponentId: {2}\tAlarmCodeId: {3}\tEvent: {4}",
                 *    AlarmEvent.sTimeStamp, AlarmEvent.sMessageId, AlarmHeader.cId, AlarmEvent.sAlarmCodeId, AlarmEvent.sEvent);
                 * }
                 */
                RSMPGS.JSon.SendJSonPacket(AlarmHeader.type, AlarmHeader.mId, sSendBuffer, true);
                if (RSMPGS.MainForm.checkBox_ViewOnlyFailedPackets.Checked == false)
                {
                    RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Info, "Sent alarm message, AlarmCode: " + AlarmObject.sAlarmCodeId + ", Type: " + AlarmHeader.type + "/" + AlarmHeader.aSp + ", MsgId: " + AlarmHeader.mId);
                }
            }
            catch (Exception e)
            {
                RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Error, "Failed to create alarm message: {0}", e.Message);
            }
        }
        public void AddAlarmEventToList(cAlarmObject AlarmObject, cAlarmEvent AlarmEvent)
        {
            ListViewItem lvItem = listView_AlarmEvents.Items.Add(AlarmEvent.sTimeStamp);

            lvItem.SubItems.Add(AlarmObject.RoadSideObject.sComponentId + " / " + AlarmObject.RoadSideObject.sObject);
            lvItem.SubItems.Add(AlarmEvent.sMessageId);
            lvItem.SubItems.Add(AlarmEvent.sAlarmCodeId);
            lvItem.SubItems.Add(AlarmEvent.sDirection);
            lvItem.SubItems.Add(AlarmEvent.sEvent);

            foreach (cAlarmEventReturnValue AlarmReturnValues in AlarmEvent.AlarmEventReturnValues)
            {
                lvItem.SubItems.Add(AlarmReturnValues.sName);
                lvItem.SubItems.Add(AlarmReturnValues.sValue);
            }
        }
        /*
         * private void listView_Alarms_SelectedIndexChanged(object sender, EventArgs e)
         * {
         * listView_AlarmEvents.Items.Clear();
         * if (listView_Alarms.SelectedItems.Count == 0)
         * {
         *  return;
         * }
         * cAlarmObject AlarmObject = (cAlarmObject)listView_Alarms.SelectedItems[0].Tag;
         * foreach (cAlarmEvent AlarmEvent in AlarmObject.AlarmEvents)
         * {
         *  AddAlarmEventToList(AlarmObject, listView_Alarms.SelectedItems[0], AlarmEvent);
         * }
         * }
         */

        public void AddAlarmEventToAlarmObjectAndToList(cAlarmObject AlarmObject, cAlarmEvent AlarmEvent)
        {
            if (RSMPGS_Main.iMaxEventsPerObject <= 0)
            {
                return;
            }

            AlarmObject.AlarmEvents.Add(AlarmEvent);

            while (AlarmObject.AlarmEvents.Count > RSMPGS_Main.iMaxEventsPerObject)
            {
                listView_AlarmEvents.Items.RemoveAt(0);
            }

            AddAlarmEventToList(AlarmObject, AlarmEvent);
        }
        private void listView_Alarms_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            ListView     listview = (ListView)sender;
            ListViewItem lvItem;

            int iSelectedColumn = 0;

            if (listview.SelectedItems.Count == 0)
            {
                return;
            }

            lvItem = listview.SelectedItems[0];

            ListViewHitTestInfo lvHitTest = listview.HitTest(LastMouseX, LastMouseY);

            foreach (ListViewItem.ListViewSubItem ScanSubItem in lvItem.SubItems)
            {
                if (lvHitTest.SubItem == ScanSubItem)
                {
                    break;
                }
                iSelectedColumn++;
            }

            try
            {
                // Tag is ex Value_2
                if (listview.Columns[iSelectedColumn].Tag.ToString().StartsWith("Value", StringComparison.OrdinalIgnoreCase))
                {
                    int               iIndex           = Int32.Parse(listview.Columns[iSelectedColumn].Tag.ToString().Substring(6));
                    cAlarmObject      AlarmObject      = (cAlarmObject)lvItem.Tag;
                    cAlarmReturnValue AlarmReturnValue = AlarmObject.AlarmReturnValues[iIndex];
                    string            sText            = lvHitTest.SubItem.Text;
                    // if (cFormsHelper.InputBox("Enter new value", "Value", ref sText, sType.Equals("base64", StringComparison.OrdinalIgnoreCase), true) == DialogResult.OK)
                    if (cFormsHelper.InputStatusBoxValueType("Enter new value", ref sText, AlarmReturnValue.Value, AlarmReturnValue.sComment, true) == DialogResult.OK)
                    {
                        AlarmReturnValue.Value.SetValue(sText);
                        lvHitTest.SubItem.Text = sText;
                    }
                }
            }
            catch
            {
            }
        }
        // Create from CSV-file
        public cAlarmReturnValue(cAlarmObject AlarmObject, string sCompleteRow, ref int iIndex)
        {
            sName = cHelper.Item(sCompleteRow, iIndex++, ';').Trim();

            if (IsValid())
            {
                string sType       = cHelper.Item(sCompleteRow, iIndex++, ';').Trim();
                string sValueRange = cHelper.Item(sCompleteRow, iIndex++, ';').Trim();
                sComment = cHelper.Item(sCompleteRow, iIndex++, ';').Trim();

                string sValueTypeKey = AlarmObject.sObjectType + "\t" + "alarms" + "\t" + AlarmObject.sAlarmCodeId + "\t" + AlarmObject.sSpecificObject + "\t" + sName;

                RSMPGS.ProcessImage.CreateAndAddValueTypeObject(sValueTypeKey, sName, sType, sValueRange, sComment);

                Value = new cValue(sValueTypeKey, true);
            }
        }
        private void contextMenuStrip_Alarm_Opening(object sender, CancelEventArgs e)
        {
            ListViewItem lvItem = (listView_Alarms.SelectedItems.Count > 0) ? listView_Alarms.SelectedItems[0] : null;

            if (lvItem == null || (RSMPGS.RSMPConnection.ConnectionStatus() != cTcpSocket.ConnectionStatus_Connected &&
                                   cHelper.IsSettingChecked("BufferAndSendAlarmsWhenConnect") == false))
            {
                ToolStripMenuItem_Active.Enabled      = false;
                ToolStripMenuItem_Acknowledge.Enabled = false;
                ToolStripMenuItem_Suspend.Enabled     = false;
            }
            else
            {
                cAlarmObject AlarmObject = (cAlarmObject)lvItem.Tag;
                ToolStripMenuItem_Active.Enabled      = true;
                ToolStripMenuItem_Acknowledge.Enabled = AlarmObject.bAcknowledged == false;
                ToolStripMenuItem_Suspend.Enabled     = true;
                ToolStripMenuItem_Active.Checked      = AlarmObject.bActive == true;
                ToolStripMenuItem_Suspend.Checked     = AlarmObject.bSuspended == true;
            }
        }
Exemple #12
0
        public void AddAlarmEventToAlarmObjectAndToList(cAlarmObject AlarmObject, cAlarmEvent AlarmEvent)
        {
            if (RSMPGS_Main.bWriteEventsContinous)
            {
                RSMPGS.SysLog.EventLog("Alarm;{0}\tMId: {1}\tComponentId: {2}\tAlarmCodeId: {3}\tDirection: {4}\tEvent: {5}",
                                       AlarmEvent.sTimeStamp, AlarmEvent.sMessageId, AlarmObject.RoadSideObject.sComponentId, AlarmEvent.sAlarmCodeId, AlarmEvent.sDirection, AlarmEvent.sEvent);
            }

            if (RSMPGS_Main.iMaxEventsPerObject <= 0)
            {
                return;
            }

            AlarmObject.AlarmEvents.Add(AlarmEvent);

            while (AlarmObject.AlarmEvents.Count > RSMPGS_Main.iMaxEventsPerObject)
            {
                listView_AlarmEvents.Items.RemoveAt(0);
            }

            AddAlarmEventToList(AlarmObject, AlarmEvent);
        }
Exemple #13
0
        private void ToolStripMenuItem_SendAlarmEvent_Click(object sender, EventArgs e)
        {
            ToolStripMenuItem menuitem    = (ToolStripMenuItem)sender;
            ListViewItem      lvItem      = listView_Alarms.SelectedItems[0];
            cAlarmObject      AlarmObject = (cAlarmObject)lvItem.Tag;

            switch (menuitem.Tag.ToString())
            {
            case "AcknowledgeAndSend":
                RSMPGS.JSon.CreateAndSendAlarmMessage(AlarmObject, cJSon.AlarmSpecialisation.Acknowledge);
                break;

            case "SuspendAndSend":
                RSMPGS.JSon.CreateAndSendAlarmMessage(AlarmObject, AlarmObject.bSuspended ? cJSon.AlarmSpecialisation.Resume : cJSon.AlarmSpecialisation.Suspend);
                break;

            case "RequestAndSend":
                RSMPGS.JSon.CreateAndSendAlarmMessage(AlarmObject, cJSon.AlarmSpecialisation.Request);
                break;
            }
            lvItem.SubItems[0].Text = AlarmObject.StatusAsText();
        }
        public RSMP_Messages.AlarmHeaderAndBody CreateAndSendAlarmMessage(cAlarmObject AlarmObject, AlarmSpecialisation alarmSpecialisation, out cAlarmEvent AlarmEvent)
        {
            string sSendBuffer;

            return(CreateAndSendAlarmMessage(AlarmObject, alarmSpecialisation, false, out sSendBuffer, out AlarmEvent));
        }
        private void ToolStripMenuItem_SendAlarmEvent_Click(object sender, EventArgs e)
        {
            if (listView_Alarms.SelectedItems.Count == 0)
            {
                return;
            }

            ToolStripMenuItem menuitem    = (ToolStripMenuItem)sender;
            ListViewItem      lvItem      = listView_Alarms.SelectedItems[0];
            cAlarmObject      AlarmObject = (cAlarmObject)lvItem.Tag;
            cAlarmEvent       AlarmEvent  = null;

            AlarmObject.dtLastChangedAlarmStatus = DateTime.Now;

            switch (menuitem.Tag.ToString())
            {
            case "ActiveAndSend":

                AlarmObject.bActive = AlarmObject.bActive == false;
                if (AlarmObject.bActive)
                {
                    AlarmObject.AlarmCount++;
                    AlarmObject.bAcknowledged = false;
                    RSMPGS.JSon.CreateAndSendAlarmMessage(AlarmObject, cJSon.AlarmSpecialisation.Issue, out AlarmEvent);
                }
                else
                {
                    RSMPGS.JSon.CreateAndSendAlarmMessage(AlarmObject, cJSon.AlarmSpecialisation.Issue, out AlarmEvent);
                }
                break;

            case "AcknowledgeAndSend":

                AlarmObject.bAcknowledged = true;
                RSMPGS.JSon.CreateAndSendAlarmMessage(AlarmObject, cJSon.AlarmSpecialisation.Acknowledge, out AlarmEvent);
                //JSon.CreateAndSendAlarmMessage(AlarmObject, cJSon.AlarmSpecialisation_Acknowledge);
                //foreach (cAlarmEvent ScanAlarmEvent in AlarmObject.AlarmEvents)
                //{
                RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Info, "Local ack of alarm: " + AlarmObject.sAlarmCodeId);
                //RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Info, "Local ack of alarm, TimeStamp: " + ScanAlarmEvent.sTimeStamp + ", MsgId: " + ScanAlarmEvent.sMessageId);// + ", SequenceNumber: " + ScanAlarmEvent.sSequenceNumber);
                //}
                //AlarmObject.AlarmEvents.Clear();
                //while (AlarmObject.AlarmEvents.Count > 0) AlarmObject.AlarmEvents.RemoveAt(0);
                //listView_AlarmEvents.Items.Clear();
                break;

            case "SuspendAndSend":

                AlarmObject.bSuspended = AlarmObject.bSuspended == false;
                RSMPGS.JSon.CreateAndSendAlarmMessage(AlarmObject, cJSon.AlarmSpecialisation.Suspend, out AlarmEvent);
                //JSon.CreateAndSendAlarmMessage(AlarmObject, cJSon.AlarmSpecialisation_Suspend);
                break;
            }

            if (AlarmEvent != null)
            {
                AddAlarmEventToAlarmObjectAndToList(AlarmObject, AlarmEvent);
            }

            UpdateAlarmListView(AlarmObject);
        }
        public RSMP_Messages.AlarmHeaderAndBody CreateAndSendAlarmMessage(cAlarmObject AlarmObject, AlarmSpecialisation alarmSpecialisation)
        {
            cAlarmEvent AlarmEvent;

            return(CreateAndSendAlarmMessage(AlarmObject, alarmSpecialisation, out AlarmEvent));
        }
        public RSMP_Messages.AlarmHeaderAndBody CreateAndSendAlarmMessage(cAlarmObject AlarmObject, AlarmSpecialisation alarmSpecialisation, bool bCreateMessageOnly, out string sSendBuffer)
        {
            cAlarmEvent AlarmEvent;

            return(CreateAndSendAlarmMessage(AlarmObject, alarmSpecialisation, bCreateMessageOnly, out sSendBuffer, out AlarmEvent));
        }
Exemple #18
0
        public void LoadProcessImageValues(RSMPGS_Main MainForm, string FileName)
        {
            bool bWeAreConnected = false;

            try
            {
                if (RSMPGS.RSMPConnection != null)
                {
                    bWeAreConnected = RSMPGS.RSMPConnection.ConnectionStatus() == cTcpSocket.ConnectionStatus_Connected;
                }

                List <RSMP_Messages.Status_VTQ> sS = new List <RSMP_Messages.Status_VTQ>();

                //StreamReader swReferenceFile = new StreamReader((System.IO.Stream)File.OpenRead(FileName), encoding);
                //swReferenceFile.Close();

                /*
                 * [26108.AB+26108=881CG001.Passagedetektor.Passagedetektor DP1.AB+26108=881DP001.Alarms]
                 * A904.Active=True
                 *
                 * [26108.AB+26108=881CG001.Passagedetektor.Passagedetektor DP1.AB+26108=881DP001.AlarmEvents]
                 * A904.AlarmEvent_0.MessageId=f56ad0f6-7c4c-4b51-a602-8ba9fadf6ea8
                 * A904.AlarmEvent_0.TimeStamp=2011-11-16T12:52:39.437
                 * [26108.AB+26108=881CG001.Passagedetektor.Passagedetektor DP1.AB+26108=881DP001.Status]
                 * S0001.status 1.Status=10
                 */

                foreach (cRoadSideObject RoadSideObject in RSMPGS.ProcessImage.RoadSideObjects.Values)
                {
                    bool bSomeThingWasChangedInAggregatedStatus = false;

                    if (MainForm.checkBox_ProcessImageLoad_AlarmStatus.Checked)
                    {
                        foreach (cAlarmObject AlarmObject in RoadSideObject.AlarmObjects)
                        {
                            string sSection   = RoadSideObject.UniqueId() + ".Alarms";
                            string sParameter = AlarmObject.sAlarmCodeId + ".Active";

                            cAlarmEvent  AlarmEvent     = null;
                            cAlarmObject NewAlarmObject = new cAlarmObject();

                            NewAlarmObject.bActive       = cPrivateProfile.GetIniFileInt(FileName, RoadSideObject.UniqueId() + ".Alarms", AlarmObject.sAlarmCodeId + ".Active", 0) != 0;
                            NewAlarmObject.bSuspended    = cPrivateProfile.GetIniFileInt(FileName, RoadSideObject.UniqueId() + ".Alarms", AlarmObject.sAlarmCodeId + ".Suspended", 0) != 0;
                            NewAlarmObject.bAcknowledged = cPrivateProfile.GetIniFileInt(FileName, RoadSideObject.UniqueId() + ".Alarms", AlarmObject.sAlarmCodeId + ".Acknowledged", 0) != 0;

                            AlarmObject.AlarmEvents.Clear();

                            foreach (cAlarmReturnValue AlarmReturnValue in AlarmObject.AlarmReturnValues)
                            {
                                string sValue = cPrivateProfile.GetIniFileString(FileName, RoadSideObject.UniqueId() + ".Alarms", AlarmObject.sAlarmCodeId + "." + AlarmReturnValue.sName + ".Value", "?");

                                if (sValue != "?")
                                {
                                    AlarmReturnValue.Value.SetValue(sValue);
                                }
                            }

                            if (AlarmObject.bSuspended != NewAlarmObject.bSuspended)
                            {
                                AlarmObject.bSuspended = NewAlarmObject.bSuspended;
                                if (bWeAreConnected)
                                {
                                    RSMPGS.JSon.CreateAndSendAlarmMessage(AlarmObject, cJSon.AlarmSpecialisation.Suspend);
                                }
                            }

                            if (AlarmObject.bActive != NewAlarmObject.bActive)
                            {
                                AlarmObject.bActive = NewAlarmObject.bActive;
                                if (bWeAreConnected)
                                {
                                    if (NewAlarmObject.bActive)
                                    {
                                        RSMPGS.JSon.CreateAndSendAlarmMessage(AlarmObject, cJSon.AlarmSpecialisation.Issue, out AlarmEvent);
                                        if (AlarmEvent != null)
                                        {
                                            AlarmObject.AlarmEvents.Add(AlarmEvent);
                                        }
                                    }
                                    else
                                    {
                                        RSMPGS.JSon.CreateAndSendAlarmMessage(AlarmObject, cJSon.AlarmSpecialisation.Issue);
                                        AlarmObject.AlarmEvents.Clear();
                                    }
                                }
                            }

                            if (AlarmObject.bAcknowledged != NewAlarmObject.bAcknowledged)
                            {
                                AlarmObject.bAcknowledged = NewAlarmObject.bAcknowledged;
                                if (bWeAreConnected)
                                {
                                    RSMPGS.JSon.CreateAndSendAlarmMessage(AlarmObject, cJSon.AlarmSpecialisation.Acknowledge);
                                }
                                AlarmObject.AlarmEvents.Clear();
                            }

                            AlarmObject.AlarmCount = 0;


                            /*
                             *        sSection = sObjectUniqueId + ".AlarmEvents";
                             *
                             *        foreach (cAlarmReturnValue AlarmReturnValue in AlarmObject.AlarmReturnValues)
                             *        {
                             *          AlarmReturnValue.sValue = cPrivateProfile.GetIniFileString(FileName, sSection, AlarmObject.sAlarmCodeId + ".ReturnValue_" + AlarmReturnValue.sName + ".Value", "");
                             *        }
                             *        for (int iIndex = 0; ; iIndex++)
                             *        {
                             *          string sMsgId = cPrivateProfile.GetIniFileString(FileName, sSection, AlarmObject.sAlarmCodeId + ".AlarmEvent_" + iIndex.ToString() + ".MessageId", "");
                             *          string sTS = cPrivateProfile.GetIniFileString(FileName, sSection, AlarmObject.sAlarmCodeId + ".AlarmEvent_" + iIndex.ToString() + ".TimeStamp", "");
                             *          if (sMsgId.Length > 0)
                             *          {
                             *            cAlarmEvent AlarmEvent = new cAlarmEvent();
                             *            AlarmEvent.sMessageId = sMsgId;
                             *            AlarmEvent.sTimeStamp = sTS;
                             *            AlarmObject.AlarmEvents.Add(AlarmEvent);
                             *          }
                             *          else
                             *          {
                             *            break;
                             *          }
                             *
                             *        }
                             */
                        }
                    }

                    if (MainForm.checkBox_ProcessImageLoad_Status.Checked)
                    {
                        // Stored status
                        foreach (cStatusObject StatusObject in RoadSideObject.StatusObjects)
                        {
                            foreach (cStatusReturnValue StatusReturnValue in StatusObject.StatusReturnValues)
                            {
                                string sStatus = cPrivateProfile.GetIniFileString(FileName, RoadSideObject.UniqueId() + ".Status", StatusObject.sStatusCodeId + "." + StatusReturnValue.sName + ".Status", "?");
                                StatusReturnValue.bRecentlyChanged = false;
                                if (sStatus != "?")
                                {
                                    StatusReturnValue.bRecentlyChanged = StatusReturnValue.Value.GetValue().Equals(sStatus) ? false : true;
                                    StatusReturnValue.Value.SetValue(sStatus);
                                }
                            }
                        }
                        sS.Clear();
                        foreach (cSubscription Subscription in RoadSideObject.Subscriptions)
                        {
                            if (Subscription.SubscribeStatus == cSubscription.SubscribeMethod.OnChange || Subscription.SubscribeStatus == cSubscription.SubscribeMethod.IntervalAndOnChange)
                            {
                                if (Subscription.StatusReturnValue.bRecentlyChanged)
                                {
                                    RSMP_Messages.Status_VTQ s = new RSMP_Messages.Status_VTQ();
                                    s.sCI = Subscription.StatusObject.sStatusCodeId;
                                    s.n   = Subscription.StatusReturnValue.sName; // Subscription.StatusObject.StatusReturnValues .StatusReturnValues[iIndex].sName;
                                    UpdateStatusValue(ref s, Subscription.StatusReturnValue.Value.GetValueType(), Subscription.StatusReturnValue.Value.GetValue());
                                    sS.Add(s);
                                    Subscription.LastUpdate = DateTime.Now;
                                    Subscription.StatusReturnValue.bRecentlyChanged = false;
                                }
                            }
                        }

                        if (sS.Count > 0)
                        {
                            if (bWeAreConnected)
                            {
                                RSMPGS.JSon.CreateAndSendStatusUpdateMessage(RoadSideObject, sS);
                            }
                        }
                    }
                    if (MainForm.checkBox_ProcessImageLoad_AggregatedStatus.Checked)
                    {
                        if (RoadSideObject.bIsComponentGroup)
                        {
                            if (RoadSideObject.sFunctionalPosition.Equals(cPrivateProfile.GetIniFileString(FileName, RoadSideObject.UniqueId() + ".AggregatedStatus", "FunctionalPosition", "")) == false)
                            {
                                RoadSideObject.sFunctionalPosition     = cPrivateProfile.GetIniFileString(FileName, RoadSideObject.UniqueId() + ".AggregatedStatus", "FunctionalPosition", "");
                                bSomeThingWasChangedInAggregatedStatus = true;
                            }
                            if (RoadSideObject.sFunctionalState.Equals(cPrivateProfile.GetIniFileString(FileName, RoadSideObject.UniqueId() + ".AggregatedStatus", "FunctionalState", "")) == false)
                            {
                                RoadSideObject.sFunctionalState        = cPrivateProfile.GetIniFileString(FileName, RoadSideObject.UniqueId() + ".AggregatedStatus", "FunctionalState", "");
                                bSomeThingWasChangedInAggregatedStatus = true;
                            }
                            for (int iIndex = 0; iIndex < RoadSideObject.bBitStatus.GetLength(0); iIndex++)
                            {
                                if (RoadSideObject.bBitStatus[iIndex] != (cPrivateProfile.GetIniFileInt(FileName, RoadSideObject.UniqueId() + ".AggregatedStatus", "BitStatus_" + iIndex.ToString(), 0) != 0))
                                {
                                    RoadSideObject.bBitStatus[iIndex]      = cPrivateProfile.GetIniFileInt(FileName, RoadSideObject.UniqueId() + ".AggregatedStatus", "BitStatus_" + iIndex.ToString(), 0) != 0;
                                    bSomeThingWasChangedInAggregatedStatus = true;
                                }
                            }
                            if (bSomeThingWasChangedInAggregatedStatus)
                            {
                                if (MainForm.checkBox_AggregatedStatus_SendAutomaticallyWhenChanged.Checked)
                                {
                                    if (bWeAreConnected)
                                    {
                                        RSMPGS.JSon.CreateAndSendAggregatedStatusMessage(RoadSideObject);
                                    }
                                }
                            }
                        }
                    }

                    if (MainForm.treeView_SitesAndObjects.SelectedNode != null)
                    {
                        if (MainForm.treeView_SitesAndObjects.SelectedNode.Tag != null && MainForm.treeView_SitesAndObjects.SelectedNode.Parent != null)
                        {
                            if (RoadSideObject == (cRoadSideObject)MainForm.treeView_SitesAndObjects.SelectedNode.Tag)
                            {
                                MainForm.UpdateStatusListView(null, RoadSideObject);
                                MainForm.UpdateAlarmListView(null, RoadSideObject);
                                if (bSomeThingWasChangedInAggregatedStatus)
                                {
                                    for (int iIndex = 0; iIndex < RoadSideObject.bBitStatus.GetLength(0); iIndex++)
                                    {
                                        ListViewItem lvItem = MainForm.listView_AggregatedStatus_StatusBits.Items[iIndex];
                                        MainForm.SetStatusBitColor(lvItem, RoadSideObject.bBitStatus[iIndex]);
                                    }
                                    RSMPGS_Main.bIsCurrentlyChangingSelection = true;
                                    MainForm.listBox_AggregatedStatus_FunctionalPosition.ClearSelected();
                                    for (int iIndex = 0; iIndex < MainForm.listBox_AggregatedStatus_FunctionalPosition.Items.Count; iIndex++)
                                    {
                                        if (MainForm.listBox_AggregatedStatus_FunctionalPosition.Items[iIndex].Equals(RoadSideObject.sFunctionalPosition))
                                        {
                                            MainForm.listBox_AggregatedStatus_FunctionalPosition.SelectedIndex = iIndex;
                                        }
                                    }
                                    MainForm.listBox_AggregatedStatus_FunctionalState.ClearSelected();
                                    for (int iIndex = 0; iIndex < MainForm.listBox_AggregatedStatus_FunctionalState.Items.Count; iIndex++)
                                    {
                                        if (MainForm.listBox_AggregatedStatus_FunctionalState.Items[iIndex].Equals(RoadSideObject.sFunctionalState))
                                        {
                                            MainForm.listBox_AggregatedStatus_FunctionalState.SelectedIndex = iIndex;
                                        }
                                    }
                                    RSMPGS_Main.bIsCurrentlyChangingSelection = false;
                                }
                            }
                        }
                    }
                }


                /*
                 * listBox_AggregatedStatus_FunctionalPosition_SelectedIndexChanged(object sender, EventArgs e)
                 * listBox_AggregatedStatus_FunctionalState_SelectedIndexChanged(object sender, EventArgs e)
                 *
                 */
                RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Info, "Loaded Process data from '{0}'", FileName);
            }
            catch (Exception e)
            {
                RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Error, "Failed to load Process data from '{0}' - {1}", FileName, e.Message);
            }
        }
        public RSMP_Messages.AlarmHeaderAndBody CreateAndSendAlarmMessage(cAlarmObject AlarmObject, AlarmSpecialisation alarmSpecialisation, bool bCreateMessageOnly, out string sSendBuffer, out cAlarmEvent AlarmEvent)
        {
            sSendBuffer = "";

            RSMP_Messages.AlarmHeaderAndBody AlarmHeaderAndBody;
            //      RSMP_Messages.AlarmHeader AlarmHeader;


            AlarmHeaderAndBody = new RSMP_Messages.AlarmHeaderAndBody();

            AlarmEvent = new cAlarmEvent();

            try
            {
                AlarmHeaderAndBody.mType  = "rSMsg";
                AlarmHeaderAndBody.type   = "Alarm";
                AlarmHeaderAndBody.mId    = System.Guid.NewGuid().ToString();
                AlarmHeaderAndBody.ntsOId = AlarmObject.RoadSideObject.sNTSObjectId;
                AlarmHeaderAndBody.xNId   = AlarmObject.RoadSideObject.sExternalNTSId;
                AlarmHeaderAndBody.cId    = AlarmObject.RoadSideObject.sComponentId;
                AlarmHeaderAndBody.aCId   = AlarmObject.sAlarmCodeId;
                AlarmHeaderAndBody.xACId  = AlarmObject.sExternalAlarmCodeId;
                AlarmHeaderAndBody.xNACId = AlarmObject.sExternalNTSAlarmCodeId;
                AlarmHeaderAndBody.rvs    = new List <RSMP_Messages.AlarmReturnValue>();


                AlarmEvent.AlarmObject = AlarmObject;

                AlarmHeaderAndBody.ack = AlarmObject.bAcknowledged ? "Acknowledged" : "notAcknowledged";
                AlarmHeaderAndBody.aS  = AlarmObject.bActive ? "Active" : "inActive";
                AlarmHeaderAndBody.sS  = AlarmObject.bSuspended ? "Suspended" : "notSuspended";

                switch (alarmSpecialisation)
                {
                case AlarmSpecialisation.Issue:
                    AlarmHeaderAndBody.aSp = "Issue";
                    AlarmEvent.sEvent      = AlarmHeaderAndBody.aSp + " / " + AlarmHeaderAndBody.aS;
                    break;

                case AlarmSpecialisation.Acknowledge:
                    AlarmHeaderAndBody.aSp = "Acknowledge";
                    AlarmEvent.sEvent      = AlarmHeaderAndBody.aSp + " / " + AlarmHeaderAndBody.ack;
                    break;

                case AlarmSpecialisation.Suspend:
                    AlarmHeaderAndBody.aSp = "Suspend";
                    AlarmEvent.sEvent      = AlarmHeaderAndBody.aSp + " / " + AlarmHeaderAndBody.sS;
                    break;
                }

                if (AlarmObject.bActive == false && AlarmObject.bAcknowledged)
                {
                    AlarmObject.AlarmCount = 0;
                }

                if (AlarmObject.dtLastChangedAlarmStatus == DateTime.MinValue)
                {
                    AlarmObject.dtLastChangedAlarmStatus = DateTime.Now;
                }

                AlarmHeaderAndBody.aTs = CreateISO8601UTCTimeStamp(AlarmObject.dtLastChangedAlarmStatus);
                AlarmHeaderAndBody.cat = AlarmObject.sCategory;
                AlarmHeaderAndBody.pri = AlarmObject.sPriority;

                AlarmEvent.sAlarmCodeId = AlarmObject.sAlarmCodeId;
                AlarmEvent.sDirection   = "Sent";
                AlarmEvent.sTimeStamp   = UnpackISO8601UTCTimeStamp(AlarmHeaderAndBody.aTs); // String.Format("{0:yyyy-MM-dd}T{0:HH:mm:ss.fff}", UnpackISO8601UTCTimeStamp(AlarmHeaderAndBody.aTs));
                AlarmEvent.sMessageId   = AlarmHeaderAndBody.mId;

                foreach (cAlarmReturnValue AlarmReturnValue in AlarmObject.AlarmReturnValues)
                {
                    RSMP_Messages.AlarmReturnValue rv = new RSMP_Messages.AlarmReturnValue();
                    rv.n = AlarmReturnValue.sName;
                    rv.v = AlarmReturnValue.Value.GetValue();
                    AlarmHeaderAndBody.rvs.Add(rv);
                    AlarmEvent.AlarmEventReturnValues.Add(new nsRSMPGS.cAlarmEventReturnValue(rv.n, rv.v));
                }

                sSendBuffer = JSonSerializer.SerializeObject(AlarmHeaderAndBody);

                if (bCreateMessageOnly)
                {
                    return(AlarmHeaderAndBody);
                }

                if (RSMPGS.JSon.SendJSonPacket(AlarmHeaderAndBody.type, AlarmHeaderAndBody.mId, sSendBuffer, true))
                {
                    if (RSMPGS.MainForm.checkBox_ViewOnlyFailedPackets.Checked == false)
                    {
                        RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Info, "Sent alarm message, AlarmCode: " + AlarmObject.sAlarmCodeId + ", Type: " + AlarmHeaderAndBody.type + "/" + AlarmHeaderAndBody.aSp + "/" + AlarmHeaderAndBody.aS + ", MsgId: " + AlarmHeaderAndBody.mId);//, SequenceNumber: " + AlarmHeaderAndBody.sNr);
                    }
                }
                else
                {
                    if (cHelper.IsSettingChecked("BufferAndSendAlarmsWhenConnect"))
                    {
                        cBufferedMessage BufferedMessage = new cBufferedMessage(cBufferedMessage.eMessageType.Alarm, AlarmHeaderAndBody.type, AlarmHeaderAndBody.mId, sSendBuffer);
                        RSMPGS.MainForm.AddBufferedMessageToListAndListView(BufferedMessage);
                        RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Warning, "Buffered alarm message, AlarmCode: " + AlarmObject.sAlarmCodeId + ", Type: " + AlarmHeaderAndBody.type + "/" + AlarmHeaderAndBody.aSp + "/" + AlarmHeaderAndBody.aS + ", MsgId: " + AlarmHeaderAndBody.mId);// + ", SequenceNumber: " + AlarmHeaderAndBody.sNr);
                    }
                }

                //        RSMPGS.ProcessImage.SequenceNumber_Alarm++;
            }
            catch (Exception e)
            {
                RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Error, "Failed to create alarm message: {0}", e.Message);
                AlarmEvent = null;
            }

            return(AlarmHeaderAndBody);
        }
        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;
        }