/// <summary> /// Reads an XmlElement array from the stream. /// </summary> public XmlElementCollection ReadXmlElementArray(string fieldName) { bool isNil = false; XmlElementCollection values = new XmlElementCollection(); if (BeginField(fieldName, true, out isNil)) { PushNamespace(Namespaces.OpcUaXsd); while (MoveToElement("XmlElement")) { values.Add(ReadXmlElement("XmlElement")); } // check the length. if (m_context.MaxArrayLength > 0 && m_context.MaxArrayLength < values.Count) { throw new ServiceResultException(StatusCodes.BadEncodingLimitsExceeded); } PopNamespace(); EndField(fieldName); return values; } if (isNil) { return null; } return values; }
/// <summary> /// Reads an XmlElement array from the stream. /// </summary> public XmlElementCollection ReadXmlElementArray(string fieldName) { int length = ReadArrayLength(); if (length == -1) { return null; } XmlElementCollection values = new XmlElementCollection(length); for (int ii = 0; ii < length; ii++) { values.Add(ReadXmlElement(null)); } return values; }
/// <summary> /// Loads the configuration from the application configuration file. /// </summary> public static ServerTestConfiguration Load(XmlElementCollection extensions) { if (extensions == null || extensions.Count == 0) { return new ServerTestConfiguration(); } foreach (XmlElement element in extensions) { if (element.NamespaceURI != "http://opcfoundation.org/UA/SDK/ServerTest/Configuration.xsd") { continue; } XmlNodeReader reader = new XmlNodeReader(element); try { DataContractSerializer serializer = new DataContractSerializer(typeof(ServerTestConfiguration)); ServerTestConfiguration configuration = serializer.ReadObject(reader) as ServerTestConfiguration; if (configuration.Iterations <= 0) { configuration.Iterations = 1; } return configuration; } finally { reader.Close(); } } return new ServerTestConfiguration(); }
/// <summary> /// Reads an XmlElement array from the stream. /// </summary> public XmlElementCollection ReadXmlElementArray(string fieldName) { var values = new XmlElementCollection(); List<object> token = null; if (!ReadArrayField(fieldName, out token)) { return values; } for (int ii = 0; ii < token.Count; ii++) { try { m_stack.Push(token[ii]); values.Add(ReadXmlElement(null)); } finally { m_stack.Pop(); } } return values; }
/// <summary> /// Collect all the elements from XMLNode. /// </summary> private static void CollectElements(XmlNode parent, XmlElementCollection elements) { for (XmlNode node = parent.FirstChild; node != null; node = node.NextSibling) { XmlElement element = node as XmlElement; if (element != null) { elements.Add(element); CollectElements(element, elements); } } }
/// <summary> /// Returns XmlElement. /// </summary> public XmlElement GetRandomXmlElement() { if (m_XmlElements == null) { XmlTextReader reader = new XmlTextReader(Assembly.GetExecutingAssembly().GetManifestResourceStream("Opc.Ua.StackTest.SampleXmlData.xml")); XmlDocument document = new XmlDocument(); document.Load(reader); reader.Close(); XmlElementCollection elements = new XmlElementCollection(); CollectElements(document, elements); m_XmlElements = elements.ToArray(); } int index = GetInt32Range(-1, m_XmlElements.Length - 1); if (index < 0) { return null; } return m_XmlElements[index]; }