using GpsCardGatewayPosition.Common; using GpsCardGatewayPosition.Common.Helper; using GpsCardGatewayPosition.Gateway; using GpsCardGatewayPosition.Gateway.Config; using GpsCardGatewayPosition.Model.Config; using GpsCardGatewayPosition.Postion.HttpLog; using GpsCardGatewayPosition.Service.Biz; using GpsCardGatewayPosition.Service.Biz.Health; using GpsCardGatewayPosition.Service.Biz.Iot; using GpsCardGatewayPosition.Service.Biz.Location; using GpsCardGatewayPosition.Service.Biz.Pay; using GpsCardGatewayPosition.Service.Biz.Sos; using GpsCardGatewayPosition.Service.Cache; using GpsCardGatewayPosition.Service.MqProducer; using GpsCardGatewayPosition.Service.Resolver.Factory; using GpsCardGatewayPosition.Service.Resolver.Interface; using GpsCardGatewayPosition.Service.Resolver.Property; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Http; using Newtonsoft.Json; using Serilog; using TelpoDataService.Util.Clients; namespace GpsCardGatewayPosition.Postion { internal class Program { static void Main(string[] args) { //选择配置文件appsetting.json var config = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) .Build(); Log.Logger = new LoggerConfiguration() .ReadFrom.Configuration(config).Enrich.WithThreadInfo() .CreateLogger(); try { Log.Information("Starting up"); CreateHostBuilder(args).Build().Run(); } catch (Exception ex) { Log.Fatal(ex, "Application start-up failed"); } finally { Log.CloseAndFlush(); } } public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) .UseSerilog() .ConfigureServices((hostContext, services) => { var configuration = hostContext.Configuration; services.Configure(configuration.GetSection("Redis")); services.Configure(configuration.GetSection("ServiceConfig")); services.Configure(configuration.GetSection("IOTConfig")); services.Configure(configuration.GetSection("ServiceAccessConfig")); services.Configure(configuration.GetSection("WifiParam")); services.Configure(configuration.GetSection("WayzServices")); services.Configure(configuration.GetSection("GaodeServices")); JsonSerializerSettings setting = new(); JsonConvert.DefaultSettings = () => { setting.DateFormatString = "yyyy-MM-dd HH:mm:ss"; //setting.ContractResolver = new CamelCasePropertyNamesContractResolver(); setting.NullValueHandling = new NullValueHandling(); setting.Formatting = Formatting.None; return setting; }; services.AddHttpClient(Consts.DEFAULT_HTTPCLIENT_NAME, c => { c.Timeout = TimeSpan.FromSeconds(10); //超时限制 c.DefaultRequestHeaders.Add("Accept", "application/json"); //c.DefaultRequestHeaders.Connection.Add("keep-alive"); }); services.AddTelpoDataServices(opt => { opt.TelpoDataUrl = configuration["ServiceConfig:TelpoDataUrl"]; }); services.Replace(ServiceDescriptor.Singleton()); #region 注册消息解析器工厂 //services.AddSingleton(); services.AddSingleton(); //services.AddSingleton(); #endregion services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); #region services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); #endregion services.AddSingleton(); services.AddHostedService(); }); } }