基础服务api
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

Startup.cs 3.8 KiB

il y a 9 mois
il y a 10 mois
il y a 10 mois
il y a 10 mois
il y a 9 mois
il y a 9 mois
il y a 10 mois
il y a 10 mois
il y a 10 mois
il y a 10 mois
il y a 9 mois
il y a 8 mois
il y a 10 mois
il y a 8 mois
il y a 10 mois
il y a 10 mois
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. using BPA.Aliyun.OSS;
  2. using BPA.MQTTClient;
  3. using BPA.SAAS.Manage.Application.System.Dtos;
  4. using BPA.SAAS.Manage.Core;
  5. using FluentValidation.AspNetCore;
  6. using Furion;
  7. using Microsoft.AspNetCore.Builder;
  8. using Microsoft.AspNetCore.Hosting;
  9. using Microsoft.Extensions.Configuration;
  10. using Microsoft.Extensions.DependencyInjection;
  11. using Microsoft.Extensions.Hosting;
  12. using MQTTnet.Client.Connecting;
  13. using MQTTnet.Client.Disconnecting;
  14. using Newtonsoft.Json;
  15. using System;
  16. using System.Threading.Tasks;
  17. namespace BPA.SAAS.Manage.Web.Core
  18. {
  19. public class Startup : AppStartup
  20. {
  21. public void ConfigureServices(IServiceCollection services)
  22. {
  23. services.AddConsoleFormatter();
  24. services.AddJwt<JwtHandler>();
  25. CosConfig.cosInfoOptions = new CosInfoOptions(App.Configuration["cos_config:AppId"],
  26. App.Configuration["cos_config:Region"], App.Configuration["cos_config:Bucket"],
  27. App.Configuration["cos_config:SecretId"], App.Configuration["cos_config:SecretKey"]);
  28. services.AddControllersWithViews()
  29. .AddFluentValidation(fv =>
  30. {
  31. fv.RegisterValidatorsFromAssemblies(App.Assemblies);
  32. })
  33. .AddNewtonsoftJson(options =>
  34. {
  35. options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
  36. options.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss";
  37. });
  38. services.AddMqttClientHostedService(op =>
  39. {
  40. op.Port = int.Parse(App.Configuration["dev1_brokerHostSettings:Port"]);
  41. op.Server = App.Configuration["dev1_brokerHostSettings:Host"];
  42. op.UserName = App.Configuration["MqttClientSettings:UserName"];
  43. op.Password = App.Configuration["MqttClientSettings:Password"];
  44. op.mqttClientConnectedHandlerDelegate = new MqttClientConnectedHandlerDelegate(async e =>
  45. {
  46. Console.WriteLine("MQTT连接成功");
  47. });
  48. op.mqttClientDisconnectedHandlerDelegate = new MqttClientDisconnectedHandlerDelegate(async e =>
  49. {
  50. Console.WriteLine("MQTT断开连接");
  51. await Task.Delay(TimeSpan.FromSeconds(5));
  52. try
  53. {
  54. //var options = op.Server.GetService<IMqttClientOptions>();
  55. //await op.Server.GetService<IMqttClient>().ConnectAsync(options);
  56. }
  57. catch (global::System.Exception)
  58. {
  59. }
  60. });
  61. op.MqttApplicationMessageReceivedHandler = new MQTTnet.Client.Receiving.MqttApplicationMessageReceivedHandlerDelegate(async e =>
  62. {
  63. });
  64. });
  65. services.AddRemoteRequest();
  66. services.AddCorsAccessor();
  67. services.AddSqlsugarSetup(App.Configuration);
  68. services.AddControllers()
  69. .AddInjectWithUnifyResult();
  70. services.AddMvcFilter<RequestAuditFiltercs>();
  71. services.AddAliyunOss(op =>
  72. {
  73. App.Configuration.Bind("BPA:Aliyun:Oss", op);
  74. });
  75. }
  76. public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
  77. {
  78. if (env.IsDevelopment())
  79. {
  80. app.UseDeveloperExceptionPage();
  81. }
  82. app.UseHttpsRedirection();
  83. app.UseRouting();
  84. app.UseCorsAccessor();
  85. app.UseAuthentication();
  86. app.UseAuthorization();
  87. app.UseInject(string.Empty);
  88. app.UseEndpoints(endpoints =>
  89. {
  90. endpoints.MapControllers();
  91. });
  92. }
  93. }
  94. }