//============================================================ // PUBLIC METHODS //============================================================ #region Load(XPathNavigator source) /// <summary> /// Loads this <see cref="XmlRpcStructureValue"/> using the supplied <see cref="XPathNavigator"/>. /// </summary> /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param> /// <returns><b>true</b> if the <see cref="XmlRpcStructureValue"/> was initialized using the supplied <paramref name="source"/>, otherwise <b>false</b>.</returns> /// <remarks> /// <para>This method expects the supplied <paramref name="source"/> to be positioned on the XML element that represents a <see cref="XmlRpcStructureValue"/>.</para> /// </remarks> /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception> public bool Load(XPathNavigator source) { //------------------------------------------------------------ // Local members //------------------------------------------------------------ bool wasLoaded = false; //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(source, "source"); //------------------------------------------------------------ // Attempt to extract structure information //------------------------------------------------------------ if (source.HasChildren) { XPathNodeIterator memberIterator = source.Select("struct/member"); if (memberIterator != null && memberIterator.Count > 0) { while (memberIterator.MoveNext()) { XmlRpcStructureMember member = new XmlRpcStructureMember(); if (member.Load(memberIterator.Current)) { this.Members.Add(member); wasLoaded = true; } } } } return(wasLoaded); }
//============================================================ // ICOMPARABLE IMPLEMENTATION //============================================================ #region CompareTo(object obj) /// <summary> /// Compares the current instance with another object of the same type. /// </summary> /// <param name="obj">An object to compare with this instance.</param> /// <returns>A 32-bit signed integer that indicates the relative order of the objects being compared.</returns> /// <exception cref="ArgumentException">The <paramref name="obj"/> is not the expected <see cref="Type"/>.</exception> public int CompareTo(object obj) { //------------------------------------------------------------ // If target is a null reference, instance is greater //------------------------------------------------------------ if (obj == null) { return(1); } //------------------------------------------------------------ // Determine comparison result using property state of objects //------------------------------------------------------------ XmlRpcStructureMember value = obj as XmlRpcStructureMember; if (value != null) { int result = String.Compare(this.ToString(), value.ToString(), StringComparison.Ordinal); return(result); } else { throw new ArgumentException(String.Format(null, "obj is not of type {0}, type was found to be '{1}'.", this.GetType().FullName, obj.GetType().FullName), "obj"); } }
/// <summary> /// Loads this <see cref="XmlRpcStructureValue"/> using the supplied <see cref="XPathNavigator"/>. /// </summary> /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param> /// <returns><b>true</b> if the <see cref="XmlRpcStructureValue"/> was initialized using the supplied <paramref name="source"/>, otherwise <b>false</b>.</returns> /// <remarks> /// <para>This method expects the supplied <paramref name="source"/> to be positioned on the XML element that represents a <see cref="XmlRpcStructureValue"/>.</para> /// </remarks> /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception> public bool Load(XPathNavigator source) { bool wasLoaded = false; Guard.ArgumentNotNull(source, "source"); if (source.HasChildren) { XPathNodeIterator memberIterator = source.Select("struct/member"); if (memberIterator != null && memberIterator.Count > 0) { while (memberIterator.MoveNext()) { XmlRpcStructureMember member = new XmlRpcStructureMember(); if (member.Load(memberIterator.Current)) { this.Members.Add(member); wasLoaded = true; } } } } return(wasLoaded); }
/// <summary> /// Compares two specified <see cref="Collection{XmlRpcStructureMember}"/> collections. /// </summary> /// <param name="source">The first collection.</param> /// <param name="target">The second collection.</param> /// <returns>A 32-bit signed integer indicating the lexical relationship between the two comparands.</returns> /// <remarks> /// <para> /// If the collections contain the same number of elements, determines the lexical relationship between the two sequences of comparands. /// </para> /// <para> /// If the <paramref name="source"/> has an element count that is <i>greater than</i> the <paramref name="target"/> element count, returns <b>1</b>. /// </para> /// <para> /// If the <paramref name="source"/> has an element count that is <i>less than</i> the <paramref name="target"/> element count, returns <b>-1</b>. /// </para> /// </remarks> /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="target"/> is a null reference (Nothing in Visual Basic).</exception> public static int CompareSequence(Collection <XmlRpcStructureMember> source, Collection <XmlRpcStructureMember> target) { int result = 0; Guard.ArgumentNotNull(source, "source"); Guard.ArgumentNotNull(target, "target"); if (source.Count == target.Count) { for (int i = 0; i < source.Count; i++) { XmlRpcStructureMember member = source[i]; if (!target.Contains(member)) { result = -1; break; } } } else if (source.Count > target.Count) { return(1); } else if (source.Count < target.Count) { return(-1); } return(result); }
/// <summary> /// Initializes a new instance of the <see cref="XmlRpcResponse"/> class using the supplied fault code and message. /// </summary> /// <param name="faultCode">Machine-readable code that identifies the reason the remote procedure call failed.</param> /// <param name="faultMessage">Human-readable information about the reason the remote procedure call failed.</param> public XmlRpcResponse(int faultCode, string faultMessage) { XmlRpcStructureValue faultStructure = new XmlRpcStructureValue(); XmlRpcStructureMember codeMember = new XmlRpcStructureMember("faultCode", new XmlRpcScalarValue(faultCode)); XmlRpcStructureMember stringMember = new XmlRpcStructureMember("faultString", new XmlRpcScalarValue(faultMessage)); faultStructure.Members.Add(codeMember); faultStructure.Members.Add(stringMember); responseFault = faultStructure; }
/// <summary> /// Initializes a new instance of the <see cref="XmlRpcStructureValue"/> class using the supplied <see cref="XPathNodeIterator"/>. /// </summary> /// <param name="iterator">A <see cref="XPathNodeIterator"/> that represents the <i>member</i> nodes for the structured list.</param> /// <exception cref="ArgumentNullException">The <paramref name="iterator"/> is a null reference (Nothing in Visual Basic).</exception> public XmlRpcStructureValue(XPathNodeIterator iterator) { Guard.ArgumentNotNull(iterator, "iterator"); if (iterator.Count > 0) { while (iterator.MoveNext()) { XmlRpcStructureMember member = new XmlRpcStructureMember(); if (member.Load(iterator.Current)) { this.Members.Add(member); } } } }
/// <summary> /// Compares the current instance with another object of the same type. /// </summary> /// <param name="obj">An object to compare with this instance.</param> /// <returns>A 32-bit signed integer that indicates the relative order of the objects being compared.</returns> /// <exception cref="ArgumentException">The <paramref name="obj"/> is not the expected <see cref="Type"/>.</exception> public int CompareTo(object obj) { if (obj == null) { return(1); } XmlRpcStructureMember value = obj as XmlRpcStructureMember; if (value != null) { int result = String.Compare(this.ToString(), value.ToString(), StringComparison.Ordinal); return(result); } else { throw new ArgumentException(String.Format(null, "obj is not of type {0}, type was found to be '{1}'.", this.GetType().FullName, obj.GetType().FullName), "obj"); } }
/// <summary> /// Initializes a new instance of the <see cref="XmlRpcStructureValue"/> class using the supplied <see cref="XPathNodeIterator"/>. /// </summary> /// <param name="iterator">A <see cref="XPathNodeIterator"/> that represents the <i>member</i> nodes for the structured list.</param> /// <exception cref="ArgumentNullException">The <paramref name="iterator"/> is a null reference (Nothing in Visual Basic).</exception> public XmlRpcStructureValue(XPathNodeIterator iterator) { //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(iterator, "iterator"); //------------------------------------------------------------ // Parse iterator nodes to load collection //------------------------------------------------------------ if (iterator.Count > 0) { while (iterator.MoveNext()) { XmlRpcStructureMember member = new XmlRpcStructureMember(); if (member.Load(iterator.Current)) { this.Members.Add(member); } } } }
//============================================================ // INDEXERS //============================================================ #region this[string name] /// <summary> /// Gets or sets the <see cref="XmlRpcStructureMember"/> that has the specified name. /// </summary> /// <param name="name">The name that uniquely identifies the member to get or set.</param> /// <returns>The <see cref="XmlRpcStructureMember"/> with the specified name.</returns> /// <remarks> /// If no member exists for the specified <paramref name="name"/>, returns a <b>null</b> reference. /// This indexer uses a <i>case insensitive</i> comparison of the specified member <paramref name="name"/>. /// </remarks> /// <exception cref="ArgumentNullException">The <paramref name="name"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="name"/> is an empty string.</exception> /// <exception cref="ArgumentNullException">The <paramref name="value"/> is a null reference (Nothing in Visual Basic).</exception> public XmlRpcStructureMember this[string name] { get { Guard.ArgumentNotNullOrEmptyString(name, "name"); XmlRpcStructureMember result = null; foreach (XmlRpcStructureMember member in this.Members) { if (String.Compare(member.Name, name, StringComparison.OrdinalIgnoreCase) == 0) { result = member; break; } } return(result); } set { Guard.ArgumentNotNullOrEmptyString(name, "name"); Guard.ArgumentNotNull(value, "value"); for (int i = 0; i < this.Members.Count; i++) { XmlRpcStructureMember member = this.Members[i]; if (String.Compare(member.Name, name, StringComparison.OrdinalIgnoreCase) == 0) { this.Members[i] = value; break; } } } }
/// <summary> /// Initializes a new instance of the <see cref="XmlRpcResponse"/> class using the supplied fault code and message. /// </summary> /// <param name="faultCode">Machine-readable code that identifies the reason the remote procedure call failed.</param> /// <param name="faultMessage">Human-readable information about the reason the remote procedure call failed.</param> public XmlRpcResponse(int faultCode, string faultMessage) { //------------------------------------------------------------ // Initialize class state //------------------------------------------------------------ XmlRpcStructureValue faultStructure = new XmlRpcStructureValue(); XmlRpcStructureMember codeMember = new XmlRpcStructureMember("faultCode", new XmlRpcScalarValue(faultCode)); XmlRpcStructureMember stringMember = new XmlRpcStructureMember("faultString", new XmlRpcScalarValue(faultMessage)); faultStructure.Members.Add(codeMember); faultStructure.Members.Add(stringMember); responseFault = faultStructure; }