using System.Reflection; using Com.Ctrip.Framework.Apollo; using Flurl.Http; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using NeoSmart.Caching.Sqlite; using Sln.Wcs.HikRoBotApi.Domain.Dto.GbTaskSubmit; using Sln.Wcs.HikRoBotApi.Domain.Dto.GenAgvSchedulingTask; using Sln.Wcs.HikRoBotApi.Service; using Sln.Wcs.HikRoBotApi.Service.Impl; using Sln.Wcs.Repository; using Sln.Wcs.Serilog; using Sln.Wcs.Plc; using Sln.Wcs.Strategy; using ZiggyCreatures.Caching.Fusion; using ZiggyCreatures.Caching.Fusion.Serialization.NewtonsoftJson; using TargetRoute = Sln.Wcs.HikRoBotApi.Domain.Dto.GbTaskSubmit.TargetRoute; namespace Sln.Wcs { public class Program { static async Task Main(string[] args) { var services = new ServiceCollection(); ConfigureServices(services); var serviceProvider = services.BuildServiceProvider(); serviceProvider.UseSerilogExtensions(); var config = serviceProvider.GetService(); var log = serviceProvider.GetService(); log.Info($"系统启动成功,日志存放位置:{config["logPath"]}"); //禁用 SSL FlurlHttp.ConfigureClientForUrl("https://172.16.12.11") .ConfigureInnerHandler(handler => { handler.ServerCertificateCustomValidationCallback = (_, _, _, _) => true; }); var service = serviceProvider.GetService(); var res = service.GbTaskSubmit(new GbTaskSubmitDto() { TaskType = "PF-FMR-COMMON", TargetRoute = new List() { new TargetRoute(){Type = "STORAGE",Code = "R5001A02011"}, new TargetRoute(){Type = "STORAGE",Code = "R5001A01011"} } }); Task.Delay(-1).Wait(); } private static void ConfigureServices(IServiceCollection services) { var basePath = AppContext.BaseDirectory; ApolloConfigureServices(services,ref basePath,out IConfiguration apolloConfiguration); Assembly[] assemblies = { Assembly.LoadFrom(Path.Combine(basePath, "Sln.Wcs.Common.dll")), Assembly.LoadFrom(Path.Combine(basePath, "Sln.Wcs.Cache.dll")), Assembly.LoadFrom(Path.Combine(basePath, "Sln.Wcs.Repository.dll")), Assembly.LoadFrom(Path.Combine(basePath, "Sln.Wcs.HikRoBotApi.dll")), Assembly.LoadFrom(Path.Combine(basePath, "Sln.Wcs.HikRoBotSdk.dll")), Assembly.LoadFrom(Path.Combine(basePath, "Sln.Wcs.HoistApi.dll")), Assembly.LoadFrom(Path.Combine(basePath, "Sln.Wcs.HoistSdk.dll")), Assembly.LoadFrom(Path.Combine(basePath, "Sln.Wcs.Plc.dll")), Assembly.LoadFrom(Path.Combine(basePath, "Sln.Wcs.Business.dll")), Assembly.LoadFrom(Path.Combine(basePath, "Sln.Wcs.Strategy.dll")), }; services.Scan(scan => scan.FromAssemblies(assemblies) .AddClasses() .AsImplementedInterfaces() .AsSelf() .WithTransientLifetime()); services.AddSingleton(typeof(SerilogHelper)); services.AddSingleton(typeof(MaterialInStoreTest)); services.AddSqlSugarSetup(); services.AddPlcSetup(); services.AddFusionCache() .WithSerializer( new FusionCacheNewtonsoftJsonSerializer() ) .WithDistributedCache(new SqliteCache(new SqliteCacheOptions { CachePath = apolloConfiguration["cachePath"] })); } /// /// Apollo 配置中心 /// /// /// /// private static void ApolloConfigureServices(IServiceCollection services, ref string basePath, out IConfiguration apolloConfiguration) { var localConfiguration = new ConfigurationBuilder() .SetBasePath(basePath) .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) .Build(); var apolloConfigSection = localConfiguration.GetSection("apollo"); services.AddSingleton(localConfiguration); var configurationBuilder = new ConfigurationBuilder() .SetBasePath(basePath) .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) .AddApollo(apolloConfigSection) .AddDefault(); apolloConfiguration = configurationBuilder.Build(); services.Remove(new ServiceDescriptor(typeof(IConfiguration), localConfiguration)); services.AddSingleton(apolloConfiguration); } } }