public static string ExecuteCallbackMethod(Control control, string callbackArgument) { Type controlType = control.GetType(); // Deserialize the callback JSON into CLR objects //JavaScriptSerializer js = JSONSerializerFactory.GetJavaScriptSerializer(); Dictionary <string, object> callInfo = JsonHelper.DeserializeObject(callbackArgument, typeof(Dictionary <string, object>)) as Dictionary <string, object>; // Get the call information string methodName = (string)callInfo["name"]; object[] args = (object[])callInfo["args"]; string clientState = (string)callInfo["state"]; // Attempt to load the client state IClientStateManager csm = control as IClientStateManager; if (csm != null && csm.SupportsClientState) { csm.LoadClientState(clientState); } // call the method object result = null; Dictionary <string, object> error = null; try { // Find a matching static or instance method. Only public methods can be invoked MethodInfo mi = controlType.GetMethod(methodName, BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance); if (mi == null) { throw new MissingMethodException(controlType.FullName, methodName); } // Verify that the method has the corrent number of parameters as well as the ScriptControlMethodAttribute ParameterInfo[] methodParams = mi.GetParameters(); ScriptControlMethodAttribute methAttr = (ScriptControlMethodAttribute)Attribute.GetCustomAttribute(mi, typeof(ScriptControlMethodAttribute)); if (methAttr == null || !methAttr.IsScriptMethod || args.Length != methodParams.Length) { throw new MissingMethodException(controlType.FullName, methodName); } // Convert each argument to the parameter type if possible // NOTE: I'd rather have the ObjectConverter from within Microsoft.Web.Script.Serialization namespace for this object[] targetArgs = new object[args.Length]; for (int i = 0; i < targetArgs.Length; i++) { if (args[i] == null) { continue; } //targetArgs[i] = js.Deserialize<object>(args[i].ToString()); //if (args[i].GetType() == methodParams[i].ParameterType || methodParams[i].ParameterType.GetInterface(typeof(IConvertible).AssemblyQualifiedName) != null) // targetArgs[i] = Convert.ChangeType(args[i], methodParams[i].ParameterType, CultureInfo.InvariantCulture); //else //{ // JavaScriptSerializer ser = JSONSerializerFactory.GetJavaScriptSerializer(methodParams[i].ParameterType); // string str = args[i] is string ? (string)args[i] : ser.Serialize(args[i]); // targetArgs[i] = ser.DeserializeObject(str); //} targetArgs[i] = JsonHelper.DeserializeObject(args[i], methodParams[i].ParameterType); } result = mi.Invoke(control, targetArgs); } catch (Exception ex) { // Catch the exception information to relay back to the client if (ex is TargetInvocationException) { ex = ex.InnerException; } error = new Dictionary <string, object>(); error["name"] = ex.GetType().FullName; error["message"] = ex.Message; error["stackTrace"] = ex.StackTrace; TryWriteLog(ex, control); } // return the result Dictionary <string, object> resultInfo = new Dictionary <string, object>(); if (error == null) { resultInfo["result"] = result; if (csm != null && csm.SupportsClientState) { resultInfo["state"] = csm.SaveClientState(); } } else { resultInfo["error"] = error; } // Serialize the result info into JSON return(JsonHelper.Serialize(resultInfo)); }
// Token: 0x060000E6 RID: 230 RVA: 0x000039C0 File Offset: 0x00001BC0 public static string ExecuteCallbackMethod(Control control, string callbackArgument) { Type type = control.GetType(); JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer(); Dictionary <string, object> dictionary = javaScriptSerializer.DeserializeObject(callbackArgument) as Dictionary <string, object>; string text = (string)dictionary["name"]; object[] array = (object[])dictionary["args"]; string clientState = (string)dictionary["state"]; IClientStateManager clientStateManager = control as IClientStateManager; if (clientStateManager != null && clientStateManager.SupportsClientState) { clientStateManager.LoadClientState(clientState); } object value = null; string text2 = null; try { MethodInfo method = type.GetMethod(text, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public); if (method == null) { throw new MissingMethodException(type.FullName, text); } ParameterInfo[] parameters = method.GetParameters(); ExtenderControlMethodAttribute extenderControlMethodAttribute = (ExtenderControlMethodAttribute)Attribute.GetCustomAttribute(method, typeof(ExtenderControlMethodAttribute)); if (extenderControlMethodAttribute == null || !extenderControlMethodAttribute.IsScriptMethod || array.Length != parameters.Length) { throw new MissingMethodException(type.FullName, text); } object[] array2 = new object[array.Length]; for (int i = 0; i < array2.Length; i++) { if (array[i] != null) { array2[i] = Convert.ChangeType(array[i], parameters[i].ParameterType, CultureInfo.InvariantCulture); } } value = method.Invoke(control, array2); } catch (Exception innerException) { if (innerException is TargetInvocationException) { innerException = innerException.InnerException; } text2 = innerException.GetType().FullName + ":" + innerException.Message; } Dictionary <string, object> dictionary2 = new Dictionary <string, object>(); if (text2 == null) { dictionary2["result"] = value; if (clientStateManager != null && clientStateManager.SupportsClientState) { dictionary2["state"] = clientStateManager.SaveClientState(); } } else { dictionary2["error"] = text2; } return(javaScriptSerializer.Serialize(dictionary2)); }
public static string ExecuteCallbackMethod(Control control, string callbackArgument) { Type controlType = control.GetType(); // Deserialize the callback JSON into CLR objects JavaScriptSerializer js = new JavaScriptSerializer(); Dictionary <string, object> callInfo = js.DeserializeObject(callbackArgument) as Dictionary <string, object>; // Get the call information string methodName = (string)callInfo["name"]; object[] args = (object[])callInfo["args"]; string clientState = (string)callInfo["state"]; // Attempt to load the client state IClientStateManager csm = control as IClientStateManager; if (csm != null && csm.SupportsClientState) { csm.LoadClientState(clientState); } // call the method object result = null; string error = null; try { // Find a matching static or instance method. Only public methods can be invoked MethodInfo mi = controlType.GetMethod(methodName, BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance); if (mi == null) { throw new MissingMethodException(controlType.FullName, methodName); } // Verify that the method has the corrent number of parameters as well as the ExtenderControlMethodAttribute ParameterInfo[] methodParams = mi.GetParameters(); ExtenderControlMethodAttribute methAttr = (ExtenderControlMethodAttribute) Attribute.GetCustomAttribute(mi, typeof(ExtenderControlMethodAttribute)); if (methAttr == null || !methAttr.IsScriptMethod || args.Length != methodParams.Length) { throw new MissingMethodException(controlType.FullName, methodName); } // Convert each argument to the parameter type if possible // NOTE: I'd rather have the ObjectConverter from within System.Web.Script.Serialization namespace for this object[] targetArgs = new object[args.Length]; for (int i = 0; i < targetArgs.Length; i++) { if (args[i] == null) { continue; } targetArgs[i] = Convert.ChangeType(args[i], methodParams[i].ParameterType, CultureInfo.InvariantCulture); } result = mi.Invoke(control, targetArgs); } catch (Exception ex) { // Catch the exception information to relay back to the client if (ex is TargetInvocationException) { ex = ex.InnerException; } error = ex.GetType().FullName + ":" + ex.Message; } // return the result Dictionary <string, object> resultInfo = new Dictionary <string, object>(); if (error == null) { resultInfo["result"] = result; if (csm != null && csm.SupportsClientState) { resultInfo["state"] = csm.SaveClientState(); } } else { resultInfo["error"] = error; } // Serialize the result info into JSON return(js.Serialize(resultInfo)); }
public static string ExecuteCallbackMethod(Control control, Dictionary <string, object> callInfo) { string methodName = (string)callInfo["name"]; object[] args = (object[])callInfo["args"]; string clientState = (string)callInfo["state"]; // Attempt to load the client state IClientStateManager csm = control as IClientStateManager; if (csm != null && csm.SupportsClientState) { csm.LoadClientState(clientState); } // call the method object result = null; Dictionary <string, object> error = null; Type controlType = control.GetType(); try { // Find a matching static or instance method. Only public methods can be invoked MethodInfo mi = controlType.GetMethod(methodName, BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance); if (mi == null) { throw new MissingMethodException(controlType.FullName, methodName); } // Verify that the method has the corrent number of parameters as well as the ScriptControlMethodAttribute ParameterInfo[] methodParams = mi.GetParameters(); ScriptControlMethodAttribute methAttr = (ScriptControlMethodAttribute)Attribute.GetCustomAttribute(mi, typeof(ScriptControlMethodAttribute)); if (methAttr == null || !methAttr.IsScriptMethod || args.Length != methodParams.Length) { throw new MissingMethodException(controlType.FullName, methodName); } // Convert each argument to the parameter type if possible // NOTE: I'd rather have the ObjectConverter from within Microsoft.Web.Script.Serialization namespace for this object[] targetArgs = new object[args.Length]; for (int i = 0; i < targetArgs.Length; i++) { if (args[i] == null) { continue; } targetArgs[i] = JSONSerializerExecute.DeserializeObject(args[i], methodParams[i].ParameterType); } result = mi.Invoke(control, targetArgs); } catch (Exception ex) { // Catch the exception information to relay back to the client if (ex is TargetInvocationException) { ex = ex.InnerException; } error = new Dictionary <string, object>(); error["name"] = ex.GetType().FullName; error["message"] = ex.Message; if (WebUtility.AllowResponseExceptionStackTrace()) { error["stackTrace"] = ex.StackTrace; } else { error["stackTrace"] = string.Empty; } TryWriteLog(ex, control); } // return the result Dictionary <string, object> resultInfo = new Dictionary <string, object>(); if (error == null) { resultInfo["result"] = result; if (csm != null && csm.SupportsClientState) { resultInfo["state"] = csm.SaveClientState(); } } else { resultInfo["error"] = error; } // Serialize the result info into JSON return(JSONSerializerExecute.Serialize(resultInfo)); }