/// <summary> /// Does the simulation. /// </summary> /// <param name="state">The state.</param> private void DoSimulation(object state) { try { { DataRow row = m_generator.GenerateFluidLevelTestReport(); BaseObjectState well = (BaseObjectState)FindPredefinedNode(new NodeId((string)row[BrowseNames.UidWell], NamespaceIndex), typeof(BaseObjectState)); if (well != null && well.AreEventsMonitored) { BaseEventState e = m_generator.GetFluidLevelTestReport(SystemContext, NamespaceIndex, row); well.ReportEvent(SystemContext, e); } } { DataRow row = m_generator.GenerateInjectionTestReport(); BaseObjectState well = (BaseObjectState)FindPredefinedNode(new NodeId((string)row[BrowseNames.UidWell], NamespaceIndex), typeof(BaseObjectState)); if (well != null && well.AreEventsMonitored) { BaseEventState e = m_generator.GetInjectionTestReport(SystemContext, NamespaceIndex, row); well.ReportEvent(SystemContext, e); } } } catch (Exception e) { Utils.Trace(e, "Unexpected error during simulation."); } }
private void InitializeInternal(BaseEventState alarm, NodeId branchId = null) { string alarmName = AlarmName; string alarmNodeId = (string)m_parent.NodeId.Identifier + "." + AlarmName; alarm.SymbolicName = alarmName; NodeId createNodeId = null; QualifiedName createQualifiedName = new QualifiedName(alarmName, NamespaceIndex); LocalizedText createLocalizedText = null; bool isBranch = IsBranch(branchId); createNodeId = new NodeId(alarmNodeId, NamespaceIndex); createLocalizedText = new LocalizedText(alarmName); alarm.ReferenceTypeId = ReferenceTypeIds.HasComponent; alarm.Create( SystemContext, createNodeId, createQualifiedName, createLocalizedText, true); if (!isBranch) { m_trigger.AddReference(ReferenceTypes.HasCondition, false, m_alarm.NodeId); m_parent.AddChild(alarm); } }
/// <summary> /// Creates an instance of an event. /// </summary> public BaseEventState CreateInstance(ServerSystemContext context, AeEventTypeState eventType) { BaseEventState instance = null; switch (eventType.EventType.EventTypeMapping) { case EventTypeMapping.AlarmConditionType: { instance = new AlarmConditionState(null); break; } case EventTypeMapping.AuditEventType: { instance = new AuditEventState(null); break; } case EventTypeMapping.BaseEventType: { instance = new BaseEventState(null); break; } case EventTypeMapping.DeviceFailureEventType: { instance = new DeviceFailureEventState(null); break; } case EventTypeMapping.DiscreteAlarmType: { instance = new DiscreteAlarmState(null); break; } case EventTypeMapping.NonExclusiveDeviationAlarmType: { instance = new NonExclusiveDeviationAlarmState(null); break; } case EventTypeMapping.ExclusiveLevelAlarmType: { instance = new ExclusiveLevelAlarmState(null); break; } case EventTypeMapping.LimitAlarmType: { instance = new LimitAlarmState(null); break; } case EventTypeMapping.NonExclusiveLevelAlarmType: { instance = new NonExclusiveLevelAlarmState(null); break; } case EventTypeMapping.OffNormalAlarmType: { instance = new OffNormalAlarmState(null); break; } case EventTypeMapping.SystemEventType: { instance = new SystemEventState(null); break; } case EventTypeMapping.TripAlarmType: { instance = new TripAlarmState(null); break; } } return(instance); }
/// <summary> /// Updates the base event. /// </summary> private void UpdateBaseEvent(BaseEventState instance, EventType eventType, ONEVENTSTRUCT e) { BinaryEncoder encoder = new BinaryEncoder(ServiceMessageContext.GlobalContext); encoder.WriteString(null, e.szSource); encoder.WriteString(null, e.szConditionName); encoder.WriteInt32(null, e.ftActiveTime.dwHighDateTime); encoder.WriteInt32(null, e.ftActiveTime.dwLowDateTime); encoder.WriteInt32(null, e.dwCookie); byte[] eventId = encoder.CloseAndReturnBuffer(); NodeId eventTypeId = AeParsedNodeId.Construct(e.dwEventType, e.dwEventCategory, e.szConditionName, m_namespaceIndex); NodeId sourceNode = AeModelUtils.ConstructIdForSource(e.szSource, null, m_namespaceIndex); string sourceName = e.szSource; DateTime time = ComUtils.GetDateTime(e.ftTime); DateTime receiveTime = DateTime.UtcNow; LocalizedText message = e.szMessage; ushort severity = (ushort)e.dwSeverity; instance.TypeDefinitionId = eventTypeId; instance.SetChildValue(m_defaultContext, Opc.Ua.BrowseNames.EventId, eventId, false); instance.SetChildValue(m_defaultContext, Opc.Ua.BrowseNames.EventType, eventTypeId, false); instance.SetChildValue(m_defaultContext, Opc.Ua.BrowseNames.SourceNode, sourceNode, false); instance.SetChildValue(m_defaultContext, Opc.Ua.BrowseNames.SourceName, sourceName, false); instance.SetChildValue(m_defaultContext, Opc.Ua.BrowseNames.Time, time, false); instance.SetChildValue(m_defaultContext, Opc.Ua.BrowseNames.ReceiveTime, receiveTime, false); instance.SetChildValue(m_defaultContext, Opc.Ua.BrowseNames.Message, message, false); instance.SetChildValue(m_defaultContext, Opc.Ua.BrowseNames.Severity, severity, false); }
/// <summary> /// Called when refresh events arrive from the server. /// </summary> /// <param name="events">The events.</param> /// <param name="lastRefresh">if set to <c>true</c> if the refresh is complete.</param> public void OnRefresh(ONEVENTSTRUCT[] events, bool lastRefresh) { lock (m_callbackLock) { // check if refresh was abandoned. if (m_refreshEvents == null) { return; } // dispatch events. for (int ii = 0; ii < events.Length; ii++) { BaseEventState e = DispatchEvent(events[ii]); if (e != null) { m_refreshEvents.Add(e); } } // signal end of refresh. if (lastRefresh) { m_refreshComplete.Set(); } } }
public NodeHandle FindBranchNodeHandle(ISystemContext systemContext, NodeHandle initialHandle, CallMethodRequest methodToCall) { NodeHandle nodeHandle = initialHandle; if (IsAckConfirm(methodToCall.MethodId)) { AlarmHolder holder = GetAlarmHolder(methodToCall.ObjectId); if (holder != null) { if (holder.HasBranches()) { byte[] eventId = GetEventIdFromAckConfirmMethod(methodToCall); if (eventId != null) { BaseEventState state = holder.GetBranch(eventId); if (state != null) { nodeHandle = new NodeHandle(); nodeHandle.NodeId = methodToCall.ObjectId; nodeHandle.Node = state; nodeHandle.Validated = true; } } } } } return(nodeHandle); }
protected new void Initialize( uint alarmTypeIdentifier, string name) { m_alarmTypeIdentifier = alarmTypeIdentifier; if (m_alarm != null) { // Call the base class to set parameters base.Initialize(alarmTypeIdentifier, name); BaseEventState alarm = GetAlarm(); alarm.EventId.Value = Guid.NewGuid().ToByteArray(); alarm.EventType.Value = new NodeId(alarmTypeIdentifier, GetNameSpaceIndex(alarmTypeIdentifier)); alarm.SourceNode.Value = m_trigger.NodeId; alarm.SourceName.Value = m_trigger.SymbolicName; alarm.Time.Value = DateTime.UtcNow; alarm.ReceiveTime.Value = alarm.Time.Value; alarm.Message.Value = name + " Initialized"; alarm.Severity.Value = AlarmDefines.INACTIVE_SEVERITY; // TODO Implement for Optionals - Needs to go to all places where Time is set. alarm.LocalTime = null; } }
private AcknowledgeableConditionState GetAlarm(BaseEventState alarm = null) { if (alarm == null) { alarm = m_alarm; } return((AcknowledgeableConditionState)alarm); }
private BaseEventState GetAlarm(BaseEventState alarm = null) { if (alarm == null) { alarm = m_alarm; } return((BaseEventState)alarm); }
private AlarmConditionState GetAlarm(BaseEventState alarm = null) { if (alarm == null) { alarm = m_alarm; } return((AlarmConditionState)alarm); }
/// <summary> /// Called when a Node produces an event. /// </summary> /// <param name="context">The system context.</param> /// <param name="node">The affected node.</param> /// <param name="e">The event.</param> public void OnReportEvent(ISystemContext context, NodeState node, IFilterTarget e) { List <IEventMonitoredItem> eventMonitoredItems = new List <IEventMonitoredItem>(); lock (NodeManager.Lock) { if (EventMonitoredItems == null) { return; } for (int ii = 0; ii < EventMonitoredItems.Count; ii++) { IEventMonitoredItem monitoredItem = EventMonitoredItems[ii]; // enqueue event for role permission validation eventMonitoredItems.Add(monitoredItem); } } for (int ii = 0; ii < eventMonitoredItems.Count; ii++) { IEventMonitoredItem monitoredItem = eventMonitoredItems[ii]; BaseEventState baseEventState = e as BaseEventState; if (baseEventState != null) { ServiceResult validationResult = NodeManager.ValidateRolePermissions(new OperationContext(monitoredItem), baseEventState?.EventType?.Value, PermissionType.ReceiveEvents); if (ServiceResult.IsBad(validationResult)) { // skip event reporting for EventType without permissions continue; } validationResult = NodeManager.ValidateRolePermissions(new OperationContext(monitoredItem), baseEventState?.SourceNode?.Value, PermissionType.ReceiveEvents); if (ServiceResult.IsBad(validationResult)) { // skip event reporting for SourceNode without permissions continue; } } lock (NodeManager.Lock) { // enqueue event monitoredItem?.QueueEvent(e); } } }
public BaseEventState GetBranch(byte[] eventId) { BaseEventState state = null; ConditionState alarm = m_alarm as ConditionState; if (alarm != null) { state = alarm.GetBranch(eventId); } return(state); }
/// <summary> /// Called when events arrive from the server. /// </summary> /// <param name="events">The events.</param> public void OnEvent(ONEVENTSTRUCT[] events) { for (int ii = 0; ii < events.Length; ii++) { BaseEventState e = DispatchEvent(events[ii]); if (e != null) { lock (m_monitoredItems) { for (int jj = 0; jj < m_monitoredItems.Count; jj++) { m_monitoredItems[jj].QueueEvent(e); } } } } }
/// <summary> /// Called when a Node produces an event. /// </summary> /// <param name="context">The system context.</param> /// <param name="node">The affected node.</param> /// <param name="e">The event.</param> public void OnReportEvent(ISystemContext context, NodeState node, IFilterTarget e) { lock (NodeManager.Lock) { if (EventMonitoredItems == null) { return; } for (int ii = 0; ii < EventMonitoredItems.Count; ii++) { IEventMonitoredItem monitoredItem = EventMonitoredItems[ii]; BaseEventState baseEventState = e as BaseEventState; if (baseEventState != null) { ServiceResult validationResult = NodeManager.ValidateRolePermissions(new OperationContext(monitoredItem), baseEventState?.EventType?.Value, PermissionType.ReceiveEvents); if (ServiceResult.IsBad(validationResult)) { // ignore invalid permission type events continue; } validationResult = NodeManager.ValidateRolePermissions(new OperationContext(monitoredItem), baseEventState?.SourceNode?.Value, PermissionType.ReceiveEvents); if (ServiceResult.IsBad(validationResult)) { // ignore invalid permission type events continue; } // enque event monitoredItem.QueueEvent(e); } } } }
/// <summary> /// Dispatches the event. /// </summary> private BaseEventState DispatchEvent(ONEVENTSTRUCT e) { NodeId typeId = AeParsedNodeId.Construct(e.dwEventType, e.dwEventCategory, e.szConditionName, m_namespaceIndex); // find the type. AeEventTypeState eventType = m_cache.FindType(m_defaultContext, typeId); if (eventType == null) { return(null); } // create a new instance. BaseEventState instance = m_cache.CreateInstance(m_defaultContext, eventType); if (instance == null) { return(null); } // fill in fields. UpdateBaseEvent(instance, eventType.EventType, e); if (instance is AuditEventState) { UpdateAuditEvent((AuditEventState)instance, eventType.EventType, e); } if (instance is AlarmConditionState) { UpdateAlarm((AlarmConditionState)instance, eventType.EventType, e); } if (instance is ExclusiveLimitAlarmState) { UpdateExclusiveLimitAlarm((ExclusiveLimitAlarmState)instance, eventType.EventType, e); } else if (instance is NonExclusiveLimitAlarmState) { UpdateNonExclusiveLimitAlarm((NonExclusiveLimitAlarmState)instance, eventType.EventType, e); } // process attributes. bool ackCommentFound = false; object[] values = ComUtils.GetVARIANTs(ref e.pEventAttributes, e.dwNumEventAttrs, false); for (int ii = 0; ii < eventType.EventType.Attributes.Count; ii++) { EventAttribute attribute = eventType.EventType.Attributes[ii]; if (ii >= e.dwNumEventAttrs) { continue; } if (!ackCommentFound && AeTypeCache.IsKnownName(attribute.Description, "ACK COMMENT")) { ConditionState condition = instance as ConditionState; if (condition != null) { condition.Comment = new ConditionVariableState <LocalizedText>(condition); condition.Comment.BrowseName = Opc.Ua.BrowseNames.Comment; condition.Comment.Value = new LocalizedText(values[ii] as string); } ackCommentFound = true; continue; } PropertyState property = new PropertyState(instance); property.SymbolicName = attribute.Description; property.BrowseName = new QualifiedName(property.SymbolicName, m_namespaceIndex); property.Value = values[ii]; instance.AddChild(property); } return(instance); }
/// <summary> /// Called when a Node produces an event. /// </summary> /// <param name="context">The system context.</param> /// <param name="node">The affected node.</param> /// <param name="e">The event.</param> public void OnReportEvent(ISystemContext context, NodeState node, IFilterTarget e) { List <IEventMonitoredItem> eventMonitoredItems = new List <IEventMonitoredItem>(); lock (NodeManager.Lock) { if (EventMonitoredItems == null) { return; } for (int ii = 0; ii < EventMonitoredItems.Count; ii++) { IEventMonitoredItem monitoredItem = EventMonitoredItems[ii]; // enqueue event for role permission validation eventMonitoredItems.Add(monitoredItem); } } for (int ii = 0; ii < eventMonitoredItems.Count; ii++) { IEventMonitoredItem monitoredItem = eventMonitoredItems[ii]; BaseEventState baseEventState = e as BaseEventState; if (baseEventState != null) { #region Filter out audit events in case the Server_Auditing values is false or the channel is not encrypted if (e is AuditEventState) { // check Server.Auditing flag and skip if false if (!NodeManager.Server.EventManager.ServerAuditing) { continue; } else { // check if channel is not encrypted and skip if so OperationContext operationContext = (context as SystemContext)?.OperationContext as OperationContext; if (operationContext != null && operationContext.ChannelContext.EndpointDescription.SecurityMode != MessageSecurityMode.SignAndEncrypt && operationContext.ChannelContext.EndpointDescription.TransportProfileUri != Profiles.HttpsBinaryTransport) { continue; } } } #endregion ServiceResult validationResult = NodeManager.ValidateRolePermissions(new OperationContext(monitoredItem), baseEventState?.EventType?.Value, PermissionType.ReceiveEvents); if (ServiceResult.IsBad(validationResult)) { // skip event reporting for EventType without permissions continue; } validationResult = NodeManager.ValidateRolePermissions(new OperationContext(monitoredItem), baseEventState?.SourceNode?.Value, PermissionType.ReceiveEvents); if (ServiceResult.IsBad(validationResult)) { // skip event reporting for SourceNode without permissions continue; } } lock (NodeManager.Lock) { // enqueue event monitoredItem?.QueueEvent(e); } } }
private void MonitorMethodUpdateNotification(MonitoredItem monitoredItem, MonitoredItemNotificationEventArgs e) { try { if (!(e.NotificationValue is EventFieldList notification)) { return; } NodeId eventTypeId = null; if (!(monitoredItem.Status.Filter is EventFilter filter)) { return; } for (int index = 0; index < filter.SelectClauses.Count; index++) { SimpleAttributeOperand simpleAttributeOperand = filter.SelectClauses[index]; if (simpleAttributeOperand.BrowsePath.Count != 1 || simpleAttributeOperand.BrowsePath[0] != BrowseNames.EventType) { continue; } eventTypeId = notification.EventFields[index].Value as NodeId; } // look up the known event type. Dictionary <NodeId, NodeId> eventTypeMappings = new Dictionary <NodeId, NodeId>(); if (eventTypeId == null || NodeId.IsNull(eventTypeId)) { return; } if (!eventTypeMappings.TryGetValue(eventTypeId, out NodeId knownTypeId)) { // check for a known type if (KnownEventTypes.Any(nodeId => nodeId == eventTypeId)) { knownTypeId = eventTypeId; eventTypeMappings.Add(eventTypeId, eventTypeId); } // browse for the supertypes of the event type. if (knownTypeId == null) { ReferenceDescriptionCollection supertypes = new ReferenceDescriptionCollection(); // find all of the children of the field. BrowseDescription nodeToBrowse = new BrowseDescription { NodeId = eventTypeId, BrowseDirection = BrowseDirection.Inverse, ReferenceTypeId = ReferenceTypeIds.HasSubtype, IncludeSubtypes = false, // more efficient to use IncludeSubtypes=False when possible. NodeClassMask = 0, // the HasSubtype reference already restricts the targets to Types. ResultMask = (uint)BrowseResultMask.All }; ReferenceDescriptionCollection references = _applicationInstanceManager.Browse(nodeToBrowse); while (references != null && references.Count > 0) { // should never be more than one supertype. supertypes.Add(references[0]); // only follow references within this server. if (references[0].NodeId.IsAbsolute) { break; } // get the references for the next level up. nodeToBrowse.NodeId = (NodeId)references[0].NodeId; references = _applicationInstanceManager.Browse(nodeToBrowse); } // find the first super type that matches a known event type. foreach (ReferenceDescription referenceDescription in supertypes) { foreach (NodeId nodeId in KnownEventTypes) { if (nodeId != referenceDescription.NodeId) { continue; } knownTypeId = nodeId; eventTypeMappings.Add(eventTypeId, knownTypeId); break; } if (knownTypeId != null) { break; } } } } if (knownTypeId == null) { return; } // all of the known event types have a UInt32 as identifier. uint?id = knownTypeId.Identifier as uint?; if (id == null) { return; } // construct the event based on the known event type. BaseEventState baseEventState = null; switch (id.Value) { case ObjectTypes.ConditionType: { baseEventState = new ConditionState(null); break; } case ObjectTypes.DialogConditionType: { baseEventState = new DialogConditionState(null); break; } case ObjectTypes.AlarmConditionType: { baseEventState = new AlarmConditionState(null); break; } case ObjectTypes.ExclusiveLimitAlarmType: { baseEventState = new ExclusiveLimitAlarmState(null); break; } case ObjectTypes.NonExclusiveLimitAlarmType: { baseEventState = new NonExclusiveLimitAlarmState(null); break; } case ObjectTypes.AuditEventType: { baseEventState = new AuditEventState(null); break; } case ObjectTypes.AuditUpdateMethodEventType: { baseEventState = new AuditUpdateMethodEventState(null); break; } default: { baseEventState = new BaseEventState(null); break; } } // get the filter which defines the contents of the notification. filter = monitoredItem.Status.Filter as EventFilter; // initialize the event with the values in the notification. baseEventState.Update(_applicationInstanceManager.Session.SystemContext, filter.SelectClauses, notification); // save the original notification. baseEventState.Handle = notification; // construct the audit object. if (baseEventState is AuditUpdateMethodEventState audit) { // look up the condition type metadata in the local cache. string sourceName = ""; if (audit.SourceName.Value != null) { sourceName = Utils.Format("{0}", audit.SourceName.Value); } string type = ""; if (audit.TypeDefinitionId != null) { type = Utils.Format("{0}", _applicationInstanceManager.Session.NodeCache.Find(audit.TypeDefinitionId)); } string method = ""; if (audit.MethodId != null) { method = Utils.Format("{0}", _applicationInstanceManager.Session.NodeCache.Find( BaseVariableState.GetValue(audit.MethodId))); } string status = ""; if (audit.Status != null) { status = Utils.Format("{0}", audit.Status.Value); } string time = ""; if (audit.Time != null) { time = Utils.Format("{0:HH:mm:ss.fff}", audit.Time.Value.ToLocalTime()); } string message = ""; if (audit.Message != null) { message = Utils.Format("{0}", audit.Message.Value); } string inputArguments = ""; if (audit.InputArguments != null) { inputArguments = Utils.Format("{0}", new Variant(audit.InputArguments.Value)); } InformationDisplay( $"sourceName: {sourceName}, type:{type}, method:{method}, status:{status}, time:{time}, message:{message}, inputArguments:{inputArguments}"); } } catch (Exception ex) { InformationDisplay($"Monitored Item Notification exception: {ex.StackTrace}"); } }
/// <summary> /// Creates a new history request. /// </summary> private HistoryReadRequest CreateHistoryReadRequest( ServerSystemContext context, ReadEventDetails details, NodeHandle handle, HistoryReadValueId nodeToRead) { FilterContext filterContext = new FilterContext(context.NamespaceUris, context.TypeTable, context.PreferredLocales); LinkedList <BaseEventState> events = new LinkedList <BaseEventState>(); for (ReportType ii = ReportType.FluidLevelTest; ii <= ReportType.InjectionTest; ii++) { DataView view = null; if (handle.Node is WellState) { view = m_generator.ReadHistoryForWellId( ii, (string)handle.Node.NodeId.Identifier, details.StartTime, details.EndTime); } else { view = m_generator.ReadHistoryForArea( ii, handle.Node.NodeId.Identifier as string, details.StartTime, details.EndTime); } LinkedListNode <BaseEventState> pos = events.First; bool sizeLimited = (details.StartTime == DateTime.MinValue || details.EndTime == DateTime.MinValue); foreach (DataRowView row in view) { // check if reached max results. if (sizeLimited) { if (events.Count >= details.NumValuesPerNode) { break; } } BaseEventState e = m_generator.GetReport(context, NamespaceIndex, ii, row.Row); if (details.Filter.WhereClause != null && details.Filter.WhereClause.Elements.Count > 0) { if (!details.Filter.WhereClause.Evaluate(filterContext, e)) { continue; } } bool inserted = false; for (LinkedListNode <BaseEventState> jj = pos; jj != null; jj = jj.Next) { if (jj.Value.Time.Value > e.Time.Value) { events.AddBefore(jj, e); pos = jj; inserted = true; break; } } if (!inserted) { events.AddLast(e); pos = null; } } } HistoryReadRequest request = new HistoryReadRequest(); request.Events = events; request.TimeFlowsBackward = details.StartTime == DateTime.MinValue || (details.EndTime != DateTime.MinValue && details.EndTime < details.StartTime); request.NumValuesPerNode = details.NumValuesPerNode; request.Filter = details.Filter; request.FilterContext = filterContext; return(request); }
protected virtual void SetActive(BaseEventState state, bool activeState) { }
/// <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="knownEventTypes">The known event types.</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, Type> knownEventTypes, Dictionary <NodeId, NodeId> eventTypeMappings) { // find the event type. NodeId eventTypeId = FindEventType(monitoredItem, notification); if (eventTypeId == null) { return(null); } // look up the known event type. Type knownType = null; NodeId knownTypeId = null; if (eventTypeMappings.TryGetValue(eventTypeId, out knownTypeId)) { knownType = knownEventTypes[knownTypeId]; } // try again. if (knownType == null) { if (knownEventTypes.TryGetValue(eventTypeId, out knownType)) { knownTypeId = eventTypeId; eventTypeMappings.Add(eventTypeId, eventTypeId); } } // try mapping it to a known type. if (knownType == null) { // browse for the supertypes of the event type. ReferenceDescriptionCollection supertypes = ClientUtils.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++) { NodeId superTypeId = (NodeId)supertypes[ii].NodeId; if (knownEventTypes.TryGetValue(superTypeId, out knownType)) { knownTypeId = superTypeId; eventTypeMappings.Add(eventTypeId, superTypeId); } if (knownTypeId != null) { break; } } // can't do anything with unknown types. if (knownTypeId == null) { return(null); } } // construct the event based on the known event type. BaseEventState e = (BaseEventState)Activator.CreateInstance(knownType, new object[] { (NodeState)null }); // 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); }
/// <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. if (session is null) { return(null); } e.Update(session.SystemContext, filter.SelectClauses, notification); // save the orginal notification. e.Handle = notification; return(e); }
/// <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. var eventTypeId = FindEventType(monitoredItem, notification); if (eventTypeId == null) { return(null); } // look up the known event type. NodeId knownTypeId; if (!eventTypeMappings.TryGetValue(eventTypeId, out knownTypeId)) { // check for a known type if (KnownEventTypes.Any(t => t == eventTypeId)) { knownTypeId = eventTypeId; eventTypeMappings.Add(eventTypeId, eventTypeId); } // browse for the supertypes of the event type. if (knownTypeId == null) { var supertypes = 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. foreach (var t in supertypes) { foreach (var nodeId in KnownEventTypes) { if (nodeId == t.NodeId) { knownTypeId = nodeId; 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. var id = knownTypeId.Identifier as uint?; if (id == null) { return(null); } // construct the event based on the known event type. BaseEventState e; 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. var filter = monitoredItem.Status.Filter as EventFilter; // initialize the event with the values in the notification. if (filter != null) { e.Update(session.SystemContext, filter.SelectClauses, notification); } // save the orginal notification. e.Handle = notification; return(e); }
protected void Log(string caller, string message, BaseEventState alarm = null) { LogMessage(LogLevel.Information, caller, message); }
public BaseEventState FindBranch() { BaseEventState state = null; return(state); }
/// <summary> /// Reads history events. /// </summary> protected override void HistoryReadEvents( ServerSystemContext context, ReadEventDetails details, TimestampsToReturn timestampsToReturn, IList <HistoryReadValueId> nodesToRead, IList <HistoryReadResult> results, IList <ServiceResult> errors, List <NodeHandle> nodesToProcess, IDictionary <NodeId, NodeState> cache) { for (int ii = 0; ii < nodesToProcess.Count; ii++) { NodeHandle handle = nodesToProcess[ii]; HistoryReadValueId nodeToRead = nodesToRead[handle.Index]; HistoryReadResult result = results[handle.Index]; HistoryReadRequest request = null; // load an exising request. if (nodeToRead.ContinuationPoint != null) { request = LoadContinuationPoint(context, nodeToRead.ContinuationPoint); if (request == null) { errors[handle.Index] = StatusCodes.BadContinuationPointInvalid; continue; } } // create a new request. else { request = CreateHistoryReadRequest( context, details, handle, nodeToRead); } // process events until the max is reached. HistoryEvent events = new HistoryEvent(); while (request.NumValuesPerNode == 0 || events.Events.Count < request.NumValuesPerNode) { if (request.Events.Count == 0) { break; } BaseEventState e = null; if (request.TimeFlowsBackward) { e = request.Events.Last.Value; request.Events.RemoveLast(); } else { e = request.Events.First.Value; request.Events.RemoveFirst(); } events.Events.Add(GetEventFields(request, e)); } errors[handle.Index] = ServiceResult.Good; // check if a continuation point is requred. if (request.Events.Count > 0) { // only set if both end time and start time are specified. if (details.StartTime != DateTime.MinValue && details.EndTime != DateTime.MinValue) { result.ContinuationPoint = SaveContinuationPoint(context, request); } } // check if no data returned. else { errors[handle.Index] = StatusCodes.GoodNoData; } // return the data. result.HistoryData = new ExtensionObject(events); } }
protected override void SetActive(BaseEventState baseEvent, bool activeState) { AlarmConditionState alarm = GetAlarm(baseEvent); alarm.SetActiveState(SystemContext, activeState); }
protected void LogError(string caller, string message, BaseEventState alarm = null) { LogMessage(LogLevel.Error, caller, message); }