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.
 
 
 

59 lines
2.4 KiB

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