/// <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); }
/// <summary> /// Initializes a new instance of the <see cref="XmlRpcResponse"/> class using the supplied <see cref="XmlRpcStructureValue"/>. /// </summary> /// <param name="fault">A <see cref="XmlRpcStructureValue"/> that represents the response to the remote procedure call.</param> /// <exception cref="ArgumentNullException">The <paramref name="fault"/> is a null reference (Nothing in Visual Basic).</exception> public XmlRpcResponse(XmlRpcStructureValue fault) { Guard.ArgumentNotNull(fault, "fault"); responseFault = fault; }