using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Server.Kestrel.Core; using System.Configuration; using System.Net; using System.Net.Http; using System.Net.Sockets; using System.Text; using WCS.BLL.Config; using WCS.BLL.DbModels; using WCS.BLL.Manager; using WCS.BLL.Services.IService; using WCS.BLL.Services.Service; using WCS.WebApi; using WCS.WebApi.Controllers; namespace WebApi { public class Program { public static void Main(string[] args) { try { //初始化websocket WebSoceketManager.InitWebSocket(); //初始化数据库 DbInit.InitDb(); //初始化配置文件 LocalFile.SaveConfig(); //初始化TCP连接 TCPClientManager.InitTcpClient(); //初始化货架缓存信息 ShelfManager.InitShelves(); //报警信息重发线程 WarningManager.StartWarningMessageThread(); //盟讯公司后台线程 if (LocalFile.Config.IsMx) { MXBackgroundThread.InitBackgroundThread(); var str = string.Empty; MXBackgroundThread.SendDingDingMsg($"【{LocalFile.Config.GroupName}】后台服务启动成功", new List { "104379" }, ref str); } //清理后台文本日志 Task.Run(async () => { while (true) { try { //清理三个月以前的日志 WCS.BLL.Logs.Clear(TimeSpan.FromDays(92)); //每一天执行一次 await Task.Delay(1000 * 60 * 60 * 24); } catch (Exception ex) { } } }); var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); //生成物料码、生成单据码采用单例模式 builder.Services.AddSingleton(); var app = builder.Build(); app.UseMiddleware(); // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) { app.UseSwagger(); app.UseSwaggerUI(); } app.UseAuthorization(); app.MapControllers(); app.Run("http://0.0.0.0:8888");//0.0.0.0表示仅接收ipv4 } catch (Exception ex) { Console.WriteLine(ex.Message); } } } }