using System.Reflection; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using NeoSmart.Caching.Sqlite; using Sln.Imm.Daemon.Business; using Sln.Imm.Daemon.Cache; using Sln.Imm.Daemon.Config; using Sln.Imm.Daemon.Opc; using Sln.Imm.Daemon.Opc.Impl; using Sln.Imm.Daemon.Repository; using Sln.Imm.Daemon.Serilog; using ZiggyCreatures.Caching.Fusion; using ZiggyCreatures.Caching.Fusion.Serialization.NewtonsoftJson; namespace Sln.Imm.Daemon { internal class Program { public static IServiceProvider? ServiceProvider = null; static void Main(string[] args) { var services = new ServiceCollection(); ConfigureServices(services); ServiceProvider = services.BuildServiceProvider(); ServiceProvider.UseSerilogExtensions(); var appConfig = ServiceProvider.GetService(); var log = ServiceProvider.GetService(); log.Info($"系统启动成功,日志存放位置:{appConfig.logPath}"); var deviceCollectionBusiness = ServiceProvider.GetService(); deviceCollectionBusiness?.Handle(); //IOpcService _opcService = ServiceProvider.GetService(); //var result = _opcService.ConnectAsync("opc.tcp://192.168.0.100:62541/SharpNodeSettings/OpcUaServer").Result; //if (result) //{ // while (true) // { // var info = _opcService.ReadNodeAsync(new List() // { // "ns=2;s=Devices/分厂一/车间一/测试空设备/压力", // "ns=2;s=Devices/分厂一/车间一/测试空设备/温度", // "ns=2;s=Devices/分厂一/车间一/测试空设备/条码" // }); // var infos = _opcService.BrowseNodesAsync("ns=2;s=Devices/分厂一/车间一/测试空设备"); // Thread.Sleep(5000); // } //} Task.Delay(-1).Wait(); } private static void ConfigureServices(IServiceCollection services) { services.AddSingleton(provider => { var configurationBuilder = new ConfigurationBuilder() .SetBasePath(AppDomain.CurrentDomain.BaseDirectory) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true); IConfiguration configuration = configurationBuilder.Build(); var ap = configuration.GetSection("AppConfig").Get(); return ap; }); Assembly[] assemblies = { Assembly.LoadFrom("Sln.Imm.Daemon.Common.dll"), Assembly.LoadFrom("Sln.Imm.Daemon.Repository.dll"), Assembly.LoadFrom("Sln.Imm.Daemon.Cache.dll"), Assembly.LoadFrom("Sln.Imm.Daemon.Business.dll"), Assembly.LoadFrom("Sln.Imm.Daemon.Opc.dll"), // Assembly.LoadFrom("Sln.Iot.Business.dll"), }; services.Scan(scan => scan.FromAssemblies(assemblies) .AddClasses() .AsImplementedInterfaces() .AsSelf() .WithSingletonLifetime()); services.AddSingleton(typeof(SerilogHelper)); services.AddSqlSugarSetup(); services.AddFusionCache() .WithSerializer( new FusionCacheNewtonsoftJsonSerializer() ) .WithDistributedCache( new SqliteCache(new SqliteCacheOptions { CachePath = "F:\\桌面\\数据缓存\\FusionCache.db" //CachePath = "/Users/wenxiansheng/Public/WorkSpace/Mesnac/项目资料/澳柯玛注塑车间MES项目/数据缓存/FusionCache.db" })); } } }