ibms-dome/AlarmMonitorWorkerService/Program.cs

68 lines
2.8 KiB
C#
Raw Permalink Normal View History

2022-10-14 16:08:54 +08:00
using AlarmMonitorWorkerService.Quartz;
using AlarmMonitorWorkerService.Quartz.Jobs;
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.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 AlarmMonitorWorkerService
{
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;
#region DBHelper <EFBFBD>`<EFBFBD>J
services.Configure<DBConfig>(configuration.GetSection("DBConfig"));
services.AddTransient<IDatabaseHelper, DatabaseHelper>();
#endregion DBHelper <EFBFBD>`<EFBFBD>J
#region Repository <EFBFBD>`<EFBFBD>J
//services.AddTransient<IBackendRepository, BackendRepository>();
//services.AddTransient<IBackgroundServiceRepository, BackgroundServiceRepository>();
services.AddTransient<IFrontendRepository, FrontendRepository>();
services.AddTransient<IBaseRepository, BaseRepository>();
#endregion Repository <EFBFBD>`<EFBFBD>J
//<2F>K<EFBFBD>[Quartz<74>A<EFBFBD><41>
services.AddTransient<IJobFactory, SingletonJobFactory>();
services.AddTransient<ISchedulerFactory, StdSchedulerFactory>();
services.AddHostedService<QuartzHostedService>();
#region <EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܵe<EFBFBD><EFBFBD>(<EFBFBD>]<EFBFBD>w3<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>@<EFBFBD><EFBFBD>)
services.AddSingleton<AlarmMonitorJob>();
services.AddSingleton(
new JobSchedule(jobType: typeof(AlarmMonitorJob), cronExpression: configuration.GetValue<string>("BackgroundServiceCron:AlarmMonitorJob"))
);
#endregion
}).ConfigureLogging((hostContext, logFactory) => {
IConfiguration configuration = hostContext.Configuration;
//logFactory.AddFile("Logs/log-{Date}.txt");
logFactory.AddFile(configuration.GetValue<string>("LoggerPath") + "/log-{Date}.txt");
});
}
}