Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 

65 linhas
2.6 KiB

  1. using JT808.Gateway.Abstractions.Enums;
  2. using JT808.Gateway.ReplyMessage;
  3. using JT808.Gateway.MsgLogging;
  4. using JT808.Gateway.Traffic;
  5. using JT808.Gateway.MsgIdHandler;
  6. using JT808.Gateway.SessionNotice;
  7. using JT808.Protocol;
  8. using Microsoft.Extensions.Configuration;
  9. using Microsoft.Extensions.DependencyInjection;
  10. using Microsoft.Extensions.DependencyInjection.Extensions;
  11. using Microsoft.Extensions.Hosting;
  12. using Microsoft.Extensions.Logging;
  13. using System;
  14. using System.Threading.Tasks;
  15. using JT808.Gateway.SimpleServer.Impl;
  16. using JT808.Gateway.SimpleServer.Services;
  17. using JT808.Gateway.Abstractions;
  18. using JT808.Gateway.Transmit;
  19. using JT808.Gateway.SimpleServer.Jobs;
  20. namespace JT808.Gateway.SimpleServer
  21. {
  22. class Program
  23. {
  24. static async Task Main(string[] args)
  25. {
  26. var serverHostBuilder = new HostBuilder()
  27. .ConfigureAppConfiguration((hostingContext, config) =>
  28. {
  29. config.SetBasePath(AppDomain.CurrentDomain.BaseDirectory);
  30. config.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);
  31. })
  32. .ConfigureLogging((context, logging) =>
  33. {
  34. logging.AddConsole();
  35. logging.SetMinimumLevel(LogLevel.Trace);
  36. })
  37. .ConfigureServices((hostContext, services) =>
  38. {
  39. services.AddSingleton<ILoggerFactory, LoggerFactory>();
  40. services.AddSingleton(typeof(ILogger<>), typeof(Logger<>));
  41. //使用内存队列实现会话通知
  42. services.AddSingleton<JT808SessionService>();
  43. services.AddSingleton<IJT808SessionProducer, JT808SessionProducer>();
  44. services.AddSingleton<IJT808SessionConsumer, JT808SessionConsumer>();
  45. services.AddJT808Configure()
  46. .AddNormalGateway(hostContext.Configuration)
  47. .ReplaceNormalReplyMessageHandler<JT808NormalReplyMessageHandlerImpl>()
  48. .AddMsgLogging<JT808MsgLogging>()
  49. .AddTraffic()
  50. .AddSessionNotice()
  51. .AddTransmit(hostContext.Configuration)
  52. .AddTcp()
  53. .AddUdp()
  54. .AddGrpc()
  55. .Builder();
  56. //流量统计
  57. services.AddHostedService<TrafficJob>();
  58. });
  59. await serverHostBuilder.RunConsoleAsync();
  60. }
  61. }
  62. }