You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

122 lines
3.8 KiB

9 months ago
using Autofac;
using Autofac.Extensions.DependencyInjection;
using HybirdFrameworkCore.Autofac;
7 months ago
using HybirdFrameworkCore.AutoTask;
9 months ago
using HybirdFrameworkCore.Configuration;
using HybirdFrameworkCore.Entity;
7 months ago
using HybirdFrameworkCore.Redis;
using log4net;
using Service.Car.Server;
using Service.Help.ElectricMeter.ElectricClient;
using Service.Humiture.Client;
using Service.TBox.Server;
using Service.Ups.Client;
9 months ago
using SqlSugar;
using SqlSugar.IOC;
var builder = WebApplication.CreateBuilder(args);
var log = LogManager.GetLogger(typeof(Program));
9 months ago
builder.Host.UseServiceProviderFactory(new AutofacServiceProviderFactory());
builder.Host.ConfigureContainer<ContainerBuilder>(cb =>
{
cb.Register(c =>
{
7 months ago
var db = new SqlSugarScope(new ConnectionConfig
9 months ago
{
ConfigId = AppSettingsConstVars.ConfigId,
7 months ago
ConnectionString = AppSettingsConstVars.DbSqlConnection, // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
9 months ago
DbType = AppSettingsConstVars.DbDbType == IocDbType.MySql.ToString() ? DbType.MySql : DbType.SqlServer,
IsAutoCloseConnection = true,
7 months ago
InitKeyType = InitKeyType.Attribute // <20><><EFBFBD>ʹ<EFBFBD><CAB9>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Խ<EFBFBD><D4BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʶ<EFBFBD><CAB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ InitKeyType.Attribute
9 months ago
});
return db;
}).As<ISqlSugarClient>().InstancePerLifetimeScope();
7 months ago
8 months ago
9 months ago
cb.RegisterModule(new AutofacModuleRegister());
});
//跨域
builder.Services.AddCors(options =>
{
options.AddPolicy
(name: "myCors",
builde =>
{
builde.WithOrigins("*", "*", "*")
.AllowAnyOrigin()
.AllowAnyHeader()
.AllowAnyMethod();
}
);
});
9 months ago
7 months ago
builder.Services.AddSwaggerGen(c =>
{
var basePath = Path.GetDirectoryName(AppContext.BaseDirectory);
//c.IncludeXmlComments(Path.Combine(basePath, Assembly.GetExecutingAssembly().GetName().Name+".xml"), true);
c.IncludeXmlComments(Path.Combine(basePath, "WebStarter.xml"), true);
c.IncludeXmlComments(Path.Combine(basePath, "Entity.xml"), true);
c.IncludeXmlComments(Path.Combine(basePath, "HybirdFrameworkCore.xml"), true);
7 months ago
7 months ago
});
builder.Services.AddControllers().AddJsonOptions(configure =>
{
configure.JsonSerializerOptions.Converters.Add(new DatetimeJsonConverter());
});
7 months ago
//redis
var redisConnectionString = AppSettingsHelper.GetContent("Redis", "Connection");
7 months ago
var instanceName = AppSettingsHelper.GetContent("Redis", "InstanceName");//默认数据库
var defaultDb = int.Parse(AppSettingsHelper.GetContent("Redis", "DefaultDB") ?? "0");
7 months ago
if (redisConnectionString != null && instanceName != null)
builder.Services.AddSingleton(new RedisHelper(redisConnectionString, instanceName, defaultDb));
7 months ago
9 months ago
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Logging.AddLog4Net("log4net.config");
var app = builder.Build();
8 months ago
9 months ago
// Configure the HTTP request pipeline.
// Configure the HTTP request pipeline.
app.UseSwagger();
app.UseSwaggerUI();
app.UseStaticFiles();
9 months ago
app.UseAuthorization();
app.UseCors("myCors");
9 months ago
app.MapControllers();
7 months ago
var list = AppSettingsHelper.GetContent("Kestrel", "Endpoints", "http", "Url");
foreach (var s in list.Split(";"))
{
log.Info($"use url={s}");
7 months ago
app.Urls.Add(s);
}
8 months ago
AppInfo.Container = app.Services.GetAutofacRoot();
var listen = builder.Configuration.GetSection("Listen");
CarServerMgr.InitServer(int.Parse(listen.GetSection("Port").Value ?? "5588"));
var tBoxListen = builder.Configuration.GetSection("TBoxListen");
TBoxServerMgr.InitTBoxServer(int.Parse(tBoxListen.GetSection("Port").Value ?? "9999"));
7 months ago
//UPS
UpsMgr.Init();
//温湿度
HumiturePlcMgr.InitRight();
HumiturePlcMgr.InitLeft();
//电表
ElectricMgr.InitRight();
ElectricMgr.InitLeft();
7 months ago
TaskInit.Init();
app.Run();