public IEnumerable<string> ExpandViewLocations(
     ViewLocationExpanderContext context,
     IEnumerable<string> viewLocations)
 {
     yield return "~/UI/{1}/Views/{0}.cshtml";
     yield return "~/UI/SharedViews/{0}.cshtml";
 }
        public IEnumerable<string> ExpandViewLocations(ViewLocationExpanderContext context,
            IEnumerable<string> viewLocations)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (viewLocations == null)
            {
                throw new ArgumentNullException(nameof(viewLocations));
            }

            var controllerActionDescriptor = context.ActionContext.ActionDescriptor as ControllerActionDescriptor;
            if (controllerActionDescriptor == null)
            {
                throw new NullReferenceException("ControllerActionDescriptor cannot be null.");
            }

            string featureName = controllerActionDescriptor.Properties["feature"] as string;
            foreach (var location in viewLocations)
            {
                yield return location.Replace("{3}", featureName);
            }
        }
Esempio n. 3
0
        /// <inheritdoc />
        public IEnumerable<string> ExpandViewLocations(ViewLocationExpanderContext context, IEnumerable<string> viewLocations)
        {
            var resultValues = new List<string>();

            string currentSiteName;
            if (context.Values.TryGetValue(CurrentSiteKey, out currentSiteName))
            {
                resultValues.Add($"/tenants/{currentSiteName}/Views/Pages/{{0}}.cshtml");
                resultValues.Add($"/tenants/{currentSiteName}/Views/{{2}}/{{1}}/{{0}}.cshtml");
                resultValues.Add($"/tenants/{currentSiteName}/Views/{{2}}/Shared/{{0}}.cshtml");
            }

            string currentTheme;
            if (context.Values.TryGetValue(CurrentThemeKey, out currentTheme))
            {
                resultValues.Add($"/Themes/{currentTheme}/Views/{{1}}/{{0}}.cshtml");
                resultValues.Add($"/Themes/{currentTheme}/Views/Shared/{{0}}.cshtml");
            }

            string currentAdminTheme;
            if (context.Values.TryGetValue(CurrentAdminThemeKey, out currentAdminTheme) && currentAdminTheme != currentTheme)
            {
                resultValues.Add($"/Themes/{currentAdminTheme}/Views/{{1}}/{{0}}.cshtml");
                resultValues.Add($"/Themes/{currentAdminTheme}/Views/Shared/{{0}}.cshtml");
            }

            resultValues.Add("/extensions/{2}/Views/{1}/{0}.cshtml");
            resultValues.Add("/extensions/{2}/Views/Shared/{0}.cshtml");

            resultValues.Add("/core/itasu.core/Views/{1}/{0}.cshtml");
            resultValues.Add("/core/itasu.core/Views/Shared/{0}.cshtml");

            resultValues.AddRange(viewLocations);
            return resultValues;
        }
        /// <inheritdoc />
        public virtual IEnumerable<string> ExpandViewLocations(
            ViewLocationExpanderContext context,
            IEnumerable<string> viewLocations)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (viewLocations == null)
            {
                throw new ArgumentNullException(nameof(viewLocations));
            }

            string value;
            context.Values.TryGetValue(ValueKey, out value);

            if (!string.IsNullOrEmpty(value))
            {
                CultureInfo culture;
                try
                {
                    culture = new CultureInfo(value);
                }
                catch (CultureNotFoundException)
                {
                    return viewLocations;
                }

                return ExpandViewLocationsCore(viewLocations, culture);
            }

            return viewLocations;
        }
        public void PopulateValues(ViewLocationExpanderContext context)
        {
            context.Values[THEME_KEY]
                = context.ActionContext.HttpContext.GetTenant<AppTenant>()?.Theme;

            context.Values[TENANT_KEY]
                = context.ActionContext.HttpContext.GetTenant<AppTenant>()?.Name.Replace(" ", "-");
        }
Esempio n. 6
0
 /// <summary>
 /// Pobiera nazwę kontrolera który wywołal akcję.
 /// </summary>
 /// <param name="context"></param>
 public void PopulateValues(ViewLocationExpanderContext context)
 {
     var controller = context.ActionContext.ActionDescriptor.DisplayName;
     var moduleName = controller.Split('.')[0];
     if (moduleName != "PersonalTrainer")
     {
         context.Values[_moduleKey] = moduleName;
     }
 }
        public void PopulateValues(ViewLocationExpanderContext context)
        {
            context.Values[THEME_KEY]
                = context.ActionContext.HttpContext.GetTenant<SiteContext>()?.Theme;

            var tenantKey = context.ActionContext.HttpContext.GetTenant<SiteContext>()?.AliasId;
            //if(string.IsNullOrWhiteSpace(tenantKey)) tenantKey = "tenant-" + context.ActionContext.HttpContext.GetTenant<SiteSettings>()?.SiteGuid.ToString();

            context.Values[TENANT_KEY] = tenantKey;
        }
        public void PopulateValues(ViewLocationExpanderContext context)
        {
            var appContext = context.ActionContext.HttpContext.RequestServices
                        .GetService(typeof(IApplicationContext)) as IApplicationContext;

            if (appContext != null && !string.IsNullOrEmpty(appContext.CurrentBlog.Theme))
            {
                context.Values["theme"] = appContext.CurrentBlog.Theme;
            }
        }
 public IEnumerable<string> ExpandViewLocations(ViewLocationExpanderContext context, IEnumerable<string> viewLocations)
 {
     var enumerable = viewLocations as string[] ?? viewLocations.ToArray();
     var themeLocations = enumerable.ToList();
     if (context.Values.ContainsKey("theme"))
     {
         themeLocations.InsertRange(0, enumerable.Select(f => f.Replace("/Views/", "/Views/" + context.Values["theme"] + "/")));
     }
     return themeLocations;
 }
        public void PopulateValues(ViewLocationExpanderContext context)
        {
            var subArea = context.ActionContext.ActionDescriptor.RouteConstraints.FirstOrDefault(
                s => s.RouteKey == "subarea" && !string.IsNullOrEmpty(s.RouteValue));

            if (subArea != null)
            {
                context.Values[_subAreaKey] = subArea.RouteValue;
            }
        }
Esempio n. 11
0
 /// <inheritdoc />
 public void PopulateValues(ViewLocationExpanderContext context)
 {
     var tenantContext = context.ActionContext.HttpContext.Features.Get<ITenantContext>();
     if (tenantContext != null)
     {
         context.Values.Add(CurrentSiteKey, tenantContext.Tenant.TenantId);
         context.Values.Add(CurrentThemeKey, "Prototype");
         context.Values.Add(CurrentAdminThemeKey, "Dashboard");
     }
 }
        public void ExpandViewLocations_ReturnsViewLocations()
        {
            ActionContext context = new ActionContext(new DefaultHttpContext(), new RouteData(), new ActionDescriptor());
            ViewLocationExpanderContext expander = new ViewLocationExpanderContext(context, "Index", null, null, true);

            IEnumerable<String> expected = new[] { "/Views/{1}/{0}.cshtml", "/Views/Shared/{0}.cshtml" };
            IEnumerable<String> actual = new ViewLocationExpander().ExpandViewLocations(expander, null);

            Assert.Equal(expected, actual);
        }
        public virtual IEnumerable<string> ExpandViewLocations(
            ViewLocationExpanderContext context,
            IEnumerable<string> viewLocations)
        {
            if (context.IsMainPage)
            {
                return viewLocations;
            }

            return ExpandViewLocationsCore(viewLocations);
        }
 public IEnumerable<string> ExpandViewLocations(
           ViewLocationExpanderContext context,
           IEnumerable<string> viewLocations)
 {
     return new[]{
         "~/{1}/Views/{0}.cshtml",
         "~/{1}/Views/shared/{0}.cshtml",
         "~/Views/Shared/{0}.cshtml",
         "/Views/{1}/{0}.cshtml",
         "~/Views/{1}/{0}.cshtml"
     };
 }
        /// <inheritdoc />
        public virtual IEnumerable<string> ExpandViewLocations(ViewLocationExpanderContext context,
                                                               IEnumerable<string> viewLocations)
        {
            var result = new List<string>();

            result.Add("/Modules/{2}/Views/{1}/{0}.cshtml");
            result.Add("/Modules/{2}/Views/Shared/{0}.cshtml");

            result.AddRange(viewLocations);

            return result;
        }
        public IEnumerable<string> ExpandViewLocations(ViewLocationExpanderContext context, IEnumerable<string> viewLocations)
        {
            var controllerActionDescriptor =
              context.ActionContext.ActionDescriptor as ControllerActionDescriptor;

            var featureName = controllerActionDescriptor.Properties["feature"] as string;

            foreach (var location in viewLocations)
            {
                yield return location.Replace("{3}", featureName);
            }
        }
 public IEnumerable<string> ExpandViewLocations(
     ViewLocationExpanderContext context,
     IEnumerable<string> viewLocations)
 {
     if (context.Values.ContainsKey(_subAreaKey))
     {
         var subArea = RazorViewEngine.GetNormalizedRouteValue(context.ActionContext, _subAreaKey);
         var subareaViewLocations = new string[]
         {
             "/Areas/{2}/Areas/" + subArea + "/Views/{1}/{0}.cshtml"
         };
         viewLocations = subareaViewLocations.Concat(viewLocations);
     }
     return viewLocations;
 }
 public IEnumerable<string> ExpandViewLocations(ViewLocationExpanderContext context, IEnumerable<string> viewLocations)
 {
     var actionDescriptor = (ControllerActionDescriptor)context.ActionContext.ActionDescriptor;
     var pluginManager = context.ActionContext.HttpContext.RequestServices.GetRequiredService<IPluginManager>();
     var pluginInfo = pluginManager[actionDescriptor.ControllerTypeInfo];
     if (pluginInfo!=null)
     {
         var prefix = pluginInfo.Plugin.UrlPrefix;
         //yield return "/" + prefix + "/Views/{1}/{0}.cshtml";
         yield return "/Views/" + prefix + "/{1}/{0}.cshtml";
         //yield return "/" + prefix + "/Views/Shared/{0}.cshtml";
         yield return "/Views/" + prefix + "/Shared/{0}.cshtml";
     }
     foreach(var viewLocation in viewLocations)
         yield return viewLocation;
 }
        public IEnumerable<String> ExpandViewLocations(ViewLocationExpanderContext context, IEnumerable<String> locations)
        {
            if (RazorViewEngine.GetNormalizedRouteValue(context.ActionContext, "area") != null)
            {
                return new[]
                {
                    "/Views/{2}/Shared/{0}.cshtml",
                    "/Views/{2}/{1}/{0}.cshtml",
                    "/Views/Shared/{0}.cshtml"
                };
            }

            return new[]
            {
                "/Views/{1}/{0}.cshtml",
                "/Views/Shared/{0}.cshtml"
            };
        }
Esempio n. 20
0
        public IEnumerable<String> ExpandViewLocations(ViewLocationExpanderContext context, IEnumerable<String> viewLocations)
        {
            if (context.Values.ContainsKey(_moduleKey))
            {
                var module = context.Values[_moduleKey];
                if (!String.IsNullOrWhiteSpace(module))
                {
                    List<String> moduleViewLocations = new List<String>();
                    moduleViewLocations.Add("/Modules/" + module + ".WebGUI/Views/{1}/{0}.cshtml");
                    moduleViewLocations.Add("/Modules/" + module + ".WebGUI/Views/Shared/{0}.cshtml");
                    if (module != "PersonalTrainerCore")
                        moduleViewLocations.Add("/Modules/" + "PersonalTrainerCore" + ".WebGUI/Views/Shared/{0}.cshtml");

                    viewLocations = moduleViewLocations.Concat(viewLocations);
                }
            }
            return viewLocations;
        }
        public IEnumerable<string> ExpandViewLocations(ViewLocationExpanderContext context, IEnumerable<string> viewLocations)
        {
            string theme = null;

            if (context.Values.TryGetValue(THEME_KEY, out theme))
            {
                IEnumerable<string> themeLocations = new[]
                {
                    $"/Themes/{theme}/{{1}}/{{0}}.cshtml",
                    $"/Themes/{theme}/Shared/{{0}}.cshtml",
                    $"/Themes/{theme}/EmailTemplates/{{0}}.cshtml"
                };

                viewLocations = themeLocations.Concat(viewLocations);
            }

            return viewLocations;
        }
        public IEnumerable<string> ExpandViewLocations(ViewLocationExpanderContext context, IEnumerable<string> viewLocations)
        {
            string tenant = null;
            string theme = null;

            if (context.Values.TryGetValue(THEME_KEY, out theme))
            {
                if (context.Values.TryGetValue(TENANT_KEY, out tenant))
                {
                    IEnumerable<string> themeLocations = new[]
                    {
                        $"/sitefiles/{tenant}/themes/{theme}/{{1}}/{{0}}.cshtml",
                        $"/sitefiles/{tenant}/themes/{theme}/Shared/{{0}}.cshtml"
                    };

                    viewLocations = themeLocations.Concat(viewLocations);
                }
                
            }

            return viewLocations;
        }
Esempio n. 23
0
 /// <summary>
 /// Invoked by a <see cref="T:Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine" /> to determine the values that would be consumed by this instance
 /// of <see cref="T:Microsoft.AspNetCore.Mvc.Razor.IViewLocationExpander" />. The calculated values are used to determine if the view location
 /// has changed since the last time it was located.
 /// </summary>
 /// <param name="context">The <see cref="T:Microsoft.AspNetCore.Mvc.Razor.ViewLocationExpanderContext" /> for the current view location
 /// expansion operation.</param>
 void IViewLocationExpander.PopulateValues(Microsoft.AspNetCore.Mvc.Razor.ViewLocationExpanderContext context)
 {
 }
Esempio n. 24
0
        /// <inheritdoc />
        public void PopulateValues(ViewLocationExpanderContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            // Using CurrentUICulture so it loads the locale specific resources for the views.
            #if NET451
            context.Values[ValueKey] = Thread.CurrentThread.CurrentUICulture.Name;
            #else
            context.Values[ValueKey] = CultureInfo.CurrentUICulture.Name;
            #endif
        }
 /// <inheritdoc />
 public void PopulateValues(ViewLocationExpanderContext context)
 {
 }
        public void ExpandViewLocations_SpecificPlugin(
            string pluginName, 
            bool exists,
            IEnumerable<string> viewLocations,
            IEnumerable<string> expectedViewLocations)
        {
            var pluginManagerMock = new Mock<IPluginManager>();
            if(exists)
                pluginManagerMock.Setup(pm => pm[It.IsAny<TypeInfo>()])
                    .Returns(new PluginInfo(new ModuleStub { UrlPrefix = pluginName }, null, null, null));;

            var services = new ServiceCollection();
            services.Add(new ServiceDescriptor(typeof(IPluginManager), pluginManagerMock.Object));

            var target = new PluginViewLocationExtender();
            var actionContext = new ActionContext { HttpContext = new DefaultHttpContext { RequestServices = services.BuildServiceProvider() } };
            actionContext.ActionDescriptor = new ControllerActionDescriptor { ControllerTypeInfo = typeof(object).GetTypeInfo() };
            var context = new ViewLocationExpanderContext(
               actionContext,
               "testView",
               "test-controller",
               "",
               false);

            var result = target.ExpandViewLocations(context, viewLocations);

            Assert.Equal(expectedViewLocations, result);
        }
 public void PopulateValues(ViewLocationExpanderContext context)
 {
     context.Values["customviewlocation"] = nameof(TuduManayerViewLocationExpander);
 }
 /// <inheritdoc />
 public virtual IEnumerable<string> ExpandViewLocations(ViewLocationExpanderContext context,
                                                        IEnumerable<string> viewLocations)
 {
     return ExpandViewLocationsCore(viewLocations);
 }
Esempio n. 29
0
        private ViewLocationCacheResult LocatePageFromViewLocations(
            ActionContext actionContext,
            string pageName,
            bool isMainPage)
        {
            var controllerName = GetNormalizedRouteValue(actionContext, ControllerKey);
            var areaName = GetNormalizedRouteValue(actionContext, AreaKey);
            var expanderContext = new ViewLocationExpanderContext(
                actionContext,
                pageName,
                controllerName,
                areaName,
                isMainPage);
            Dictionary<string, string> expanderValues = null;

            if (_options.ViewLocationExpanders.Count > 0)
            {
                expanderValues = new Dictionary<string, string>(StringComparer.Ordinal);
                expanderContext.Values = expanderValues;

                // Perf: Avoid allocations
                for (var i = 0; i < _options.ViewLocationExpanders.Count; i++)
                {
                    _options.ViewLocationExpanders[i].PopulateValues(expanderContext);
                }
            }

            var cacheKey = new ViewLocationCacheKey(
                expanderContext.ViewName,
                expanderContext.ControllerName,
                expanderContext.AreaName,
                expanderContext.IsMainPage,
                expanderValues);

            ViewLocationCacheResult cacheResult;
            if (!ViewLookupCache.TryGetValue(cacheKey, out cacheResult))
            {
                _logger.ViewLookupCacheMiss(cacheKey.ViewName, cacheKey.ControllerName);
                cacheResult = OnCacheMiss(expanderContext, cacheKey);
            }
            else
            {
                _logger.ViewLookupCacheHit(cacheKey.ViewName, cacheKey.ControllerName);
            }

            return cacheResult;
        }
Esempio n. 30
0
        private ViewLocationCacheResult OnCacheMiss(
            ViewLocationExpanderContext expanderContext,
            ViewLocationCacheKey cacheKey)
        {
            // Only use the area view location formats if we have an area token.
            IEnumerable<string> viewLocations = !string.IsNullOrEmpty(expanderContext.AreaName) ?
                _options.AreaViewLocationFormats :
                _options.ViewLocationFormats;

            for (var i = 0; i < _options.ViewLocationExpanders.Count; i++)
            {
                viewLocations = _options.ViewLocationExpanders[i].ExpandViewLocations(expanderContext, viewLocations);
            }

            ViewLocationCacheResult cacheResult = null;
            var searchedLocations = new List<string>();
            var expirationTokens = new HashSet<IChangeToken>();
            foreach (var location in viewLocations)
            {
                var path = string.Format(
                    CultureInfo.InvariantCulture,
                    location,
                    expanderContext.ViewName,
                    expanderContext.ControllerName,
                    expanderContext.AreaName);

                cacheResult = CreateCacheResult(expirationTokens, path, expanderContext.IsMainPage);
                if (cacheResult != null)
                {
                    break;
                }

                searchedLocations.Add(path);
            }

            // No views were found at the specified location. Create a not found result.
            if (cacheResult == null)
            {
                cacheResult = new ViewLocationCacheResult(searchedLocations);
            }

            var cacheEntryOptions = new MemoryCacheEntryOptions();
            cacheEntryOptions.SetSlidingExpiration(_cacheExpirationDuration);
            foreach (var expirationToken in expirationTokens)
            {
                cacheEntryOptions.AddExpirationToken(expirationToken);
            }

            return ViewLookupCache.Set<ViewLocationCacheResult>(cacheKey, cacheResult, cacheEntryOptions);
        }
 public void PopulateValues(ViewLocationExpanderContext context)
 {
     // Don't need anything here, but required by the interface
 }