Exemplo n.º 1
0
        /// <summary>
        /// Decode response then return the values
        /// </summary>
        /// <param name="xmlResponse">The response xml string as provided by server as methodResponse</param>
        /// <returns></returns>
        public static XmlRpcMethodCall[] DecodeMethodResponse(string xmlResponse)
        {
            List <XmlRpcMethodCall> methods = new List <XmlRpcMethodCall>();
            XmlReaderSettings       sett    = new XmlReaderSettings();

            sett.DtdProcessing    = DtdProcessing.Ignore;
            sett.IgnoreWhitespace = true;
            MemoryStream str = new MemoryStream(Encoding.ASCII.GetBytes(xmlResponse));

            if (xmlResponse.Contains(@"encoding=""utf-8"""))
            {
                str = new MemoryStream(Encoding.UTF8.GetBytes(xmlResponse));
            }
            XmlReader XMLread = XmlReader.Create(str, sett);

            XmlRpcMethodCall call = new XmlRpcMethodCall("methodResponse");

            // Read parameters
            while (XMLread.Read())
            {
                if (XMLread.Name == "param" && XMLread.IsStartElement())
                {
                    IXmlRpcValue val = ReadValue(XMLread);
                    if (val != null)
                    {
                        call.Parameters.Add(val);
                    }
                }
            }
            methods.Add(call);
            XMLread.Close();
            return(methods.ToArray());
        }
Exemplo n.º 2
0
        private static IXmlRpcValue ReadValue(XmlReader xmlReader)
        {
            while (xmlReader.Read())
            {
                if (xmlReader.Name == "value" && xmlReader.IsStartElement())
                {
                    xmlReader.Read();
                    if (xmlReader.Name == "string" && xmlReader.IsStartElement())
                    {
                        return(new XmlRpcValueBasic(xmlReader.ReadString(), XmlRpcBasicValueType.String));
                    }
                    else if (xmlReader.Name == "int" && xmlReader.IsStartElement())
                    {
                        return(new XmlRpcValueBasic(int.Parse(xmlReader.ReadString(), UsCulture), XmlRpcBasicValueType.Int));
                    }
                    else if (xmlReader.Name == "boolean" && xmlReader.IsStartElement())
                    {
                        return(new XmlRpcValueBasic(xmlReader.ReadString() == "1", XmlRpcBasicValueType.Boolean));
                    }
                    else if (xmlReader.Name == "double" && xmlReader.IsStartElement())
                    {
                        return(new XmlRpcValueBasic(double.Parse(xmlReader.ReadString(), UsCulture), XmlRpcBasicValueType.Double));
                    }
                    else if (xmlReader.Name == "dateTime.iso8601" && xmlReader.IsStartElement())
                    {
                        string   date   = xmlReader.ReadString();
                        int      year   = int.Parse(date.Substring(0, 4), UsCulture);
                        int      month  = int.Parse(date.Substring(4, 2), UsCulture);
                        int      day    = int.Parse(date.Substring(6, 2), UsCulture);
                        int      hour   = int.Parse(date.Substring(9, 2), UsCulture);
                        int      minute = int.Parse(date.Substring(12, 2), UsCulture);//19980717T14:08:55
                        int      sec    = int.Parse(date.Substring(15, 2), UsCulture);
                        DateTime time   = new DateTime(year, month, day, hour, minute, sec);
                        return(new XmlRpcValueBasic(time, XmlRpcBasicValueType.dateTime_iso8601));
                    }
                    else if (xmlReader.Name == "base64" && xmlReader.IsStartElement())
                    {
                        return(new XmlRpcValueBasic(BitConverter.ToInt64(Convert.FromBase64String(xmlReader.ReadString()), 0)
                                                    , XmlRpcBasicValueType.Double));
                    }
                    else if (xmlReader.Name == "struct" && xmlReader.IsStartElement())
                    {
                        XmlRpcValueStruct strct = new XmlRpcValueStruct(new List <XmlRpcStructMember>());
                        // Read members...
                        while (xmlReader.Read())
                        {
                            if (xmlReader.Name == "member" && xmlReader.IsStartElement())
                            {
                                XmlRpcStructMember member = new XmlRpcStructMember("", null);
                                xmlReader.Read();// read name
                                member.Name = xmlReader.ReadString();

                                IXmlRpcValue val = ReadValue(xmlReader);
                                if (val != null)
                                {
                                    member.Data = val;
                                    strct.Members.Add(member);
                                }
                            }
                            else if (xmlReader.Name == "struct" && !xmlReader.IsStartElement())
                            {
                                return(strct);
                            }
                        }
                        return(strct);
                    }
                    else if (xmlReader.Name == "array" && xmlReader.IsStartElement())
                    {
                        XmlRpcValueArray array = new XmlRpcValueArray();
                        // Read members...
                        while (xmlReader.Read())
                        {
                            if (xmlReader.Name == "array" && !xmlReader.IsStartElement())
                            {
                                return(array);
                            }
                            else
                            {
                                IXmlRpcValue val = ReadValue(xmlReader);
                                if (val != null)
                                {
                                    array.Values.Add(val);
                                }
                            }
                        }
                        return(array);
                    }
                }
                else
                {
                    break;
                }
            }
            return(null);
        }
Exemplo n.º 3
0
 public XmlRpcStructMember(string name, IXmlRpcValue data)
 {
     this.name = name;
     this.data = data;
 }
 public XmlRpcStructMember(string name, IXmlRpcValue data)
 {
     this.name = name;
     this.data = data;
 }