Example #1
0
        private EgoiMapList decodeResultMapList(object result)
        {
            checkResult(result);

            if (result is XmlRpcStruct[])
            {
                return(decodeMapList(result as XmlRpcStruct[]));
            }
            else if (result is XmlRpcStruct)
            {
                EgoiMapList list = new EgoiMapList();

                list.Add(decodeResultMap(result));

                return(list);
            }
            else if (result is object[]) // occurs when response is empty
            {
                return(new EgoiMapList());
            }
            else
            {
                throw new EgoiException("The response is of unexpected type: " + result + ", expecting XmlRpcStruct[]");
            }
        }
        public static String prepareMapPayload(String prepend, EgoiMap values)
        {
            StringBuilder q = new StringBuilder();

            foreach (String key in values.Keys)
            {
                Object value  = values[key];
                String result = null;

                String prefix = String.Format("{0}[{1}]", prepend, key);

                if (value is EgoiMap)
                {
                    EgoiMap map = (EgoiMap)value;
                    result = prepareMapPayload(prefix, map);
                }
                else if (value is EgoiMapList)
                {
                    EgoiMapList list = (EgoiMapList)value;
                    result = prepareListPayload(prefix, list);
                }
                else if (value is EgoiList)
                {
                    EgoiList list = (EgoiList)value;
                    result = prepareGenericListPayload(prefix, list);
                }
                else
                {
                    result = String.Format("{0}={1}&", prefix, value.ToString());
                }

                q.Append(result);
            }
            return(q.ToString());
        }
        protected EgoiType walkMap(Dictionary <string, object> map)
        {
            EgoiType r = null;

            if (map.ContainsKey("key_0"))
            {
                EgoiMapList   mrl  = new EgoiMapList();
                List <String> keys = map.Keys.ToList <string>();
                keys.Sort();
                foreach (String k in keys)
                {
                    if (!k.StartsWith("key_"))
                    {
                        continue;
                    }
                    if (map [k] is Dictionary <string, object> )
                    {
                        mrl.Add(walkValues(new EgoiMap(map [k] as Dictionary <string, object>)));
                    }
                    else
                    {
                        EgoiMap value = new EgoiMap(); value.Add("value", map [k]); mrl.Add(value);
                    }
                }
                r = mrl;
            }
            else
            {
                r = walkValues(new EgoiMap(map));
            }

            return(r);
        }
        private EgoiType walkArray(List <Dictionary <string, object> > list)
        {
            EgoiMapList mrl = new EgoiMapList();

            foreach (Dictionary <string, object> map in list)
            {
                mrl.Add(walkValues(new EgoiMap(map)));
            }
            return(mrl);
        }
Example #5
0
        private EgoiMapList decodeMapList(XmlRpcStruct[] result)
        {
            EgoiMapList list = new EgoiMapList();

            foreach (XmlRpcStruct value in result)
            {
                list.Add(decodeMap(value));
            }
            return(list);
        }
Example #6
0
        private XmlRpcStruct[] encodeMapList(EgoiMapList list)
        {
            List <XmlRpcStruct> slist = new List <XmlRpcStruct>();

            foreach (EgoiMap map in list)
            {
                slist.Add(encodeMap(map));
            }

            return(slist.ToArray <XmlRpcStruct>());
        }
        private static String prepareListPayload(String prepend, EgoiMapList list)
        {
            StringBuilder q = new StringBuilder();

            for (int i = 0; i < list.Count(); i++)
            {
                String  prefix = String.Format("{0}[{1}]", prepend, i);
                EgoiMap value  = list[i];
                q.Append(prepareMapPayload(prefix, value));
            }
            return(q.ToString());
        }
        public EgoiMapList decodeMapListResult(String method, EgoiMap arguments)
        {
            Dictionary <string, object> result = processResult(method, arguments);

            EgoiType et = walkMap(result);

            if (et is EgoiMap)
            {
                EgoiMapList eml = new EgoiMapList();

                eml.Add(et as EgoiMap);

                et = eml;
            }

            return(et as EgoiMapList);
        }
Example #9
0
        private EgoiMapList decodeMapList(object[] result)
        {
            EgoiMapList list = new EgoiMapList();

            if (result is XmlRpcStruct[])
            {
                foreach (XmlRpcStruct value in result)
                {
                    list.Add(decodeMap(value));
                }
            }

            if (result is string[])
            {
                foreach (string value in result)
                {
                    EgoiMap mapString = new EgoiMap();
                    mapString["value"] = value;
                    list.Add(mapString);
                }
            }

            return(list);
        }