/// <summary> /// Loads this <see cref="XmlRpcStructureMember"/> 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="XmlRpcStructureMember"/> 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="XmlRpcStructureMember"/>.</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) { XPathNavigator nameNavigator = source.SelectSingleNode("name"); XPathNavigator valueNavigator = source.SelectSingleNode("value"); if (nameNavigator != null && !String.IsNullOrEmpty(nameNavigator.Value)) { this.Name = nameNavigator.Value; wasLoaded = true; } if (valueNavigator != null) { IXmlRpcValue value; if (XmlRpcClient.TryParseValue(valueNavigator, out value)) { this.Value = value; wasLoaded = true; } } } return(wasLoaded); }
/// <summary> /// Compares two specified <see cref="Collection{IXmlRpcValue}"/> 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 <IXmlRpcValue> source, Collection <IXmlRpcValue> 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++) { IXmlRpcValue value = source[i]; if (!target.Contains(value)) { 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="XmlRpcStructureMember"/> class using the specified name and value. /// </summary> /// <param name="name">The name of this structure member.</param> /// <param name="value">An object that implements the <see cref="IXmlRpcValue"/> interface that represents the value of this structure member.</param> /// <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(string name, IXmlRpcValue value) { //------------------------------------------------------------ // Initialize class state using guarded properties //------------------------------------------------------------ this.Name = name; this.Value = value; }
/// <summary> /// Initializes a new instance of the <see cref="XmlRpcStructureMember"/> class using the specified name and value. /// </summary> /// <param name="name">The name of this structure member.</param> /// <param name="value">An object that implements the <see cref="IXmlRpcValue"/> interface that represents the value of this structure member.</param> /// <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(string name, IXmlRpcValue value) { //------------------------------------------------------------ // Initialize class state using guarded properties //------------------------------------------------------------ this.Name = name; this.Value = value; }
/// <summary> /// Initializes a new instance of the <see cref="XmlRpcResponse"/> class using the supplied <see cref="IXmlRpcValue"/>. /// </summary> /// <param name="parameter">A <see cref="IXmlRpcValue"/> that represents the response value that was returned for the remote procedure call.</param> /// <exception cref="ArgumentNullException">The <paramref name="parameter"/> is a null reference (Nothing in Visual Basic).</exception> public XmlRpcResponse(IXmlRpcValue parameter) { //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(parameter, "parameter"); //------------------------------------------------------------ // Initialize class state //------------------------------------------------------------ responseParameter = parameter; }
/// <summary> /// Initializes a new instance of the <see cref="XmlRpcResponse"/> class using the supplied <see cref="IXmlRpcValue"/>. /// </summary> /// <param name="parameter">A <see cref="IXmlRpcValue"/> that represents the response value that was returned for the remote procedure call.</param> /// <exception cref="ArgumentNullException">The <paramref name="parameter"/> is a null reference (Nothing in Visual Basic).</exception> public XmlRpcResponse(IXmlRpcValue parameter) { //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(parameter, "parameter"); //------------------------------------------------------------ // Initialize class state //------------------------------------------------------------ responseParameter = parameter; }
//============================================================ // PUBLIC METHODS //============================================================ #region Load(XPathNavigator source) /// <summary> /// Loads this <see cref="XmlRpcResponse"/> 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="XmlRpcResponse"/> 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="XmlRpcResponse"/>.</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 response information //------------------------------------------------------------ if (source.HasChildren) { XPathNavigator parametersNavigator = source.SelectSingleNode("params"); XPathNavigator faultNavigator = source.SelectSingleNode("fault"); if (parametersNavigator != null) { XPathNavigator valueNavigator = parametersNavigator.SelectSingleNode("param/value"); if (valueNavigator != null) { IXmlRpcValue value; if (XmlRpcClient.TryParseValue(valueNavigator, out value)) { responseParameter = value; wasLoaded = true; } } } if (faultNavigator != null) { XPathNavigator structNavigator = faultNavigator.SelectSingleNode("value"); if (structNavigator != null) { XmlRpcStructureValue structure = new XmlRpcStructureValue(); if (structure.Load(structNavigator)) { responseFault = structure; wasLoaded = true; } } } } return(wasLoaded); }
/// <summary> /// Loads this <see cref="XmlRpcResponse"/> 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="XmlRpcResponse"/> 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="XmlRpcResponse"/>.</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) { XPathNavigator parametersNavigator = source.SelectSingleNode("params"); XPathNavigator faultNavigator = source.SelectSingleNode("fault"); if (parametersNavigator != null) { XPathNavigator valueNavigator = parametersNavigator.SelectSingleNode("param/value"); if (valueNavigator != null) { IXmlRpcValue value; if (XmlRpcClient.TryParseValue(valueNavigator, out value)) { responseParameter = value; wasLoaded = true; } } } if (faultNavigator != null) { XPathNavigator structNavigator = faultNavigator.SelectSingleNode("value"); if (structNavigator != null) { XmlRpcStructureValue structure = new XmlRpcStructureValue(); if (structure.Load(structNavigator)) { responseFault = structure; wasLoaded = true; } } } } return(wasLoaded); }
//============================================================ // PUBLIC METHODS //============================================================ #region Load(XPathNavigator source) /// <summary> /// Loads this <see cref="XmlRpcStructureMember"/> 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="XmlRpcStructureMember"/> 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="XmlRpcStructureMember"/>.</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 structure member information //------------------------------------------------------------ if (source.HasChildren) { XPathNavigator nameNavigator = source.SelectSingleNode("name"); XPathNavigator valueNavigator = source.SelectSingleNode("value"); if (nameNavigator != null && !String.IsNullOrEmpty(nameNavigator.Value)) { this.Name = nameNavigator.Value; wasLoaded = true; } if (valueNavigator != null) { IXmlRpcValue value; if (XmlRpcClient.TryParseValue(valueNavigator, out value)) { this.Value = value; wasLoaded = true; } } } return(wasLoaded); }
public XmlRpcStructMember(string name, IXmlRpcValue data) { this.name = name; this.data = data; }
/// <summary> /// Initializes a new instance of the <see cref="XmlRpcResponse"/> class using the supplied <see cref="IXmlRpcValue"/>. /// </summary> /// <param name="parameter">A <see cref="IXmlRpcValue"/> that represents the response value that was returned for the remote procedure call.</param> /// <exception cref="ArgumentNullException">The <paramref name="parameter"/> is a null reference (Nothing in Visual Basic).</exception> public XmlRpcResponse(IXmlRpcValue parameter) { Guard.ArgumentNotNull(parameter, "parameter"); responseParameter = parameter; }
/// <summary> /// Initializes a new instance of the <see cref="XmlRpcStructureMember"/> class using the specified name and value. /// </summary> /// <param name="name">The name of this structure member.</param> /// <param name="value">An object that implements the <see cref="IXmlRpcValue"/> interface that represents the value of this structure member.</param> /// <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(string name, IXmlRpcValue value) { this.Name = name; this.Value = value; }
/// <summary> /// Constructs a new <see cref="IXmlRpcValue"/> object from the specified <see cref="XPathNavigator"/>. /// Parameters specify the XML data source and the variable where the new <see cref="IXmlRpcValue"/> object is returned. /// </summary> /// <param name="source">A <see cref="XPathNavigator"/> that represents the XML data source to be parsed.</param> /// <param name="value"> /// When this method returns, contains an object that represents the <see cref="IXmlRpcValue"/> specified by the <paramref name="source"/>, or <b>null</b> if the conversion failed. /// This parameter is passed uninitialized. /// </param> /// <returns> /// <b>true</b> if <paramref name="source"/> was converted successfully; otherwise, <b>false</b>. /// This operation returns <b>false</b> if the <paramref name="source"/> parameter is a null reference (Nothing in Visual Basic), /// or represents XML data that is not in the expected format. /// </returns> /// <remarks> /// The <paramref name="source"/> is expected to represent an XML-RPC <b>value</b> node. /// </remarks> public static bool TryParseValue(XPathNavigator source, out IXmlRpcValue value) { //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ if (source == null || String.Compare(source.Name, "value", StringComparison.OrdinalIgnoreCase) != 0) { value = null; return false; } //------------------------------------------------------------ // Attempt to perform conversion //------------------------------------------------------------ if(source.HasChildren) { XPathNavigator navigator = source.CreateNavigator(); if (navigator.MoveToFirstChild()) { if (String.Compare(navigator.Name, "i4", StringComparison.OrdinalIgnoreCase) == 0) { int scalar; if (Int32.TryParse(navigator.Value, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out scalar)) { value = new XmlRpcScalarValue(scalar); return true; } } else if (String.Compare(navigator.Name, "int", StringComparison.OrdinalIgnoreCase) == 0) { int scalar; if (Int32.TryParse(navigator.Value, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out scalar)) { value = new XmlRpcScalarValue(scalar); return true; } } else if (String.Compare(navigator.Name, "boolean", StringComparison.OrdinalIgnoreCase) == 0) { bool scalar; if (XmlRpcClient.TryParseBoolean(navigator.Value, out scalar)) { value = new XmlRpcScalarValue(scalar); return true; } } else if (String.Compare(navigator.Name, "string", StringComparison.OrdinalIgnoreCase) == 0) { value = new XmlRpcScalarValue(navigator.Value); return true; } else if (String.Compare(navigator.Name, "double", StringComparison.OrdinalIgnoreCase) == 0) { double scalar; if (Double.TryParse(navigator.Value, NumberStyles.Float, NumberFormatInfo.InvariantInfo, out scalar)) { value = new XmlRpcScalarValue(scalar); return true; } } else if (String.Compare(navigator.Name, "dateTime.iso8601", StringComparison.OrdinalIgnoreCase) == 0) { DateTime scalar; if (SyndicationDateTimeUtility.TryParseRfc3339DateTime(navigator.Value, out scalar)) { value = new XmlRpcScalarValue(scalar); return true; } } else if (String.Compare(navigator.Name, "base64", StringComparison.OrdinalIgnoreCase) == 0) { if(!String.IsNullOrEmpty(navigator.Value)) { try { byte[] data = Convert.FromBase64String(navigator.Value); value = new XmlRpcScalarValue(data); return true; } catch(FormatException) { value = null; return false; } } } else if (String.Compare(navigator.Name, "struct", StringComparison.OrdinalIgnoreCase) == 0) { XmlRpcStructureValue structure = new XmlRpcStructureValue(); if (structure.Load(source)) { value = structure; return true; } } else if (String.Compare(navigator.Name, "array", StringComparison.OrdinalIgnoreCase) == 0) { XmlRpcArrayValue array = new XmlRpcArrayValue(); if (array.Load(source)) { value = array; return true; } } } } else if (!String.IsNullOrEmpty(source.Value)) { value = new XmlRpcScalarValue(source.Value); return true; } //------------------------------------------------------------ // Conversion failed, so set result as null and return false //------------------------------------------------------------ value = null; return false; }
/// <summary> /// Loads this <see cref="XmlRpcStructureMember"/> 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="XmlRpcStructureMember"/> 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="XmlRpcStructureMember"/>.</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 structure member information //------------------------------------------------------------ if (source.HasChildren) { XPathNavigator nameNavigator = source.SelectSingleNode("name"); XPathNavigator valueNavigator = source.SelectSingleNode("value"); if (nameNavigator != null && !String.IsNullOrEmpty(nameNavigator.Value)) { this.Name = nameNavigator.Value; wasLoaded = true; } if (valueNavigator != null) { IXmlRpcValue value; if (XmlRpcClient.TryParseValue(valueNavigator, out value)) { this.Value = value; wasLoaded = true; } } } return wasLoaded; }
/// <summary> /// Loads this <see cref="XmlRpcResponse"/> 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="XmlRpcResponse"/> 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="XmlRpcResponse"/>.</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 response information //------------------------------------------------------------ if (source.HasChildren) { XPathNavigator parametersNavigator = source.SelectSingleNode("params"); XPathNavigator faultNavigator = source.SelectSingleNode("fault"); if (parametersNavigator != null) { XPathNavigator valueNavigator = parametersNavigator.SelectSingleNode("param/value"); if (valueNavigator != null) { IXmlRpcValue value; if (XmlRpcClient.TryParseValue(valueNavigator, out value)) { responseParameter = value; wasLoaded = true; } } } if (faultNavigator != null) { XPathNavigator structNavigator = faultNavigator.SelectSingleNode("value"); if (structNavigator != null) { XmlRpcStructureValue structure = new XmlRpcStructureValue(); if (structure.Load(structNavigator)) { responseFault = structure; wasLoaded = true; } } } } return wasLoaded; }
/// <summary> /// Constructs a new <see cref="IXmlRpcValue"/> object from the specified <see cref="XPathNavigator"/>. /// Parameters specify the XML data source and the variable where the new <see cref="IXmlRpcValue"/> object is returned. /// </summary> /// <param name="source">A <see cref="XPathNavigator"/> that represents the XML data source to be parsed.</param> /// <param name="value"> /// When this method returns, contains an object that represents the <see cref="IXmlRpcValue"/> specified by the <paramref name="source"/>, or <b>null</b> if the conversion failed. /// This parameter is passed uninitialized. /// </param> /// <returns> /// <b>true</b> if <paramref name="source"/> was converted successfully; otherwise, <b>false</b>. /// This operation returns <b>false</b> if the <paramref name="source"/> parameter is a null reference (Nothing in Visual Basic), /// or represents XML data that is not in the expected format. /// </returns> /// <remarks> /// The <paramref name="source"/> is expected to represent an XML-RPC <b>value</b> node. /// </remarks> public static bool TryParseValue(XPathNavigator source, out IXmlRpcValue value) { if (source == null || String.Compare(source.Name, "value", StringComparison.OrdinalIgnoreCase) != 0) { value = null; return(false); } if (source.HasChildren) { XPathNavigator navigator = source.CreateNavigator(); if (navigator.MoveToFirstChild()) { if (String.Compare(navigator.Name, "i4", StringComparison.OrdinalIgnoreCase) == 0) { int scalar; if (Int32.TryParse(navigator.Value, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out scalar)) { value = new XmlRpcScalarValue(scalar); return(true); } } else if (String.Compare(navigator.Name, "int", StringComparison.OrdinalIgnoreCase) == 0) { int scalar; if (Int32.TryParse(navigator.Value, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out scalar)) { value = new XmlRpcScalarValue(scalar); return(true); } } else if (String.Compare(navigator.Name, "boolean", StringComparison.OrdinalIgnoreCase) == 0) { bool scalar; if (XmlRpcClient.TryParseBoolean(navigator.Value, out scalar)) { value = new XmlRpcScalarValue(scalar); return(true); } } else if (String.Compare(navigator.Name, "string", StringComparison.OrdinalIgnoreCase) == 0) { value = new XmlRpcScalarValue(navigator.Value); return(true); } else if (String.Compare(navigator.Name, "double", StringComparison.OrdinalIgnoreCase) == 0) { double scalar; if (Double.TryParse(navigator.Value, NumberStyles.Float, NumberFormatInfo.InvariantInfo, out scalar)) { value = new XmlRpcScalarValue(scalar); return(true); } } else if (String.Compare(navigator.Name, "dateTime.iso8601", StringComparison.OrdinalIgnoreCase) == 0) { DateTime scalar; if (SyndicationDateTimeUtility.TryParseRfc3339DateTime(navigator.Value, out scalar)) { value = new XmlRpcScalarValue(scalar); return(true); } } else if (String.Compare(navigator.Name, "base64", StringComparison.OrdinalIgnoreCase) == 0) { if (!String.IsNullOrEmpty(navigator.Value)) { try { byte[] data = Convert.FromBase64String(navigator.Value); value = new XmlRpcScalarValue(data); return(true); } catch (FormatException) { value = null; return(false); } } } else if (String.Compare(navigator.Name, "struct", StringComparison.OrdinalIgnoreCase) == 0) { XmlRpcStructureValue structure = new XmlRpcStructureValue(); if (structure.Load(source)) { value = structure; return(true); } } else if (String.Compare(navigator.Name, "array", StringComparison.OrdinalIgnoreCase) == 0) { XmlRpcArrayValue array = new XmlRpcArrayValue(); if (array.Load(source)) { value = array; return(true); } } } } else if (!String.IsNullOrEmpty(source.Value)) { value = new XmlRpcScalarValue(source.Value); return(true); } value = null; return(false); }
public XmlRpcStructMember(string name, IXmlRpcValue data) { this.name = name; this.data = data; }