CreateSnapshot() public method

Creates a snapshort of the alarm.
public CreateSnapshot ( ) : UnderlyingSystemAlarm
return UnderlyingSystemAlarm
Beispiel #1
0
        /// <summary>
        /// Acknowledges an alarm.
        /// </summary>
        /// <param name="alarmName">Name of the alarm.</param>
        /// <param name="recordNumber">The record number.</param>
        /// <param name="comment">The comment.</param>
        /// <param name="userName">Name of the user.</param>
        public void AcknowledgeAlarm(string alarmName, uint recordNumber, LocalizedText comment, string userName)
        {
            UnderlyingSystemAlarm snapshot = null;

            lock (m_alarms)
            {
                UnderlyingSystemAlarm alarm = FindAlarm(alarmName, recordNumber);

                if (alarm != null)
                {
                    if (alarm.SetStateBits(UnderlyingSystemAlarmStates.Acknowledged, true))
                    {
                        alarm.Time     = DateTime.UtcNow;
                        alarm.Reason   = "The alarm was acknoweledged.";
                        alarm.Comment  = Utils.Format("{0}", comment);
                        alarm.UserName = userName;

                        alarm.SetStateBits(UnderlyingSystemAlarmStates.Confirmed, false);
                    }

                    snapshot = alarm.CreateSnapshot();
                }
            }

            if (snapshot != null)
            {
                ReportAlarmChange(snapshot);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Sets the state of the source (surpresses any active alarms).
        /// </summary>
        /// <param name="offline">if set to <c>true</c> the source is offline.</param>
        public void SetOfflineState(bool offline)
        {
            m_isOffline = offline;
            List <UnderlyingSystemAlarm> snapshots = new List <UnderlyingSystemAlarm>();

            lock (m_alarms)
            {
                for (int ii = 0; ii < m_alarms.Count; ii++)
                {
                    UnderlyingSystemAlarm alarm = m_alarms[ii];

                    if (alarm.SetStateBits(UnderlyingSystemAlarmStates.Suppressed, offline))
                    {
                        alarm.Time   = alarm.EnableTime = DateTime.UtcNow;
                        alarm.Reason = "The alarm was " + ((offline)?"suppressed.":"unsuppressed.");

                        // check if the alarm change should be reported.
                        if ((alarm.State & UnderlyingSystemAlarmStates.Enabled) != 0)
                        {
                            snapshots.Add(alarm.CreateSnapshot());
                        }
                    }
                }
            }

            // report any alarm changes after releasing the lock.
            for (int ii = 0; ii < snapshots.Count; ii++)
            {
                ReportAlarmChange(snapshots[ii]);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Adds a comment to an alarm.
        /// </summary>
        /// <param name="alarmName">Name of the alarm.</param>
        /// <param name="recordNumber">The record number.</param>
        /// <param name="comment">The comment.</param>
        /// <param name="userName">Name of the user.</param>
        public void CommentAlarm(string alarmName, uint recordNumber, LocalizedText comment, string userName)
        {
            UnderlyingSystemAlarm snapshot = null;

            lock (m_alarms)
            {
                UnderlyingSystemAlarm alarm = FindAlarm(alarmName, recordNumber);

                if (alarm != null)
                {
                    alarm.Time     = DateTime.UtcNow;
                    alarm.Reason   = "A comment was added.";
                    alarm.UserName = userName;

                    // only change the comment if a non-null comment was provided.
                    if (comment != null && (!String.IsNullOrEmpty(comment.Text) || !String.IsNullOrEmpty(comment.Locale)))
                    {
                        alarm.Comment = Utils.Format("{0}", comment);
                    }

                    snapshot = alarm.CreateSnapshot();
                }
            }

            if (snapshot != null)
            {
                ReportAlarmChange(snapshot);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Enables or disables the alarm.
        /// </summary>
        /// <param name="alarmName">Name of the alarm.</param>
        /// <param name="enabling">if set to <c>true</c> the alarm is enabled.</param>
        public void EnableAlarm(string alarmName, bool enabling)
        {
            List <UnderlyingSystemAlarm> snapshots = new List <UnderlyingSystemAlarm>();

            lock (m_alarms)
            {
                UnderlyingSystemAlarm alarm = FindAlarm(alarmName, 0);

                if (alarm != null)
                {
                    // enable/disable the alarm.
                    if (alarm.SetStateBits(UnderlyingSystemAlarmStates.Enabled, enabling))
                    {
                        alarm.Time   = alarm.EnableTime = DateTime.UtcNow;
                        alarm.Reason = "The alarm was " + ((enabling)?"enabled.":"disabled.");
                        snapshots.Add(alarm.CreateSnapshot());
                    }

                    // enable/disable any archived records for the alarm.
                    foreach (UnderlyingSystemAlarm record in m_archive.Values)
                    {
                        if (record.Name != alarmName)
                        {
                            continue;
                        }

                        if (record.SetStateBits(UnderlyingSystemAlarmStates.Enabled, enabling))
                        {
                            record.Time   = alarm.EnableTime = DateTime.UtcNow;
                            record.Reason = "The alarm was " + ((enabling)?"enabled.":"disabled.");
                            snapshots.Add(alarm.CreateSnapshot());
                        }
                    }
                }
            }

            // report any alarm changes after releasing the lock.
            for (int ii = 0; ii < snapshots.Count; ii++)
            {
                ReportAlarmChange(snapshots[ii]);
            }
        }
Beispiel #5
0
        /// <summary>
        /// Reports the current state of all conditions.
        /// </summary>
        public void Refresh()
        {
            List <UnderlyingSystemAlarm> snapshots = new List <UnderlyingSystemAlarm>();

            lock (m_alarms)
            {
                for (int ii = 0; ii < m_alarms.Count; ii++)
                {
                    UnderlyingSystemAlarm alarm = m_alarms[ii];
                    snapshots.Add(alarm.CreateSnapshot());
                }
            }

            // report any alarm changes after releasing the lock.
            for (int ii = 0; ii < snapshots.Count; ii++)
            {
                ReportAlarmChange(snapshots[ii]);
            }
        }
Beispiel #6
0
        /// <summary>
        /// Confirms an alarm.
        /// </summary>
        /// <param name="alarmName">Name of the alarm.</param>
        /// <param name="recordNumber">The record number.</param>
        /// <param name="comment">The comment.</param>
        /// <param name="userName">Name of the user.</param>
        public void ConfirmAlarm(string alarmName, uint recordNumber, LocalizedText comment, string userName)
        {
            UnderlyingSystemAlarm snapshot = null;

            lock (m_alarms)
            {
                UnderlyingSystemAlarm alarm = FindAlarm(alarmName, recordNumber);

                if (alarm != null)
                {
                    if (alarm.SetStateBits(UnderlyingSystemAlarmStates.Confirmed, true))
                    {
                        alarm.Time     = DateTime.UtcNow;
                        alarm.Reason   = "The alarm was confirmed.";
                        alarm.Comment  = Utils.Format("{0}", comment);
                        alarm.UserName = userName;

                        // remove branch.
                        if (recordNumber != 0)
                        {
                            m_archive.Remove(recordNumber);
                            alarm.SetStateBits(UnderlyingSystemAlarmStates.Deleted, true);
                        }

                        // de-activate alarm.
                        else
                        {
                            alarm.SetStateBits(UnderlyingSystemAlarmStates.Active, false);
                        }
                    }

                    snapshot = alarm.CreateSnapshot();
                }
            }

            if (snapshot != null)
            {
                ReportAlarmChange(snapshot);
            }
        }
Beispiel #7
0
        /// <summary>
        /// Updates the state of an alarm.
        /// </summary>
        private void UpdateAlarm(UnderlyingSystemAlarm alarm, long counter, int index, List <UnderlyingSystemAlarm> snapshots)
        {
            string reason = null;

            // ignore disabled alarms.
            if ((alarm.State & UnderlyingSystemAlarmStates.Enabled) == 0)
            {
                return;
            }

            // check if the alarm needs to be updated this cycle.
            if (counter % (8 + (index % 4)) == 0)
            {
                // check if it is time to activate.
                if ((alarm.State & UnderlyingSystemAlarmStates.Active) == 0)
                {
                    reason = "The alarm is active.";

                    alarm.SetStateBits(UnderlyingSystemAlarmStates.Active, true);
                    alarm.SetStateBits(UnderlyingSystemAlarmStates.Acknowledged | UnderlyingSystemAlarmStates.Confirmed, false);
                    alarm.Severity   = EventSeverity.Low;
                    alarm.ActiveTime = DateTime.UtcNow;

                    switch (alarm.AlarmType)
                    {
                    case "HighAlarm":
                    {
                        alarm.SetStateBits(UnderlyingSystemAlarmStates.Limits, false);
                        alarm.SetStateBits(UnderlyingSystemAlarmStates.High, true);
                        break;
                    }

                    case "HighLowAlarm":
                    {
                        alarm.SetStateBits(UnderlyingSystemAlarmStates.Limits, false);
                        alarm.SetStateBits(UnderlyingSystemAlarmStates.Low, true);
                        break;
                    }
                    }
                }

                // bump the severity.
                else if ((alarm.State & UnderlyingSystemAlarmStates.Acknowledged) == 0)
                {
                    if (alarm.Severity < EventSeverity.High)
                    {
                        reason = "The alarm severity has increased.";

                        Array values = Enum.GetValues(typeof(EventSeverity));

                        for (int ii = 0; ii < values.Length; ii++)
                        {
                            EventSeverity severity = (EventSeverity)values.GetValue(ii);

                            if (severity > alarm.Severity)
                            {
                                alarm.Severity = severity;
                                break;
                            }
                        }

                        if (alarm.Severity > EventSeverity.Medium)
                        {
                            switch (alarm.AlarmType)
                            {
                            case "HighLowAlarm":
                            {
                                alarm.SetStateBits(UnderlyingSystemAlarmStates.Limits, false);
                                alarm.SetStateBits(UnderlyingSystemAlarmStates.LowLow, true);
                                break;
                            }
                            }
                        }
                    }

                    // give up on the alarm.
                    else
                    {
                        // create an archived state that needs to be acknowledged.
                        if (alarm.AlarmType == "TripAlarm")
                        {
                            // check the number of archived states.
                            int count = 0;

                            foreach (UnderlyingSystemAlarm record in m_archive.Values)
                            {
                                if (record.Name == alarm.Name)
                                {
                                    count++;
                                }
                            }
                            // limit the number of archived states to avoid filling up the display.
                            if (count < 2)
                            {
                                // archive the current state.
                                UnderlyingSystemAlarm snapshot = alarm.CreateSnapshot();
                                snapshot.RecordNumber = ++m_nextRecordNumber;
                                snapshot.Severity     = EventSeverity.Low;
                                m_archive.Add(snapshot.RecordNumber, snapshot);
                                snapshots.Add(snapshot);
                            }
                        }

                        reason = "The alarm was deactivated by the system.";
                        alarm.SetStateBits(UnderlyingSystemAlarmStates.Active, false);
                        //alarm.SetStateBits(UnderlyingSystemAlarmStates.Acknowledged | UnderlyingSystemAlarmStates.Confirmed, true);
                        alarm.Severity = EventSeverity.Low;
                    }
                }
            }

            // update the reason.
            if (reason != null)
            {
                alarm.Time   = DateTime.UtcNow;
                alarm.Reason = reason;

                // return a snapshot used to report the state change.
                snapshots.Add(alarm.CreateSnapshot());
            }

            // no change so nothing to report.
        }
        /// <summary>
        /// Updates the state of an alarm.
        /// </summary>
        private void UpdateAlarm(UnderlyingSystemAlarm alarm, long counter, int index, List<UnderlyingSystemAlarm> snapshots)
        {
            string reason = null;
            
            // ignore disabled alarms.
            if ((alarm.State & UnderlyingSystemAlarmStates.Enabled) == 0)
            {
                return;
            }

            // check if the alarm needs to be updated this cycle.
            if (counter % (8 + (index%4)) == 0)
            {
                // check if it is time to activate.
                if ((alarm.State & UnderlyingSystemAlarmStates.Active) == 0)
                {
                    reason = "The alarm is active.";

                    alarm.SetStateBits(UnderlyingSystemAlarmStates.Active, true);
                    alarm.SetStateBits(UnderlyingSystemAlarmStates.Acknowledged | UnderlyingSystemAlarmStates.Confirmed, false);
                    alarm.Severity = EventSeverity.Low;
                    alarm.ActiveTime = DateTime.UtcNow;

                    switch (alarm.AlarmType)
                    {
                        case "HighAlarm":
                        {
                            alarm.SetStateBits(UnderlyingSystemAlarmStates.Limits, false);
                            alarm.SetStateBits(UnderlyingSystemAlarmStates.High, true);
                            break;
                        }

                        case "HighLowAlarm":
                        {
                            alarm.SetStateBits(UnderlyingSystemAlarmStates.Limits, false);
                            alarm.SetStateBits(UnderlyingSystemAlarmStates.Low, true);
                            break;
                        }
                    }
                }

                // bump the severity.
                else if ((alarm.State & UnderlyingSystemAlarmStates.Acknowledged) == 0)
                {
                    if (alarm.Severity < EventSeverity.High)
                    {
                        reason = "The alarm severity has increased.";

                        Array values = Enum.GetValues(typeof(EventSeverity));

                        for (int ii = 0; ii < values.Length; ii++)
                        {
                            EventSeverity severity = (EventSeverity)values.GetValue(ii);

                            if (severity > alarm.Severity)
                            {
                                alarm.Severity = severity;
                                break;
                            }
                        }

                        if (alarm.Severity > EventSeverity.Medium)
                        {
                            switch (alarm.AlarmType)
                            {
                                case "HighLowAlarm":
                                {
                                    alarm.SetStateBits(UnderlyingSystemAlarmStates.Limits, false);
                                    alarm.SetStateBits(UnderlyingSystemAlarmStates.LowLow, true);
                                    break;
                                }
                            }
                        }
                    }

                    // give up on the alarm.
                    else
                    {
                        // create an archived state that needs to be acknowledged.
                        if (alarm.AlarmType == "TripAlarm")
                        {
                            // check the number of archived states.
                            int count = 0;

                            foreach (UnderlyingSystemAlarm record in m_archive.Values)
                            {
                                if (record.Name == alarm.Name)
                                {
                                    count++;
                                }
                            }
                            // limit the number of archived states to avoid filling up the display.
                            if (count < 2)
                            {
                                // archive the current state.
                                UnderlyingSystemAlarm snapshot = alarm.CreateSnapshot();
                                snapshot.RecordNumber = ++m_nextRecordNumber;
                                snapshot.Severity = EventSeverity.Low;
                                m_archive.Add(snapshot.RecordNumber, snapshot);
                                snapshots.Add(snapshot);
                            }
                        }

                        reason = "The alarm was deactivated by the system.";
                        alarm.SetStateBits(UnderlyingSystemAlarmStates.Active, false);
                        //alarm.SetStateBits(UnderlyingSystemAlarmStates.Acknowledged | UnderlyingSystemAlarmStates.Confirmed, true);
                        alarm.Severity = EventSeverity.Low;
                    }
                }
            }

            // update the reason.
            if (reason != null)
            {
                alarm.Time = DateTime.UtcNow;
                alarm.Reason = reason;

                // return a snapshot used to report the state change.
                snapshots.Add(alarm.CreateSnapshot());
            }

            // no change so nothing to report.
        }