Пример #1
0
        private void OnPostAcquireRequestState(object sender, EventArgs eventArgs)
        {
            HttpApplication app     = (HttpApplication)sender;
            HttpRequest     request = app.Context.Request;

            if (DirectMethod.IsStaticMethodRequest(request) && RequestManager.IsAjaxRequest)
            {
                this.ProcessRequest(app, request);
            }
        }
Пример #2
0
        public virtual DirectMethod Clone()
        {
            DirectMethod dm = new DirectMethod(this.method, this.attribute);

            dm.methodParams = this.Params;
            dm.name = this.Name;
            dm.controlID = this.ControlID;

            return dm;
        }
Пример #3
0
        public virtual DirectMethod Clone()
        {
            DirectMethod dm = new DirectMethod(this.method, this.attribute);

            dm.methodParams = this.Params;
            dm.name         = this.Name;
            dm.controlID    = this.ControlID;

            return(dm);
        }
        public void ProcessRequest(HttpContext context)
        {
            DirectResponse responseObject = new DirectResponse(true);

            try
            {
                HandlerMethods handler    = HandlerMethods.GetHandlerMethods(context, context.Request.FilePath);
                string         methodName = HandlerMethods.GetMethodName(context);

                if (handler == null)
                {
                    throw new Exception("The Method '{0}' has not been defined.".FormatWith(context.Request.FilePath));
                }

                if (methodName.IsEmpty())
                {
                    throw new Exception("No methodName has been set in the configuration.");
                }

                DirectMethod directMethod = handler.GetStaticMethod(methodName);

                if (directMethod == null)
                {
                    throw new Exception("The static DirectMethod '{0}' has not been defined.".FormatWith(methodName));
                }

                responseObject.Result = directMethod.Invoke();
            }
            catch (Exception e)
            {
                if (HandlerMethods.RethrowException(context))
                {
                    throw e;
                }

                responseObject.Success      = false;
                responseObject.ErrorMessage = IsDebugging ? e.ToString() : e.Message;
            }

            context.Response.Cache.SetNoServerCaching();
            context.Response.Cache.SetMaxAge(TimeSpan.Zero);
            context.Response.Write(responseObject.ToString());
            context.Response.End();
        }
Пример #5
0
        private void ProcessRequest(HttpApplication app, HttpRequest request)
        {
            DirectResponse responseObject = new DirectResponse(true);

            try
            {
                HttpContext context = HttpContext.Current;

                // Get handler
                HandlerMethods handler = HandlerMethods.GetHandlerMethods(context, request.FilePath);

                if (handler == null)
                {
                    throw new Exception("The Method '{0}' has not been defined.".FormatWith(request.FilePath));
                }

                // Get method name to invoke
                string methodName = HandlerMethods.GetMethodName(context);

                if (methodName.IsEmpty())
                {
                    throw new Exception("No methodName has been set in the configuration.");
                }


                DirectMethod directMethod = handler.GetStaticMethod(methodName);

                if (directMethod == null)
                {
                    throw new Exception("The static DirectMethod '{0}' has not been defined.".FormatWith(directMethod));
                }

                object result = directMethod.Invoke();

                if (!ResourceManager.AjaxSuccess)
                {
                    responseObject.Success      = false;
                    responseObject.ErrorMessage = ResourceManager.AjaxErrorMessage;
                }
                else
                {
                    responseObject.Result = result;
                    responseObject.Script = ResourceManager.GetInstanceScript();
                }
            }
            catch (TargetInvocationException e)
            {
                if (HandlerMethods.RethrowException(HttpContext.Current))
                {
                    throw;
                }

                responseObject.Success      = false;
                responseObject.ErrorMessage = IsDebugging ? e.InnerException.ToString() : e.InnerException.Message;
            }
            catch (Exception e)
            {
                if (HandlerMethods.RethrowException(HttpContext.Current))
                {
                    throw;
                }

                responseObject.Success      = false;
                responseObject.ErrorMessage = IsDebugging ? e.ToString() : e.Message;
            }

            app.Context.Response.Clear();
            app.Context.Response.ClearContent();
            app.Context.Response.ClearHeaders();
            app.Context.Response.StatusCode  = 200;
            app.Context.Response.ContentType = "application/json";
            app.Context.Response.Charset     = "utf-8";
            app.Context.Response.Cache.SetNoServerCaching();
            app.Context.Response.Cache.SetMaxAge(TimeSpan.Zero);
            app.Context.Response.Write(responseObject.ToString());
            app.CompleteRequest();
        }