You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
120 lines
3.8 KiB
C#
120 lines
3.8 KiB
C#
using System.Net;
|
|
using Autofac;
|
|
using Autofac.Extensions.DependencyInjection;
|
|
using DS.Module.AutofacModule;
|
|
using DS.Module.CaiNiaoApi;
|
|
using DS.Module.Core;
|
|
using DS.Module.Core.Extensions;
|
|
using DS.Module.Core.ServiceExtensions;
|
|
using DS.Module.Hangfire;
|
|
using DS.Module.HkOpenApi;
|
|
using DS.Module.Jwt;
|
|
using DS.Module.Modbus;
|
|
using DS.Module.SMS;
|
|
using DS.Module.SqlSugar;
|
|
using DS.Module.Swagger;
|
|
using DS.Module.UserModule;
|
|
using DS.WMS.WebApi;
|
|
using Hangfire;
|
|
using Hangfire.Dashboard.BasicAuthorization;
|
|
using Microsoft.AspNetCore.StaticFiles;
|
|
using NLog.Web;
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
// builder.WebHost.UseKestrel(options =>
|
|
// {
|
|
// options.Listen(IPAddress.Any, 9997);
|
|
// });
|
|
builder.Logging.AddNLog("nlog.config");
|
|
// Add services to the container.
|
|
//Autofac注入
|
|
builder.Host
|
|
.UseServiceProviderFactory(new AutofacServiceProviderFactory())
|
|
.ConfigureContainer<ContainerBuilder>(builder => { builder.RegisterModule(new AutofacModuleRegister()); });
|
|
|
|
|
|
builder.Services.AddAppWebInstal();
|
|
builder.Services.AddCorsInstall();
|
|
builder.Services.AddSqlsugarInstall();
|
|
builder.Services.AddSwaggerInstall();
|
|
builder.Services.AddUserModuleInstall();//用户服务
|
|
builder.Services.AddSmsModuleInstall();//短信服务
|
|
|
|
builder.Services.AddHKModuleInstall();//海康服务
|
|
builder.Services.AddJwtInstall();
|
|
// builder.Services.AddHangfireInstall();//Hangfire
|
|
builder.Services.AddModbusInstall();//Modbus服务
|
|
builder.Services.AddCaiNiaoModuleInstall();//菜鸟服务
|
|
// 3、配置中间件
|
|
var app = builder.Build();
|
|
// if (app.Environment.IsDevelopment())
|
|
// {
|
|
// builder.WebHost.UseKestrel(options => { options.Listen(IPAddress.Any, 9997); });
|
|
// }
|
|
// app.InitializeApplication();
|
|
|
|
//if (app.Environment.IsDevelopment())
|
|
//{
|
|
// app.UseDeveloperExceptionPage();
|
|
//}
|
|
//else
|
|
//{
|
|
// app.UseExceptionHandler("/Error");
|
|
// //app.UseHsts();
|
|
//}
|
|
//swagger
|
|
app.UseSwagger();
|
|
app.UseSwaggerUI(c =>
|
|
{
|
|
c.SwaggerEndpoint("/swagger/v1/swagger.json", AppSetting.Configuration["SwaggerDoc:Version"]);
|
|
});
|
|
//跨域
|
|
var policyName = AppSetting.Configuration["Cors:PolicyName"];
|
|
if (!policyName.IsNullOrEmpty())
|
|
{
|
|
app.UseCors(policyName); //添加跨域中间件
|
|
}
|
|
// app.UseHangfireServer();
|
|
// app.UseHangfireDashboard("/hangfire", new DashboardOptions
|
|
// {
|
|
// Authorization = new[] {new BasicAuthAuthorizationFilter(new BasicAuthAuthorizationFilterOptions
|
|
// {
|
|
// RequireSsl = false,
|
|
// SslRedirect = false,
|
|
// LoginCaseSensitive = true,
|
|
// Users = new []
|
|
// {
|
|
// new BasicAuthAuthorizationUser
|
|
// {
|
|
// Login = "admin",
|
|
// PasswordClear = "admin"
|
|
// }
|
|
// }
|
|
// })}
|
|
// });
|
|
app.UseRouting();
|
|
|
|
app.UseStaticFiles();
|
|
//文件
|
|
//app.UseStaticFiles(new StaticFileOptions
|
|
//{
|
|
// //FileProvider = new PhysicalFileProvider(Directory.GetCurrentDirectory()),
|
|
// //设置不限制content-type 该设置可以下载所有类型的文件,但是不建议这么设置,因为不安全
|
|
// //下面设置可以下载apk和nupkg类型的文件
|
|
// ContentTypeProvider = new FileExtensionContentTypeProvider(new Dictionary<string, string>
|
|
// {
|
|
// { ".apk", "application/vnd.android.package-archive" }
|
|
// })
|
|
//});
|
|
ServiceLocator.Instance = app.Services;
|
|
ServiceLocator.ApplicationBuilder = app;
|
|
// 先开启认证
|
|
app.UseAuthentication();
|
|
// 然后是授权中间件
|
|
app.UseAuthorization();
|
|
app.UseEndpoints(endpoints => { endpoints.MapControllers(); });
|
|
// SendModbusMessage */5 * * * * ?
|
|
// RecurringJob.AddOrUpdate<ISendModbusMessageService>((a) => a.SendModbusMessage(), "0 0/1 * * * ? ", TimeZoneInfo.Local);
|
|
// RecurringJob.AddOrUpdate<ISendModbusMessageService>((a) => a.SendModbusMessage(), "*/10 * * * * ?", TimeZoneInfo.Local);
|
|
// BackgroundJob.Enqueue<ISendModbusMessageService>(c => c.SendModbusMessage());
|
|
app.Run(); |