XmlRpcRequestDeserializer.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. namespace Nwc.XmlRpc
  2. {
  3. using System;
  4. using System.Collections;
  5. using System.Diagnostics;
  6. using System.IO;
  7. using System.Xml;
  8. /// <summary>Class to deserialize XML data representing a request.</summary>
  9. public class XmlRpcRequestDeserializer : XmlRpcDeserializer
  10. {
  11. static private XmlRpcRequestDeserializer _singleton;
  12. /// <summary>A static singleton instance of this deserializer.</summary>
  13. [Obsolete("This object is now thread safe, just use an instance.", false)]
  14. static public XmlRpcRequestDeserializer Singleton
  15. {
  16. get
  17. {
  18. if (_singleton == null)
  19. _singleton = new XmlRpcRequestDeserializer();
  20. return _singleton;
  21. }
  22. }
  23. /// <summary>Static method that parses XML data into a request using the Singleton.</summary>
  24. /// <param name="xmlData"><c>StreamReader</c> containing an XML-RPC request.</param>
  25. /// <returns><c>XmlRpcRequest</c> object resulting from the parse.</returns>
  26. override public Object Deserialize(TextReader xmlData)
  27. {
  28. XmlTextReader reader = new XmlTextReader(xmlData);
  29. XmlRpcRequest request = new XmlRpcRequest();
  30. bool done = false;
  31. lock (this)
  32. {
  33. Reset();
  34. while (!done && reader.Read())
  35. {
  36. DeserializeNode(reader); // Parent parse...
  37. switch (reader.NodeType)
  38. {
  39. case XmlNodeType.EndElement:
  40. switch (reader.Name)
  41. {
  42. case METHOD_NAME:
  43. request.MethodName = _text;
  44. break;
  45. case METHOD_CALL:
  46. done = true;
  47. break;
  48. case PARAM:
  49. request.Params.Add(_value);
  50. _text = null;
  51. break;
  52. }
  53. break;
  54. }
  55. }
  56. }
  57. return request;
  58. }
  59. }
  60. }