Пример #1
0
 /// <summary>
 /// Loads a nodeset from a stream.
 /// </summary>
 /// <param name="istrm">The input stream.</param>
 /// <returns>The set of nodes</returns>
 public static NodeSet Read(Stream istrm)
 {
     using (XmlReader reader = XmlReader.Create(istrm, Utils.DefaultXmlReaderSettings()))
     {
         DataContractSerializer serializer = new DataContractSerializer(typeof(NodeSet));
         return(serializer.ReadObject(reader) as NodeSet);
     }
 }
Пример #2
0
        /// <summary>
        /// Reads the schema information from a XML document.
        /// </summary>
        public void LoadFromXml(ISystemContext context, Stream istrm, bool updateTables)
        {
            ServiceMessageContext messageContext = new ServiceMessageContext();

            messageContext.NamespaceUris = context.NamespaceUris;
            messageContext.ServerUris    = context.ServerUris;
            messageContext.Factory       = context.EncodeableFactory;

            using (XmlReader reader = XmlReader.Create(istrm, Utils.DefaultXmlReaderSettings()))
            {
                XmlQualifiedName root    = new XmlQualifiedName("ListOfNodeState", Namespaces.OpcUaXsd);
                XmlDecoder       decoder = new XmlDecoder(null, reader, messageContext);

                NamespaceTable namespaceUris = new NamespaceTable();

                if (!decoder.LoadStringTable("NamespaceUris", "NamespaceUri", namespaceUris))
                {
                    namespaceUris = null;
                }

                // update namespace table.
                if (updateTables)
                {
                    if (namespaceUris != null && context.NamespaceUris != null)
                    {
                        for (int ii = 0; ii < namespaceUris.Count; ii++)
                        {
                            context.NamespaceUris.GetIndexOrAppend(namespaceUris.GetString((uint)ii));
                        }
                    }
                }

                StringTable serverUris = new StringTable();

                if (!decoder.LoadStringTable("ServerUris", "ServerUri", context.ServerUris))
                {
                    serverUris = null;
                }

                // update server table.
                if (updateTables)
                {
                    if (serverUris != null && context.ServerUris != null)
                    {
                        for (int ii = 0; ii < serverUris.Count; ii++)
                        {
                            context.ServerUris.GetIndexOrAppend(serverUris.GetString((uint)ii));
                        }
                    }
                }

                // set mapping.
                decoder.SetMappingTables(namespaceUris, serverUris);

                decoder.PushNamespace(Namespaces.OpcUaXsd);

                NodeState state = NodeState.LoadNode(context, decoder);

                while (state != null)
                {
                    this.Add(state);

                    state = NodeState.LoadNode(context, decoder);
                }

                decoder.Close();
            }
        }
        /// <summary>
        /// Creates the configuration object from the configuration section.
        /// </summary>
        /// <param name="parent">The parent object.</param>
        /// <param name="configContext">The configuration context object.</param>
        /// <param name="section">The section as XML node.</param>
        /// <returns>The created section handler object.</returns>
        public object Create(object parent, object configContext, System.Xml.XmlNode section)
        {
            if (section == null)
            {
                throw new ArgumentNullException(nameof(section));
            }

            XmlNode element = section.FirstChild;

            while (element != null && typeof(XmlElement) != element.GetType())
            {
                element = element.NextSibling;
            }

            using (XmlReader reader = XmlReader.Create(new StringReader(element.OuterXml), Utils.DefaultXmlReaderSettings()))
            {
                DataContractSerializer serializer    = new DataContractSerializer(typeof(ConfigurationLocation));
                ConfigurationLocation  configuration = serializer.ReadObject(reader) as ConfigurationLocation;
                return(configuration);
            }
        }