Exemplo n.º 1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseBrowserLink();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseAuthentication();

            app.UseStaticFiles();

            // Using hangfire
            GlobalConfiguration.Configuration.UseSqlServerStorage(Configuration.GetConnectionString("FlightConnection"));
            BackgroundJob.Enqueue(() => Console.WriteLine("Getting started with hangfire!"));
            app.UseHangfireDashboard();
            app.UseHangfireServer();

            // Check planes that are yet to take off
            RecurringJob.AddOrUpdate(() => _flight.CheckFlightsForTakeOff(), Cron.Minutely);
            // Check planes that are flying to land them if necessary
            RecurringJob.AddOrUpdate(() => _flight.CheckFlightsForLanding(), Cron.Minutely);
            // Check planes that are under maintenance for ending the maintenance
            RecurringJob.AddOrUpdate(() => _flight.CheckPlanesForOffMaintenance(), Cron.Minutely);
            // Generate random flights
            RecurringJob.AddOrUpdate(() => _flight.GenerateRandomFlight(), Cron.HourInterval(6));


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