public DextopApiInvocationResult Invoke(string action, string[] arguments, DextopFormSubmit form) { var method = controller.GetType().GetMethod(action); if (method == null) { throw new DextopException("Cannot find method '{0}' in controller type '{1}'.", action, controller.GetType()); } var parameters = method.GetParameters(); var p = new object[parameters.Length]; int offset = form == null ? 0 : 1; if (form != null) { p[0] = form; } for (var i = 0; i < Math.Min(p.Length, arguments.Length); i++) { p[i + offset] = DextopUtil.DecodeValue(arguments[i], parameters[i + offset].ParameterType); } try { var value = method.Invoke(controller, p); return(DextopApiInvocationResult.Success(value)); } catch (Exception ex) { return(DextopApiInvocationResult.Exception(ex)); } }
void IHttpAsyncHandler.EndProcessRequest(IAsyncResult asyncResult) { if (errorHandler != null) { errorHandler.EndInvoke(asyncResult); } else { LongPollingResult result; try { result = session.EndHandlingLongPollingRequest(asyncResult, start); } catch (Exception ex) { Debug.WriteLine("Long polling exception.", ex); //Application should handle the request and give a valid result. //Any exception is a sign that session is not valid anymore. result = new LongPollingResult { type = "rpc", name = "message", success = false, data = new DextopRemoteMethodCallException { exception = ex.Message, type = "session" } }; } context.Response.ContentType = "application/json"; DextopUtil.Encode(result, context.Response.Output); } }
private string Serialize(IList <object> data) { if (data == null) { return(null); } return(DextopUtil.Encode(serializer.Serialize(data))); }
object ChangeType(object value, Type type) { if (value == null) { return(type.IsValueType ? Activator.CreateInstance(type) : null); } if (value is String) { return(DextopUtil.DecodeValue((String)value, type)); } return(Codaxy.Common.Convert.ChangeTypeInvariant(value, type)); }
void WriteException(HttpContext context, Exception ex) { //Application should handle the request and give a valid result. //Any exception is a sign that session is not valid anymore. var result = new LongPollingResult { type = "rpc", name = "message", success = false, data = new DextopRemoteMethodCallException { exception = ex.Message, type = "session" } }; context.Response.ContentType = "application/json"; DextopUtil.Encode(result, context.Response.Output); }