Example #1
0
 /// <inheritdoc/>
 public Schema.DataType TryResolve(Schema.ImportDirective import,
                                   XmlQualifiedName typeName)
 {
     if (import == null)
     {
         throw new ArgumentNullException(nameof(import));
     }
     if (typeName.IsNullOrEmpty())
     {
         throw new ArgumentNullException(nameof(typeName));
     }
     if (!_cache.TryGetValue(import, out var types))
     {
         import = import.Copy();
         types  = Load(import);
         if (types == null)
         {
             // Try any version
             import.TargetVersion = null;
             types = Load(import);
             if (types == null)
             {
                 return(null);
             }
         }
         _cache.Add(import, types);
     }
     return(types.TryResolve(import, typeName));
 }
 /// <inheritdoc/>
 public DataType TryResolve(ImportDirective import, XmlQualifiedName typeName)
 {
     if (import == null)
     {
         throw new ArgumentNullException(nameof(import));
     }
     if (typeName.IsNullOrEmpty())
     {
         throw new ArgumentNullException(nameof(typeName));
     }
     foreach (var resolver in _resolvers)
     {
         try {
             var type = resolver.TryResolve(import, typeName);
             if (type != null)
             {
                 return(type);
             }
         }
         catch {
             continue;
         }
     }
     return(null);
 }
 /// <inheritdoc/>
 public NodeDesign TryResolve(Namespace ns, XmlQualifiedName symbolicId)
 {
     if (ns == null)
     {
         throw new ArgumentNullException(nameof(ns));
     }
     if (symbolicId.IsNullOrEmpty())
     {
         throw new ArgumentNullException(nameof(symbolicId));
     }
     if (!_resolvers.TryGetValue(ns, out var resolver))
     {
         resolver = LoadDesign(ns) as INodeResolver;
         if (resolver == null)
         {
             return(null);
         }
         _resolvers.Add(ns, resolver);
         if (!_assigners.ContainsKey(ns))
         {
             if (LoadIdentifiers(ns) is INodeIdAssigner assigner)
             {
                 _assigners.Add(ns, assigner);
             }
         }
     }
     return(resolver.TryResolve(ns, symbolicId));
 }
 /// <inheritdoc/>
 public NodeDesign TryResolve(Namespace ns, XmlQualifiedName symbolicId)
 {
     if (ns == null)
     {
         throw new ArgumentNullException(nameof(ns));
     }
     if (symbolicId.IsNullOrEmpty())
     {
         throw new ArgumentNullException(nameof(symbolicId));
     }
     foreach (var resolver in _resolvers)
     {
         try {
             // Try to delegate to one of the resolvers
             var node = resolver.TryResolve(ns, symbolicId);
             if (node != null)
             {
                 return(node);
             }
         }
         catch {
             continue;
         }
     }
     return(null);
 }
Example #5
0
 /// <summary>
 /// Get symbolic id for a node that is either root or has the specified parent.
 /// </summary>
 /// <param name="parent"></param>
 /// <param name="symbolicName"></param>
 /// <returns></returns>
 public static XmlQualifiedName CreateSymbolicId(this NodeDesign parent,
                                                 XmlQualifiedName symbolicName)
 {
     if (symbolicName.IsNullOrEmpty())
     {
         throw new ArgumentNullException(nameof(symbolicName));
     }
     return(new XmlQualifiedName(CreateSymbolicId(parent?.SymbolicId?.Name, symbolicName.Name),
                                 symbolicName.Namespace));
 }
Example #6
0
        /// <summary>
        /// Adds a reference to the AddressSpace.
        /// </summary>
        /// <param name="sourceIndex">Index of the source node that must be registered before this method is called.</param>
        /// <param name="referenceTypeName">Name of the reference type.</param>
        /// <param name="inverse">if set to <c>true</c> it is inverse reference.</param>
        /// <param name="targetName">Name of the target element this reference points to.</param>
        public void AddReference(int sourceIndex, XmlQualifiedName referenceTypeName, bool inverse, XmlQualifiedName targetName)
        {
            //targetName can be null in case of HasTypeDefinition of basic types.
            this.Assert((referenceTypeName != null && !referenceTypeName.IsEmpty), sourceIndex, "The reference type name of the reference cannot be null or empty");
            if (targetName.IsNullOrEmpty() || referenceTypeName.IsNullOrEmpty())
            {
                return;
            }
            int targetIndex = TryGetAndAddIfNeeded(targetName.ToString());

            this.AddReference(sourceIndex, referenceTypeName, inverse, targetIndex);
        }
        /// <summary>
        /// Convert type declartion type to design type
        /// </summary>
        /// <param name="baseType"></param>
        /// <returns></returns>
        private static XmlQualifiedName ToDesignBaseDataType(this XmlQualifiedName baseType)
        {
            if (baseType.IsNullOrEmpty())
            {
                return(null);
            }
            switch (baseType.Name)
            {
            case "ExtensionObject":
                return(Constants.Structure);

            case "Variant":
                return(Constants.BaseDataType);
            }
            return(new XmlQualifiedName(baseType.Name, Namespaces.OpcUa));
        }
Example #8
0
 /// <inheritdoc/>
 public DataType TryResolve(ImportDirective import, XmlQualifiedName typeName)
 {
     if (import == null)
     {
         throw new ArgumentNullException(nameof(import));
     }
     if (typeName.IsNullOrEmpty())
     {
         throw new ArgumentNullException(nameof(typeName));
     }
     // We only resolve if we own the namespace.
     if (import.Namespace == _dictionary.TargetNamespace &&
         (import.TargetVersion == null ||
          import.TargetVersion == _dictionary.TargetVersion))
     {
         return(ResolveType(typeName));
     }
     return(null);
 }
Example #9
0
        /// <summary>
        /// Validates the base type of a complex type.
        /// </summary>
        /// <param name="complexType"></param>
        /// <param name="baseType"></param>
        /// <param name="fields"></param>
        private void ValidateBaseType(ComplexType complexType,
                                      XmlQualifiedName baseType, Dictionary <string, FieldType> fields)
        {
            if (baseType.IsNullOrEmpty())
            {
                return;
            }
            var parentType = ResolveType(baseType);

            if (!(parentType is ComplexType complexParent))
            {
                throw new FormatException($"The base type '{baseType}' for complex type " +
                                          $"'{complexType.Name}' is not a complex type.");
            }
            ValidateBaseType(complexType, complexParent.BaseType, fields);
            foreach (var field in complexParent.Field)
            {
                fields.Add(field.Name, field);
            }
        }
 /// <inheritdoc/>
 public object TryAssignId(Namespace ns, XmlQualifiedName symbolicId)
 {
     if (ns == null)
     {
         throw new ArgumentNullException(nameof(ns));
     }
     if (symbolicId.IsNullOrEmpty())
     {
         throw new ArgumentNullException(nameof(symbolicId));
     }
     if (!_assigners.TryGetValue(ns, out var assigner))
     {
         assigner = LoadIdentifiers(ns) as INodeIdAssigner;
         if (assigner == null)
         {
             return(null);
         }
     }
     return(assigner.TryAssignId(ns, symbolicId));
 }
Example #11
0
 /// <summary>
 /// Resolve type
 /// </summary>
 /// <param name="typeName"></param>
 /// <returns></returns>
 public DataType ResolveType(XmlQualifiedName typeName)
 {
     if (typeName.IsNullOrEmpty())
     {
         return(null);
     }
     if (!_datatypes.TryGetValue(typeName, out var dataType))
     {
         if (typeName.Namespace != _dictionary.TargetNamespace)
         {
             // Try and resolve through the import directives
             dataType = ResolveFromImports(typeName, dataType);
         }
     }
     // If type declartion, resolve the source type
     if (dataType is TypeDeclaration declaration)
     {
         return(ResolveType(declaration.SourceType));
     }
     return(dataType);
 }
 /// <summary>
 /// Checks whether the qname is valid
 /// </summary>
 /// <param name="qname"></param>
 /// <returns></returns>
 public static bool IsValid(this XmlQualifiedName qname)
 {
     return(!qname.IsNullOrEmpty() && !string.IsNullOrEmpty(qname.Namespace) &&
            IsValidName(qname.Name));
 }