A class that manages the mapping between the local and remote namespace indexes.
Exemple #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ComDaProxy"/> class.
 /// </summary>
 public ComDaProxy()
 {
     m_mapper             = new ComNamespaceMapper();
     m_browseCacheManager = new ComDaBrowseCache(m_mapper);
     m_browseManager      = new ComDaBrowseManager(m_mapper, m_browseCacheManager);
     m_groupManager       = new ComDaGroupManager(m_mapper, m_browseManager);
 }
Exemple #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ComDaProxy"/> class.
        /// </summary>
        public ComDaProxy()
		{
            m_mapper = new ComNamespaceMapper();
            m_browseCacheManager = new ComDaBrowseCache(m_mapper);
            m_browseManager = new ComDaBrowseManager(m_mapper, m_browseCacheManager);
            m_groupManager = new ComDaGroupManager(m_mapper, m_browseManager);
        }
Exemple #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ComDaProxy"/> class.
        /// </summary>
        public ComHdaProxy()
		{
            m_mapper = new ComNamespaceMapper();
            m_browseCacheManager = new ComDaBrowseCache(m_mapper);
            m_browseManager = new ComDaBrowseManager(m_mapper, m_browseCacheManager);
            m_itemManager = new ComHdaItemManager(m_mapper);
            m_transactions = new Dictionary<int,Transaction>();
        }
Exemple #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ComDaGroupManager"/> class.
 /// </summary>
 /// <param name="mapper">The mapper.</param>
 /// <param name="browser">The browser.</param>
 public ComDaGroupManager(ComNamespaceMapper mapper, ComDaBrowseManager browser)
 {
     m_mapper  = mapper;
     m_browser = browser;
     m_groups  = new List <ComDaGroup>();
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ComDaBrowseManager"/> class.
 /// </summary>
 /// <param name="mapper">The object used to map namespace indexes.</param>
 /// <param name="cache">The cache.</param>
 public ComDaBrowseManager(ComNamespaceMapper mapper, ComDaBrowseCache cache)
 {
     m_mapper             = mapper;
     m_cache              = cache;
     m_continuationPoints = new Dictionary <string, ContinuationPoint>();
 }
Exemple #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ComHdaItemManager"/> class.
 /// </summary>
 /// <param name="mapper">The object used to map namespace indexes.</param>
 public ComHdaItemManager(ComNamespaceMapper mapper)
 {
     m_mapper  = mapper;
     m_handles = new Dictionary <int, InternalHandle>();
     m_items   = new Dictionary <string, Item>();
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="ComDaBrowseManager"/> class.
        /// </summary>
        /// <param name="mapper">The object used to map namespace indexes.</param>
        /// <param name="cache">The cache.</param>
        public ComDaBrowseManager(ComNamespaceMapper mapper, ComDaBrowseCache cache)
		{
            m_mapper = mapper;
            m_cache = cache;
            m_continuationPoints = new Dictionary<string, ContinuationPoint>();
        }
Exemple #8
0
        /// <summary>
        /// Collects instance declarations nodes from with a type.
        /// </summary>
        public static void CollectInstanceDeclarations(
            Session session,
            ComNamespaceMapper mapper,
            NodeState node,
            AeEventAttribute parent,
            List<AeEventAttribute> instances,
            IDictionary<string, AeEventAttribute> map)
        {
            List<BaseInstanceState> children = new List<BaseInstanceState>();
            node.GetChildren(session.SystemContext, children);
            
            if (children.Count == 0)
            {
                return;
            }

            // process the children.
            for (int ii = 0; ii < children.Count; ii++)
            {
                BaseInstanceState instance = children[ii];

                // only interested in objects and variables.
                if (instance.NodeClass != NodeClass.Object && instance.NodeClass != NodeClass.Variable)
                {
                    return;
                }

                // ignore instances without a modelling rule.
                if (NodeId.IsNull(instance.ModellingRuleId))
                {
                    return;
                }

                // create a new declaration.
                AeEventAttribute declaration = new AeEventAttribute();

                declaration.RootTypeId = (parent != null)?parent.RootTypeId:node.NodeId;
                declaration.NodeId = (NodeId)instance.NodeId;
                declaration.BrowseName = instance.BrowseName;
                declaration.NodeClass = instance.NodeClass;
                declaration.Description = (instance.Description != null)?instance.Description.ToString():null;
                
                // get data type information.
                BaseVariableState variable = instance as BaseVariableState;
 
                if (variable != null)
                {
                    declaration.DataType = variable.DataType;
                    declaration.ValueRank = variable.ValueRank;

                    if (!NodeId.IsNull(variable.DataType))
                    {
                        declaration.BuiltInType = DataTypes.GetBuiltInType(declaration.DataType, session.TypeTree);
                    }
                }

                if (!LocalizedText.IsNullOrEmpty(instance.DisplayName))
                {
                    declaration.DisplayName = instance.DisplayName.Text;
                }
                else
                {
                    declaration.DisplayName = instance.BrowseName.Name;
                }

                if (parent != null)
                {
                    declaration.BrowsePath = new QualifiedNameCollection(parent.BrowsePath);
                    declaration.BrowsePathDisplayText = Utils.Format("{0}/{1}", parent.BrowsePathDisplayText, mapper.GetLocalBrowseName(instance.BrowseName));
                    declaration.DisplayPath = Utils.Format("{0}/{1}", parent.DisplayPath, instance.DisplayName);
                }
                else
                {
                    declaration.BrowsePath = new QualifiedNameCollection();
                    declaration.BrowsePathDisplayText = Utils.Format("{0}", instance.BrowseName);
                    declaration.DisplayPath = Utils.Format("{0}", instance.DisplayName);
                }

                declaration.BrowsePath.Add(instance.BrowseName);

                // check if reading an overridden declaration.
                AeEventAttribute overriden = null;

                if (map.TryGetValue(declaration.BrowsePathDisplayText, out overriden))
                {
                    declaration.OverriddenDeclaration = overriden;
                }

                map[declaration.BrowsePathDisplayText] = declaration;

                // only interested in variables.
                if (instance.NodeClass == NodeClass.Variable)
                {
                    instances.Add(declaration);
                }

                // recusively build tree.
                CollectInstanceDeclarations(session, mapper, instance, declaration, instances, map);
            }
        }
Exemple #9
0
        /// <summary>
        /// Collects instance declarations nodes from with a type.
        /// </summary>
        public static void CollectInstanceDeclarations(
            Session session,
            ComNamespaceMapper mapper,
            NodeId typeId,
            AeEventAttribute parent,
            List<AeEventAttribute> instances,
            IDictionary<string, AeEventAttribute> map)
        {
            // find the children.
            BrowseDescription nodeToBrowse = new BrowseDescription();

            if (parent == null)
            {
                nodeToBrowse.NodeId = typeId;
            }
            else
            {
                nodeToBrowse.NodeId = parent.NodeId;
            }

            nodeToBrowse.BrowseDirection = BrowseDirection.Forward;
            nodeToBrowse.ReferenceTypeId = ReferenceTypeIds.HasChild;
            nodeToBrowse.IncludeSubtypes = true;
            nodeToBrowse.NodeClassMask = (uint)(NodeClass.Object | NodeClass.Variable);
            nodeToBrowse.ResultMask = (uint)BrowseResultMask.All;

            // ignore any browsing errors.
            ReferenceDescriptionCollection references = Browse(session, nodeToBrowse, false);

            if (references == null)
            {
                return;
            }

            // process the children.
            List<NodeId> nodeIds = new List<NodeId>();
            List<AeEventAttribute> children = new List<AeEventAttribute>();

            for (int ii = 0; ii < references.Count; ii++)
            {
                ReferenceDescription reference = references[ii];

                if (reference.NodeId.IsAbsolute)
                {
                    continue;
                }

                // create a new declaration.
                AeEventAttribute child = new AeEventAttribute();

                child.RootTypeId = typeId;
                child.NodeId = (NodeId)reference.NodeId;
                child.BrowseName = reference.BrowseName;
                child.NodeClass = reference.NodeClass;

                if (!LocalizedText.IsNullOrEmpty(reference.DisplayName))
                {
                    child.DisplayName = reference.DisplayName.Text;
                }
                else
                {
                    child.DisplayName = reference.BrowseName.Name;
                }

                if (parent != null)
                {
                    child.BrowsePath = new QualifiedNameCollection(parent.BrowsePath);
                    child.BrowsePathDisplayText = Utils.Format("{0}/{1}", parent.BrowsePathDisplayText, mapper.GetLocalBrowseName(reference.BrowseName));
                    child.DisplayPath = Utils.Format("{0}/{1}", parent.DisplayPath, reference.DisplayName);
                }
                else
                {
                    child.BrowsePath = new QualifiedNameCollection();
                    child.BrowsePathDisplayText = Utils.Format("{0}", reference.BrowseName);
                    child.DisplayPath = Utils.Format("{0}", reference.DisplayName);
                }

                child.BrowsePath.Add(reference.BrowseName);

                // check if reading an overridden declaration.
                AeEventAttribute overriden = null;

                if (map.TryGetValue(child.BrowsePathDisplayText, out overriden))
                {
                    child.OverriddenDeclaration = overriden;
                }

                map[child.BrowsePathDisplayText] = child;

                // add to list.
                children.Add(child);
                nodeIds.Add(child.NodeId);
            }

            // check if nothing more to do.
            if (children.Count == 0)
            {
                return;
            }

            // find the modelling rules.
            List<NodeId> modellingRules = FindTargetOfReference(session, nodeIds, Opc.Ua.ReferenceTypeIds.HasModellingRule, false);

            if (modellingRules != null)
            {
                for (int ii = 0; ii < nodeIds.Count; ii++)
                {
                    children[ii].ModellingRule = modellingRules[ii];

                    // if the modelling rule is null then the instance is not part of the type declaration.
                    if (NodeId.IsNull(modellingRules[ii]))
                    {
                        map.Remove(children[ii].BrowsePathDisplayText);
                    }
                }
            }

            // update the descriptions.
            UpdateInstanceDescriptions(session, children, false);

            // recusively collect instance declarations for the tree below.
            for (int ii = 0; ii < children.Count; ii++)
            {
                if (!NodeId.IsNull(children[ii].ModellingRule))
                {
                    instances.Add(children[ii]);
                    CollectInstanceDeclarations(session, mapper, typeId, children[ii], instances, map);
                }
            }
        }
Exemple #10
0
        /// <summary>
        /// Converts a UA value to an HDA attribute value.
        /// </summary>
        /// <param name="session">The session.</param>
        /// <param name="mapper">The mapper.</param>
        /// <param name="attributeId">The attribute id.</param>
        /// <param name="value">The value.</param>
        /// <returns></returns>
        internal static DaValue GetAttributeValue(Session session, ComNamespaceMapper mapper, uint attributeId, DataValue value)
        {
            switch (attributeId)
            {
                case INTERNAL_ATTRIBUTE_ANNOTATION:
                {
                    DaValue result = new DaValue();

                    Annotation annotation = value.GetValue<Annotation>(null);

                    if (annotation == null)
                    {
                        result.Error = ResultIds.E_BADTYPE;
                        return result;
                    }

                    result.Value = annotation;
                    result.HdaQuality = ComUtils.GetHdaQualityCode(value.StatusCode);
                    result.Timestamp = value.SourceTimestamp;
                    result.Error = ResultIds.S_OK;

                    return result;
                }

                case Constants.OPCHDA_ENG_UNITS:
                {
                    DaValue result = new DaValue();

                    EUInformation engineeringUnits = value.GetValue<EUInformation>(null);

                    if (engineeringUnits == null)
                    {
                        result.Error = ResultIds.E_INVALIDATTRID;
                        return result;
                    }

                    if (engineeringUnits.DisplayName != null)
                    {
                        result.Value = engineeringUnits.DisplayName.Text;
                    }

                    result.HdaQuality = ComUtils.GetHdaQualityCode(value.StatusCode);
                    result.Timestamp = value.SourceTimestamp;
                    result.Error = ResultIds.S_OK;

                    return result;
                }

                case Constants.OPCHDA_HIGH_ENTRY_LIMIT:
                case Constants.OPCHDA_NORMAL_MAXIMUM:
                {
                    DaValue result = new DaValue();

                    Range range = value.GetValue<Range>(null);

                    if (range == null)
                    {
                        result.Error = ResultIds.E_INVALIDATTRID;
                        return result;
                    }

                    result.Value = range.High;
                    result.HdaQuality = ComUtils.GetHdaQualityCode(value.StatusCode);
                    result.Timestamp = value.SourceTimestamp;
                    result.Error = ResultIds.S_OK;

                    return result;
                }

                case Constants.OPCHDA_LOW_ENTRY_LIMIT:
                case Constants.OPCHDA_NORMAL_MINIMUM:
                {
                    DaValue result = new DaValue();

                    Range range = value.GetValue<Range>(null);

                    if (range == null)
                    {
                        result.Error = ResultIds.E_INVALIDATTRID;
                        return result;
                    }

                    result.Value = range.Low;
                    result.HdaQuality = ComUtils.GetHdaQualityCode(value.StatusCode);
                    result.Timestamp = value.SourceTimestamp;
                    result.Error = ResultIds.S_OK;

                    return result;
                }

                case Constants.OPCHDA_MAX_TIME_INT:
                case Constants.OPCHDA_MIN_TIME_INT:
                {
                    DaValue result = new DaValue();

                    int error = ComHdaProxy.MapReadStatusToErrorCode(value.StatusCode);

                    if (error < 0)
                    {
                        result.Error = error;
                        return result;
                    }

                    // need to support the VT_CY type.
                    result.Value = (decimal)value.GetValue<double>(0);
                    result.HdaQuality = ComUtils.GetHdaQualityCode(value.StatusCode);
                    result.Timestamp = value.SourceTimestamp;
                    result.Error = ResultIds.S_OK;

                    return result;
                }

                default:
                case Constants.OPCHDA_ITEMID:
                case Constants.OPCHDA_ARCHIVING:
                case Constants.OPCHDA_STEPPED:
                case Constants.OPCHDA_EXCEPTION_DEV:
                case Constants.OPCHDA_EXCEPTION_DEV_TYPE:
                case Constants.OPCHDA_DERIVE_EQUATION:
                {
                    return mapper.GetLocalDataValue(value);
                }
            }
        }
Exemple #11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ComDaGroupManager"/> class.
        /// </summary>
        /// <param name="mapper">The mapper.</param>
        /// <param name="browser">The browser.</param>
        public ComDaGroupManager(ComNamespaceMapper mapper, ComDaBrowseManager browser)
		{
            m_mapper = mapper;
            m_browser = browser;
            m_groups = new List<ComDaGroup>();
        }
        /// <summary>
        /// Collects instance declarations nodes from with a type.
        /// </summary>
        public static void CollectInstanceDeclarations(
            Session session,
            ComNamespaceMapper mapper,
            NodeState node,
            AeEventAttribute parent,
            List <AeEventAttribute> instances,
            IDictionary <string, AeEventAttribute> map)
        {
            List <BaseInstanceState> children = new List <BaseInstanceState>();

            node.GetChildren(session.SystemContext, children);

            if (children.Count == 0)
            {
                return;
            }

            // process the children.
            for (int ii = 0; ii < children.Count; ii++)
            {
                BaseInstanceState instance = children[ii];

                // only interested in objects and variables.
                if (instance.NodeClass != NodeClass.Object && instance.NodeClass != NodeClass.Variable)
                {
                    return;
                }

                // ignore instances without a modelling rule.
                if (NodeId.IsNull(instance.ModellingRuleId))
                {
                    return;
                }

                // create a new declaration.
                AeEventAttribute declaration = new AeEventAttribute();

                declaration.RootTypeId  = (parent != null)?parent.RootTypeId:node.NodeId;
                declaration.NodeId      = (NodeId)instance.NodeId;
                declaration.BrowseName  = instance.BrowseName;
                declaration.NodeClass   = instance.NodeClass;
                declaration.Description = (instance.Description != null)?instance.Description.ToString():null;

                // get data type information.
                BaseVariableState variable = instance as BaseVariableState;

                if (variable != null)
                {
                    declaration.DataType  = variable.DataType;
                    declaration.ValueRank = variable.ValueRank;

                    if (!NodeId.IsNull(variable.DataType))
                    {
                        declaration.BuiltInType = DataTypes.GetBuiltInType(declaration.DataType, session.TypeTree);
                    }
                }

                if (!LocalizedText.IsNullOrEmpty(instance.DisplayName))
                {
                    declaration.DisplayName = instance.DisplayName.Text;
                }
                else
                {
                    declaration.DisplayName = instance.BrowseName.Name;
                }

                if (parent != null)
                {
                    declaration.BrowsePath            = new QualifiedNameCollection(parent.BrowsePath);
                    declaration.BrowsePathDisplayText = Utils.Format("{0}/{1}", parent.BrowsePathDisplayText, mapper.GetLocalBrowseName(instance.BrowseName));
                    declaration.DisplayPath           = Utils.Format("{0}/{1}", parent.DisplayPath, instance.DisplayName);
                }
                else
                {
                    declaration.BrowsePath            = new QualifiedNameCollection();
                    declaration.BrowsePathDisplayText = Utils.Format("{0}", instance.BrowseName);
                    declaration.DisplayPath           = Utils.Format("{0}", instance.DisplayName);
                }

                declaration.BrowsePath.Add(instance.BrowseName);

                // check if reading an overridden declaration.
                AeEventAttribute overriden = null;

                if (map.TryGetValue(declaration.BrowsePathDisplayText, out overriden))
                {
                    declaration.OverriddenDeclaration = overriden;
                }

                map[declaration.BrowsePathDisplayText] = declaration;

                // only interested in variables.
                if (instance.NodeClass == NodeClass.Variable)
                {
                    instances.Add(declaration);
                }

                // recusively build tree.
                CollectInstanceDeclarations(session, mapper, instance, declaration, instances, map);
            }
        }
        /// <summary>
        /// Collects instance declarations nodes from with a type.
        /// </summary>
        public static void CollectInstanceDeclarations(
            Session session,
            ComNamespaceMapper mapper,
            NodeId typeId,
            AeEventAttribute parent,
            List <AeEventAttribute> instances,
            IDictionary <string, AeEventAttribute> map)
        {
            // find the children.
            BrowseDescription nodeToBrowse = new BrowseDescription();

            if (parent == null)
            {
                nodeToBrowse.NodeId = typeId;
            }
            else
            {
                nodeToBrowse.NodeId = parent.NodeId;
            }

            nodeToBrowse.BrowseDirection = BrowseDirection.Forward;
            nodeToBrowse.ReferenceTypeId = ReferenceTypeIds.HasChild;
            nodeToBrowse.IncludeSubtypes = true;
            nodeToBrowse.NodeClassMask   = (uint)(NodeClass.Object | NodeClass.Variable);
            nodeToBrowse.ResultMask      = (uint)BrowseResultMask.All;

            // ignore any browsing errors.
            ReferenceDescriptionCollection references = Browse(session, nodeToBrowse, false);

            if (references == null)
            {
                return;
            }

            // process the children.
            List <NodeId>           nodeIds  = new List <NodeId>();
            List <AeEventAttribute> children = new List <AeEventAttribute>();

            for (int ii = 0; ii < references.Count; ii++)
            {
                ReferenceDescription reference = references[ii];

                if (reference.NodeId.IsAbsolute)
                {
                    continue;
                }

                // create a new declaration.
                AeEventAttribute child = new AeEventAttribute();

                child.RootTypeId = typeId;
                child.NodeId     = (NodeId)reference.NodeId;
                child.BrowseName = reference.BrowseName;
                child.NodeClass  = reference.NodeClass;

                if (!LocalizedText.IsNullOrEmpty(reference.DisplayName))
                {
                    child.DisplayName = reference.DisplayName.Text;
                }
                else
                {
                    child.DisplayName = reference.BrowseName.Name;
                }

                if (parent != null)
                {
                    child.BrowsePath            = new QualifiedNameCollection(parent.BrowsePath);
                    child.BrowsePathDisplayText = Utils.Format("{0}/{1}", parent.BrowsePathDisplayText, mapper.GetLocalBrowseName(reference.BrowseName));
                    child.DisplayPath           = Utils.Format("{0}/{1}", parent.DisplayPath, reference.DisplayName);
                }
                else
                {
                    child.BrowsePath            = new QualifiedNameCollection();
                    child.BrowsePathDisplayText = Utils.Format("{0}", reference.BrowseName);
                    child.DisplayPath           = Utils.Format("{0}", reference.DisplayName);
                }

                child.BrowsePath.Add(reference.BrowseName);

                // check if reading an overridden declaration.
                AeEventAttribute overriden = null;

                if (map.TryGetValue(child.BrowsePathDisplayText, out overriden))
                {
                    child.OverriddenDeclaration = overriden;
                }

                map[child.BrowsePathDisplayText] = child;

                // add to list.
                children.Add(child);
                nodeIds.Add(child.NodeId);
            }

            // check if nothing more to do.
            if (children.Count == 0)
            {
                return;
            }

            // find the modelling rules.
            List <NodeId> modellingRules = FindTargetOfReference(session, nodeIds, Opc.Ua.ReferenceTypeIds.HasModellingRule, false);

            if (modellingRules != null)
            {
                for (int ii = 0; ii < nodeIds.Count; ii++)
                {
                    children[ii].ModellingRule = modellingRules[ii];

                    // if the modelling rule is null then the instance is not part of the type declaration.
                    if (NodeId.IsNull(modellingRules[ii]))
                    {
                        map.Remove(children[ii].BrowsePathDisplayText);
                    }
                }
            }

            // update the descriptions.
            UpdateInstanceDescriptions(session, children, false);

            // recusively collect instance declarations for the tree below.
            for (int ii = 0; ii < children.Count; ii++)
            {
                if (!NodeId.IsNull(children[ii].ModellingRule))
                {
                    instances.Add(children[ii]);
                    CollectInstanceDeclarations(session, mapper, typeId, children[ii], instances, map);
                }
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ComHdaItemManager"/> class.
        /// </summary>
        /// <param name="mapper">The object used to map namespace indexes.</param>
        public ComHdaItemManager(ComNamespaceMapper mapper)
		{
            m_mapper = mapper;
            m_handles = new Dictionary<int, InternalHandle>();
            m_items = new Dictionary<string, Item>();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ComDaBrowseCache"/> class.
        /// </summary>
        /// <param name="mapper">The object used to map namespace indexes.</param>
        public ComDaBrowseCache(ComNamespaceMapper mapper)
		{
            m_mapper = mapper;
            m_cache = new Dictionary<string,BrowseElement>();
            m_browseBlockSize = 10;
        }