Invoke() private method

private Invoke ( ) : object
return object
Ejemplo n.º 1
0
        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();
        }
Ejemplo n.º 2
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();
        }