123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- using HslCommunication.LogNet;
- using Microsoft.EntityFrameworkCore;
- using NPOI.SS.Formula.Functions;
- using ProductionLineMonitor.EntityFramework;
- namespace ProductionLineMonitor.WebAPI
- {
- public class Program
- {
- public static void Main(string[] args)
- {
- 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();
- DBOptions.ConnectionString = builder.Configuration.GetSection("ConnectionStrings")["DefaultConnection"];
- builder.Services.AddDbContext<ProductionLineContext>(
- opt => opt.UseSqlite(DBOptions.ConnectionString,
- b => b.MigrationsAssembly("ProductionLineMonitor.WebAPI")));
- var app = builder.Build();
- app.UseSwagger();
- app.UseSwaggerUI();
- app.UseAuthorization();
- app.MapControllers();
- // Hsl Authorization
- var rev = HslCommunication.Authorization.SetAuthorizationCode("3e54799d-f65f-4be6-9e34-517ea9ee294c");
- if (rev == false)
- throw new NotImplementedException("hsl ¼¤»îʧ°Ü£¡");
- // MQTT Client
- string ip = builder.Configuration.GetSection("MqttOptions")["IpAddress"];
- int port = int.Parse(builder.Configuration.GetSection("MqttOptions")["Port"]);
- string clientId = builder.Configuration.GetSection("MqttOptions")["ClientId"];
- string path = AppContext.BaseDirectory;
- ILogNet log = new LogNetDateTime($"{path}\\Logs", GenerateMode.ByEveryDay);
- app.UseHostMqtt(ip, port, clientId, log);
- app.Run();
- }
- }
- }
|