Пример #1
0
        /// <summary>
        /// Finds an event, whether it is the original event, or a branch
        /// </summary>
        /// <param name="eventId">Desired Event Id</param>
        /// <returns>ConditionState branch if it exists</returns>
        public virtual ConditionState GetEventByEventId(byte[] eventId)
        {
            ConditionState alarm = null;

            if (this.EventId.Value.SequenceEqual(eventId))
            {
                alarm = this;
            }
            else
            {
                alarm = GetBranch(eventId);
            }

            return(alarm);
        }
        /// <summary>
        /// Determines whether a specified branch exists, and returns it as AcknowledgeableConditionState
        /// </summary>
        /// <param name="eventId">Desired Event Id</param>
        /// <returns>
        /// AcknowledgeableConditionState branch if it exists
        /// </returns>
        private AcknowledgeableConditionState GetAcknowledgeableBranch(byte[] eventId)
        {
            AcknowledgeableConditionState acknowledgeableBranch = null;
            ConditionState branch = GetBranch(eventId);

            if (branch != null)
            {
                object acknowledgeable = branch as AcknowledgeableConditionState;
                if (acknowledgeable != null)
                {
                    acknowledgeableBranch = (AcknowledgeableConditionState)acknowledgeable;
                }
            }

            return(acknowledgeableBranch);
        }
Пример #3
0
        /// <summary>
        /// Determines whether a specified branch exists, and returns it as ConditionState
        /// </summary>
        /// <param name="eventId">Desired Event Id</param>
        /// <returns>ConditionState branch if it exists</returns>
        public ConditionState GetBranch(byte[] eventId)
        {
            ConditionState alarm = null;

            Dictionary <string, ConditionState> branches = GetBranches();

            foreach (ConditionState branchEvent in branches.Values)
            {
                if (branchEvent.EventId.Value.SequenceEqual(eventId))
                {
                    alarm = branchEvent;
                    break;
                }
            }

            return(alarm);
        }
Пример #4
0
        /// <summary>
        /// Constructs an event object from a notification.
        /// </summary>
        /// <param name="session">The session.</param>
        /// <param name="monitoredItem">The monitored item that produced the notification.</param>
        /// <param name="notification">The notification.</param>
        /// <param name="eventTypeMappings">Mapping between event types and known event types.</param>
        /// <returns>
        /// The event object. Null if the notification is not a valid event type.
        /// </returns>
        public static BaseEventState ConstructEvent(
            Session session,
            MonitoredItem monitoredItem,
            EventFieldList notification,
            Dictionary<NodeId,NodeId> eventTypeMappings)
        {
            // find the event type.
            NodeId eventTypeId = FindEventType(monitoredItem, notification);

            if (eventTypeId == null)
            {
                return null;
            }

            // look up the known event type.
            NodeId knownTypeId = null;

            if (!eventTypeMappings.TryGetValue(eventTypeId, out knownTypeId))
            {
                // check for a known type
                for (int jj = 0; jj < KnownEventTypes.Length; jj++)
                {
                    if (KnownEventTypes[jj] == eventTypeId)
                    {
                        knownTypeId = eventTypeId;
                        eventTypeMappings.Add(eventTypeId, eventTypeId);
                        break;
                    }
                }
                
                // browse for the supertypes of the event type.
                if (knownTypeId == null)
                {
                    ReferenceDescriptionCollection supertypes = FormUtils.BrowseSuperTypes(session, eventTypeId, false);

                    // can't do anything with unknown types.
                    if (supertypes == null)
                    {
                        return null;
                    }

                    // find the first supertype that matches a known event type.
                    for (int ii = 0; ii < supertypes.Count; ii++)
                    {
                        for (int jj = 0; jj < KnownEventTypes.Length; jj++)
                        {
                            if (KnownEventTypes[jj] == supertypes[ii].NodeId)
                            {
                                knownTypeId = KnownEventTypes[jj];
                                eventTypeMappings.Add(eventTypeId, knownTypeId);
                                break;
                            }
                        }

                        if (knownTypeId != null)
                        {
                            break;
                        }
                    }
                }
            }

            if (knownTypeId == null)
            {
                return null;
            }

            // all of the known event types have a UInt32 as identifier.
            uint? id = knownTypeId.Identifier as uint?;

            if (id == null)
            {
                return null;
            }

            // construct the event based on the known event type.
            BaseEventState e = null;

            switch (id.Value)
            {
                case ObjectTypes.ConditionType: { e = new ConditionState(null); break; }
                case ObjectTypes.DialogConditionType: { e = new DialogConditionState(null); break; }
                case ObjectTypes.AlarmConditionType: { e = new AlarmConditionState(null); break; }
                case ObjectTypes.ExclusiveLimitAlarmType: { e = new ExclusiveLimitAlarmState(null); break; }
                case ObjectTypes.NonExclusiveLimitAlarmType: { e = new NonExclusiveLimitAlarmState(null); break; }
                case ObjectTypes.AuditEventType: { e = new AuditEventState(null); break; }
                case ObjectTypes.AuditUpdateMethodEventType: { e = new AuditUpdateMethodEventState(null); break; }

                default:
                {
                    e = new BaseEventState(null);
                    break;
                }
            }

            // get the filter which defines the contents of the notification.
            EventFilter filter = monitoredItem.Status.Filter as EventFilter;

            // initialize the event with the values in the notification.
            e.Update(session.SystemContext, filter.SelectClauses, notification);

            // save the orginal notification.
            e.Handle = notification;

            return e;
        }
Пример #5
0
        /// <summary>
        /// Called when the alarm is confirmed.
        /// </summary>
        private ServiceResult OnConfirm(
            ISystemContext context,
            ConditionState condition,
            byte[] eventId,
            LocalizedText comment)
        {
            AlarmConditionState alarm = FindAlarmByEventId(eventId);

            if (alarm == null)
            {
                return StatusCodes.BadEventIdUnknown;
            }

            m_source.ConfirmAlarm(alarm.SymbolicName, GetRecordNumber(alarm), comment, GetUserName(context));

            return ServiceResult.Good;
        }
Пример #6
0
 /// <summary>
 /// Called when the alarm is enabled or disabled.
 /// </summary>
 private ServiceResult OnEnableDisableAlarm(
     ISystemContext context,
     ConditionState condition,
     bool enabling)
 {
     m_source.EnableAlarm(condition.SymbolicName, enabling);
     return ServiceResult.Good;
 }