/// <summary>
        /// Generates a single file containing all of the classes.
        /// </summary>
        public static void Save(this IModelDesign _model, string filePath)
        {
            var context = new SystemContext {
                NamespaceUris = new NamespaceTable()
            };
            var nodes      = _model.GetNodes(context);
            var collection = nodes.ToNodeStateCollection(context);

            // open the output file.
            var outputFile = string.Format(@"{0}\{1}.PredefinedNodes.xml", filePath, _model.Name);

            using (var ostrm = File.Open(outputFile, FileMode.Create)) {
                collection.SaveAsXml(context, ostrm);
            }

            // save as nodeset.
            var outputFile2 = string.Format(@"{0}\{1}.NodeSet.xml", filePath, _model.Name);

            using (var ostrm = File.Open(outputFile2, FileMode.Create)) {
                collection.SaveAsNodeSet(ostrm, context);
            }

            // save as nodeset2.
            var outputFile3 = string.Format(@"{0}\{1}.NodeSet2.xml", filePath, _model.Name);

            using (Stream ostrm = File.Open(outputFile3, FileMode.Create)) {
                var model = new ModelTableEntry {
                    ModelUri                 = _model.Namespace,
                    Version                  = _model.Version,
                    PublicationDate          = _model.PublicationDate ?? DateTime.MinValue,
                    PublicationDateSpecified = _model.PublicationDate != null
                };
                // if (_model.Dependencies != null) {
                //     model.RequiredModel = new List<ModelTableEntry>(_model.Dependencies.Values).ToArray();
                // }
                NodeSet2.Create(nodes, model, _model.PublicationDate, context).Save(ostrm);
            }

            // save as json.
            var outputFile4 = string.Format(@"{0}\{1}.NodeSet.json", filePath, _model.Name);

            using (var ostrm = File.Open(outputFile4, FileMode.Create)) {
                collection.SaveAsJson(ostrm, Formatting.Indented, context);
            }
        }
예제 #2
0
        /// <inheritdoc/>
        public async Task LoadAsync(Stream stream, string contentType, CancellationToken ct)
        {
            ct.Register(() => _loader.CompleteAsync(true).Wait());

            _source = null; // TODO

            var context = _codec.Context.ToSystemContext();

            if (contentType == ContentMimeType.UaNodesetXml)
            {
                // If nodeset, read as nodeset xml
                var nodeset = NodeSet2.Load(stream);
                foreach (var node in nodeset.GetNodeStates(context))
                {
                    ct.ThrowIfCancellationRequested();
                    if (node != null)
                    {
                        await WriteNodeAsync(node, context);
                    }
                }
            }
            else
            {
                // Otherwise decode from stream
                using (var decoder = new ModelDecoder(stream, contentType, _codec.Context)) {
                    while (true)
                    {
                        ct.ThrowIfCancellationRequested();
                        var node = decoder.ReadEncodeable <EncodeableNodeModel>(null);
                        if (node == null)
                        {
                            break;
                        }
                        await WriteNodeAsync(node.Node, context);
                    }
                }
            }
            await _loader.CompleteAsync();
        }
 /// <summary>
 /// Writes the collection to a stream using the Opc.Ua.Schema.UANodeSet schema.
 /// </summary>
 /// <param name="collection"></param>
 /// <param name="ostrm"></param>
 /// <param name="lastModified"></param>
 /// <param name="context"></param>
 /// <param name="model"></param>
 public static void SaveAsNodeSet2(this NodeStateCollection collection, Stream ostrm,
                                   DateTime?lastModified, ISystemContext context, ModelTableEntry model = null) =>
 NodeSet2.Create(collection.ToNodeModels(context), model, lastModified, context).Save(ostrm);