Inheritance: System.SystemException
Esempio n. 1
0
        internal void Invoke(String function, Object[] args, Delegate callback, Boolean byRef, Byte encryptMode)
        {
            RequestState requestState = new RequestState();

            requestState.function     = function;
            requestState.args         = args;
            requestState.syncCallback = callback;
            requestState.byRef        = byRef;
            requestState.encryptMode  = encryptMode;
            requestQueue.Enqueue(requestState);
            try {
                BeginKeyExchange();
            }
            catch (Exception e) {
                PHPRPC_Error error        = new PHPRPC_Error(1, e.Message);
                Type         callbackType = callback.GetType();
                if (callbackType.IsGenericType)
                {
                    callback.DynamicInvoke(null, args, output, error, true);
                }
                else
                {
                    ((PHPRPC_Callback)callback)(error, args, output, error);
                }
            }
        }
Esempio n. 2
0
        public Object Invoke(String function, Object[] args, Boolean byRef)
        {
            Hashtable data = Invoke(function, args, byRef, encryptMode);

            warning = (PHPRPC_Error)data["warning"];
            output  = (String)data["output"];
            return(data["result"]);
        }
Esempio n. 3
0
        private void InvokeCallback(Object state)
        {
            RequestState requestState = state as RequestState;
            Hashtable    result       = GetResponseBody(requestState.response, requestState.encryptMode);
            PHPRPC_Error error;
            Int32        errno = (Int32)result["phprpc_errno"];

            if (errno > 0)
            {
                String errstr = (String)result["phprpc_errstr"];
                error = new PHPRPC_Error(errno, errstr);
            }
            else
            {
                error = null;
            }
            if (result.ContainsKey("phprpc_output"))
            {
                output = (String)result["phprpc_output"];
            }
            else
            {
                output = String.Empty;
            }
            if (requestState.syncCallback != null)
            {
                Delegate callback     = (Delegate)requestState.syncCallback;
                Type     callbackType = callback.GetType();
                Object[] args         = requestState.args;
                Object   retval       = error;
                if (result.ContainsKey("phprpc_result"))
                {
                    if (result.ContainsKey("phprpc_args"))
                    {
                        args = (Object[])PHPConvert.ToArray((AssocArray)Deserialize(Decrypt((Byte[])result["phprpc_args"], 1, requestState.encryptMode)), typeof(Object[]), encoding);
                    }
                    retval = Deserialize(Decrypt((Byte[])result["phprpc_result"], 2, requestState.encryptMode));
                }
                if (callbackType.IsGenericType)
                {
                    Type resultType = callbackType.GetGenericArguments()[0];
                    if (retval != error)
                    {
                        callback.DynamicInvoke(PHPConvert.ChangeType(retval, resultType, encoding), args, output, error, false);
                    }
                    else
                    {
                        callback.DynamicInvoke(null, args, output, error, true);
                    }
                }
                else
                {
                    ((PHPRPC_Callback)callback)(retval, args, output, error);
                }
            }
        }
Esempio n. 4
0
        public Hashtable Invoke(String function, Object[] args, Boolean byRef, Byte encryptMode)
        {
            Hashtable data = new Hashtable();

            data["warning"] = null;
            data["output"]  = String.Empty;
            try {
                KeyExchange(ref encryptMode);
                StringBuilder requestBody = new StringBuilder();
                requestBody.Append("phprpc_func=").Append(function);
                if (args != null && args.Length > 0)
                {
                    requestBody.Append("&phprpc_args=");
                    requestBody.Append(Base64Encode(Encrypt(Serialize(args), 1, encryptMode)).Replace("+", "%2B"));
                }
                requestBody.Append("&phprpc_encrypt=").Append(encryptMode);
                if (!byRef)
                {
                    requestBody.Append("&phprpc_ref=false");
                }
                Hashtable result = POST(requestBody.ToString());
                Int32     errno  = (Int32)result["phprpc_errno"];
                if (errno > 0)
                {
                    String errstr = (String)result["phprpc_errstr"];
                    data["warning"] = new PHPRPC_Error(errno, errstr);
                }
                if (result.ContainsKey("phprpc_output"))
                {
                    data["output"] = (String)result["phprpc_output"];
                }
                if (result.ContainsKey("phprpc_result"))
                {
                    if (result.ContainsKey("phprpc_args"))
                    {
                        Object[] arguments = (Object[])PHPConvert.ToArray((AssocArray)Deserialize(Decrypt((Byte[])result["phprpc_args"], 1, encryptMode)), typeof(Object[]), encoding);
                        for (Int32 i = 0; i < Math.Min(args.Length, arguments.Length); i++)
                        {
                            args[i] = arguments[i];
                        }
                    }
                    data["result"] = Deserialize(Decrypt((Byte[])result["phprpc_result"], 2, encryptMode));
                }
                else
                {
                    data["result"] = warning;
                }
            }
            catch (PHPRPC_Error e) {
                data["result"] = e;
            }
            catch (Exception e) {
                data["result"] = new PHPRPC_Error(1, e.ToString());
            }
            return(data);
        }
Esempio n. 5
0
        private void DoError(Object state)
        {
            RequestState requestState = state as RequestState;
            PHPRPC_Error error        = new PHPRPC_Error(1, requestState.error.Message);

            if (requestState.syncCallback != null)
            {
                Delegate callback     = (Delegate)requestState.syncCallback;
                Type     callbackType = callback.GetType();
                if (callbackType.IsGenericType)
                {
                    callback.DynamicInvoke(null, requestState.args, "", error, true);
                }
                else
                {
                    ((PHPRPC_Callback)callback)(error, requestState.args, "", error);
                }
            }
        }