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.

129 rindas
5.4KB

  1. using GpsCardGatewayPosition.Common;
  2. using GpsCardGatewayPosition.Common.Helper;
  3. using GpsCardGatewayPosition.Gateway;
  4. using GpsCardGatewayPosition.Gateway.Config;
  5. using GpsCardGatewayPosition.Model.Config;
  6. using GpsCardGatewayPosition.Postion.HttpLog;
  7. using GpsCardGatewayPosition.Service.Biz;
  8. using GpsCardGatewayPosition.Service.Biz.Health;
  9. using GpsCardGatewayPosition.Service.Biz.Iot;
  10. using GpsCardGatewayPosition.Service.Biz.Location;
  11. using GpsCardGatewayPosition.Service.Biz.Pay;
  12. using GpsCardGatewayPosition.Service.Biz.Sos;
  13. using GpsCardGatewayPosition.Service.Cache;
  14. using GpsCardGatewayPosition.Service.MqProducer;
  15. using GpsCardGatewayPosition.Service.Resolver.Factory;
  16. using GpsCardGatewayPosition.Service.Resolver.Interface;
  17. using GpsCardGatewayPosition.Service.Resolver.Property;
  18. using Microsoft.Extensions.Configuration;
  19. using Microsoft.Extensions.DependencyInjection;
  20. using Microsoft.Extensions.DependencyInjection.Extensions;
  21. using Microsoft.Extensions.Hosting;
  22. using Microsoft.Extensions.Http;
  23. using Newtonsoft.Json;
  24. using Serilog;
  25. using TelpoDataService.Util.Clients;
  26. namespace GpsCardGatewayPosition.Postion
  27. {
  28. internal class Program
  29. {
  30. static void Main(string[] args)
  31. {
  32. //选择配置文件appsetting.json
  33. var config = new ConfigurationBuilder()
  34. .SetBasePath(Directory.GetCurrentDirectory())
  35. .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
  36. .Build();
  37. Log.Logger = new LoggerConfiguration()
  38. .ReadFrom.Configuration(config).Enrich.WithThreadInfo()
  39. .CreateLogger();
  40. try
  41. {
  42. Log.Information("Starting up");
  43. CreateHostBuilder(args).Build().Run();
  44. }
  45. catch (Exception ex)
  46. {
  47. Log.Fatal(ex, "Application start-up failed");
  48. }
  49. finally
  50. {
  51. Log.CloseAndFlush();
  52. }
  53. }
  54. public static IHostBuilder CreateHostBuilder(string[] args) =>
  55. Host.CreateDefaultBuilder(args)
  56. .UseSerilog()
  57. .ConfigureServices((hostContext, services) =>
  58. {
  59. var configuration = hostContext.Configuration;
  60. services.Configure<RedisConfig>(configuration.GetSection("Redis"));
  61. services.Configure<ServiceConfig>(configuration.GetSection("ServiceConfig"));
  62. services.Configure<IotConfig>(configuration.GetSection("IOTConfig"));
  63. services.Configure<ServiceAccessConfig>(configuration.GetSection("ServiceAccessConfig"));
  64. services.Configure<WifiParamConfig>(configuration.GetSection("WifiParam"));
  65. services.Configure<WayzServicesConfig>(configuration.GetSection("WayzServices"));
  66. services.Configure<GaodeServicesConfig>(configuration.GetSection("GaodeServices"));
  67. JsonSerializerSettings setting = new();
  68. JsonConvert.DefaultSettings = () =>
  69. {
  70. setting.DateFormatString = "yyyy-MM-dd HH:mm:ss";
  71. //setting.ContractResolver = new CamelCasePropertyNamesContractResolver();
  72. setting.NullValueHandling = new NullValueHandling();
  73. setting.Formatting = Formatting.None;
  74. return setting;
  75. };
  76. services.AddHttpClient(Consts.DEFAULT_HTTPCLIENT_NAME, c =>
  77. {
  78. c.Timeout = TimeSpan.FromSeconds(10); //超时限制
  79. c.DefaultRequestHeaders.Add("Accept", "application/json");
  80. //c.DefaultRequestHeaders.Connection.Add("keep-alive");
  81. });
  82. services.AddTelpoDataServices(opt =>
  83. {
  84. opt.TelpoDataUrl = configuration["ServiceConfig:TelpoDataUrl"];
  85. });
  86. services.Replace(ServiceDescriptor.Singleton<IHttpMessageHandlerBuilderFilter, CustomLoggingFilter>());
  87. #region 注册消息解析器工厂
  88. //services.AddSingleton<IResolverFactory, ResolverFactory>();
  89. services.AddSingleton<ResolverFactory>();
  90. //services.AddSingleton<PropertyResolverFactory>();
  91. #endregion
  92. services.AddSingleton<GlobalService>();
  93. services.AddSingleton<PersonCacheManager>();
  94. services.AddSingleton<DeviceCacheManager>();
  95. services.AddSingleton<PayLogic>();
  96. services.AddSingleton<SosLogic>();
  97. services.AddSingleton<HealthLogic>();
  98. services.AddSingleton<WifiPositionResolver>();
  99. services.AddSingleton<WifiPlus2PositionResolver>();
  100. services.AddSingleton<GpsPositionResolver>();
  101. services.AddSingleton<LbsGsmPositionResolver>();
  102. services.AddSingleton<MessageProducer>();
  103. services.AddSingleton<MqProcessLogic>();
  104. #region
  105. services.AddSingleton<DeviceIotOpenService>();
  106. services.AddSingleton<WayzService>();
  107. services.AddSingleton<GaodeService>();
  108. services.AddSingleton<LocationLogic>();
  109. #endregion
  110. services.AddSingleton<HttpHelper>();
  111. services.AddHostedService<Worker>();
  112. });
  113. }
  114. }