You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

98 lines
3.9 KiB
C#

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<AppConfig>();
var log = ServiceProvider.GetService<SerilogHelper>();
log.Info($"系统启动成功,日志存放位置:{appConfig.logPath}");
var deviceCollectionBusiness = ServiceProvider.GetService<DeviceCollectionBusiness>();
deviceCollectionBusiness?.Handle();
//IOpcService _opcService = ServiceProvider.GetService<OpcUaService>();
//var result = _opcService.ConnectAsync("opc.tcp://192.168.0.100:62541/SharpNodeSettings/OpcUaServer").Result;
//if (result)
//{
// while (true)
// {
// var info = _opcService.ReadNodeAsync(new List<string>()
// {
// "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<AppConfig>(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<AppConfig>();
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"
}));
}
}
}