public void ProcessRequest(HttpContext context) { var requests = GetActionRequest(context); var responses = new List<Response>(); foreach (var request in requests) { DextopApiInvocationResult result; try { using (var apiContext = DextopApi.Resolve<DextopApiContext>()) { var controllerType = Type.GetType(request.data[0]); apiContext.Scope = DextopUtil.Decode<DextopConfig>(request.data[1]); apiContext.HttpContext = new HttpContextWrapper(context); var controller = apiContext.ResolveController(controllerType); controller.OnInitialize(); try { controller.OnExecuting(); result = controller.Invoke(request.data[2], DextopUtil.Decode<string[]>(request.data[3])); controller.OnExecuted(); } catch (Exception ex) { controller.OnError(ex); throw; } } } catch(Exception ex) { result = DextopApiInvocationResult.Exception(ex); } var response = new Response { action = request.action, method = request.method, type = request.type, tid = request.tid, result = result }; responses.Add(response); } DextopUtil.Encode(responses, context.Response.Output); }
internal IList<Response> HandleRemotingRequest(HttpContext context, Request[] requests) { if (Culture != null) Thread.CurrentThread.CurrentCulture = Culture; HttpContext = context; var responses = new List<Response>(); foreach (var request in requests) { /* This part blocks out of order processing of direct transactions for 2 seconds. * This is important as two sequential http request can come in different order than sent. * Luckily Ext.direct has tid field. */ int waitCounter = 20; while (request.tid > lastTid + 1 && --waitCounter>0) { Thread.Sleep(100); } if (request.tid > lastTid) lastTid = request.tid; var call = new DextopRemoteMethodCall { FormSubmit = request.FormSubmit, RemoteId = request.data[0], Arguments = DextopUtil.Decode<String[]>(request.data[2]), MethodName = request.data[1] }; var response = new Response { type = "rpc", method = request.method, tid = request.tid, action = request.action }; responses.Add(response); try { response.result = ExecuteMethodCall(call); } catch (Exception ex) { response.result = new DextopRemoteMethodCallResult { success = false, result = new DextopRemoteMethodCallException { type = "rpc", exception = ex.Message, stackTrace = ex.StackTrace } }; } } HttpContext = null; return responses; }
public void ProcessRequest(HttpContext context) { var ajaxRequest = context.Request.QueryString["ajax"] == "1"; if (ajaxRequest) { ProcessAjaxRequest(context); return; } var formSubmit = context.Request.QueryString["formSubmit"] == "1"; var upload = formSubmit && context.Request.Form["extUpload"] == "true"; var requests = upload ? GetUploadRequest(context) : GetActionRequest(context); var responses = new List<Response>(); foreach (var request in requests) { DextopApiInvocationResult result; try { using (var apiContext = DextopApi.Resolve<DextopApiContext>()) { var controllerType = Type.GetType(request.data[0]); apiContext.Scope = DextopUtil.Decode<DextopConfig>(request.data[1]); apiContext.HttpContext = new HttpContextWrapper(context); var controller = apiContext.ResolveController(controllerType); controller.OnInitialize(); try { controller.OnExecuting(); result = controller.Invoke(request.data[2], request.FormSubmit, DextopUtil.Decode<string[]>(request.data[3])); controller.OnExecuted(); } catch (Exception ex) { controller.OnError(ex); throw; } } } catch (Exception ex) { result = DextopApiInvocationResult.Exception(ex); } var response = new Response { action = request.action, method = request.method, type = request.type, tid = request.tid, result = result }; responses.Add(response); } DextopUtil.Encode(responses, context.Response.Output); }