Opc.Ua.RelativePath.Parse C# (CSharp) Method

Parse() public static method

Parses a relative path formatted as a string.
public static Parse ( string browsePath, ITypeTable typeTree ) : RelativePath
browsePath string
typeTree ITypeTable
return RelativePath
        public static RelativePath Parse(string browsePath, ITypeTable typeTree)
        {
            if (typeTree == null) throw new ArgumentNullException("typeTree");

            // parse the string.
            RelativePathFormatter formatter = RelativePathFormatter.Parse(browsePath);

            // convert the browse names to node ids.
            RelativePath relativePath = new RelativePath();

            foreach (RelativePathFormatter.Element element in formatter.Elements)
            {
                RelativePathElement parsedElement = new RelativePathElement();

                parsedElement.ReferenceTypeId = null;
                parsedElement.IsInverse = false;
                parsedElement.IncludeSubtypes = element.IncludeSubtypes;
                parsedElement.TargetName = element.TargetName;

                switch (element.ElementType)
                {
                    case RelativePathFormatter.ElementType.AnyHierarchical:
                    {
                        parsedElement.ReferenceTypeId = ReferenceTypeIds.HierarchicalReferences;
                        break;
                    }

                    case RelativePathFormatter.ElementType.AnyComponent:
                    {
                        parsedElement.ReferenceTypeId = ReferenceTypeIds.Aggregates;
                        break;
                    }

                    case RelativePathFormatter.ElementType.ForwardReference:
                    {
                        parsedElement.ReferenceTypeId = typeTree.FindReferenceType(element.ReferenceTypeName);
                        break;
                    }

                    case RelativePathFormatter.ElementType.InverseReference:
                    {
                        parsedElement.ReferenceTypeId = typeTree.FindReferenceType(element.ReferenceTypeName);
                        parsedElement.IsInverse = true;
                        break;
                    }
                }

                if (NodeId.IsNull(parsedElement.ReferenceTypeId))
                {
                    throw ServiceResultException.Create(
                        StatusCodes.BadSyntaxError,
                        "Could not convert BrowseName to a ReferenceTypeId: {0}",
                        element.ReferenceTypeName);
                }

                relativePath.Elements.Add(parsedElement);
            }

            return relativePath;
        }
        

Same methods

RelativePath::Parse ( string browsePath, ITypeTable typeTree, Opc.Ua.NamespaceTable currentTable, Opc.Ua.NamespaceTable targetTable ) : RelativePath

Usage Example

コード例 #1
0
 /// <summary>
 /// Creates an operand that references a component/property of a type.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="typeDefinitionId">The type definition identifier.</param>
 /// <param name="browsePath">The browse path.</param>
 /// <param name="attributeId">The attribute identifier.</param>
 /// <param name="indexRange">The index range.</param>
 public AttributeOperand(
     FilterContext context,
     ExpandedNodeId typeDefinitionId,
     string browsePath,
     uint attributeId,
     string indexRange)
 {
     m_nodeId      = ExpandedNodeId.ToNodeId(typeDefinitionId, context.NamespaceUris);
     m_browsePath  = RelativePath.Parse(browsePath, context.TypeTree);
     m_attributeId = attributeId;
     m_indexRange  = indexRange;
     m_alias       = null;
 }