Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 

63 righe
2.5 KiB

  1. using JT808.Gateway.Abstractions;
  2. using JT808.Gateway.Configurations;
  3. using JT808.Gateway.Internal;
  4. using JT808.Gateway.Services;
  5. using JT808.Gateway.Session;
  6. using JT808.Protocol;
  7. using Microsoft.Extensions.Configuration;
  8. using Microsoft.Extensions.DependencyInjection;
  9. using Microsoft.Extensions.DependencyInjection.Extensions;
  10. using System;
  11. using System.Runtime.CompilerServices;
  12. [assembly: InternalsVisibleTo("JT808.Gateway.TestHosting")]
  13. [assembly: InternalsVisibleTo("JT808.Gateway.Test")]
  14. namespace JT808.Gateway
  15. {
  16. public static partial class JT808GatewayExtensions
  17. {
  18. public static IJT808GatewayBuilder AddJT808Gateway(this IJT808Builder jt808Builder,Action<JT808Configuration> config)
  19. {
  20. IJT808GatewayBuilder server = new JT808GatewayBuilderDefault(jt808Builder);
  21. server.JT808Builder.Services.Configure(config);
  22. server.AddJT808Core();
  23. return server;
  24. }
  25. public static IJT808GatewayBuilder AddJT808Gateway(this IJT808Builder jt808Builder, IConfiguration configuration)
  26. {
  27. IJT808GatewayBuilder server = new JT808GatewayBuilderDefault(jt808Builder);
  28. server.JT808Builder.Services.Configure<JT808Configuration>(configuration.GetSection("JT808Configuration"));
  29. server.AddJT808Core();
  30. return server;
  31. }
  32. public static IJT808GatewayBuilder AddTcp(this IJT808GatewayBuilder config)
  33. {
  34. config.JT808Builder.Services.AddHostedService<JT808TcpServer>();
  35. config.JT808Builder.Services.AddHostedService<JT808TcpReceiveTimeoutHostedService>();
  36. return config;
  37. }
  38. public static IJT808GatewayBuilder AddUdp(this IJT808GatewayBuilder config)
  39. {
  40. config.JT808Builder.Services.AddHostedService<JT808UdpServer>();
  41. config.JT808Builder.Services.AddHostedService<JT808UdpReceiveTimeoutHostedService>();
  42. return config;
  43. }
  44. public static IJT808GatewayBuilder AddGrpc(this IJT808GatewayBuilder config)
  45. {
  46. config.JT808Builder.Services.AddHostedService<JT808GrpcServer>();
  47. return config;
  48. }
  49. private static IJT808GatewayBuilder AddJT808Core(this IJT808GatewayBuilder config)
  50. {
  51. config.JT808Builder.Services.TryAddSingleton<JT808AtomicCounterServiceFactory>();
  52. config.JT808Builder.Services.TryAddSingleton<JT808SessionManager>();
  53. config.JT808Builder.Services.AddHostedService<JT808MsgReplyHostedService>();
  54. return config;
  55. }
  56. }
  57. }