Beispiel #1
0
        public static RouteValueDictionary GetRouteViewDictionary(string areaName, string moduleName, IDictionary <string, object> dictionary)
        {
            RouteValueDictionary routeValues = dictionary != null ? new RouteValueDictionary(dictionary) : new RouteValueDictionary();

            routeValues["area"] = AreaHelpers.FormatMvcAreaName(areaName, moduleName);
            return(routeValues);
        }
        internal static void DetermineAreaAndModule <TController>(RouteCollection routes, out string areaName, out string moduleName) where TController : ControllerBase
        {
            areaName = moduleName = null;

            string controllerNamespace = typeof(TController).Namespace;

            if (string.IsNullOrEmpty(controllerNamespace))
            {
                throw new ArgumentException("The controller type is not defines a namespace.");
            }

            foreach (RouteBase route in from r in routes
                     let ns = RouteHelpers.GetMvcNamespaces(r)
                              where ns != null && ns.Contains(controllerNamespace)
                              select r)
            {
                if (!string.IsNullOrEmpty(areaName) && !string.IsNullOrEmpty(moduleName))
                {
                    break;
                }

                if (string.IsNullOrEmpty(areaName))
                {
                    areaName = AreaHelpers.GetAreaName(route);
                }
                if (string.IsNullOrEmpty(moduleName))
                {
                    moduleName = AreaHelpers.GetModuleName(route);
                }
            }
        }
Beispiel #3
0
        public static RouteValueDictionary GetRouteViewDictionary(string areaName, string moduleName, object arguments)
        {
            RouteValueDictionary routeValues = arguments != null ? new RouteValueDictionary(arguments) : new RouteValueDictionary();

            routeValues["area"] = AreaHelpers.FormatMvcAreaName(areaName, moduleName);
            return(routeValues);
        }
Beispiel #4
0
        public static RouteValueDictionary GetRouteViewDictionary(string areaName, string moduleName)
        {
            RouteValueDictionary routeValues = new RouteValueDictionary();

            routeValues["area"] = AreaHelpers.FormatMvcAreaName(areaName, moduleName);
            return(routeValues);
        }
        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));
            }
        }
Beispiel #6
0
 public ModuleAreaRegistrationContext(string moduleAreaName, string moduleName, RouteCollection routes, object state)
     : base(moduleName, routes, state)
 {
     typeof(AreaRegistrationContext).GetProperty(((MemberExpression)((Expression <Func <AreaRegistrationContext, string> >)((obj) => obj.AreaName)).Body).Member.Name, BindingFlags.Instance | BindingFlags.Public).SetValue(this, AreaHelpers.FormatMvcAreaName(this.ModuleAreaName = moduleAreaName, this.ModuleName = moduleName), null);
 }
 public static string ModularAction(this UrlHelper helper, string actionName, string controllerName, string areaName, string moduleName, IDictionary <string, object> dictionary)
 {
     return(helper.Action(actionName, controllerName, AreaHelpers.GetRouteViewDictionary(areaName, moduleName, dictionary)));
 }
 public static string ModularAction(this UrlHelper helper, string actionName, string controllerName, string areaName, object arguments)
 {
     return(helper.Action(actionName, controllerName, AreaHelpers.GetRouteViewDictionary(areaName, AreaHelpers.GetModuleName(helper.RequestContext.RouteData), arguments)));
 }