2022-10-27 12:48:42 +00:00
using Microsoft.EntityFrameworkCore ;
using Microsoft.Extensions.DependencyInjection ;
2022-11-01 12:23:49 +00:00
using Quartz ;
using birzha_contracts.Jobs ;
2022-11-03 11:21:35 +00:00
using Microsoft.Extensions.Configuration ;
using birzha_contracts.Managers ;
2022-10-27 12:48:42 +00:00
var builder = WebApplication . CreateBuilder ( args ) ;
2022-11-01 12:23:49 +00:00
builder . Services . AddDbContext < MvcContractContext > ( options = >
options . UseSqlServer ( builder . Configuration . GetConnectionString ( "MvcContractContext" ) ? ? throw new InvalidOperationException ( "Connection string 'MvcContractContext' not found." ) ) ) ;
2022-10-27 12:48:42 +00:00
2022-11-03 11:21:35 +00:00
var time = ConfigManager . AppSetting [ "UpdateTime" ] ;
2022-10-27 12:48:42 +00:00
builder . Services . AddControllersWithViews ( ) ;
2022-11-01 12:23:49 +00:00
builder . Services . AddQuartz ( q = >
{
q . UseMicrosoftDependencyInjectionJobFactory ( ) ;
var jobKey = new JobKey ( "HelloWorldJob" ) ;
2022-11-21 12:47:08 +00:00
var updateJobKey = new JobKey ( "UpdateJob" ) ;
2022-11-01 12:23:49 +00:00
q . AddJob < HelloWorldJob > ( opts = > opts . WithIdentity ( jobKey ) ) ;
2022-11-21 12:47:08 +00:00
q . AddJob < UpdateJob > ( opts = > opts . WithIdentity ( updateJobKey ) ) ;
2022-11-03 11:21:35 +00:00
2022-11-01 12:23:49 +00:00
q . AddTrigger ( opts = > opts
. ForJob ( jobKey )
. WithIdentity ( "HelloWorldJob-trigger" )
2022-11-03 11:21:35 +00:00
. WithCronSchedule ( time ) ) ;
2022-11-01 12:23:49 +00:00
2022-11-21 12:47:08 +00:00
q . AddTrigger ( opts = > opts
. ForJob ( updateJobKey )
. WithIdentity ( "UpdateJob-trigger" )
. WithCronSchedule ( time ) ) ;
2022-11-01 12:23:49 +00:00
} ) ;
builder . Services . AddQuartzHostedService ( q = > q . WaitForJobsToComplete = true ) ;
2022-10-27 12:48:42 +00:00
var app = builder . Build ( ) ;
if ( ! app . Environment . IsDevelopment ( ) )
{
app . UseExceptionHandler ( "/Home/Error" ) ;
app . UseHsts ( ) ;
}
app . UseHttpsRedirection ( ) ;
app . UseStaticFiles ( ) ;
app . UseRouting ( ) ;
app . UseAuthorization ( ) ;
app . MapControllerRoute (
name : "default" ,
pattern : "{controller=Home}/{action=Index}/{id?}" ) ;
app . Run ( ) ;