コード例 #1
0
        public void ProcessAjaxRequest(HttpContext context)
        {
            var controllerTypeString = context.Request.QueryString["_apiControllerType"];
            var controllerType       = Type.GetType(controllerTypeString);

            try
            {
                using (var apiContext = DextopApi.Resolve <DextopApiContext>())
                {
                    if (context.Request.QueryString["_apiScope"] != null)
                    {
                        apiContext.Scope = DextopUtil.Decode <DextopConfig>(context.Request.QueryString["_apiScope"]);
                    }

                    apiContext.HttpContext = new HttpContextWrapper(context);
                    var controller = apiContext.ResolveController(controllerType);
                    try
                    {
                        controller.OnProcessAjaxRequest(context);
                    }
                    catch (Exception ex)
                    {
                        controller.OnError(ex);
                        throw;
                    }
                }
            }
            catch
            {
                context.Response.StatusCode = 500;
            }
        }
コード例 #2
0
        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);
        }