public UIRouterConfig GetFormatConfig()
        {
            UIRouterConfig result = new UIRouterConfig();

            //format ui router
            if (null != this.UIRouter && this.UIRouter.Count > 0)
            {
                foreach (var router in this.UIRouter)
                {
                    var uirouter = RouterHelper.FormatStaticUIRouter(router.Key);
                    var filePath = router.Value;
                    if (!Path.IsPathRooted(filePath))
                    {
                        filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, filePath);
                    }

                    result.UIRouter.Add(uirouter, filePath);
                }
            }

            //format log router
            if (!string.IsNullOrWhiteSpace(this.LogRouter))
            {
                result.LogRouter = RouterHelper.FormatWebApiRouter(this.LogRouter);
            }

            //format log handler
            if (null != this.LogHandler)
            {
                result.LogHandler = this.LogHandler;
            }

            return(result);
        }
Example #2
0
        public static IAppBuilder UseUIRouter(this IAppBuilder app, UIRouterConfig config)
        {
            //use cros middleware
            app.UseCors(CorsOptions.AllowAll);


            //format user input config
            config = config.GetFormatConfig();


            if (!string.IsNullOrWhiteSpace(config.LogRouter))
            {
                //use log api middleware
                LoggingEvent.LogHandler = config.LogHandler;

                try
                {
                    var webApiConfig = new HttpConfiguration();
                    webApiConfig.Routes.MapHttpRoute(
                        name: "UIRouterLoggApi",
                        routeTemplate: config.LogRouter,
                        defaults: new { controller = "Log" }
                        );
                    app.UseWebApi(webApiConfig);
                }
                catch (System.Exception)
                {
                    throw new Exception("Log router setting constains error!");
                }
            }


            try
            {
                //use ui static files server middleware
                foreach (var item in config.UIRouter)
                {
                    var fileSystem = new PhysicalFileSystem(item.Value);

                    var options = new FileServerOptions
                    {
                        EnableDirectoryBrowsing = true,
                        FileSystem  = fileSystem,
                        RequestPath = new PathString(item.Key)
                    };

                    app.UseFileServer(options);
                }
            }
            catch (Exception e)
            {
                throw new Exception($"UI router settings contain error: {e.ToString()}");
            }


            return(app);
        }