|
- 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<RedisConfig>(configuration.GetSection("Redis"));
- services.Configure<ServiceConfig>(configuration.GetSection("ServiceConfig"));
- services.Configure<IotConfig>(configuration.GetSection("IOTConfig"));
- services.Configure<ServiceAccessConfig>(configuration.GetSection("ServiceAccessConfig"));
- services.Configure<WifiParamConfig>(configuration.GetSection("WifiParam"));
- services.Configure<WayzServicesConfig>(configuration.GetSection("WayzServices"));
- services.Configure<GaodeServicesConfig>(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<IHttpMessageHandlerBuilderFilter, CustomLoggingFilter>());
-
- #region 注册消息解析器工厂
- //services.AddSingleton<IResolverFactory, ResolverFactory>();
- services.AddSingleton<ResolverFactory>();
- //services.AddSingleton<PropertyResolverFactory>();
-
- #endregion
- services.AddSingleton<GlobalService>();
- services.AddSingleton<PersonCacheManager>();
- services.AddSingleton<DeviceCacheManager>();
- services.AddSingleton<PayLogic>();
- services.AddSingleton<SosLogic>();
- services.AddSingleton<HealthLogic>();
-
- services.AddSingleton<WifiPositionResolver>();
- services.AddSingleton<WifiPlus2PositionResolver>();
- services.AddSingleton<GpsPositionResolver>();
- services.AddSingleton<LbsGsmPositionResolver>();
-
- services.AddSingleton<MessageProducer>();
- services.AddSingleton<MqProcessLogic>();
-
- #region
- services.AddSingleton<DeviceIotOpenService>();
- services.AddSingleton<WayzService>();
- services.AddSingleton<GaodeService>();
- services.AddSingleton<LocationLogic>();
- #endregion
-
-
- services.AddSingleton<HttpHelper>();
- services.AddHostedService<Worker>();
- });
- }
- }
|