/// <summary> /// Saves the current <see cref="XmlRpcScalarValue"/> to the specified <see cref="XmlWriter"/>. /// </summary> /// <param name="writer">The <see cref="XmlWriter"/> to which you want to save.</param> /// <exception cref="ArgumentNullException">The <paramref name="writer"/> is a null reference (Nothing in Visual Basic).</exception> public void WriteTo(XmlWriter writer) { //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(writer, "writer"); //------------------------------------------------------------ // Write XML representation of the current instance //------------------------------------------------------------ writer.WriteStartElement("value"); if (this.ValueType != XmlRpcScalarValueType.None) { writer.WriteStartElement(XmlRpcClient.ScalarTypeAsString(this.ValueType)); writer.WriteString(XmlRpcScalarValue.ValueAsString(this.ValueType, this.Value)); writer.WriteEndElement(); } else { writer.WriteString(this.Value != null ? this.Value.ToString() : String.Empty); } writer.WriteEndElement(); }
/// <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> /// Loads this <see cref="XmlRpcArrayValue"/> 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="XmlRpcArrayValue"/> 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="XmlRpcArrayValue"/>.</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 dataNavigator = source.SelectSingleNode("array/data"); if (dataNavigator != null && dataNavigator.HasChildren) { XPathNodeIterator valueIterator = dataNavigator.Select("value"); if (valueIterator != null && valueIterator.Count > 0) { while (valueIterator.MoveNext()) { IXmlRpcValue value; if (XmlRpcClient.TryParseValue(valueIterator.Current, out value)) { this.Values.Add(value); wasLoaded = true; } } } } } return(wasLoaded); }
/// <summary> /// Called when a corresponding asynchronous send operation completes. /// </summary> /// <param name="result">The result of the asynchronous operation.</param> private static void AsyncSendCallback(IAsyncResult result) { XmlRpcResponse response = null; WebRequest httpWebRequest = null; XmlRpcClient client = null; Uri host = null; XmlRpcMessage message = null; WebRequestOptions options = null; object userToken = null; if (result.IsCompleted) { object[] parameters = (object[])result.AsyncState; httpWebRequest = parameters[0] as WebRequest; client = parameters[1] as XmlRpcClient; host = parameters[2] as Uri; message = parameters[3] as XmlRpcMessage; options = parameters[4] as WebRequestOptions; userToken = parameters[5]; if (client != null) { WebResponse httpWebResponse = (WebResponse)httpWebRequest.EndGetResponse(result); response = new XmlRpcResponse(httpWebResponse); client.OnMessageSent(new XmlRpcMessageSentEventArgs(host, message, response, options, userToken)); client.SendOperationInProgress = false; } } }
/// <summary> /// Sends the specified message to an XML-RPC server to execute a remote procedure call. /// This method does not block the calling thread and allows the caller to pass an object to the method that is invoked when the operation completes. /// </summary> /// <param name="message">A <see cref="XmlRpcMessage"/> that represents the information needed to execute the remote procedure call.</param> /// <param name="userToken">A user-defined object that is passed to the method invoked when the asynchronous operation completes.</param> /// <remarks> /// <para> /// To receive notification when the remote procedure call has been sent or the operation has been cancelled, add an event handler to the <see cref="SendCompleted"/> event. /// You can cancel a <see cref="SendAsync(XmlRpcMessage, Object)"/> operation by calling the <see cref="SendAsyncCancel()"/> method. /// </para> /// </remarks> /// <exception cref="ArgumentNullException">The <paramref name="message"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="InvalidOperationException">The <see cref="Host"/> is a <b>null</b> reference (Nothing in Visual Basic).</exception> /// <exception cref="InvalidOperationException">This <see cref="XmlRpcClient"/> has a <see cref="SendAsync(XmlRpcMessage, Object)"/> call in progress.</exception> //[HostProtectionAttribute(SecurityAction.LinkDemand, ExternalThreading = true)] public void SendAsync(XmlRpcMessage message, Object userToken) { Guard.ArgumentNotNull(message, "message"); if (this.Host == null) { throw new InvalidOperationException(String.Format(null, "Unable to send XML-RPC message. The Host property has not been initialized. \n\r Message payload: {0}", message)); } else if (this.SendOperationInProgress) { throw new InvalidOperationException(String.Format(null, "Unable to send XML-RPC message. The XmlRpcClient has a SendAsync call in progress. \n\r Message payload: {0}", message)); } this.SendOperationInProgress = true; this.AsyncSendHasBeenCancelled = false; asyncHttpWebRequest = XmlRpcClient.CreateWebRequest(this.Host, this.UserAgent, message, this.UseDefaultCredentials, this.clientOptions); object[] state = new object[6] { asyncHttpWebRequest, this, this.Host, message, this.clientOptions, userToken }; IAsyncResult result = asyncHttpWebRequest.BeginGetResponse(new AsyncCallback(AsyncSendCallback), state); ThreadPool.RegisterWaitForSingleObject(result.AsyncWaitHandle, new WaitOrTimerCallback(AsyncTimeoutCallback), state, this.Timeout, true); }
//============================================================ // PUBLIC METHODS //============================================================ #region Load(XPathNavigator source) /// <summary> /// Loads this <see cref="XmlRpcScalarValue"/> 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="XmlRpcScalarValue"/> 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="XmlRpcScalarValue"/>.</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 scalar parameter information //------------------------------------------------------------ if (source.HasChildren) { if (source.MoveToFirstChild()) { XmlRpcScalarValueType type = XmlRpcScalarValueType.None; if (String.Compare(source.Name, "i4", StringComparison.OrdinalIgnoreCase) == 0) { // Framework prefers the <int> designator for integers, so this handles when the <i4> designator is utilized. type = XmlRpcScalarValueType.Integer; } else { type = XmlRpcClient.ScalarTypeByName(source.Name); } if (type != XmlRpcScalarValueType.None) { this.ValueType = type; if (!String.IsNullOrEmpty(source.Value)) { this.Value = XmlRpcScalarValue.StringAsValue(type, source.Value); } wasLoaded = true; } } } else { if (!String.IsNullOrEmpty(source.Value)) { this.Value = source.Value; wasLoaded = true; } } return(wasLoaded); }
//============================================================ // 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); }
//============================================================ // PRIVATE METHODS //============================================================ #region StringAsValue(XmlRpcScalarValueType type, string scalar) /// <summary> /// Returns an <see cref="Object"/> that represents the converted value for the specified <see cref="XmlRpcScalarValueType"/>. /// </summary> /// <param name="type">The <see cref="XmlRpcScalarValueType"/> that indicates the expected data type for the scalar value.</param> /// <param name="scalar">The string representation of the scalar value.</param> /// <returns>An <see cref="Object"/> that represents the converted value for the specified <paramref name="type"/> and <paramref name="scalar"/>.</returns> /// <exception cref="ArgumentNullException">The <paramref name="scalar"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="scalar"/> is an empty string.</exception> private static object StringAsValue(XmlRpcScalarValueType type, string scalar) { //------------------------------------------------------------ // Local members //------------------------------------------------------------ object result = String.Empty; //------------------------------------------------------------ // Validate parameters //------------------------------------------------------------ Guard.ArgumentNotNullOrEmptyString(scalar, "scalar"); //------------------------------------------------------------ // Convert string representation to expected value type //------------------------------------------------------------ switch (type) { case XmlRpcScalarValueType.Base64: result = Convert.FromBase64String(scalar); break; case XmlRpcScalarValueType.Boolean: bool boolean; if (XmlRpcClient.TryParseBoolean(scalar, out boolean)) { result = boolean; } break; case XmlRpcScalarValueType.DateTime: result = SyndicationDateTimeUtility.ParseRfc3339DateTime(scalar); break; case XmlRpcScalarValueType.Double: result = Double.Parse(scalar, NumberStyles.Float, NumberFormatInfo.InvariantInfo); break; case XmlRpcScalarValueType.Integer: result = Int32.Parse(scalar, NumberStyles.Float, NumberFormatInfo.InvariantInfo); break; case XmlRpcScalarValueType.String: result = scalar.Trim(); break; } return(result); }
/// <summary> /// Initializes a new instance of the <see cref="XmlRpcArrayValue"/> class using the supplied <see cref="XPathNodeIterator"/>. /// </summary> /// <param name="iterator">A <see cref="XPathNodeIterator"/> that represents the <i>value</i> nodes for the array.</param> /// <exception cref="ArgumentNullException">The <paramref name="iterator"/> is a null reference (Nothing in Visual Basic).</exception> public XmlRpcArrayValue(XPathNodeIterator iterator) { Guard.ArgumentNotNull(iterator, "iterator"); if (iterator.Count > 0) { while (iterator.MoveNext()) { IXmlRpcValue value; if (XmlRpcClient.TryParseValue(iterator.Current, out value)) { this.Values.Add(value); } } } }
//============================================================ // PUBLIC METHODS //============================================================ #region Load(XPathNavigator source) /// <summary> /// Loads this <see cref="XmlRpcMessage"/> 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="XmlRpcMessage"/> 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="XmlRpcMessage"/>.</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 scalar parameter information //------------------------------------------------------------ if (source.HasChildren) { XPathNavigator methodNameNavigator = source.SelectSingleNode("methodName"); XPathNavigator parametersNavigator = source.SelectSingleNode("params"); if (methodNameNavigator != null && !String.IsNullOrEmpty(methodNameNavigator.Value)) { this.MethodName = methodNameNavigator.Value; wasLoaded = true; } if (parametersNavigator != null) { XPathNodeIterator valueIterator = parametersNavigator.Select("param/value"); if (valueIterator != null && valueIterator.Count > 0) { while (valueIterator.MoveNext()) { IXmlRpcValue value; if (XmlRpcClient.TryParseValue(valueIterator.Current, out value)) { this.Parameters.Add(value); wasLoaded = true; } } } } } return(wasLoaded); }
/// <summary> /// Saves the current <see cref="XmlRpcScalarValue"/> to the specified <see cref="XmlWriter"/>. /// </summary> /// <param name="writer">The <see cref="XmlWriter"/> to which you want to save.</param> /// <exception cref="ArgumentNullException">The <paramref name="writer"/> is a null reference (Nothing in Visual Basic).</exception> public void WriteTo(XmlWriter writer) { Guard.ArgumentNotNull(writer, "writer"); writer.WriteStartElement("value"); if (this.ValueType != XmlRpcScalarValueType.None) { writer.WriteStartElement(XmlRpcClient.ScalarTypeAsString(this.ValueType)); writer.WriteString(XmlRpcScalarValue.ValueAsString(this.ValueType, this.Value)); writer.WriteEndElement(); } else { writer.WriteString(this.Value != null ? this.Value.ToString() : String.Empty); } writer.WriteEndElement(); }
/// <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); }
//============================================================ // CLASS SUMMARY //============================================================ /// <summary> /// Provides example code for the XmlRpcClient class. /// </summary> public static void ClassExample() { #region XmlRpcClient // Initialize the XML-RPC client XmlRpcClient client = new XmlRpcClient(); client.Host = new Uri("http://bob.example.net/xmlrpcserver"); // Construct a Pingback peer-to-peer notification XML-RPC message XmlRpcMessage message = new XmlRpcMessage("pingback.ping"); message.Encoding = Encoding.UTF8; message.Parameters.Add(new XmlRpcScalarValue("http://alice.example.org/#p123")); // sourceURI message.Parameters.Add(new XmlRpcScalarValue("http://bob.example.net/#foo")); // targetURI // Send a synchronous pingback ping XmlRpcResponse response = client.Send(message); // Verify response to the trackback ping if (response != null) { if (response.Fault != null) { XmlRpcStructureMember faultCode = response.Fault["faultCode"]; XmlRpcStructureMember faultMessage = response.Fault["faultString"]; if (faultCode != null && faultMessage != null) { // Handle the pingback ping error condition that occurred } } else { XmlRpcScalarValue successInformation = response.Parameter as XmlRpcScalarValue; if (successInformation != null) { // Pingback request was successful, return should be a string containing information the server deems useful. } } } #endregion }
//============================================================ // 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); }
/// <summary> /// Initializes a new instance of the <see cref="XmlRpcArrayValue"/> class using the supplied <see cref="XPathNodeIterator"/>. /// </summary> /// <param name="iterator">A <see cref="XPathNodeIterator"/> that represents the <i>value</i> nodes for the array.</param> /// <exception cref="ArgumentNullException">The <paramref name="iterator"/> is a null reference (Nothing in Visual Basic).</exception> public XmlRpcArrayValue(XPathNodeIterator iterator) { //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(iterator, "iterator"); //------------------------------------------------------------ // Parse iterator nodes to load collection //------------------------------------------------------------ if (iterator.Count > 0) { while (iterator.MoveNext()) { IXmlRpcValue value; if (XmlRpcClient.TryParseValue(iterator.Current, out value)) { this.Values.Add(value); } } } }
//============================================================ // PUBLIC METHODS //============================================================ #region Load(XPathNavigator source) /// <summary> /// Loads this <see cref="XmlRpcArrayValue"/> 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="XmlRpcArrayValue"/> 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="XmlRpcArrayValue"/>.</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 array information //------------------------------------------------------------ if (source.HasChildren) { XPathNavigator dataNavigator = source.SelectSingleNode("array/data"); if (dataNavigator != null && dataNavigator.HasChildren) { XPathNodeIterator valueIterator = dataNavigator.Select("value"); if (valueIterator != null && valueIterator.Count > 0) { while (valueIterator.MoveNext()) { IXmlRpcValue value; if (XmlRpcClient.TryParseValue(valueIterator.Current, out value)) { this.Values.Add(value); wasLoaded = true; } } } } } return(wasLoaded); }
/// <summary> /// Sends the specified message to an XML-RPC server to execute a remote procedure call. /// </summary> /// <param name="message">A <see cref="XmlRpcMessage"/> that represents the information needed to execute the remote procedure call.</param> /// <returns>A <see cref="XmlRpcResponse"/> that represents the server's response to the remote procedure call.</returns> /// <exception cref="ArgumentNullException">The <paramref name="message"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="InvalidOperationException">The <see cref="Host"/> is a <b>null</b> reference (Nothing in Visual Basic).</exception> /// <exception cref="InvalidOperationException">This <see cref="XmlRpcClient"/> has a <see cref="SendAsync(XmlRpcMessage, Object)"/> call in progress.</exception> public XmlRpcResponse Send(XmlRpcMessage message) { XmlRpcResponse response = null; Guard.ArgumentNotNull(message, "message"); if (this.Host == null) { throw new InvalidOperationException(String.Format(null, "Unable to send XML-RPC message. The Host property has not been initialized. \n\r Message payload: {0}", message)); } else if (this.SendOperationInProgress) { throw new InvalidOperationException(String.Format(null, "Unable to send XML-RPC message. The XmlRpcClient has a SendAsync call in progress. \n\r Message payload: {0}", message)); } WebRequest webRequest = XmlRpcClient.CreateWebRequest(this.Host, this.UserAgent, message, this.UseDefaultCredentials, this.clientOptions); using (WebResponse webResponse = (WebResponse)webRequest.GetResponse()) { response = new XmlRpcResponse(webResponse); } return(response); }
/// <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); }