Esempio n. 1
0
        /// <summary>
        /// Maps rpc data to XML.
        /// </summary>
        /// <param name="rpcData">The rpc data.</param>
        /// <returns>The XML element.</returns>
        public XElement MapData(XRpcData rpcData)
        {
            if (rpcData == null)
            {
                throw new ArgumentNullException(nameof(rpcData));
            }

            return(new XElement("param", MapValue(rpcData)));
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="XmlRpcReader"/> class.
        /// </summary>
        public XmlRpcReader()
        {
            _dispatch = new Dictionary <string, Func <XElement, XRpcData> >
            {
                { "i4", x => new XRpcData <int> {
                      Value = (int)x
                  } },
                { "int", x => new XRpcData <int> {
                      Value = (int)x
                  } },
                { "boolean", x => new XRpcData <bool> {
                      Value = (string)x == "1"
                  } },
                { "string", x => new XRpcData <string> {
                      Value = (string)x
                  } },
                { "double", x => new XRpcData <double> {
                      Value = (double)x
                  } },
                { "dateTime.iso8601", x => {
                      DateTime parsedDateTime;

                      // try parsing a "normal" datetime string then try what live writer gives us
                      if (!DateTime.TryParse(x.Value, out parsedDateTime) &&
                          !DateTime.TryParseExact(x.Value, "yyyyMMddTHH:mm:ss", DateTimeFormatInfo.CurrentInfo, DateTimeStyles.None, out parsedDateTime))
                      {
                          parsedDateTime = DateTime.Now;
                      }

                      return(new XRpcData <DateTime> {
                            Value = parsedDateTime
                        });
                  } },
                { "base64", x => new XRpcData <byte[]> {
                      Value = Convert.FromBase64String((string)x)
                  } },
                { "struct", x => XRpcData.For(MapToStruct(x)) },
                { "array", x => XRpcData.For(MapToArray(x)) },
            };
        }
        public void ArrayAndStructShouldWorkAsExpected()
        {
            var mapper = new XmlRpcWriter();

            var arr         = new XRpcArray();
            var structParam = XRpcData.For(new XRpcStruct());

            arr.Data.Add(structParam);
            arr.Data.Add(XRpcData.For(19));

            structParam.Value.Members.Add("Hello", XRpcData.For("world"));

            var element = mapper.MapArray(arr);

            Assert.That(NoSpace(element.ToString()), Is.EqualTo(NoSpace(@"
<array><data>
<value><struct>
<member><name>Hello</name><value><string>world</string></value></member>
</struct></value>
<value><int>19</int></value>
</data></array>
")));
        }
Esempio n. 4
0
        /// <summary>
        /// Maps rpc data to XML.
        /// </summary>
        /// <param name="rpcData">The rpc data.</param>
        /// <returns>The XML element.</returns>
        public XElement MapData(XRpcData rpcData)
        {
            Argument.ThrowIfNull(rpcData, "rpcData");

            return(new XElement("param", MapValue(rpcData)));
        }
Esempio n. 5
0
 /// <summary>
 /// Maps rpc data to XML.
 /// </summary>
 /// <param name="rpcData">The rpc data.</param>
 /// <returns>The XML element.</returns>
 private XElement MapValue(XRpcData rpcData)
 {
     return(new XElement("value", _dispatch[rpcData.Type](rpcData)));
 }
Esempio n. 6
0
        /// <summary>
        /// Maps rpc data to XML.
        /// </summary>
        /// <param name="rpcData">The rpc data.</param>
        /// <returns>The XML element.</returns>
        public XElement MapData(XRpcData rpcData) {
            Argument.ThrowIfNull(rpcData, "rpcData");

            return new XElement("param", MapValue(rpcData));
        }
Esempio n. 7
0
 /// <summary>
 /// Maps rpc data to XML.
 /// </summary>
 /// <param name="rpcData">The rpc data.</param>
 /// <returns>The XML element.</returns>
 private XElement MapValue(XRpcData rpcData) {
     return new XElement("value", _dispatch[rpcData.Type](rpcData));
 }