Program.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using HslCommunication.LogNet;
  2. using Microsoft.EntityFrameworkCore;
  3. using NPOI.SS.Formula.Functions;
  4. using ProductionLineMonitor.EntityFramework;
  5. namespace ProductionLineMonitor.WebAPI
  6. {
  7. public class Program
  8. {
  9. public static void Main(string[] args)
  10. {
  11. var builder = WebApplication.CreateBuilder(args);
  12. // Add services to the container.
  13. builder.Services.AddControllers();
  14. // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
  15. builder.Services.AddEndpointsApiExplorer();
  16. builder.Services.AddSwaggerGen();
  17. DBOptions.ConnectionString = builder.Configuration.GetSection("ConnectionStrings")["DefaultConnection"];
  18. builder.Services.AddDbContext<ProductionLineContext>(
  19. opt => opt.UseSqlite(DBOptions.ConnectionString,
  20. b => b.MigrationsAssembly("ProductionLineMonitor.WebAPI")));
  21. var app = builder.Build();
  22. app.UseSwagger();
  23. app.UseSwaggerUI();
  24. app.UseAuthorization();
  25. app.MapControllers();
  26. // Hsl Authorization
  27. var rev = HslCommunication.Authorization.SetAuthorizationCode("3e54799d-f65f-4be6-9e34-517ea9ee294c");
  28. if (rev == false)
  29. throw new NotImplementedException("hsl ¼¤»îʧ°Ü£¡");
  30. // MQTT Client
  31. string ip = builder.Configuration.GetSection("MqttOptions")["IpAddress"];
  32. int port = int.Parse(builder.Configuration.GetSection("MqttOptions")["Port"]);
  33. string clientId = builder.Configuration.GetSection("MqttOptions")["ClientId"];
  34. string path = AppContext.BaseDirectory;
  35. ILogNet log = new LogNetDateTime($"{path}\\Logs", GenerateMode.ByEveryDay);
  36. app.UseHostMqtt(ip, port, clientId, log);
  37. app.Run();
  38. }
  39. }
  40. }