后厨api
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

86 lines
2.9 KiB

  1. using BPA.MQTTClient;
  2. using BPA.SAAS.KitChenManage.Core;
  3. using Furion;
  4. using Microsoft.AspNetCore.Builder;
  5. using Microsoft.AspNetCore.Hosting;
  6. using Microsoft.Extensions.DependencyInjection;
  7. using Microsoft.Extensions.Hosting;
  8. using MQTTnet.Client.Connecting;
  9. using MQTTnet.Client.Disconnecting;
  10. using ProtoBuf.Meta;
  11. using System;
  12. using System.Threading.Tasks;
  13. namespace BPA.SAAS.KitChenManage.Web.Core
  14. {
  15. public class Startup : AppStartup
  16. {
  17. public void ConfigureServices(IServiceCollection services)
  18. {
  19. services.AddConsoleFormatter();
  20. services.AddJwt<JwtHandler>();
  21. services.AddMqttClientHostedService(op =>
  22. {
  23. op.Port = int.Parse(App.Configuration["dev1_brokerHostSettings:Port"]);
  24. op.Server = App.Configuration["dev1_brokerHostSettings:Host"];
  25. op.UserName = App.Configuration["MqttClientSettings:UserName"];
  26. op.Password = App.Configuration["MqttClientSettings:Password"];
  27. op.mqttClientConnectedHandlerDelegate = new MqttClientConnectedHandlerDelegate(async e =>
  28. {
  29. Console.WriteLine("MQTT连接成功");
  30. });
  31. op.mqttClientDisconnectedHandlerDelegate = new MqttClientDisconnectedHandlerDelegate(async e =>
  32. {
  33. Console.WriteLine("MQTT断开连接");
  34. await Task.Delay(TimeSpan.FromSeconds(5));
  35. try
  36. {
  37. //var options = op.Server.GetService<IMqttClientOptions>();
  38. //await op.Server.GetService<IMqttClient>().ConnectAsync(options);
  39. }
  40. catch (global::System.Exception)
  41. {
  42. }
  43. });
  44. op.MqttApplicationMessageReceivedHandler = new MQTTnet.Client.Receiving.MqttApplicationMessageReceivedHandlerDelegate(async e =>
  45. {
  46. });
  47. });
  48. // services.GetService<IMqttClientOptions>();
  49. services.AddTaskServices();
  50. services.AddCorsAccessor();
  51. services.AddRemoteRequest();
  52. services.AddSqlsugarSetup(App.Configuration);
  53. services.AddControllers()
  54. .AddInjectWithUnifyResult();
  55. }
  56. public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
  57. {
  58. if (env.IsDevelopment())
  59. {
  60. app.UseDeveloperExceptionPage();
  61. }
  62. app.UseHttpsRedirection();
  63. app.UseRouting();
  64. app.UseCorsAccessor();
  65. app.UseAuthentication();
  66. app.UseAuthorization();
  67. app.UseInject(string.Empty);
  68. app.UseEndpoints(endpoints =>
  69. {
  70. endpoints.MapControllers();
  71. });
  72. }
  73. }
  74. }