예제 #1
0
        private string GetPathFromGeneralName(ControllerArgs controllerContext, ViewType viewType, string name)
        {
            var virtualPath = string.Empty;

            var locations = ViewLocations.Where(x => x.ViewType == viewType).ToList();

            if ((locations == null) || (locations.Count == 0))
            {
                throw new InvalidOperationException("locations must not be null or emtpy.");
            }

            List <string> sl = new List <string>(locations.Count);

            foreach (var loc in locations)
            {
                virtualPath = loc.GetPath(controllerContext, name);
                if (FileExists(controllerContext, virtualPath))
                {
                    ViewLocationCache.InsertViewLocation(controllerContext.HttpContext, controllerContext.GetChacheKey(viewType, name), virtualPath);
                    return(virtualPath);
                }

                sl.Add(virtualPath);
            }
            var str = string.Join("\n", sl);

            throw new DirectoryNotFoundException(str);
        }
예제 #2
0
        public string GetPath(ControllerArgs args, string viewName)
        {
            if (Themed)
            {
                switch (ViewType)
                {
                case ViewType.MasterPage:
                    return(string.Format(Path, args.RouteName, args.ThemeName, args.ControllerName, viewName));

                case ViewType.View:
                    return(string.Format(Path, args.RouteName, args.ThemeName, args.ControllerName, viewName));

                case ViewType.Partial:
                    return(string.Format(Path, args.RouteName, args.ThemeName, args.ControllerName, viewName));

                default:
                    throw new Exception();
                }
            }
            switch (ViewType)
            {
            case ViewType.MasterPage:
                return(string.Format(Path, args.Area, args.ControllerName, viewName));

            case ViewType.View:
                return(string.Format(Path, args.Area, args.ControllerName, viewName));

            case ViewType.Partial:
                return(string.Format(Path, args.Area, args.ControllerName, viewName));

            default:
                throw new Exception();
            }
        }
예제 #3
0
        public override ViewEngineResult FindView(ControllerContext controllerContext, string viewName, string masterName, bool useCache)
        {
            if (string.IsNullOrEmpty(viewName))
            {
                throw new ArgumentException("viewName must be specified.", "viewName");
            }

            ControllerArgs controllerArgs = new ControllerArgs(controllerContext);

            var    viewPath   = GetPath(controllerArgs, ViewType.View, viewName, useCache);
            string masterPath = string.Empty;


            if (!string.IsNullOrEmpty(masterName))
            {
                masterPath = GetPath(controllerArgs, ViewType.MasterPage, masterName, useCache);
            }

            if (!string.IsNullOrEmpty(viewPath) && (!string.IsNullOrEmpty(masterPath) || string.IsNullOrEmpty(masterName)))
            {
                return(new ViewEngineResult(CreateView(controllerContext, viewPath, masterPath), this));
            }

            throw new DirectoryNotFoundException(string.Format("Вьюха {1} не найдена для  {0} ", controllerArgs.ControllerName, viewName));
        }
예제 #4
0
        private string GetPathFromSpecificName(ControllerArgs controllerContext, ViewType viewType, string name)
        {
            var virtualPath = name;

            if (!FileExists(controllerContext, name))
            {
                throw new Exception(virtualPath);
            }
            ViewLocationCache.InsertViewLocation(controllerContext.HttpContext, controllerContext.GetChacheKey(viewType, name), virtualPath);
            return(virtualPath);
        }
예제 #5
0
        public override ViewEngineResult FindPartialView(ControllerContext controllerContext, string partialViewName, bool useCache)
        {
            if (string.IsNullOrEmpty(partialViewName))
            {
                throw new ArgumentException(@"partialViewName must be specified.", "partialViewName");
            }

            var con = new ControllerArgs(controllerContext);

            var partialViewPath = GetPath(con, ViewType.Partial, partialViewName, useCache);

            return(new ViewEngineResult(CreatePartialView(controllerContext, partialViewPath), this));
        }
예제 #6
0
 private bool FileExists(ControllerArgs controllerContext, string virtualPath)
 {
     try
     {
         return(File.Exists(controllerContext.HttpContext.Server.MapPath(virtualPath)));
     }
     catch (HttpException exception)
     {
         if (exception.GetHttpCode() != 0x194)
         {
             throw;
         }
         return(false);
     }
     catch
     {
         return(false);
     }
 }
예제 #7
0
        private string GetPath(ControllerArgs controllerContext, ViewType viewType, string name, bool useCache)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new Exception("Имя вида не задано");
            }


            if (!useCache)
            {
                return(IsSpecificPath(name)
                    ? GetPathFromSpecificName(controllerContext, viewType, name)
                    : GetPathFromGeneralName(controllerContext, viewType, name));
            }


            string key = controllerContext.GetChacheKey(viewType, name);

            var viewLocation = ViewLocationCache.GetViewLocation(controllerContext.HttpContext, key);

            return(viewLocation ?? (IsSpecificPath(name)
                ? GetPathFromSpecificName(controllerContext, viewType, name)
                : GetPathFromGeneralName(controllerContext, viewType, name)));
        }