Zxd.Core/code/EmployeeDepartmentDetailWorker/Program.cs

92 lines
3.6 KiB
C#

using DG.EntityFramework;
using EmployeeDepartmentDetailServices.Config;
using Exceptionless;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Quartz.Impl;
using Quartz.Spi;
using Quartz;
using Serilog;
using Zxd.EntityFramework;
using DG.Core;
using EmployeeDepartmentDetailServices.Worker;
try
{
var env = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
Console.WriteLine($"Env: {env}");
var config = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json")
.AddJsonFile($"appsettings.{env ?? "Production"}.json", true)
.AddJsonFile("Serilog.json")
.AddJsonFile($"Serilog.{env ?? "Production"}.json", true)
.Build();
var logger = new LoggerConfiguration()
.ReadFrom.Configuration(config)
.WriteTo.Exceptionless(config.GetValue<string>("Exceptionless:ApiKey"), config.GetValue<string>("Exceptionless:ServerUrl"), new string[] { "WeworkUserWorker" })
.CreateLogger();
Log.Logger = logger;
Log.Information("Starting ResourceFlowWorker");
IServiceCollection services = new ServiceCollection();
services.AddLogging(logging =>
{
logging.ClearProviders();
logging.AddSerilog();
});
services.AddSingleton<IConfiguration>(config);
services.AddOptions()
.Configure<SystemConfig>(e => config.GetSection("SystemConfig").Bind(e));
ExceptionlessClient.Default.Startup(config.GetValue<string>("Exceptionless:ApiKey"));
ExceptionlessClient.Default.Configuration.ServerUrl = config.GetValue<string>("Exceptionless:ServerUrl");
ExceptionlessClient.Default.Configuration.DefaultTags.Add("zxd-ResourceFlowWorker");
//services.AddRedis(config);
services.AddDGEntityFramework<ZxdDbContext>(options =>
{
options.UseMySql(config.GetConnectionString("zxdcrm"), ServerVersion.AutoDetect(config.GetConnectionString("zxdcrm")));
});
services.AddDGEntityFramework<DncmsbaseDbContext>(options =>
{
options.UseMySql(config.GetConnectionString("dncmsbase"), ServerVersion.AutoDetect(config.GetConnectionString("dncmsbase")));
});
services.AddDGEntityFramework<UserCenterDbContext>(options =>
{
options.UseMySql(config.GetConnectionString("usercenter"), ServerVersion.AutoDetect(config.GetConnectionString("usercenter")));
});
services.AddDGEntityFramework<DncmsDbContext>(options =>
{
options.UseMySql(config.GetConnectionString("dncms"), ServerVersion.AutoDetect(config.GetConnectionString("dncms")));
});
services.AddDGEntityFramework<CompanyBaseConfDbContext>(options =>
{
options.UseMySql(config.GetConnectionString("companyBaseConf"), ServerVersion.AutoDetect(config.GetConnectionString("companyBaseConf")));
});
//services.AddDGEntityFramework<HgActionDbContext>(options =>
//{
// options.UseMySql(config.GetConnectionString("hgaction"), ServerVersion.AutoDetect(config.GetConnectionString("hgaction")));
//});
services.AddDGEntityFramework<CrmCloudDbContext>(options =>
{
options.UseMySql(config.GetConnectionString("crmcloud"), ServerVersion.AutoDetect(config.GetConnectionString("crmcloud")));
});
services.AddWorker(config);
services.AddDGHttpClient();
services.AddRegisterWorker<SynchronousWorker>();
var builder = new HostBuilder();
await builder.RunConsoleAsync();
}
catch (Exception ex)
{
Log.Fatal(ex, "Host terminated unexpectedly");
}
finally
{
Log.CloseAndFlush();
}