aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Common-Source/XmlRpcCS/XmlRpcRequestSerializer.cs
blob: 8099bdb334550ae2955250d3c7278053d0772df1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
namespace Nwc.XmlRpc
{
    using System;
    using System.Collections;
    using System.Xml;
    using System.IO;

    /// <summary>Class responsible for serializing an XML-RPC request.</summary>
    /// <remarks>This class handles the request envelope, depending on <c>XmlRpcSerializer</c>
    /// to serialize the payload.</remarks>
    /// <seealso cref="XmlRpcSerializer"/>
    public class XmlRpcRequestSerializer : XmlRpcSerializer
    {
        static private XmlRpcRequestSerializer _singleton;
        /// <summary>A static singleton instance of this deserializer.</summary>
        static public XmlRpcRequestSerializer Singleton
        {
            get
            {
                if (_singleton == null)
                    _singleton = new XmlRpcRequestSerializer();

                return _singleton;
            }
        }

        /// <summary>Serialize the <c>XmlRpcRequest</c> to the output stream.</summary>
        /// <param name="output">An <c>XmlTextWriter</c> stream to write data to.</param>
        /// <param name="obj">An <c>XmlRpcRequest</c> to serialize.</param>
        /// <seealso cref="XmlRpcRequest"/>
        override public void Serialize(XmlTextWriter output, Object obj)
        {
            XmlRpcRequest request = (XmlRpcRequest)obj;
            output.WriteStartDocument();
            output.WriteStartElement(METHOD_CALL);
            output.WriteElementString(METHOD_NAME, request.MethodName);
            output.WriteStartElement(PARAMS);
            foreach (Object param in request.Params)
            {
                output.WriteStartElement(PARAM);
                output.WriteStartElement(VALUE);
                SerializeObject(output, param);
                output.WriteEndElement();
                output.WriteEndElement();
            }

            output.WriteEndElement();
            output.WriteEndElement();
        }
    }
}