Пример #1
0
        private static void LoadRoutes(
            RoutesConfig config,
            XmlNode documentElement
            )
        {
            if (documentElement.Name != "Routes") return;

            foreach (XmlNode node in documentElement.ChildNodes)
            {
                if (node.Name == "IRegisterRoutes")
                {

                    XmlAttributeCollection attributeCollection
                        = node.Attributes;

                    if (attributeCollection["type"] != null
                        && typeof(IRegisterRoutes).IsAssignableFrom(Type.GetType(attributeCollection["type"].Value)))
                    {
                        IRegisterRoutes registrar = Activator.CreateInstance(Type.GetType(attributeCollection["type"].Value)) as IRegisterRoutes;
                        config.RouteRegistrars.Add(registrar);
                    }

                }
            }
        }
Пример #2
0
        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new HandleErrorAttribute());

            try
            {
                RoutesConfig registrarConfig = RoutesConfig.GetConfig();

                foreach (IRegisterRoutes registrar in registrarConfig.RouteRegistrars)
                {
                    try
                    {
                        registrar.RegisterGlobalFilters(filters);
                    }
                    catch (Exception ex)
                    {
                        log.Error(ex);
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
            }
        }
Пример #3
0
        private static void LoadRoutes(
            RoutesConfig config,
            XmlNode documentElement
            )
        {
            if (documentElement.Name != "Routes")
            {
                return;
            }

            foreach (XmlNode node in documentElement.ChildNodes)
            {
                if (node.Name == "IRegisterRoutes")
                {
                    XmlAttributeCollection attributeCollection
                        = node.Attributes;

                    if (attributeCollection["type"] != null &&
                        typeof(IRegisterRoutes).IsAssignableFrom(Type.GetType(attributeCollection["type"].Value)))
                    {
                        IRegisterRoutes registrar = Activator.CreateInstance(Type.GetType(attributeCollection["type"].Value)) as IRegisterRoutes;
                        config.RouteRegistrars.Add(registrar);
                    }
                }
            }
        }
Пример #4
0
        public static void Register(HttpConfiguration config)
        {
            // enable attribute routing
            config.MapHttpAttributeRoutes();

            try
            {
                RoutesConfig registrarConfig = RoutesConfig.GetConfig();

                foreach (IRegisterRoutes registrar in registrarConfig.RouteRegistrars)
                {
                    try
                    {
                        registrar.Register(config);
                    }
                    catch (Exception ex)
                    {
                        log.Error(ex);
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
            }


            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
                );
        }
Пример #5
0
        public static void Register(HttpConfiguration config)
        {
            // enable attribute routing
            config.MapHttpAttributeRoutes();

            try
            {
                RoutesConfig registrarConfig = RoutesConfig.GetConfig();

                foreach (IRegisterRoutes registrar in registrarConfig.RouteRegistrars)
                {
                    try
                    {
                        registrar.Register(config);
                    }
                    catch (Exception ex)
                    {
                        log.Error(ex);
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
            }

            Mapper.Initialize(c => c.AddProfile <MappingProfile>());

            var settings = config.Formatters.JsonFormatter.SerializerSettings;

            settings.ContractResolver = new CamelCasePropertyNamesContractResolver();
            // Comment out line below for production
            settings.Formatting = Newtonsoft.Json.Formatting.Indented;
            // The setting below is to make the Angular File Manager work
            settings.DateFormatString = "yyyy-MM-dd HH:mm:ss";

            config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html"));
            config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("multipart/form-data"));
            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
                );

            config.Routes.MapHttpRoute(
                name: "FileService",
                routeTemplate: "FileService/{controller}/{id}",
                defaults: new { controller = "FileService", id = RouteParameter.Optional, action = RouteParameter.Optional }
                );

            //config.Routes.MapHttpRoute(
            //	name: "BadWord",
            //	routeTemplate: "BadWord/{action}/{id}",
            //	defaults: new {controller = "BadWord", action = "CheckString", id = RouteParameter.Optional }
            //);
        }
Пример #6
0
        public static RoutesConfig GetConfig()
        {
            RoutesConfig config = new RoutesConfig();


            if (
                (HttpRuntime.Cache["RoutesConfig"] != null) &&
                (HttpRuntime.Cache["RoutesConfig"] is RoutesConfig)
                )
            {
                return((RoutesConfig)HttpRuntime.Cache["RoutesConfig"]);
            }


            String configFolderName = WebConfigSettings.RouteConfigPath; //"~/Setup/RouteRegistrars/";

            string pathToConfigFolder = System.Web.Hosting.HostingEnvironment.MapPath(configFolderName);

            if (!Directory.Exists(pathToConfigFolder))
            {
                return(config);
            }

            DirectoryInfo directoryInfo
                = new DirectoryInfo(pathToConfigFolder);

            FileInfo[] routeFiles = directoryInfo.GetFiles("*.config");

            foreach (FileInfo fileInfo in routeFiles)
            {
                XmlDocument routeConfigFile = new XmlDocument();
                routeConfigFile.Load(fileInfo.FullName);
                LoadRoutes(config, routeConfigFile.DocumentElement);
            }


            //cache can be cleared by touching Web.config
            CacheDependency cacheDependency
                = new CacheDependency(HttpContext.Current.Server.MapPath("~/Web.config"));


            HttpRuntime.Cache.Insert(
                "RoutesConfig",
                config,
                cacheDependency,
                DateTime.Now.AddMinutes(5),
                TimeSpan.Zero,
                CacheItemPriority.Default,
                null);

            return(config);
        }
Пример #7
0
        public static RoutesConfig GetConfig()
        {
            RoutesConfig config = new RoutesConfig();

            if (
                (HttpRuntime.Cache["RoutesConfig"] != null)
                && (HttpRuntime.Cache["RoutesConfig"] is RoutesConfig)
            )
            {
                return (RoutesConfig)HttpRuntime.Cache["RoutesConfig"];
            }

            String configFolderName = WebConfigSettings.RouteConfigPath; //"~/Setup/RouteRegistrars/";

            string pathToConfigFolder = System.Web.Hosting.HostingEnvironment.MapPath(configFolderName);

            if (!Directory.Exists(pathToConfigFolder)) return config;

            DirectoryInfo directoryInfo
                = new DirectoryInfo(pathToConfigFolder);

            FileInfo[] routeFiles = directoryInfo.GetFiles("*.config");

            foreach (FileInfo fileInfo in routeFiles)
            {
                XmlDocument routeConfigFile = new XmlDocument();
                routeConfigFile.Load(fileInfo.FullName);
                LoadRoutes(config, routeConfigFile.DocumentElement);

            }

             //cache can be cleared by touching Web.config
            CacheDependency cacheDependency
                = new CacheDependency(HttpContext.Current.Server.MapPath("~/Web.config"));

            HttpRuntime.Cache.Insert(
                "RoutesConfig",
                config,
                cacheDependency,
                DateTime.Now.AddMinutes(5),
                TimeSpan.Zero,
                CacheItemPriority.Default,
                null);

            return config;
        }
Пример #8
0
        public static void RegisterRoutes(RouteCollection routes)
        {
            try
            {
                routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

                routes.MapRoute(
                    name: "FileManager",
                    url: "FileManager/{action}/{id}",
                    defaults: new { controller = "FileManager", action = "Index", id = UrlParameter.Optional }
                    );

                //routes.MapRoute(
                //	name: "BadWord",
                //	url: "BadWord/{action}",
                //	defaults: new { controller = "BadWord", action = "CheckString" }
                //);

                RoutesConfig registrarConfig = RoutesConfig.GetConfig();

                foreach (IRegisterRoutes registrar in registrarConfig.RouteRegistrars)
                {
                    try
                    {
                        registrar.RegisterRoutes(routes);
                    }
                    catch (Exception ex)
                    {
                        log.Error(ex);
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
            }

            //if (WebConfigSettings.AddDefaultMvcRoute)
            //{
            //	routes.MapRoute(
            //		name: "Default",
            //		url: "{controller}/{action}/{id}",
            //		defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            //	);
            //}
        }