Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 

69 rindas
3.1 KiB

  1. using System;
  2. using System.Threading.Tasks;
  3. using Microsoft.Extensions.DependencyInjection;
  4. using Microsoft.Extensions.Hosting;
  5. using Microsoft.Extensions.Logging;
  6. using JT808.Protocol;
  7. using Microsoft.Extensions.Configuration;
  8. using NLog.Extensions.Logging;
  9. using JT808.Gateway.TestHosting.Jobs;
  10. using JT808.Gateway.Kafka;
  11. using JT808.Gateway.InMemoryMQ;
  12. using JT808.Gateway.ReplyMessage;
  13. using JT808.Gateway.Client;
  14. namespace JT808.Gateway.TestHosting
  15. {
  16. class Program
  17. {
  18. static async Task Main(string[] args)
  19. {
  20. var serverHostBuilder = new HostBuilder()
  21. .ConfigureAppConfiguration((hostingContext, config) =>
  22. {
  23. config.SetBasePath(AppDomain.CurrentDomain.BaseDirectory)
  24. .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
  25. .AddJsonFile($"appsettings.{ hostingContext.HostingEnvironment.EnvironmentName}.json", optional: true, reloadOnChange: true);
  26. })
  27. .ConfigureLogging((context, logging) =>
  28. {
  29. Console.WriteLine($"Environment.OSVersion.Platform:{Environment.OSVersion.Platform.ToString()}");
  30. NLog.LogManager.LoadConfiguration($"Configs/nlog.{Environment.OSVersion.Platform.ToString()}.config");
  31. logging.AddNLog(new NLogProviderOptions { CaptureMessageTemplates = true, CaptureMessageProperties = true });
  32. logging.SetMinimumLevel(LogLevel.Trace);
  33. })
  34. .ConfigureServices((hostContext, services) =>
  35. {
  36. services.AddSingleton<ILoggerFactory, LoggerFactory>();
  37. services.AddSingleton(typeof(ILogger<>), typeof(Logger<>));
  38. services.AddJT808Configure()
  39. //添加客户端工具
  40. //.AddClient()
  41. //.AddGateway(options =>
  42. ////{
  43. //// options.TcpPort = 808;
  44. //// options.UdpPort = 808;
  45. ////})
  46. .AddGateway(hostContext.Configuration)
  47. .AddTcp()
  48. .AddUdp()
  49. .AddGrpc()
  50. //InMemoryMQ
  51. .AddServerInMemoryMQ()
  52. .AddInMemoryReplyMessage()
  53. //kafka插件
  54. //.AddServerKafkaMsgProducer(hostContext.Configuration)
  55. //.AddServerKafkaMsgReplyConsumer(hostContext.Configuration)
  56. //.AddServerKafkaSessionProducer(hostContext.Configuration)
  57. ;
  58. //grpc客户端调用
  59. //services.AddHostedService<CallGrpcClientJob>();
  60. //客户端测试
  61. //services.AddHostedService<UpJob>();
  62. });
  63. await serverHostBuilder.RunConsoleAsync();
  64. }
  65. }
  66. }