ibms-dome/FrontendWorkerService/Program.cs
2022-10-14 16:08:54 +08:00

93 lines
4.2 KiB
C#
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using FrontendWorkerService.Models;
using FrontendWorkerService.Quartz;
using FrontendWorkerService.Quartz.Jobs;
using Microsoft.AspNetCore.Hosting;
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 FrontendWorkerService
{
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.Configure<ObixApiConfig>(configuration.GetSection("ObixApiConfig"));
#region DBHelper ª`¤J
services.Configure<DBConfig>(configuration.GetSection("DBConfig"));
services.AddTransient<IDatabaseHelper, DatabaseHelper>();
#endregion DBHelper ª`¤J
#region Repository ª`¤J
//services.AddTransient<IBackendRepository, BackendRepository>();
//services.AddTransient<IBackgroundServiceRepository, BackgroundServiceRepository>();
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 ­q¾\³]³ÆÂI¦ì(³]©w¨C¤Ñ01:00 AM °õ¦æ¤@¦¸)
services.AddSingleton<OnTimeDeviceSubscriptionJob>();
services.AddSingleton(
new JobSchedule(jobType: typeof(OnTimeDeviceSubscriptionJob), cronExpression: configuration.GetValue<string>("BackgroundServiceCron:OnTimeDeviceSubscriptionJob"))
);
#endregion
#region §ó·s§Y®É­È(³]©w5¬í°õ¦æ¤@¦¸)
services.AddSingleton<OnTimeDeviceRawDataJob>();
services.AddSingleton(
new JobSchedule(jobType: typeof(OnTimeDeviceRawDataJob), cronExpression: configuration.GetValue<string>("BackgroundServiceCron:OnTimeDeviceRawDataJob"))
);
#endregion
#region §Y®É§iĵ­q¾\³]³ÆÂI¦ì(³]©w¨C¤Ñ01:00 AM °õ¦æ¤@¦¸)
services.AddSingleton<OntimeAlarmDeviceSubscriptionJob>();
services.AddSingleton(
new JobSchedule(jobType: typeof(OntimeAlarmDeviceSubscriptionJob), cronExpression: configuration.GetValue<string>("BackgroundServiceCron:OntimeAlarmDeviceSubscriptionJob"))
);
#endregion
#region §ó·s§iĵ³]³Æª¬ºA­È(³]©w5¬í°õ¦æ¤@¦¸)
services.AddSingleton<OntimeAlarmDeviceRawDataJob>();
services.AddSingleton(
new JobSchedule(jobType: typeof(OntimeAlarmDeviceRawDataJob), cronExpression: configuration.GetValue<string>("BackgroundServiceCron:OntimeAlarmDeviceRawDataJob"))
);
#endregion
}).ConfigureLogging((hostContext, logFactory) => {
IConfiguration configuration = hostContext.Configuration;
//logFactory.AddFile("Logs/log-{Date}.txt");
logFactory.AddFile(configuration.GetValue<string>("LoggerPath") + "/log-{Date}.txt");
});
}
}