Esempio n. 1
0
        public void GetAvailableDisplayModesForContextWithRestrictingPageElements()
        {
            // Arrange
            Mock <HttpContextBase> httpContext = new Mock <HttpContextBase>(MockBehavior.Strict);
            var displayModeProvider            = new DisplayModeProvider();

            displayModeProvider.Modes.Clear();
            var displayMode1 = new Mock <IDisplayMode>(MockBehavior.Strict);

            displayMode1.Setup(d => d.CanHandleContext(It.IsAny <HttpContextBase>())).Returns(true);
            displayModeProvider.Modes.Add(displayMode1.Object);

            var displayMode2 = new Mock <IDisplayMode>(MockBehavior.Strict);

            displayMode2.Setup(d => d.CanHandleContext(It.IsAny <HttpContextBase>())).Returns(false);
            displayModeProvider.Modes.Add(displayMode2.Object);

            var displayMode3 = new Mock <IDisplayMode>(MockBehavior.Strict);

            displayMode3.Setup(d => d.CanHandleContext(It.IsAny <HttpContextBase>())).Returns(true);
            displayModeProvider.Modes.Add(displayMode3.Object);

            // Act
            var availableDisplayModes = displayModeProvider.GetAvailableDisplayModesForContext(httpContext.Object, displayMode2.Object, requireConsistentDisplayMode: true).ToList();

            // Assert
            var availableDisplayMode = Assert.Single(availableDisplayModes);

            Assert.Equal(displayMode3.Object, availableDisplayMode);
        }
        public void GetAvailableDisplayModesReturnsOnlyModesThatCanHandleContext()
        {
            // Arrange
            Mock <HttpContextBase> httpContext = new Mock <HttpContextBase>(MockBehavior.Strict);
            var displayModeProvider            = new DisplayModeProvider();

            displayModeProvider.Modes.Clear();
            var displayMode1 = new Mock <IDisplayMode>(MockBehavior.Strict);

            displayMode1.Setup(d => d.CanHandleContext(It.IsAny <HttpContextBase>())).Returns(false);
            displayModeProvider.Modes.Add(displayMode1.Object);

            var displayMode2 = new Mock <IDisplayMode>(MockBehavior.Strict);

            displayMode2.Setup(d => d.CanHandleContext(It.IsAny <HttpContextBase>())).Returns(true);
            displayModeProvider.Modes.Add(displayMode2.Object);

            var displayMode3 = new Mock <IDisplayMode>(MockBehavior.Strict);

            displayMode3.Setup(d => d.CanHandleContext(It.IsAny <HttpContextBase>())).Returns(false);
            displayModeProvider.Modes.Add(displayMode3.Object);

            // Act
            var availableDisplayModes = displayModeProvider.GetAvailableDisplayModesForContext(httpContext.Object, displayMode1.Object, requireConsistentDisplayMode: false).ToList();

            // Assert
            Assert.Equal(1, availableDisplayModes.Count);
            Assert.Equal(displayMode2.Object, availableDisplayModes[0]);
        }
Esempio n. 3
0
        private string GetPath(ControllerContext controllerContext, string[] locations, string[] areaLocations, string locationsPropertyName, string name, string controllerName, string theme, string cacheKeyPrefix, bool useCache, out string[] searchedLocations)
        {
            searchedLocations = EmptyLocations;

            if (string.IsNullOrEmpty(name))
            {
                return(string.Empty);
            }

            string areaName = GetAreaName(controllerContext.RouteData);

            bool usingAreas = !string.IsNullOrEmpty(areaName);

            var viewLocations = GetViewLocations(locations, usingAreas ? areaLocations : null);

            if (!viewLocations.Any())
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, "Properties cannot be null or empty - {0}", locationsPropertyName));
            }

            bool nameRepresentsPath = IsSpecificPath(name);

            string cacheKey = CreateCacheKey(cacheKeyPrefix, name, nameRepresentsPath ? string.Empty : controllerName, areaName, theme);

            if (useCache)
            {
                // Only look at cached display modes that can handle the context.
                IEnumerable <IDisplayMode> possibleDisplayModes = DisplayModeProvider.GetAvailableDisplayModesForContext(controllerContext.HttpContext, controllerContext.DisplayMode);

                foreach (IDisplayMode displayMode in possibleDisplayModes)
                {
                    string cachedLocation = ViewLocationCache.GetViewLocation(controllerContext.HttpContext, AppendDisplayModeToCacheKey(cacheKey, displayMode.DisplayModeId));

                    if (cachedLocation == null)
                    {
                        // If any matching display mode location is not in the cache, fall back to the uncached behavior, which will repopulate all of our caches.
                        return(null);
                    }

                    // A non-empty cachedLocation indicates that we have a matching file on disk. Return that result.
                    if (cachedLocation.Length > 0)
                    {
                        if (controllerContext.DisplayMode == null)
                        {
                            controllerContext.DisplayMode = displayMode;
                        }

                        return(cachedLocation);
                    }

                    // An empty cachedLocation value indicates that we don't have a matching file on disk. Keep going down the list of possible display modes.
                }

                // GetPath is called again without using the cache.
                return(null);
            }

            return(nameRepresentsPath ? GetPathFromSpecificName(controllerContext, name, cacheKey, ref searchedLocations) : GetPathFromGeneralName(controllerContext, viewLocations, name, controllerName, areaName, theme, cacheKey, ref searchedLocations));
        }
        private string GetPath(ControllerContext controllerContext, string[] locations, string[] areaLocations, string[] moduleLocations, string[] moduleAreaLocations, string locationsPropertyName, string name, string controllerName, string cacheKeyPrefix, bool useCache, out string[] searchedLocations)
        {
            searchedLocations = g_emptyLocations;

            if (String.IsNullOrEmpty(name))
            {
                return(String.Empty);
            }

            string moduleName   = AreaHelpers.GetModuleName(controllerContext.RouteData);
            string areaName     = AreaHelpers.GetAreaName(controllerContext.RouteData);
            bool   usingModules = !string.IsNullOrEmpty(moduleName);
            bool   usingAreas   = !String.IsNullOrEmpty(areaName);
            List <ViewLocation> viewLocations = GetViewLocations(
                locations,
                usingModules || !usingAreas ? null : areaLocations,
                !usingModules ? null : moduleLocations,
                !usingModules || !usingAreas ? null : moduleAreaLocations);

            if (viewLocations.Count == 0)
            {
                throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture,
                                                                  "The property '{0}' cannot be null or empty.", locationsPropertyName));
            }

            bool   nameRepresentsPath = IsSpecificPath(name);
            string cacheKey           = this.CreateCacheKey(cacheKeyPrefix, name, (nameRepresentsPath) ? String.Empty : controllerName, areaName, moduleName);

            if (useCache)
            {
                // Only look at cached display modes that can handle the context.
                string cachedLocation = null;
                IEnumerable <IDisplayMode> possibleDisplayModes = DisplayModeProvider.GetAvailableDisplayModesForContext(controllerContext.HttpContext, controllerContext.DisplayMode);
                foreach (IDisplayMode displayMode in possibleDisplayModes)
                {
                    cachedLocation = ViewLocationCache.GetViewLocation(controllerContext.HttpContext, this.AppendDisplayModeToCacheKey(cacheKey, displayMode.DisplayModeId));

                    if (cachedLocation != null)
                    {
                        if (controllerContext.DisplayMode == null)
                        {
                            controllerContext.DisplayMode = displayMode;
                        }
                        break;
                    }
                }

                // if cachedLocation is null GetPath will be called again without using the cache.
                return(cachedLocation);
            }
            else
            {
                return((nameRepresentsPath) ?
                       this.GetPathFromSpecificName(controllerContext, name, cacheKey, ref searchedLocations) :
                       this.GetPathFromGeneralName(controllerContext, viewLocations, name, controllerName, areaName, moduleName, cacheKey, ref searchedLocations));
            }
        }
Esempio n. 5
0
        private string GetPath(ControllerContext controllerContext, string[] locations, string[] areaLocations,
                               string locationsPropertyName, string name, string controllerName, string cacheKeyPrefix, bool useCache,
                               out string[] searchedLocations)
        {
            searchedLocations = _emptyLocations;

            if (string.IsNullOrEmpty(name))
            {
                return(string.Empty);
            }

            var areaName      = AreaHelpers.GetAreaName(controllerContext.RouteData);
            var usingAreas    = !string.IsNullOrEmpty(areaName);
            var viewLocations = GetViewLocations(locations, usingAreas ? areaLocations : null);

            if (viewLocations.Count == 0)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture,
                                                                  HotcakesResources.Common_PropertyCannotBeNullOrEmpty, locationsPropertyName));
            }

            var nameRepresentsPath = IsSpecificPath(name);
            var rootFolder         = HotcakesApplication.Current.ViewsVirtualPath;
            var cacheKey           = CreateCacheKey(cacheKeyPrefix, name, nameRepresentsPath ? string.Empty : controllerName,
                                                    areaName, rootFolder);

            if (useCache)
            {
                // Only look at cached display modes that can handle the context.
                var possibleDisplayModes =
                    DisplayModeProvider.GetAvailableDisplayModesForContext(controllerContext.HttpContext,
                                                                           controllerContext.DisplayMode);
                foreach (var displayMode in possibleDisplayModes)
                {
                    var cachedLocation = ViewLocationCache.GetViewLocation(controllerContext.HttpContext,
                                                                           AppendDisplayModeToCacheKey(cacheKey, displayMode.DisplayModeId));

                    if (cachedLocation != null)
                    {
                        if (controllerContext.DisplayMode == null)
                        {
                            controllerContext.DisplayMode = displayMode;
                        }

                        return(cachedLocation);
                    }
                }

                // GetPath is called again without using the cache.
                return(null);
            }
            return(nameRepresentsPath
                ? GetPathFromSpecificName(controllerContext, name, rootFolder, cacheKey, ref searchedLocations)
                : GetPathFromGeneralName(controllerContext, viewLocations, name, controllerName, areaName, rootFolder,
                                         cacheKey, ref searchedLocations));
        }
        private string GetPath(ControllerContext controllerContext, string[] areaLocations, string[] sharedLocations, string name, string controllerName, string cacheKeyPrefix, bool useCache, out string[] searchedLocations)
        {
            searchedLocations = _emptyLocations;

            if (String.IsNullOrEmpty(name))
            {
                return(String.Empty);
            }

            var areaName = AreaHelpers.GetAreaName(controllerContext.RouteData);
            List <ViewLocation> viewLocations = GetViewLocations(sharedLocations, areaLocations);

            bool   nameRepresentsPath = IsSpecificPath(name);
            string cacheKey           = CreateCacheKey(cacheKeyPrefix, name, (nameRepresentsPath) ? String.Empty : controllerName, areaName);

            if (useCache)
            {
                // Only look at cached display modes that can handle the context.
                IEnumerable <IDisplayMode> possibleDisplayModes = DisplayModeProvider.GetAvailableDisplayModesForContext(controllerContext.HttpContext, controllerContext.DisplayMode);
                foreach (IDisplayMode displayMode in possibleDisplayModes)
                {
                    string cachedLocation = ViewLocationCache.GetViewLocation(controllerContext.HttpContext, AppendDisplayModeToCacheKey(cacheKey, displayMode.DisplayModeId));

                    if (cachedLocation == null)
                    {
                        // If any matching display mode location is not in the cache, fall back to the uncached behavior, which will repopulate all of our caches.
                        return(null);
                    }

                    // A non-empty cachedLocation indicates that we have a matching file on disk. Return that result.
                    if (cachedLocation.Length > 0)
                    {
                        if (controllerContext.DisplayMode == null)
                        {
                            controllerContext.DisplayMode = displayMode;
                        }

                        return(cachedLocation);
                    }
                    // An empty cachedLocation value indicates that we don't have a matching file on disk. Keep going down the list of possible display modes.
                }

                // GetPath is called again without using the cache.
                return(null);
            }
            else
            {
                return(nameRepresentsPath
                    ? GetPathFromSpecificName(controllerContext, name, cacheKey, ref searchedLocations)
                    : GetPathFromGeneralName(controllerContext, viewLocations, name, controllerName, areaName, cacheKey, ref searchedLocations));
            }
        }
        private string ResolveViewPath(string viewName, string areaName, string[] viewLocationFormats, string[] areaViewLocationFormats, List <string> viewLocationsSearched, ControllerContext controllerContext)
        {
            if (string.IsNullOrEmpty(viewName))
            {
                return(null);
            }

            var controllerName = controllerContext.RouteData.GetRequiredString("controller");

            if (IsSpecificPath(viewName))
            {
                var normalized = NormalizeViewName(viewName);

                viewLocationsSearched.Add(viewName);
                return(_views.ContainsKey(normalized) ? normalized : null);
            }

            areaViewLocationFormats = (areaName == null ? null : areaViewLocationFormats) ?? new string[0];
            viewLocationFormats     = viewLocationFormats ?? new string[0];

            var httpContext           = controllerContext.HttpContext;
            var availableDisplayModes = DisplayModeProvider.GetAvailableDisplayModesForContext(httpContext, controllerContext.DisplayMode);

            foreach (var displayMode in availableDisplayModes)
            {
                for (var i = 0; i < areaViewLocationFormats.Length; i++)
                {
                    var path = string.Format(areaViewLocationFormats[i], viewName, controllerName, areaName);
                    if (TryResolveView(httpContext, displayMode, ref path, viewLocationsSearched))
                    {
                        return(path);
                    }
                }

                for (var i = 0; i < viewLocationFormats.Length; i++)
                {
                    var path = string.Format(viewLocationFormats[i], viewName, controllerName);
                    if (TryResolveView(httpContext, displayMode, ref path, viewLocationsSearched))
                    {
                        return(path);
                    }
                }
            }

            return(null);
        }
Esempio n. 8
0
        private string GetPath(ControllerContext controllerContext, IEnumerable <string> locations, string[] areaLocations, string name, string controllerName, string cacheKeyPrefix, bool useCache, out IList <string> searchedLocations)
        {
            searchedLocations = new List <string>();

            if (string.IsNullOrEmpty(name))
            {
                return(string.Empty);
            }

            var areaName      = GetAreaName(controllerContext.RouteData);
            var usingAreas    = !string.IsNullOrEmpty(areaName);
            var viewLocations = GetViewLocations(locations, usingAreas ? areaLocations : null);

            var isSpecificPath = IsSpecificPath(name);
            var cacheKey       = CreateCacheKey(cacheKeyPrefix, name, isSpecificPath ? string.Empty : controllerName, areaName);

            // Check the cache using the first display mode, i.e. the most specific.

            var displayMode = DisplayModeProvider.GetAvailableDisplayModesForContext(controllerContext.HttpContext, controllerContext.DisplayMode).First();

            if (useCache)
            {
                // Look in the cache.

                var cachedLocation = ViewLocationCache.GetViewLocation(controllerContext.HttpContext, AppendDisplayModeToCacheKey(cacheKey, displayMode.DisplayModeId));
                if (cachedLocation != null)
                {
                    // The location has been found for this display mode meaning it has been resolved either way.

                    if (controllerContext.DisplayMode == null)
                    {
                        controllerContext.DisplayMode = displayMode;
                    }
                    return(cachedLocation == DoesNotExist ? string.Empty : cachedLocation);
                }
            }

            return(isSpecificPath
                ? GetPathFromSpecificName(controllerContext, name, cacheKey, out searchedLocations)
                : GetPathFromGeneralName(controllerContext, viewLocations, displayMode, name, controllerName, areaName, cacheKey, out searchedLocations));
        }
        private string GetPath(ControllerContext controllerContext, string[] locations, string[] areaLocations, string locationsPropertyName, string name, string controllerName, string cacheKeyPrefix, bool useCache, out string[] searchedLocations)
        {
            searchedLocations = _emptyLocations;

            if (String.IsNullOrEmpty(name))
            {
                return(String.Empty);
            }

            string areaName = GetAreaName(controllerContext.RouteData);

            //little hack to get nop's admin area to be in /Administration/ instead of /Nop/Admin/ or Areas/Admin/
            if (!string.IsNullOrEmpty(areaName) && areaName.Equals("admin", StringComparison.InvariantCultureIgnoreCase))
            {
                var newLocations = areaLocations.ToList();
                newLocations.Insert(0, "~/Administration/Views/{1}/{0}.cshtml");
                newLocations.Insert(0, "~/Administration/Views/Shared/{0}.cshtml");
                areaLocations = newLocations.ToArray();
            }

            bool usingAreas = !String.IsNullOrEmpty(areaName);
            List <ViewLocation> viewLocations = GetViewLocations(locations, (usingAreas) ? areaLocations : null);

            if (viewLocations.Count == 0)
            {
                throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture,
                                                                  "", locationsPropertyName));
            }

            bool   nameRepresentsPath = IsSpecificPath(name);
            string cacheKey           = CreateCacheKey(cacheKeyPrefix, name, (nameRepresentsPath) ? String.Empty : controllerName, areaName);

            if (useCache)
            {
                // Only look at cached display modes that can handle the context.
                IEnumerable <IDisplayMode> possibleDisplayModes = DisplayModeProvider.GetAvailableDisplayModesForContext(controllerContext.HttpContext, controllerContext.DisplayMode);
                foreach (IDisplayMode displayMode in possibleDisplayModes)
                {
                    string cachedLocation = ViewLocationCache.GetViewLocation(controllerContext.HttpContext, AppendDisplayModeToCacheKey(cacheKey, displayMode.DisplayModeId));

                    if (cachedLocation == null)
                    {
                        // If any matching display mode location is not in the cache, fall back to the uncached behavior, which will repopulate all of our caches.
                        return(null);
                    }

                    // A non-empty cachedLocation indicates that we have a matching file on disk. Return that result.
                    if (cachedLocation.Length > 0)
                    {
                        if (controllerContext.DisplayMode == null)
                        {
                            controllerContext.DisplayMode = displayMode;
                        }

                        return(cachedLocation);
                    }
                    // An empty cachedLocation value indicates that we don't have a matching file on disk. Keep going down the list of possible display modes.
                }

                // GetPath is called again without using the cache.
                return(null);
            }
            else
            {
                return(nameRepresentsPath
                    ? GetPathFromSpecificName(controllerContext, name, cacheKey, ref searchedLocations)
                    : GetPathFromGeneralName(controllerContext, viewLocations, name, controllerName, areaName, cacheKey, ref searchedLocations));
            }
        }
        public void GetAvailableDisplayModesReturnsOnlyModesThatCanHandleContext()
        {
            // Arrange
            Mock<HttpContextBase> httpContext = new Mock<HttpContextBase>(MockBehavior.Strict);
            var displayModeProvider = new DisplayModeProvider();
            displayModeProvider.Modes.Clear();
            var displayMode1 = new Mock<IDisplayMode>(MockBehavior.Strict);
            displayMode1.Setup(d => d.CanHandleContext(It.IsAny<HttpContextBase>())).Returns(false);
            displayModeProvider.Modes.Add(displayMode1.Object);

            var displayMode2 = new Mock<IDisplayMode>(MockBehavior.Strict);
            displayMode2.Setup(d => d.CanHandleContext(It.IsAny<HttpContextBase>())).Returns(true);
            displayModeProvider.Modes.Add(displayMode2.Object);

            var displayMode3 = new Mock<IDisplayMode>(MockBehavior.Strict);
            displayMode3.Setup(d => d.CanHandleContext(It.IsAny<HttpContextBase>())).Returns(false);
            displayModeProvider.Modes.Add(displayMode3.Object);

            // Act
            var availableDisplayModes = displayModeProvider.GetAvailableDisplayModesForContext(httpContext.Object, displayMode1.Object, requireConsistentDisplayMode: false).ToList();

            // Assert
            Assert.Equal(1, availableDisplayModes.Count);
            Assert.Equal(displayMode2.Object, availableDisplayModes[0]);
        }
Esempio n. 11
0
        protected virtual string ResolveViewPath(
            ControllerContext controllerContext,
            string areaName,
            string[] locations,
            string[] areaLocations,
            string locationsPropertyName,
            string name,
            string controllerName,
            string theme,
            string cacheKeyPrefix,
            bool useCache,
            out string[] searchedLocations)
        {
            searchedLocations = _emptyLocations;

            if (String.IsNullOrEmpty(name))
            {
                return(String.Empty);
            }

            bool usingAreas = !String.IsNullOrEmpty(areaName);

            if (usingAreas)
            {
                var isAdminArea = areaName.IsCaseInsensitiveEqual("admin");

                // "ExtraAreaViewLocations" gets injected by AdminThemedAttribute
                var extraAreaViewLocations = controllerContext.RouteData.DataTokens["ExtraAreaViewLocations"] as string[];

                if (extraAreaViewLocations != null && extraAreaViewLocations.Length > 0)
                {
                    var newLocations = areaLocations.ToList();
                    var viewType     = cacheKeyPrefix == "Partial"
                                                ? ViewType.Partial
                                                : ViewType.Layout;

                    if (isAdminArea)
                    {
                        // the admin area cannot fallback to itself. Prepend to list.
                        ExpandLocationFormats(extraAreaViewLocations, viewType).Reverse().Each(x => newLocations.Insert(0, x));
                    }
                    else
                    {
                        newLocations.AddRange(ExpandLocationFormats(extraAreaViewLocations, viewType));
                    }

                    areaLocations = newLocations.ToArray();
                }
            }

            var viewLocations = GetViewLocations(locations, (usingAreas) ? areaLocations : null);

            if (viewLocations.Count == 0)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, "Properties cannot be null or empty.", new object[] { locationsPropertyName }));
            }

            bool   nameRepresentsPath = IsSpecificPath(name);
            string cacheKey           = CreateCacheKey(cacheKeyPrefix, name, (nameRepresentsPath) ? String.Empty : controllerName, areaName, theme);

            if (useCache)
            {
                // Only look at cached display modes that can handle the context.
                var possibleDisplayModes = DisplayModeProvider.GetAvailableDisplayModesForContext(controllerContext.HttpContext, controllerContext.DisplayMode);
                foreach (var displayMode in possibleDisplayModes)
                {
                    string cachedLocation = ViewLocationCache.GetViewLocation(controllerContext.HttpContext, AppendDisplayModeToCacheKey(cacheKey, displayMode.DisplayModeId));

                    if (cachedLocation == null)
                    {
                        // If any matching display mode location is not in the cache, fall back to the uncached behavior, which will repopulate all of our caches.
                        return(null);
                    }

                    // A non-empty cachedLocation indicates that we have a matching file on disk. Return that result.
                    if (cachedLocation.Length > 0)
                    {
                        if (controllerContext.DisplayMode == null)
                        {
                            controllerContext.DisplayMode = displayMode;
                        }

                        return(cachedLocation);
                    }
                    // An empty cachedLocation value indicates that we don't have a matching file on disk. Keep going down the list of possible display modes.
                }

                // ResolveViewPath is called again without using the cache.
                return(null);
            }
            else
            {
                return(nameRepresentsPath
                                        ? GetPathFromSpecificName(controllerContext, name, cacheKey, ref searchedLocations)
                                        : GetPathFromGeneralName(controllerContext, viewLocations, name, controllerName, areaName, theme, cacheKey, ref searchedLocations));
            }
        }
 /// <summary>
 /// Method returns display modes that are valid for current request context
 /// </summary>
 /// <param name="controllerContext">Current controller context</param>
 /// <returns>Valid display modes for current request ordered by their priority (e.g. ["Tablet", "Mobile", ""])</returns>
 private string[] GetAvailableDisplayModesForContext(ControllerContext controllerContext)
 {
     return(DisplayModeProvider.GetAvailableDisplayModesForContext(controllerContext.HttpContext, controllerContext.DisplayMode)
            .Select(mode => mode.DisplayModeId)
            .ToArray());
 }
Esempio n. 13
0
        protected virtual string GetPath(ControllerContext controllerContext, string[] locations, string[] areaLocations, string locationsPropertyName, string name, string controllerName, string cacheKeyPrefix, bool useCache, out string[] searchedLocations)
        {
            searchedLocations = _emptyLocations;

            if (String.IsNullOrEmpty(name))
            {
                return(String.Empty);
            }

            string assembilesname = Assembly.GetAssembly(controllerContext.Controller.GetType()).GetName().Name;
            string areaName       = GetAreaName(controllerContext.RouteData);

            areaName = (areaName == null ? (controllerContext.RouteData.DataTokens["Namespaces"] as string[])[0].Replace(".Controllers", "") : areaName);

            var newLocations = areaLocations.ToList();
            var typeAgent    = EngineContext.Current.Resolve <ITypeFinder>();

            newLocations.Insert(0, "~/Applications/" + assembilesname + "/Views/{1}/{0}.cshtml");
            newLocations.Insert(0, "~/Applications/" + assembilesname + "/Views/Shared/{0}.cshtml");
            areaLocations = newLocations.ToArray();

            bool usingAreas = !String.IsNullOrEmpty(areaName);

            List <ViewLocation> viewLocations = GetViewLocations(locations, (usingAreas) ? areaLocations : null);


            if (viewLocations.Count == 0)
            {
                throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, "Properties cannot be null or empty - {0}", locationsPropertyName));
            }

            bool   nameRepresentsPath = IsSpecificPath(name);
            string cacheKey           = CreateCacheKey(cacheKeyPrefix, name, (nameRepresentsPath) ? String.Empty : controllerName, areaName);

            if (useCache)
            {
                // Only look at cached display modes that can handle the context.
                IEnumerable <IDisplayMode> possibleDisplayModes = DisplayModeProvider.GetAvailableDisplayModesForContext(controllerContext.HttpContext, controllerContext.DisplayMode);
                foreach (IDisplayMode displayMode in possibleDisplayModes)
                {
                    string cachedLocation = ViewLocationCache.GetViewLocation(controllerContext.HttpContext, AppendDisplayModeToCacheKey(cacheKey, displayMode.DisplayModeId));

                    if (cachedLocation == null)
                    {
                        // If any matching display mode location is not in the cache, fall back to the uncached behavior, which will repopulate all of our caches.
                        return(nameRepresentsPath
                            ? GetPathFromSpecificName(controllerContext, name, cacheKey, ref searchedLocations)
                            : GetPathFromGeneralName(controllerContext, viewLocations, name, controllerName, areaName, cacheKey, ref searchedLocations));
                    }

                    // A non-empty cachedLocation indicates that we have a matching file on disk. Return that result.
                    if (cachedLocation.Length > 0)
                    {
                        if (controllerContext.DisplayMode == null)
                        {
                            controllerContext.DisplayMode = displayMode;
                        }

                        return(cachedLocation);
                    }
                    // An empty cachedLocation value indicates that we don't have a matching file on disk. Keep going down the list of possible display modes.
                }

                // GetPath is called again without using the cache.
                return(null);
            }
            else
            {
                return(nameRepresentsPath
                    ? GetPathFromSpecificName(controllerContext, name, cacheKey, ref searchedLocations)
                    : GetPathFromGeneralName(controllerContext, viewLocations, name, controllerName, areaName, cacheKey, ref searchedLocations));
            }
        }