Esempio n. 1
0
        /// <summary>
        /// Load the standard types from the included resources
        /// </summary>
        /// <returns></returns>
        internal static IModelDesign LoadStandardModel()
        {
            var assembly = typeof(ModelDesignFile).Assembly;
            var prefix   = assembly.GetName().Name;

            // Load built in types
            var builtInTypes = assembly
                               .DeserializeFromXmlManifestResource <ModelDesign>(
                prefix + ".Stack.Design.BuiltIn.BuiltInTypes.xml");

            // Load default type dictionaries
            var typeDictionary = Types.Standard.ToModelDesign();

            // Load standard types
            var standardTypes = assembly
                                .DeserializeFromXmlManifestResource <ModelDesign>(
                prefix + ".Stack.Design.BuiltIn.StandardTypes.xml");

            // Add all to the standard types (i.e. all in opcfoundation.org/UA)
            var nodes = new List <NodeDesign>();

            nodes.AddRange(builtInTypes.Items);
            nodes.AddRange(typeDictionary.Items);
            nodes.AddRange(standardTypes.Items);
            standardTypes.Items         = nodes.ToArray();
            standardTypes.TargetVersion = null; // Allow matching to any version

            var ids = assembly.GetManifestResourceStream(
                prefix + ".Stack.Design.BuiltIn.StandardTypes.csv");
            var identifiers = new IdentifierFile(ids,
                                                 standardTypes.TargetNamespace, standardTypes.TargetVersion);

            // Return model
            return(new ModelDesignFile(standardTypes, identifiers, null));
        }
Esempio n. 2
0
 /// <summary>
 /// Load design from file and optional identifier file
 /// </summary>
 /// <param name="designFile"></param>
 /// <param name="resolver"></param>
 /// <returns></returns>
 public static IModelDesign Load(string designFile, INodeResolver resolver = null)
 {
     using (var stream = File.OpenRead(designFile)) {
         var             model          = stream.DeserializeFromXml <ModelDesign>();
         var             identifierFile = Path.ChangeExtension(designFile, "csv");
         INodeIdAssigner assigner       = null;
         if (File.Exists(identifierFile))
         {
             using (var stream2 = File.OpenRead(identifierFile)) {
                 assigner = new IdentifierFile(stream2, model.TargetNamespace, model.TargetVersion);
             }
         }
         return(new ModelDesignFile(model, assigner, resolver ?? new CompositeModelResolver()));
     }
 }