Beispiel #1
0
        /// <summary>
        /// Returns the last event produced for any conditions belonging to the node or its chilren.
        /// </summary>
        /// <param name="context">The system context.</param>
        /// <param name="events">The list of condition events to return.</param>
        /// <param name="includeChildren">Whether to recursively report events for the children.</param>
        public override void ConditionRefresh(ISystemContext context, List <IFilterTarget> events, bool includeChildren)
        {
            // need to check if this source has already been processed during this refresh operation.
            for (var ii = 0; ii < events.Count; ii++)
            {
                if (events[ii] is InstanceStateSnapshot e && ReferenceEquals(e.Handle, this))
                {
                    return;
                }
            }

            // report the dialog.
            if (_dialog != null)
            {
                // do not refresh dialogs that are not active.
                if (_dialog.Retain.Value)
                {
                    // create a snapshot.
                    var e = new InstanceStateSnapshot();
                    e.Initialize(context, _dialog);

                    // set the handle of the snapshot to check for duplicates.
                    e.Handle = this;

                    events.Add(e);
                }
            }

            // the alarm objects act as a cache for the last known state and are used to generate refresh events.
            foreach (var alarm in _alarms.Values)
            {
                // do not refresh alarms that are not in an interesting state.
                if (!alarm.Retain.Value)
                {
                    continue;
                }

                // create a snapshot.
                var e = new InstanceStateSnapshot();
                e.Initialize(context, alarm);

                // set the handle of the snapshot to check for duplicates.
                e.Handle = this;

                events.Add(e);
            }

            // report any active branches.
            foreach (var alarm in _branches.Values)
            {
                // create a snapshot.
                var e = new InstanceStateSnapshot();
                e.Initialize(context, alarm);

                // set the handle of the snapshot to check for duplicates.
                e.Handle = this;

                events.Add(e);
            }
        }
        /// <summary>
        /// Reports the changes to the alarm.
        /// </summary>
        private void ReportChanges(AlarmConditionState alarm)
        {
            // report changes to node attributes.
            alarm.ClearChangeMasks(m_nodeManager.SystemContext, true);

            // check if events are being monitored for the source.
            if (this.AreEventsMonitored)
            {
                // create a snapshot.
                InstanceStateSnapshot e = new InstanceStateSnapshot();
                e.Initialize(m_nodeManager.SystemContext, alarm);

                // report the event.
                alarm.ReportEvent(m_nodeManager.SystemContext, e);
            }
        }
        public override void ConditionRefresh(ISystemContext context, List <IFilterTarget> events, bool includeChildren)
        {
            foreach (var @event in events)
            {
                InstanceStateSnapshot instanceSnapShotForExistingEvent = @event as InstanceStateSnapshot;
                if (instanceSnapShotForExistingEvent != null && Object.ReferenceEquals(instanceSnapShotForExistingEvent.Handle, this))
                {
                    return;
                }
            }
            foreach (var alarm in _alarmNodes.Values)
            {
                if (!alarm.Retain.Value)
                {
                    continue;
                }

                InstanceStateSnapshot instanceStateSnapshotNewAlarm = new InstanceStateSnapshot();
                instanceStateSnapshotNewAlarm.Initialize(context, alarm);
                instanceStateSnapshotNewAlarm.Handle = this;
                events.Add(instanceStateSnapshotNewAlarm);
            }
        }
        public void ReportEvent(ConditionState alarm = null)
        {
            if (alarm == null)
            {
                alarm = GetAlarm();
            }

            if (alarm.EnabledState.Id.Value)
            {
                alarm.EventId.Value     = Guid.NewGuid().ToByteArray();
                alarm.Time.Value        = DateTime.UtcNow;
                alarm.ReceiveTime.Value = alarm.Time.Value;

                Log("ReportEvent", " Value " + m_alarmController.GetValue().ToString() +
                    " Message " + alarm.Message.Value.Text);

                alarm.ClearChangeMasks(SystemContext, true);

                InstanceStateSnapshot eventSnapshot = new InstanceStateSnapshot();
                eventSnapshot.Initialize(SystemContext, alarm);
                alarm.ReportEvent(SystemContext, eventSnapshot);
            }
        }