// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(
            IApplicationBuilder app,
            IHostingEnvironment env,
            IApplicationLifetime applicationLifetime,
            IRouteAnalyzer routeAnalyzer
            )
        {
            m_routeAnalyzer = routeAnalyzer;

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseBrowserLink();
            }
            else
            {
                app.UseExceptionHandler("/Error");
            }

            app.UseStaticFiles();

            app.UseMvc(routes =>
            {
                routes.MapRouteAnalyzer("/routes");
                routes.MapRoute(
                    name: "default",
                    template: "{controller}/{action=Index}/{id?}");
            });

            // Lifetime events
            applicationLifetime.ApplicationStarted.Register(OnStarted);
            applicationLifetime.ApplicationStopping.Register(OnStopping);
            applicationLifetime.ApplicationStopped.Register(OnStopped);
        }
Esempio n. 2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(
            IApplicationBuilder app,
            IWebHostEnvironment env,
            IHostApplicationLifetime applicationLifetime,
            IRouteAnalyzer routeAnalyzer
            )
        {
            m_routeAnalyzer = routeAnalyzer;

            app.UseRouting();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseBrowserLink();
            }
            else
            {
                app.UseExceptionHandler("/Error");
            }

            app.UseStaticFiles();

            app.UseEndpoints(config =>
            {
                config.MapControllers();
                config.MapRouteAnalyzer();
            });

            // Lifetime events
            applicationLifetime.ApplicationStarted.Register(OnStarted);
            applicationLifetime.ApplicationStopping.Register(OnStopping);
            applicationLifetime.ApplicationStopped.Register(OnStopped);
        }
Esempio n. 3
0
        public IList <RouteInfo> GetAllRouteInfo()
        {
            var dllFile = Directory.GetFiles(Environment.CurrentDirectory, $"{this.projectName}.dll", SearchOption.AllDirectories).FirstOrDefault();

            if (string.IsNullOrEmpty(dllFile))
            {
                throw new ArgumentException($"No {this.projectName}.dll file found under the directory: {Environment.CurrentDirectory}.");
            }

            Console.WriteLine($"the project name:{this.projectName}.");
            Console.WriteLine($"find dll file:{dllFile}.");

            Assembly assembly = Assembly.LoadFile(dllFile);
            Type     type     = assembly.GetTypes().FirstOrDefault(o => o.Name == "Startup");

            if (type == null)
            {
                throw new ArgumentException($"No Startup.cs class found under the dll file: {dllFile}.");
            }

            var builder = new WebHostBuilder()
                          .UseEnvironment("Development")
                          .UseContentRoot(AppContext.BaseDirectory)
                          .UseStartup(type);

            TestServer     server   = new TestServer(builder);
            IRouteAnalyzer services = (IRouteAnalyzer)server.Host.Services.GetService(typeof(IRouteAnalyzer));
            var            client   = server.CreateClient();

            return(services.GetAllRouteInfo());
        }
Esempio n. 4
0
 public HomeController(
     ICurrent current,
     IPushService pushService,
     IRouteAnalyzer routeAnalyzer,
     IOnlineManager onlineManager,
     ILogger <HomeController> logger,
     ITokenService tokenService,
     IDeviceService deviceService,
     ITypeFinder typeFinder,
     ITypeResolve typeResolve,
     IDbContext dbContext,
     DbContextFactory dbContextFactory,
     ICache cache,
     IBackgroundJobManager backgroundJobManager,
     IOptions <HangfireOptions> hangfireOption)
 {
     _current              = current;
     _tokenService         = tokenService;
     _deviceService        = deviceService;
     _typeFinder           = typeFinder;
     _typeResolve          = typeResolve;
     _dbContext            = dbContext;
     _dbContextFactory     = dbContextFactory;
     _cache                = cache;
     _backgroundJobManager = backgroundJobManager;
     _hangfireOptions      = hangfireOption.Value;
     _pushService          = pushService;
     _routeAnalyzer        = routeAnalyzer;
     _logger               = logger;
 }
Esempio n. 5
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app,
                              IHostingEnvironment env,
                              IApplicationLifetime applicationLifetime,
                              UserManager <User> userManager,
                              RoleManager <IdentityRole> roleManager,
                              IRouteAnalyzer routeAnalyzer,
                              MoviesPlaceContext context)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseHsts();
            }

            app.UseMiddleware <JWTInHeaderMiddleware>();

            app.ConfigureExceptionHandler(_logger);

            app.UseHttpsRedirection();

            app.UseAuthentication();

            app.UseHttpsRedirection();

            app.SeedDatabase();

            app.UseMvc();

            applicationLifetime.ApplicationStarted.Register(() =>
            {
                var infos = routeAnalyzer.GetAllRouteInformations();
                Debug.WriteLine("======== ALL ROUTE INFORMATION ========");
                foreach (var info in infos)
                {
                    Debug.WriteLine(info.ToString());
                }
                Debug.WriteLine("");
                Debug.WriteLine("");
            });
        }
Esempio n. 6
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure
        (
            IApplicationBuilder app,
            IHostingEnvironment env,
            IApplicationLifetime applicationLifetime,
            IRouteAnalyzer routeAnalyzer,
            ILoggerFactory loggerFactory
        )
        {
            //Uncomment the following to view an incoming request and its path
            //app.Use(async (context, next) =>
            //{
            //    // Do work that doesn't write to the Response.
            //    await next.Invoke();
            //    // Do logging or other work that doesn't write to the Response.
            //});

            app.UseAuthentication();
            app.UseMvc();

            // Uncomment the following to view the routes and their actions that the WebApi finds at startup
            //var routeInfo = routeAnalyzer.GetAllRouteInformations();
        }
Esempio n. 7
0
 /// <summary>
 /// 初始化一个<see cref="DefaultRazorHtmlGenerator"/>类型的实例
 /// </summary>
 /// <param name="routeAnalyzer">路由分析器</param>
 public DefaultRazorHtmlGenerator(IRouteAnalyzer routeAnalyzer)
 {
     _routeAnalyzer = routeAnalyzer;
 }
Esempio n. 8
0
 /// <summary>
 /// 初始化一个<see cref="DefaultRazorHtmlGenerator"/>类型的实例
 /// </summary>
 /// <param name="routeAnalyzer">路由分析器</param>
 public DefaultRazorHtmlGenerator(ILogger <DefaultRazorHtmlGenerator> logger, IRouteAnalyzer routeAnalyzer)
 {
     _logger        = logger;
     _routeAnalyzer = routeAnalyzer;
 }
 public RouteAnalyzerController(IRouteAnalyzer routeAnalyzer)
 {
     _routeAnalyzer = routeAnalyzer;
 }
Esempio n. 10
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(
            IApplicationBuilder app,
            IWebHostEnvironment env,
            ILoggerFactory loggerFactory,
            IAntiforgery antiforgery,
            IHostApplicationLifetime applicationLifetime, // Add
            IRouteAnalyzer routeAnalyzer,
            IServiceProvider services)
        {
            // move to Program.cs - loggerFactory.AddConsole (this.Configuration.GetSection ("Logging"));
            // move to Program.cs - loggerFactory.AddDebug ();

            // app.UseStaticFiles();

            this.webStartup.Configure(app, env, antiforgery, services);
            app.UseStaticFiles(new StaticFileOptions()
            {
                OnPrepareResponse = c => {
                    //Do not add cache to json files. We need to have new versions when we add new translations.
                    c.Context.Response.GetTypedHeaders().CacheControl = !c.Context.Request.Path.Value.Contains(".json")
                        ? new CacheControlHeaderValue()
                    {
                        MaxAge = TimeSpan.FromDays(30)      // Cache everything except json for 30 days
                    }
                        : new CacheControlHeaderValue()
                    {
                        MaxAge = TimeSpan.FromMinutes(15)      // Cache json for 15 minutes
                    };
                }
            });
            app.UseSpaStaticFiles();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions {
                    HotModuleReplacement         = true,
                    HotModuleReplacementEndpoint = "/dist/"
                });
                app.UseSwagger();
                app.UseSwaggerUI(c => {
                    c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
                });

                // Enable middleware to serve swagger-ui (HTML, JS, CSS etc.), specifying the Swagger JSON endpoint.

                app.MapWhen(x => !x.Request.Path.Value.StartsWith("/swagger", StringComparison.OrdinalIgnoreCase), builder => {
                    builder.UseMvc(routes => {
                        routes.MapSpaFallbackRoute(
                            name: "spa-fallback",
                            defaults: new { controller = "Home", action = "Index" });
                    });
                });
            }
            else
            {
                app.UseMvc(routes => {
                    routes.MapRoute(
                        name: "default",
                        template: "{controller=Home}/{action=Index}/{id?}");

                    routes.MapRoute(
                        "Sitemap",
                        "sitemap.xml",
                        new { controller = "Home", action = "SitemapXml" });

                    routes.MapSpaFallbackRoute(
                        name: "spa-fallback",
                        defaults: new { controller = "Home", action = "Index" });
                });
                app.UseExceptionHandler("/Home/Error");
            }

            // display all routes
            //applicationLifetime.ApplicationStarted.Register(() =>
            //{
            //    var infos = routeAnalyzer.GetAllRouteInformations();
            //    Console.WriteLine("======== ALL ROUTE INFORMATION ========");
            //    foreach (var info in infos)
            //    {
            //        Console.WriteLine(info.ToString());
            //    }
            //    Console.WriteLine("");
            //    Console.WriteLine("");
            //});

            app.UseSpa(spa =>
            {
                // To learn more about options for serving an Angular SPA from ASP.NET Core,
                // see https://go.microsoft.com/fwlink/?linkid=864501

                spa.Options.SourcePath = "ClientApp";

                if (env.IsDevelopment())
                {
                    spa.UseAngularCliServer(npmScript: "start");
                }
            });
        }
 public RouteAnalyzer_MainController(IRouteAnalyzer routeAnalyzer)
 {
     m_routeAnalyzer = routeAnalyzer;
 }
Esempio n. 12
0
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, Microsoft.AspNetCore.Hosting.IApplicationLifetime applicationLifetime, IRouteAnalyzer routeAnalyzer)
        {
            app.UseRouting();
            // global cors policy
            app.UseCors(x => x
                        .AllowAnyOrigin()
                        .AllowAnyMethod()
                        .AllowAnyHeader());

            app.UseAuthentication();
            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
Esempio n. 13
0
 public RouteAnalyzerController(IActionDescriptorCollectionProvider provider)
 {
     _routeAnalyzer = new RouteAnalyzer(provider);
 }