/// <summary> /// Generates the code from the contents of the address space. /// </summary> private async Task Validate() { m_descriptions = new Dictionary <XmlQualifiedName, TypeDescription>(); m_validatedDescriptions = new List <TypeDescription>(); m_warnings = new List <string>(); // import types from referenced dictionaries. if (Dictionary.Import != null) { foreach (ImportDirective directive in Dictionary.Import) { await Import(directive).ConfigureAwait(false); } } else { // always import builtin types, unless wellknown library if (!WellKnownDictionaries.Any(n => String.Equals(n[0], Dictionary.TargetNamespace))) { ImportDirective directive = new ImportDirective { Namespace = Namespaces.OpcUa }; await Import(directive).ConfigureAwait(false); } } // import types from imported dictionaries. foreach (TypeDescription description in m_descriptions.Values) { ValidateDescription(description); } // import types from target dictionary. if (Dictionary.Items != null) { foreach (TypeDescription description in Dictionary.Items) { ImportDescription(description, Dictionary.TargetNamespace); m_validatedDescriptions.Add(description); } // validate types from target dictionary. foreach (TypeDescription description in m_validatedDescriptions) { ValidateDescription(description); m_warnings.Add(String.Format(CultureInfo.InvariantCulture, "{0} '{1}' validated.", description.GetType().Name, description.Name)); } } }
/// <summary> /// Imports a dictionary identified by an import directive. /// </summary> private void Import(ImportDirective directive) { // check if already loaded. if (LoadedFiles.ContainsKey(directive.Namespace)) { return; } TypeDictionary dictionary = (TypeDictionary)Load(typeof(TypeDictionary), directive.Namespace, directive.Location); // verify namespace. if (!String.IsNullOrEmpty(dictionary.TargetNamespace) && directive.Namespace != dictionary.TargetNamespace) { throw Exception("Imported dictionary '{0}' does not match uri specified: '{1}'.", dictionary.TargetNamespace, directive.Namespace); } // save file. LoadedFiles.Add(dictionary.TargetNamespace, dictionary); // import nested dictionaries. if (dictionary.Import != null) { for (int ii = 0; ii < dictionary.Import.Length; ii++) { Import(dictionary.Import[ii]); } } // import types. if (dictionary.Items != null) { foreach (TypeDescription description in dictionary.Items) { ImportDescription(description, dictionary.TargetNamespace); } } }