Exemplo n.º 1
0
 /// <summary>
 /// Compare method based off the Attribute NodeId
 /// </summary>
 /// <param name="x"></param>
 /// <param name="y"></param>
 private static int EventAttributeNodeIdCompare(EventAttribute x, EventAttribute y)
 {
     return x.strNodeId.CompareTo(y.strNodeId);
 }
Exemplo n.º 2
0
        /// <summary>
        /// Initializing the configuration data. (allUsers + @"\Application Data\OPC Foundation\COM Interop\" + remoteServerDlg.PseudoClassID)
        /// </summary>
        private void InitConfigInfo(string configFileName)
        {
            try
            {
                Browser browser = new Browser(m_session);
                ReferenceDescriptionCollection references = browser.Browse(Opc.Ua.ObjectTypes.BaseEventType);

                if (references == null)
                {
                    throw new Exception("No BaseEventType found in the type hierarchy");
                }

                foreach (ReferenceDescription reference in references)
                {
                    // check for base event types.
                    if (reference.NodeClass == NodeClass.ObjectType)
                    {
                        int cattype = OpcRcw.Ae.Constants.SIMPLE_EVENT;

                        if (reference.NodeId == Opc.Ua.ObjectTypes.ConditionType)
                        {
                            cattype = OpcRcw.Ae.Constants.CONDITION_EVENT;
                        }
                        else if (reference.NodeId == Opc.Ua.ObjectTypes.AuditEventType)
                        {
                            cattype = OpcRcw.Ae.Constants.TRACKING_EVENT;
                        }

                        ProcessNodeAsCategory((NodeId)reference.NodeId, cattype);
                    }

                    // check for properties.
                    else if (reference.NodeClass == NodeClass.Variable)
                    {
                        if (reference.TypeDefinition == Opc.Ua.VariableTypeIds.PropertyType)
                        {
                            ProcessNodeAsAttribute(Opc.Ua.ObjectTypes.BaseEventType, reference);
                        }
                    }
                }

                // Add two special attribute for compatibility with AE COM
                EventAttribute attr1 = new EventAttribute();
                attr1.AttributeID = Global.TheGlobal.StdAttrIds[1];
                attr1.strNodeId = "Areas";
                attr1.BrowseName = "AECOMAreas";
                attr1.BrowseNameNSIndex = 0;
                attr1.AttrDesc = "Areas";
                attr1.strDataTypeNodeId = DataTypes.GetDataTypeId(typeof(string[])).ToString();
                attr1.strEventNodeId = "";
                attr1.IsArray = true;
                attr1.ActualDataType = typeof(string[]);
                m_EventAttributes.Add(attr1);

                attr1 = new EventAttribute();
                attr1.AttributeID = Global.TheGlobal.StdAttrIds[0];
                attr1.strNodeId = "AckComment";
                attr1.BrowseName = "AECOMAckComment";
                attr1.BrowseNameNSIndex = 0;
                attr1.AttrDesc = "AckComment";
                attr1.strDataTypeNodeId = DataTypes.GetDataTypeId(typeof(string)).ToString();
                attr1.strEventNodeId = "";
                attr1.IsArray = false;
                attr1.ActualDataType = typeof(string);
                m_EventAttributes.Add(attr1);

                m_EventAttributes.Sort(EventAttributeNodeIdCompare);
                m_EventCategories.Sort(EventCategoryBrowseNameCompare);

                m_configFile.Categories = m_EventCategories.ToArray();
                m_configFile.Attributes = m_EventAttributes.ToArray();
                m_configFile.LastEventCategoryID = m_catID;
                m_configFile.LastEventAttributeID = m_attrID;

                m_configFile.SavedNamespaceTable = m_session.NamespaceUris.ToArray();

            }
            catch (Exception e)
            {
                Utils.Trace(e, "Unexpected error in InitConfigInfo");
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Adds a node as an attribute to the EventCategories list
        /// </summary>
        /// <param name="EventTypeNodeId">The event type node</param>
        /// <param name="AttrRef">The reference node being added as an attribute</param>
        private void ProcessNodeAsAttribute(NodeId EventTypeNodeId, ReferenceDescription AttrRef)
        {
            try
            {
                EventAttribute attr = new EventAttribute();
                DataValue value = new DataValue();

                attr.AttributeID = m_attrID++;
                attr.strNodeId = AttrRef.NodeId.ToString();
                attr.BrowseName = AttrRef.BrowseName.Name;
                attr.BrowseNameNSIndex = AttrRef.BrowseName.NamespaceIndex;
                attr.AttrDesc = AttrRef.DisplayName.Text;

                Node node = m_session.ReadNode((NodeId)AttrRef.NodeId);
                node.Read(null, Attributes.DataType, value);
                NodeId typenode = (NodeId)value.Value;
                attr.strDataTypeNodeId = typenode.ToString();
                attr.ActualDataType = DataTypes.GetSystemType(typenode, EncodeableFactory.GlobalFactory);
                attr.strEventNodeId = EventTypeNodeId.ToString();

                node.Read(null, Attributes.ValueRank, value);
                //TODO: Used to be ArraySize. Does ValueRank have the same definition?
                if ((int)value.Value >= 0) //TODO: is there a constant that can be used
                    attr.IsArray = true;
                else
                    attr.IsArray = false;

                m_EventAttributes.Add(attr);
            }
            catch (Exception e)
            {
                Utils.Trace(e, "Unexpected error in ProcessNodesAsAttribute");
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// Compare method based off the Attribute Description
 /// </summary>
 /// <param name="x"></param>
 /// <param name="y"></param>
 private static int EventAttributeDescCompare(EventAttribute x, EventAttribute y)
 {
     int c = x.AttrDesc.ToLower().CompareTo(y.AttrDesc.ToLower());
     if (c != 0)
         return c;
     else
     {
         if ((x.ActualDataType != null) && (y.ActualDataType != null))
             return x.ActualDataType.Name.CompareTo(y.ActualDataType.Name);
         else
             return 0;
     }
 }