160 lines
7.3 KiB
C#
160 lines
7.3 KiB
C#
using Backend.Models;
|
||
using BackendWorkerService.Quartz;
|
||
using BackendWorkerService.Quartz.Jobs;
|
||
using BackendWorkerService.Services.Implement;
|
||
using BackendWorkerService.Services.Interface;
|
||
using Microsoft.Extensions.Configuration;
|
||
using Microsoft.Extensions.DependencyInjection;
|
||
using Microsoft.Extensions.Hosting;
|
||
using Microsoft.Extensions.Logging;
|
||
using Quartz;
|
||
using Quartz.Impl;
|
||
using Quartz.Spi;
|
||
using Repository.BackendRepository.Implement;
|
||
using Repository.BackendRepository.Interface;
|
||
using Repository.BaseRepository.Implement;
|
||
using Repository.BaseRepository.Interface;
|
||
using Repository.FrontendRepository.Implement;
|
||
using Repository.FrontendRepository.Interface;
|
||
using Repository.Helper;
|
||
using Repository.Models;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Threading.Tasks;
|
||
|
||
namespace BackendWorkerService
|
||
{
|
||
public class Program
|
||
{
|
||
public static void Main(string[] args)
|
||
{
|
||
CreateHostBuilder(args).Build().Run();
|
||
}
|
||
|
||
public static IHostBuilder CreateHostBuilder(string[] args) =>
|
||
Host.CreateDefaultBuilder(args)
|
||
.UseWindowsService()
|
||
.ConfigureServices((hostContext, services) =>
|
||
{
|
||
IConfiguration configuration = hostContext.Configuration;
|
||
|
||
services.AddLogging(
|
||
builder =>
|
||
{
|
||
builder.AddFilter("Microsoft", LogLevel.Warning)
|
||
.AddFilter("System", LogLevel.Warning)
|
||
.AddFilter("NToastNotify", LogLevel.Warning)
|
||
.AddConsole();
|
||
});
|
||
|
||
//services.AddHostedService<Worker>();
|
||
|
||
//#region °T®§³qª¾
|
||
|
||
//#region SMPT°t¸m
|
||
//services.AddTransient<ISendEmailService, SendEmailService>();
|
||
//services.Configure<SMTPConfig>(configuration.GetSection("SMTPConfig"));
|
||
//#endregion
|
||
|
||
//#region SMS°t¸m
|
||
//services.AddTransient<ISendSMSService, SendSMSService>();
|
||
//services.Configure<SMSConfig>(configuration.GetSection("SMSConfig"));
|
||
//#endregion
|
||
|
||
//#region Line Notify°t¸m
|
||
//services.AddTransient<ISendLineNotifyService, SendLineNotifyService>();
|
||
//#endregion
|
||
|
||
//#endregion °T®§³qª¾
|
||
|
||
#region DBHelper ª`¤J
|
||
services.Configure<DBConfig>(configuration.GetSection("DBConfig"));
|
||
services.AddTransient<IDatabaseHelper, DatabaseHelper>();
|
||
#endregion DBHelper ª`¤J
|
||
|
||
|
||
#region BackEndConfigHelper ª`¤J
|
||
services.Configure<BackEndConfig>(configuration.GetSection("BackEndConfig"));
|
||
services.AddTransient<IBackEndConfigHelper, BackEndConfigHelper>();
|
||
#endregion BackEndConfigHelper ª`¤J
|
||
|
||
|
||
#region Repository ª`¤J
|
||
services.AddTransient<IBackendRepository, BackendRepository>();
|
||
services.AddTransient<IBackgroundServiceRepository, BackgroundServiceRepository>();
|
||
services.AddTransient<IBackgroundServiceMsSqlRepository, BackgroundServiceMsSqlRepository>();
|
||
services.AddTransient<IFrontendRepository, FrontendRepository>();
|
||
services.AddTransient<IBaseRepository, BaseRepository>();
|
||
#endregion Repository ª`¤J
|
||
|
||
//²K¥[QuartzªA°È
|
||
services.AddTransient<IJobFactory, SingletonJobFactory>();
|
||
services.AddTransient<ISchedulerFactory, StdSchedulerFactory>();
|
||
services.AddHostedService<QuartzHostedService>();
|
||
|
||
//#region I´º°õ¦æpµe(³]©w1min°õ¦æ¤@¦¸)
|
||
//services.AddSingleton<ExecutionBackgroundServicePlanJob>();
|
||
//services.AddSingleton(
|
||
//new JobSchedule(jobType: typeof(ExecutionBackgroundServicePlanJob), cronExpression: configuration.GetValue<string>("BackgroundServiceCron:ExecutionBackgroundServicePlanJob"))
|
||
//);
|
||
//#endregion
|
||
|
||
//#region °T®§³qª¾(³]©w¨C 30min °õ¦æ¤@¦¸)
|
||
//services.AddSingleton<MessageNotificationJob>();
|
||
//services.AddSingleton(
|
||
//new JobSchedule(jobType: typeof(MessageNotificationJob), cronExpression: configuration.GetValue<string>("BackgroundServiceCron:MessageNotificationJob"))
|
||
//);
|
||
//#endregion
|
||
|
||
//#region ©w®É±N¯S©w¸ê®Æªí¥[¤J¦Ü¬£°e¥ô°È(³]©w¨C¤é 2AM °õ¦æ¤@¦¸)
|
||
//services.AddSingleton<RegularUpdateDBTableJob>();
|
||
//services.AddSingleton(
|
||
//new JobSchedule(jobType: typeof(RegularUpdateDBTableJob), cronExpression: configuration.GetValue<string>("BackgroundServiceCron:RegularUpdateDBTableJob"))
|
||
//);
|
||
//#endregion
|
||
|
||
//#region ¸ê®Æ¬£°e(³]©w¨C 5min °õ¦æ¤@¦¸)
|
||
//services.AddSingleton<DataDeliveryJob>();
|
||
//services.AddSingleton(
|
||
//new JobSchedule(jobType: typeof(DataDeliveryJob), cronExpression: configuration.GetValue<string>("BackgroundServiceCron:DataDeliveryJob"))
|
||
//);
|
||
//#endregion
|
||
|
||
#region °±¨®³õºÞ²z(³]©w¨C 5¬í °õ¦æ¤@¦¸)
|
||
services.AddSingleton<ParkingJob>();
|
||
services.AddSingleton(
|
||
new JobSchedule(jobType: typeof(ParkingJob), cronExpression: configuration.GetValue<string>("BackgroundServiceCron:ParkingJob"))
|
||
);
|
||
#endregion
|
||
|
||
#region ¹q¿öÂkÀÉ(³]©w¨C ¤p®É °õ¦æ¤@¦¸)
|
||
services.AddSingleton<ArchiveElectricMeterHourJob>();
|
||
services.AddSingleton(
|
||
new JobSchedule(jobType: typeof(ArchiveElectricMeterHourJob), cronExpression: configuration.GetValue<string>("BackgroundServiceCron:ArchiveElectricMeterHourJob"))
|
||
);
|
||
#endregion
|
||
|
||
#region ¹q¿öÂkÀÉ(³]©w¨C ¤Ñ °õ¦æ¤@¦¸)
|
||
services.AddSingleton<ArchiveElectricMeterDayJob>();
|
||
services.AddSingleton(
|
||
new JobSchedule(jobType: typeof(ArchiveElectricMeterDayJob), cronExpression: configuration.GetValue<string>("BackgroundServiceCron:ArchiveElectricMeterDayJob"))
|
||
);
|
||
#endregion
|
||
|
||
#region ©w®É¨ú±o®ð¶HAPI
|
||
//services.AddSingleton<Quartz.Jobs.WeatherAPIJob>();
|
||
//services.AddSingleton(
|
||
//new JobSchedule(jobType: typeof(Quartz.Jobs.WeatherAPIJob), cronExpression: configuration.GetValue<string>("BackgroundServiceCron:WeatherAPIJob"))
|
||
//);
|
||
#endregion
|
||
|
||
}).ConfigureLogging((hostContext, logFactory) => {
|
||
IConfiguration configuration = hostContext.Configuration;
|
||
|
||
//logFactory.AddFile("Logs/log-{Date}.txt");
|
||
logFactory.AddFile(configuration.GetValue<string>("LoggerPath") + "/log-{Date}.txt");
|
||
});
|
||
}
|
||
}
|