コード例 #1
0
        public void OnResultExecuting(ResultExecutingContext filterContext)
        {
            ViewResult viewResult = filterContext.Result as ViewResult;

            if (viewResult != null)
            {
                HttpServerUtilityBase server = filterContext.HttpContext.Server;

                string controllerName = filterContext.RouteData.GetRequiredString("controller");

                string viewName =
                    !string.IsNullOrEmpty(viewResult.ViewName)
                        ? viewResult.ViewName
                        : filterContext.RouteData.GetRequiredString("action");

                string baseViewPath = filterContext.IsRazorView() ? RazorViewPath : ViewPath;
                string viewExtension = filterContext.IsRazorView() ? ".cshtml" : ".aspx";
                string currentViewPath = baseViewPath + controllerName + Path.AltDirectorySeparatorChar + viewName + viewExtension;

                string exampleControllerPath = ControllerPath + controllerName + Path.AltDirectorySeparatorChar + viewName + "Controller.cs";

                string descriptionPath =
                    server.MapPath(DescriptionPath + Path.AltDirectorySeparatorChar + controllerName +
                    Path.AltDirectorySeparatorChar + "Descriptions" +
                    Path.AltDirectorySeparatorChar + viewName + ".html");

                var viewData = filterContext.Controller.ViewData;

                if (System.IO.File.Exists(descriptionPath))
                {
                    var descriptionText = System.IO.File.ReadAllText(descriptionPath);
            #if MVC3
                    viewData["Description"] = new HtmlString(descriptionText);
            #else
                    viewData["Description"] = descriptionText;
            #endif
                }

                var codeFiles = new Dictionary<string, string>();
                codeFiles["View"] = currentViewPath;
                codeFiles["Controller"] = exampleControllerPath;
                RegisterLayoutPages(filterContext, codeFiles);

                viewData["codeFiles"] = codeFiles;
            }
        }
コード例 #2
0
 private string GetCurrentFileName(ResultExecutingContext filterContext)
 {
     if (string.IsNullOrEmpty(RazorFileName))
     {
         return FileName;
     }
     else
     {
         return filterContext.IsRazorView() ? RazorFileName : FileName;
     }
 }
コード例 #3
0
 private void RegisterLayoutPages(ResultExecutingContext filterContext, Dictionary<string, string> codeFiles)
 {
     if (filterContext.IsRazorView())
     {
         codeFiles["_Layout.cshtml"] = LayoutPagePath;
     }
     else
     {
         codeFiles["Site.Master"] = MasterPagePath;
     }
 }