コード例 #1
0
        private static string EvalComponentExpression(ExpressionParser parser, TemplateToken token, TemplateParserContext context)
        {
            TemplateToken.ParameterizedExpression pExpr = token.ExtractParameters();

            string componentName = pExpr.MainExpression;

            if (pExpr.MainExpression.StartsWith("(") && pExpr.MainExpression.EndsWith(")"))
            {
                componentName = parser.Evaluate <string>(pExpr.MainExpression, context, token.TokenPosition);
            }

            TemplateParserContext newContext = (TemplateParserContext)context.CreateLocal();

            foreach (string varName in pExpr.Parameters.Keys)
            {
                newContext.SetLocal(varName, parser.Evaluate(pExpr.Parameters[varName], context));
            }

            ControllerAction viewComponent = WebAppHelper.GetViewComponent(componentName);

            if (viewComponent == null)
            {
                throw new TemplateRenderingException("View component " + componentName + " not found", token.TokenPosition);
            }

            try
            {
                return(WebAppHelper.RunViewComponent(viewComponent, newContext));
            }
            catch (Exception e)
            {
                throw new TemplateRenderingException("Error rendering view component " + componentName, e, token.TokenPosition);
            }
        }
コード例 #2
0
        private string RunPage(string url, bool post)
        {
            for (; ;)
            {
                _redirectedPage = null;
                _currentPage    = url;

                try
                {
                    HttpContextBase.CreateContext(this, post ? "POST" : "GET", url, post ? _postData : null);

                    if (ContextCreated != null)
                    {
                        ContextCreated(this, new ContextCreatedEventArgs(this, WebAppContext.HttpContext));
                    }

                    IHttpRequest httpRequest = WebAppContext.Request;

                    string path = UrlHelper.GetUrlPath(httpRequest.AppRelativeCurrentExecutionFilePath,
                                                       httpRequest.PathInfo);

                    ControllerAction controllerAction = WebAppHelper.GetControllerAction(path);

                    MvcPageHandler pageHandler = new MvcPageHandler(controllerAction);

                    pageHandler.ProcessRequest(WebAppContext.HttpContext);

                    _isNewSession = false;

                    _view = WebAppContext.HttpContext.Response.RenderedView;
                }
                catch (TargetInvocationException ex)
                {
                    Exception ex2 = ExceptionHelper.ResolveTargetInvocationException(ex);

                    if (!(ex2 is EndResponseException))
                    {
                        throw ex2;
                    }
                }
                catch (EndResponseException)
                {
                }

                _redirectedPage = ((OfflineHttpResponse)WebAppContext.HttpContext.Response).RedirectedUrl;

                PostData.Clear();

                if (!_followRedirects || _redirectedPage == null)
                {
                    return(WebAppContext.Response.Output);
                }

                post = false;
                url  = _redirectedPage;
            }
        }
コード例 #3
0
        public static string RenderComponent(View view, string name, params object[] parameters)
        {
            TemplateParserContext newContext = new TemplateParserContext(view, view.ViewTemplate);

            for (int i = 0; i < parameters.Length; i += 2)
            {
                newContext.SetLocal((string)parameters[i], parameters[i + 1], parameters[i + 1] == null ? typeof(object) : parameters[i + 1].GetType());
            }

            return(WebAppHelper.RunViewComponent(WebAppHelper.GetViewComponent(name), newContext));
        }
コード例 #4
0
        public static void CreateContext(OfflineWebSession webSession, string method, string url, NameValueCollection postData)
        {
            WebAppConfig.Init(webSession.MapPath);

            HttpContextBase context = new OfflineHttpContext(webSession, method, url, postData);

            Current = context;

            context.SessionObject = WebAppHelper.CreateSessionObject();

            WebAppConfig.Fire_SessionCreated(context.SessionObject);
        }
コード例 #5
0
 internal void TearDownController(Controller controller, TemplateParserContext context)
 {
     try
     {
         foreach (MethodInfo method in _teardownMethods)
         {
             method.Invoke(controller, WebAppHelper.CreateParameters(method, context));
         }
     }
     catch (TargetInvocationException ex)
     {
         throw ExceptionHelper.ResolveTargetInvocationException(ex);
     }
 }
コード例 #6
0
        internal void SetupController(Controller controller, TemplateParserContext context)
        {
            try
            {
                foreach (MethodInfo method in _setupMethods)
                {
                    method.Invoke(controller, WebAppHelper.CreateParameters(method, context));
                }
            }
            catch (TargetInvocationException ex)
            {
                throw ExceptionHelper.ResolveTargetInvocationException(ex);
            }

            RegisterAjaxMethods(controller);
        }
コード例 #7
0
        public static void CreateContext(HttpContext httpContext)
        {
            WebAppConfig.Init();

            HttpContextBase context = new OnlineHttpContext(httpContext);

            Current = context;

            if (httpContext.Session == null)
            {
                return;
            }

            context.SessionObject = WebAppHelper.CreateSessionObject();

            WebAppConfig.Fire_SessionCreated(context.SessionObject);
        }
コード例 #8
0
ファイル: HttpModule.cs プロジェクト: ibeae/ThinkAway.net
        private static void PostResolveRequestCache(object sender, EventArgs e)
        {
            WebAppConfig.Init();

            HttpContext httpContext = ((HttpApplication)sender).Context;
            HttpRequest httpRequest = httpContext.Request;

            IHttpHandler httpHandler = null;

            string path = UrlHelper.GetUrlPath(httpRequest.AppRelativeCurrentExecutionFilePath, httpRequest.PathInfo);

            if (path.StartsWith("_$ajax$_.axd/"))
            {
                httpHandler = new AjaxPageHandler(path);
            }
            else if (path.StartsWith("_$res$_.axd"))
            {
                httpHandler = new ResourceHttpHandler(path);
            }
            else
            {
                ControllerAction controllerAction = WebAppHelper.GetControllerAction(path);

                if (controllerAction != null)
                {
                    httpHandler = new PageHandler(new MvcPageHandler(controllerAction));
                }
            }

            if (httpHandler != null)
            {
                httpContext.Items[_contextItemKey] = new RequestData(httpContext.Request.RawUrl, httpHandler);

                httpContext.RewritePath("~/ProMesh.axd");
            }
        }
コード例 #9
0
        private static void RunAjaxMethod(string pageUrl)
        {
            IHttpResponse response = WebAppContext.Response;

            response.ContentType = "application/json";

            string[] parts = pageUrl.Split('/');

            if (parts.Length != 3)
            {
                throw new ThinkAwayMvcException("Unrecognized Ajax URL");
            }

            string assemblyName = UrlHelper.DecodeFromUrl(parts[0]);
            string className    = UrlHelper.DecodeFromUrl(parts[1]);
            string methodName   = UrlHelper.DecodeFromUrl(parts[2]);

            Type type = Type.GetType(className + ", " + assemblyName);

            if (type == null)
            {
                response.Write(AjaxHelper.GenerateJSONError("Unknown class " + className + " in assembly " + assemblyName));
                return;
            }


            Type       currentType = type;
            MethodInfo method      = null;

            while (method == null && currentType != null && currentType != typeof(object))
            {
                method = currentType.GetMethod(methodName);

                currentType = currentType.BaseType;
            }

            if (method == null)
            {
                response.Write(AjaxHelper.GenerateJSONError("Unknown method " + methodName + " in class " + className));
                return;
            }

            AjaxAttribute[] ajaxAttributes = (AjaxAttribute[])method.GetCustomAttributes(typeof(AjaxAttribute), false);

            if (ajaxAttributes.Length == 0 && !method.IsDefined(typeof(AjaxOkAttribute), true))
            {
                response.Write(AjaxHelper.GenerateJSONError("Method " + methodName + " is not an Ajax method"));
                return;
            }

            bool returnXml = ajaxAttributes.Length > 0 && ajaxAttributes[0].ReturnXml;

            object obj = null;

            if (!method.IsStatic)
            {
                obj = Activator.CreateInstance(type);
            }

            if (returnXml)
            {
                response.ContentType = "text/xml";
            }

            response.Write(WebAppHelper.RunAjaxMethod(method, obj, returnXml));
        }
コード例 #10
0
 public object Invoke(object target, TemplateParserContext parserContext)
 {
     return(Invoke(target, WebAppHelper.CreateParameters(_methodInfo, parserContext)));
 }
コード例 #11
0
 public object Invoke(object target)
 {
     return(Invoke(target, WebAppHelper.CreateParameters(_methodInfo)));
 }
コード例 #12
0
        public void ProcessRequest(HttpContextBase httpContext)
        {
            httpContext.Handler = this;

            string baseUrl = UrlHelper.GetUrlPath(httpContext.Request.AppRelativeCurrentExecutionFilePath, httpContext.Request.PathInfo);

            Stopwatch stopWatchRun    = new Stopwatch();
            Stopwatch stopWatchRender = new Stopwatch();
            Stopwatch stopWatchTotal  = new Stopwatch();

            ActionResult actionResult = null;

            try
            {
                try
                {
                    stopWatchTotal.Start();

                    try
                    {
                        stopWatchRun.Start();

                        actionResult = WebAppHelper.RunControllerAction(_controllerAction);
                    }
                    finally
                    {
                        stopWatchRun.Stop();
                    }

                    if (actionResult != null)
                    {
                        try
                        {
                            stopWatchRender.Start();

                            actionResult.Execute(httpContext);
                        }
                        finally
                        {
                            stopWatchRender.Stop();
                        }
                    }
                }
                finally
                {
                    stopWatchTotal.Stop();

                    if (WebAppConfig.LoggingProvider != null)
                    {
                        WebAppConfig.LoggingProvider.LogPage(WebAppContext.Session.SessionID,
                                                             baseUrl,
                                                             GetQueryString(),
                                                             WebAppContext.Session.LanguageCode,
                                                             actionResult != null ? actionResult.LayoutName : null,
                                                             actionResult != null ? actionResult.ViewName : null,
                                                             (int)stopWatchRun.ElapsedMilliseconds,
                                                             (int)stopWatchRender.ElapsedMilliseconds,
                                                             (int)stopWatchTotal.ElapsedMilliseconds);
                    }
                }
            }

            catch (EndResponseException)
            {
                // occurs when Response.End() is called from an offline session (unit test)
            }

            catch (ThreadAbortException)
            {
                throw; // Occurs when Response.End() is called. Rethrow it, because it is handled by the ASP.NET runtime
            }

            catch (Exception ex)
            {
                if (ex.InnerException is ThreadAbortException)
                {
                    throw ex.InnerException;
                }

                WebAppConfig.Fire_ExceptionHandler(ex);
            }
        }