Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            Toco t = new Toco();

            t.Login("tu_email@de_tocorre.com", "tu_password");
            t.Profile();
            t.Scraps(0, 0, 0, 0, 3);
            t.Msg(0, 0, 0, 0, 0, 0);
            t.SetMotd(0, "--- Venga Emma! Venga Rafael! --- (seteado desde el glorioso TOCOAPI)");
            List <Tocobject> l = t.ExecuteSystemMultiCall();

            Session      session = (Session)l[0];
            GenericValue profile = (GenericValue)l[1];
            Scrap        scrap   = (Scrap)l[2];
            Msgs         msgs    = (Msgs)l[3];
            GenericValue motd    = (GenericValue)l[4];

            if (!session.fault)
            {
                Console.WriteLine("Got session id: " + session.sid_id);
            }
            else
            {
                Console.WriteLine("Error! - Couldn't get session. Check your username and password -> Server said: " + session.fault_value.struct_value["faultString"].string_value);
            }

            if (!msgs.fault)
            {
                Console.WriteLine("Got " + msgs.entries.Count + " messages");
                Console.WriteLine("----");
                foreach (Msg m in msgs.entries.Values)
                {
                    Console.WriteLine("MsgId: " + m.msg_id);
                    Console.WriteLine(m.text);
                }
                Console.WriteLine("----");
            }

            Console.Read();
        }
Ejemplo n.º 2
0
        public static Scrap FromValue(Value p_Value)
        {
            // value would be an struct
            // member -> scrap_id
            // value -> struct with scrapentry info

            Scrap s = new Scrap();

            s._sql = p_Value.struct_value["sql"].string_value;

            foreach (KeyValuePair<String, Value> kvp in p_Value.struct_value["scrap"].struct_value)
            {
                Int32 scrap_id = 0;
                if (Int32.TryParse(kvp.Key, out scrap_id))
                {
                    ScrapEntry se = ScrapEntry.FromValue(kvp.Value, scrap_id);
                    s._entries.Add(scrap_id, se);
                }
                else
                {
                    throw new Exception("Invalid scrap_id -> [" + kvp.Key + "]");
                }
            }

            return s;
        }
Ejemplo n.º 3
0
        // Execute multi :(
        public List <Tocobject> ExecuteSystemMultiCall()
        {
            MethodCall mc = new MethodCall(Toco.SYSTEM_MULTI_CALL_METHOD);

            // prepare unique parameter with multiple calls
            Value varray = new Value(tocorre.XmlRpc.Type.XMLRPC_TYPE_ARRAY);

            foreach (MethodCall mcc in m_MethodCalls)
            {
                Value vcall = new Value(tocorre.XmlRpc.Type.XMLRPC_TYPE_STRUCT);
                vcall.AddToStruct("methodName", new Value(tocorre.XmlRpc.Type.XMLRPC_TYPE_STRING, mcc.method_name));
                Value vparams = new Value(tocorre.XmlRpc.Type.XMLRPC_TYPE_ARRAY);
                foreach (Value param in mcc.parameters)
                {
                    vparams.AddToArray(param);
                }
                vcall.AddToStruct("params", vparams);
                varray.AddToArray(vcall);
            }
            mc.AddParameter(varray);
            Call           c  = new Call("http://www.tocorre.com/ext/rpc/rpc_api.php", mc);
            MethodResponse mr = c.Execute();

            // unique return is an array type Value. Each array element has a Value
            // corresponding to the return value of the nth method call queued
            List <Tocobject> ret = new List <Tocobject>();

            Int32 i = 0;

            foreach (MethodCall mcc in m_MethodCalls)
            {
                Value v = mr.values[0].array_value[i];
                switch (mcc.method_name)
                {
                case LOGIN_METHOD:
                    if (v.type == tocorre.XmlRpc.Type.XMLRPC_TYPE_ARRAY)
                    {
                        ret.Add(Session.FromValue(v.array_value[0]));
                    }
                    else
                    {
                        ret.Add(new Session(true, v));
                    }
                    break;

                case PROFILE_METHOD:
                    if (v.type == tocorre.XmlRpc.Type.XMLRPC_TYPE_ARRAY)
                    {
                        ret.Add(GenericValue.FromValue(v.array_value[0]));
                    }
                    else
                    {
                        ret.Add(new GenericValue(true, v));
                    }
                    break;

                case SCRAPS_METHOD:
                    if (v.type == tocorre.XmlRpc.Type.XMLRPC_TYPE_ARRAY)
                    {
                        ret.Add(Scrap.FromValue(v.array_value[0]));
                    }
                    else
                    {
                        ret.Add(new Scrap(true, v));
                    }
                    break;

                case MSG_METHOD:
                    if (v.type == tocorre.XmlRpc.Type.XMLRPC_TYPE_ARRAY)
                    {
                        ret.Add(Msgs.FromValue(v.array_value[0]));
                    }
                    else
                    {
                        ret.Add(new Msgs(true, v));
                    }
                    break;

                case FLUSH_METHOD:
                    if (v.type == tocorre.XmlRpc.Type.XMLRPC_TYPE_ARRAY)
                    {
                        ret.Add(GenericValue.FromValue(v.array_value[0]));
                    }
                    else
                    {
                        ret.Add(new GenericValue(true, v));
                    }

                    break;

                case SET_MOTD_METHOD:
                    if (v.type == tocorre.XmlRpc.Type.XMLRPC_TYPE_ARRAY)
                    {
                        ret.Add(GenericValue.FromValue(v.array_value[0]));
                    }
                    else
                    {
                        ret.Add(new GenericValue(true, v));
                    }
                    break;

                default:
                    throw new Exception("Unexpected method name: " + mcc.method_name);
                }
                i++;
            }

            return(ret);
        }