|
|
|
@ -6,17 +6,18 @@ using HybirdFrameworkCore.Autofac;
|
|
|
|
|
using HybirdFrameworkCore.Configuration;
|
|
|
|
|
using HybirdFrameworkCore.Entity;
|
|
|
|
|
using HybirdFrameworkCore.Redis;
|
|
|
|
|
using log4net;
|
|
|
|
|
using Mapster;
|
|
|
|
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
|
|
|
|
using Microsoft.IdentityModel.Tokens;
|
|
|
|
|
using Service.Cloud.Client;
|
|
|
|
|
using Service.Execute;
|
|
|
|
|
using Service.Execute.StaticTools;
|
|
|
|
|
using Service.Plc.Client;
|
|
|
|
|
using SqlSugar;
|
|
|
|
|
using SqlSugar.IOC;
|
|
|
|
|
|
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
|
var log = LogManager.GetLogger(typeof(Program));
|
|
|
|
|
|
|
|
|
|
builder.Host.UseServiceProviderFactory(new AutofacServiceProviderFactory());
|
|
|
|
|
builder.Host.ConfigureContainer<ContainerBuilder>(cb =>
|
|
|
|
@ -63,17 +64,12 @@ builder.Services.AddCors(options =>
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//redis
|
|
|
|
|
var section = builder.Configuration.GetSection("Redis");
|
|
|
|
|
//连接字符串
|
|
|
|
|
var redisConnectionString = section.GetSection("Connection").Value;
|
|
|
|
|
//实例名称
|
|
|
|
|
var instanceName = section.GetSection("InstanceName").Value;
|
|
|
|
|
//默认数据库
|
|
|
|
|
var _defaultDB = int.Parse(section.GetSection("DefaultDB").Value ?? "0");
|
|
|
|
|
var redisConnectionString = AppSettingsHelper.GetContent("Redis", "Connection");
|
|
|
|
|
var instanceName = AppSettingsHelper.GetContent("Redis", "InstanceName");//默认数据库
|
|
|
|
|
var defaultDb = int.Parse(AppSettingsHelper.GetContent("Redis", "DefaultDB") ?? "0");
|
|
|
|
|
if (redisConnectionString != null && instanceName != null)
|
|
|
|
|
builder.Services.AddSingleton(new RedisHelper(redisConnectionString, instanceName, _defaultDB));
|
|
|
|
|
builder.Services.AddSingleton(new RedisHelper(redisConnectionString, instanceName, defaultDb));
|
|
|
|
|
|
|
|
|
|
builder.Services.AddControllers().AddJsonOptions(configure =>
|
|
|
|
|
{
|
|
|
|
@ -122,12 +118,6 @@ builder.Services.AddAuthentication(options =>
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
//Json 序列化
|
|
|
|
|
builder.Services.AddControllers().AddJsonOptions(configure =>
|
|
|
|
|
{
|
|
|
|
|
configure.JsonSerializerOptions.Converters.Add(new DatetimeJsonConverter());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -136,12 +126,9 @@ var app = builder.Build();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Configure the HTTP request pipeline.
|
|
|
|
|
if (app.Environment.IsDevelopment())
|
|
|
|
|
{
|
|
|
|
|
app.UseSwagger();
|
|
|
|
|
app.UseSwaggerUI();
|
|
|
|
|
app.UseStaticFiles();
|
|
|
|
|
}
|
|
|
|
|
app.UseSwagger();
|
|
|
|
|
app.UseSwaggerUI();
|
|
|
|
|
app.UseStaticFiles();
|
|
|
|
|
|
|
|
|
|
app.UseAuthorization();
|
|
|
|
|
app.UseCors("myCors");
|
|
|
|
@ -150,6 +137,7 @@ app.MapControllers();
|
|
|
|
|
var list = AppSettingsHelper.GetContent("Kestrel", "Endpoints", "http", "Url");
|
|
|
|
|
foreach (var s in list.Split(";"))
|
|
|
|
|
{
|
|
|
|
|
log.Info($"use url={s}");
|
|
|
|
|
app.Urls.Add(s);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -157,10 +145,28 @@ foreach (var s in list.Split(";"))
|
|
|
|
|
AppInfo.Container = app.Services.GetAutofacRoot();
|
|
|
|
|
|
|
|
|
|
//云平台
|
|
|
|
|
CloudClientMgr.Init();
|
|
|
|
|
if (AppSettingsHelper.GetBool("cloud", "enable"))
|
|
|
|
|
{
|
|
|
|
|
CloudClientMgr.Init();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//PLC
|
|
|
|
|
PlcMgr.Init();
|
|
|
|
|
if (AppSettingsHelper.GetBool("plc", "enable"))
|
|
|
|
|
{
|
|
|
|
|
PlcMgr.Init();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//启动换电流程
|
|
|
|
|
//StationSoftMgr.SwappingStateMachineStart();
|
|
|
|
|
//StationSoftMgr.StartTasks();
|
|
|
|
|
if (AppSettingsHelper.GetBool("swap", "enable"))
|
|
|
|
|
{
|
|
|
|
|
StationSoftMgr.SwappingStateMachineStart();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Task
|
|
|
|
|
if (AppSettingsHelper.GetBool("task", "enable"))
|
|
|
|
|
{
|
|
|
|
|
StationSoftMgr.StartTasks();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.Run();
|