/// <summary>Creates a duplicate of the item object. All properties (including the ID) are preserved</summary> public IItem Clone() { var writer = new ResultWriter(this.AmlContext, null, null); ToAml(writer, new AmlWriterSettings()); return(writer.Result.AssertItem()); }
/// <summary>Return a result from an XmlReader indicating that it is the result of a query performed on a specific connection</summary> /// <param name="xml">XML data</param> /// <param name="query">The original query which produced the <paramref name="xml"/> response</param> /// <param name="database">The name of the database which was queried</param> /// <param name="readOnly">Whether or not the data coming back should be read-only</param> internal IReadOnlyResult FromXml(XmlReader xml, Command query, string database, bool readOnly) { var writer = new ResultWriter(this, database, query, readOnly); xml.CopyTo(writer); return(writer.Result); }
public override bool MoveToNext(string localName, string namespaceURI) { if (_stack.Count < 1 || _node == XPathNodeType.Text) { return(false); } var pos = _stack.Peek().Position; var fullName = localName; if (!string.IsNullOrEmpty(namespaceURI)) { fullName = ResultWriter.PrefixFromNamespace(namespaceURI) + ":" + localName; } while (_stack.Peek().MoveNext()) { if (_stack.Peek().Current.Name == fullName) { return(SetCurrent(_stack.Peek().Current)); } } _stack.Peek().Position = pos; return(false); }
public override bool MoveToChild(string localName, string namespaceURI) { if (!_current.Elements().Any()) { return(false); } var fullName = localName; if (!string.IsNullOrEmpty(namespaceURI)) { fullName = ResultWriter.PrefixFromNamespace(namespaceURI) + ":" + localName; } var list = new ElementList(_current.Elements()); while (list.MoveNext()) { if (list.Current.Name == fullName) { _stack.Push(list); return(SetCurrent(_stack.Peek().Current)); } } return(false); }
/// <summary> /// Return a result from a method which writes to an <see cref="XmlWriter"/> /// </summary> /// <param name="writer">The callback to write to a writer.</param> public IResult FromXml(Action <XmlWriter> writer) { using (var w = new ResultWriter(this, null, null, false)) { writer(w); return(w.Result); } }
/// <summary>Return a result from a <see cref="IAmlNode"/></summary> /// <param name="aml">XML data</param> public IResult FromXml(IAmlNode aml) { using (var writer = new ResultWriter(this, null, null, false)) { aml.ToAml(writer, new AmlWriterSettings()); return(writer.Result); } }
/// <summary>Return a result from a <see cref="Command"/></summary> /// <param name="aml">XML data</param> public IResult FromXml(Command aml) { using (var writer = new ResultWriter(this, null, null, false)) { aml.ToNormalizedAml(LocalizationContext, writer); return(writer.Result); } }
public override string GetAttribute(string name, string namespaceURI) { var prefix = ResultWriter.PrefixFromNamespace(namespaceURI); if (!string.IsNullOrEmpty(prefix)) { name = prefix + ":" + name; } return(_current.Attribute(name).Value); }
/// <summary> /// Return a result from an AML string by substituting the @0 style parameters /// with the arguments specified. /// </summary> /// <param name="xml">Query to format</param> /// <param name="args">Arguments to substitute into the query</param> public IResult FromXml(string xml, params object[] args) { using (var writer = new ResultWriter(this, null, null, false)) { var sub = new ParameterSubstitution(); sub.AddIndexedParameters(args); sub.Substitute(xml, LocalizationContext, writer); return(writer.Result); } }
/// <summary>Creates a duplicate of the item object. All properties (including the ID) are preserved</summary> public IItem Clone() { var writer = new ResultWriter(this.AmlContext, null, null); ToAml(writer, new AmlWriterSettings()); var clone = writer.Result.AssertItem(); // Make sure to transfer the null status to the new item if (IsNull && clone is Item item) { item.IsNull = true; } return(clone); }
private void Init(XmlReader reader) { while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element && reader.LocalName == "Item") { switch (reader.GetAttribute("type")) { case "ItemType": InitItemType(reader); return; case "xClassificationTree": InitXClass(reader); return; default: throw new InvalidOperationException("Cannot get classification from Item of type `" + reader.GetAttribute("type") + "`"); } } else if (reader.NodeType == XmlNodeType.Element && reader.LocalName == "class") { InitClassStruct(reader); return; } else if (reader.NodeType == XmlNodeType.Element && reader.LocalName == "Fault" && string.Equals(reader.NamespaceURI, "http://schemas.xmlsoap.org/soap/envelope/", StringComparison.OrdinalIgnoreCase)) { var writer = new ResultWriter(ElementFactory.Local, null, null); writer.WriteStartElement("SOAP-ENV", "Envelope", "http://schemas.xmlsoap.org/soap/envelope/"); writer.WriteAttributeString("xmlns", "SOAP-ENV", null, "http://schemas.xmlsoap.org/soap/envelope/"); writer.WriteStartElement("SOAP-ENV", "Body", "http://schemas.xmlsoap.org/soap/envelope/"); writer.WriteNode(reader, false); writer.WriteEndElement(); writer.WriteEndElement(); throw writer.Result.Exception; } } throw new InvalidOperationException("Unable to get classification from XML"); }
/// <summary> /// Moves to the attribute with the specified <see cref="P:System.Xml.XmlReader.LocalName" /> and <see cref="P:System.Xml.XmlReader.NamespaceURI" />. /// </summary> /// <param name="name">The local name of the attribute.</param> /// <param name="ns">The namespace URI of the attribute.</param> /// <returns> /// <c>true</c> if the attribute is found; otherwise, <c>false</c>. If <c>false</c>, the reader's position does not change. /// </returns> public override bool MoveToAttribute(string name, string ns) { var fullName = name; if (!string.IsNullOrEmpty(ns)) { fullName = ResultWriter.PrefixFromNamespace(ns) + ":" + name; } _attrs = _nodeEnum.Current.Attributes.GetEnumerator(); while (_attrs.MoveNext()) { if (_attrs.Current.Key == fullName) { _node = XmlNodeType.Attribute; return(true); } } MoveToElement(); return(false); }
public override bool MoveToAttribute(string localName, string namespaceURI) { var fullName = localName; if (!string.IsNullOrEmpty(namespaceURI)) { fullName = ResultWriter.PrefixFromNamespace(namespaceURI) + ":" + localName; } _attrs = _current.Attributes().GetEnumerator(); while (_attrs.MoveNext()) { if (_attrs.Current.Name == fullName) { _node = XPathNodeType.Attribute; _localName = localName; _prefix = ResultWriter.PrefixFromNamespace(namespaceURI); return(true); } } _node = XPathNodeType.Element; return(false); }