示例#1
0
        /// <summary>
        /// 映射Area路由数据
        /// </summary>
        /// <param name="area"></param>
        /// <param name="routes"></param>
        /// <param name="state"></param>
        public static void CreateContextAndRegister(this AreaRegistration area, RouteCollection routes, object state)
        {
            AreaRegistrationContext context = new AreaRegistrationContext(area.AreaName, routes, state);
            string thisNamespace            = area.GetType().Namespace;

            if (thisNamespace != null)
            {
                context.Namespaces.Add(thisNamespace + ".*");
            }
            area.RegisterArea(context);
        }
示例#2
0
        public static void RegisterArea(Type t, RouteCollection routes, object state)
        {
            AreaRegistration        registration = (AreaRegistration)Activator.CreateInstance(t);
            AreaRegistrationContext context      = new AreaRegistrationContext(registration.AreaName, routes, state);
            string tNamespace = registration.GetType().Namespace;

            if (tNamespace != null)
            {
                context.Namespaces.Add(tNamespace + ".*");
            }
            registration.RegisterArea(context);
        }
示例#3
0
        private static void RegisterArea(AreaRegistration registration, object state)
        {
            var    context = new AreaRegistrationContext(registration.AreaName, RouteTable.Routes, state);
            string ns      = registration.GetType().Namespace;

            if (ns != null)
            {
                context.Namespaces.Add(string.Format("{0}.*", ns));
            }

            registration.RegisterArea(context);
        }
示例#4
0
        private static void RegisterArea <T>(RouteCollection routes, object state) where T : AreaRegistration
        {
            AreaRegistration        registration        = (AreaRegistration)Activator.CreateInstance(typeof(T));
            AreaRegistrationContext registrationContext = new AreaRegistrationContext(registration.AreaName, routes, state);
            string areaNamespace = registration.GetType().Namespace;

            if (!String.IsNullOrEmpty(areaNamespace))
            {
                registrationContext.Namespaces.Add(areaNamespace + ".*");
            }
            registration.RegisterArea(registrationContext);
        }
示例#5
0
    private static void RegisterArea <T>(RouteCollection routes, object?state) where T : AreaRegistration
    {
        AreaRegistration        registration = (AreaRegistration)Activator.CreateInstance(typeof(T));
        AreaRegistrationContext context      = new(registration.AreaName, routes, state);
        string typeNamespace = registration.GetType().Namespace;

        if (typeNamespace != null)
        {
            context.Namespaces.Add(typeNamespace + ".*");
        }

        registration.RegisterArea(context);
    }
示例#6
0
        public RouteData GetAreaRouteData(string url, AreaRegistration areaConfig)
        {
            var routes = new RouteCollection();

            var areaContext = new AreaRegistrationContext(areaConfig.AreaName, routes);

            areaConfig.RegisterArea(areaContext);

            var context = new StubHttpContextForRouting(requestUrl: url);

            var routeData = routes.GetRouteData(context);

            return(routeData);
        }
示例#7
0
        private static void RegisterArea(AreaRegistration areaRegistration)
        {
            Sitecore.Diagnostics.Log.Info("Started RegisterArea", " RegisterArea ");
            var context = new AreaRegistrationContext(areaRegistration.AreaName, RouteTable.Routes);

            string @namespace = areaRegistration.GetType().Namespace;

            if (@namespace != null)
            {
                context.Namespaces.Add(@namespace + ".*");
            }

            areaRegistration.RegisterArea(context);
            Sitecore.Diagnostics.Log.Info("Ended RegisterArea", " RegisterArea");
        }
示例#8
0
        private static ModuleBase initModule(ModuleInfo module, object state)
        {
            string message        = "";
            Type   entryPointType = module.EntryType;

            try
            {
                if (entryPointType == null && module.Assembly != null)
                {
                    entryPointType = module.Assembly.GetTypes().Where(p =>
                                                                      typeof(AreaRegistration).IsAssignableFrom(p) &&            // should be subclass of AreaRegistration
                                                                      typeof(ModuleBase).IsAssignableFrom(p) &&                  // should be subcalss of ModuleBase
                                                                      p.GetConstructor(Type.EmptyTypes) != (ConstructorInfo)null // should have a paramterless ctor
                                                                      ).FirstOrDefault();
                }

                if (entryPointType != null)
                {
                    AreaRegistration ar = ((AreaRegistration)Activator.CreateInstance(entryPointType));

                    AreaRegistrationContext arc = new AreaRegistrationContext(module.Id, RouteTable.Routes, state);
                    string nameSpace            = entryPointType.Namespace;
                    if (nameSpace != null)
                    {
                        arc.Namespaces.Add(nameSpace + ".*");
                    }
                    ar.RegisterArea(arc);
                    return(ar as ModuleBase);
                }
                else
                {
                    message = string.Format("Could not find the entry point type for module '{0}'. Each module should have a class that is a subtype of 'ModuleBase'.", module.Id);
                }
            }
            catch (Exception ex)
            {
                //message = string.Format("Can not create an object of type '{0}' for module '{1}'.", entryPointType, module.Id);
                message = string.Format("An exception was thrown while instantiating '{2}', which is the entry point of module '{0}'. Details: {1}", module.Id, ex.Message, entryPointType);
            }
            // should not reach here!!
            LoggerFactory.GetFileLogger().LogCustom(message);
            return(null);
            //throw new Exception(message);
        }
        private static void RegisterArea(AreaRegistration areaRegistration, RouteCollection routeCollection)
        {
            var context = new AreaRegistrationContext(areaRegistration.AreaName, routeCollection);

            areaRegistration.RegisterArea(context);
        }
示例#10
0
        /// <summary>
        /// Manual register area
        /// </summary>
        /// <param name="areaRegistration">Area registration from Areas folder</param>
        public static void RegisterArea(AreaRegistration areaRegistration)
        {
            var areaContext = new AreaRegistrationContext(areaRegistration.AreaName, RouteTable.Routes);

            areaRegistration.RegisterArea(areaContext);
        }