/// <summary> /// Selects the attributes for the category. /// </summary> public bool SelectAttributes(uint categoryId, uint[] attributeIds) { // validate category. if (m_mapper.GetCategory(categoryId) == null) { return(false); } // validate attributes. if (attributeIds != null) { for (int ii = 0; ii < attributeIds.Length; ii++) { if (m_mapper.GetAttribute(attributeIds[ii]) == null) { return(false); } } } // update list. if (RequestedAttributeIds == null) { RequestedAttributeIds = new Dictionary <uint, uint[]>(); } if (attributeIds == null || attributeIds.Length == 0) { RequestedAttributeIds.Remove(categoryId); } else { RequestedAttributeIds[categoryId] = attributeIds; } UpdatedSelectAttributes(); return(true); }
/// <summary> /// Translates an event notification in an AE event. /// </summary> public AeEvent TranslateNotification(Session session, EventFieldList e) { AeEvent e2 = new AeEvent(); // extract the required event fields. int index = 0; e2.EventId = ExtractField <byte[]>(e, index++, null); e2.EventType = ExtractField <NodeId>(e, index++, null); e2.SourceName = ExtractField <string>(e, index++, null); e2.Time = ExtractField <DateTime>(e, index++, DateTime.MinValue); e2.Message = ExtractField <LocalizedText>(e, index++, null); e2.Severity = ExtractField <ushort>(e, index++, 0); if ((EventTypes & OpcRcw.Ae.Constants.TRACKING_EVENT) != 0) { e2.AuditUserId = ExtractField <string>(e, index++, null); } if ((EventTypes & OpcRcw.Ae.Constants.CONDITION_EVENT) != 0) { e2.BranchId = ExtractField <byte[]>(e, index++, null); e2.ConditionName = ExtractField <string>(e, index++, null); e2.Quality = ExtractField <StatusCode>(e, index++, StatusCodes.Good); e2.Comment = ExtractField <LocalizedText>(e, index++, null); e2.CommentUserId = ExtractField <string>(e, index++, null); e2.EnabledState = ExtractField <bool>(e, index++, false); e2.AckedState = ExtractField <bool>(e, index++, false); e2.ActiveState = ExtractField <bool>(e, index++, false); e2.ActiveTime = ExtractField <DateTime>(e, index++, DateTime.MinValue); e2.LimitState = ExtractField <LocalizedText>(e, index++, null); e2.HighHighState = ExtractField <LocalizedText>(e, index++, null); e2.HighState = ExtractField <LocalizedText>(e, index++, null); e2.LowState = ExtractField <LocalizedText>(e, index++, null); e2.LowLowState = ExtractField <LocalizedText>(e, index++, null); // condition id is always last. e2.ConditionId = ExtractField <NodeId>(e, e.EventFields.Count - 1, null); } // find the category for the event. e2.Category = FindCategory(session, e2); // extract any additional attributes. if (RequestedAttributeIds != null) { uint[] attributeIds = null; if (!RequestedAttributeIds.TryGetValue(e2.Category.LocalId, out attributeIds)) { return(e2); } // nothing more to do. if (attributeIds == null || attributeIds.Length == 0) { return(e2); } // search for the requested attributes. object[] values = new object[attributeIds.Length]; for (int ii = 0; ii < attributeIds.Length; ii++) { // look for matching attribute. for (int jj = 0; jj < SelectedAttributes.Count; jj++) { if (jj >= e.EventFields.Count) { break; } AeEventAttribute attribute = SelectedAttributes[jj]; if (attribute == null || attribute.LocalId != attributeIds[ii]) { continue; } values[ii] = GetLocalAttributeValue(e.EventFields[jj], attribute); } } e2.AttributeValues = values; } return(e2); }