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); } } }
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); }