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.

87 lines
3.1 KiB
C#

using Microsoft.Extensions.DependencyInjection;
using Serilog;
using SlnMesnac.Config;
using SlnMesnac.Rfid;
using SlnMesnac.Rfid.Factory;
using System;
using System.Collections.Generic;
using System.Text;
#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
* (c) 2024 WenJY
* CLR4.0.30319.42000
* LAPTOP-E0N2L34V
* SlnMesnac.Extensions
* c1e3e96b-3317-461c-abda-6af7c7d08df4
*
* WenJY
* wenjy@mesnac.com
* 2024-04-15 09:53:09
* V1.0.0
*
*
*--------------------------------------------------------------------
*
*
*
*
* V1.0.0
*--------------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
namespace SlnMesnac.Extensions
{
public static class RfidFactorySetup
{
public static void AddRfidFactorySetup(this IServiceCollection services)
{
services.AddSingleton<List<RfidAbsractFactory>>(x =>
{
AppConfig appConfig = x.GetService<AppConfig>();
List<RfidAbsractFactory> absractFactories = new List<RfidAbsractFactory>();
try
{
if (appConfig.rfidConfig != null)
{
foreach (var item in appConfig.rfidConfig)
{
if (item.isFlage)
{
RfidAbsractFactory _rfid = x.GetService<RflyFactory>();
bool connectResult = _rfid.Connect(item.equipIp, item.equipPort);
if (connectResult)
{
Log.Information($"RFID{item.equipIp}:{item.equipPort};连接成功,时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
_rfid.ConfigKey = item.equipKey;
if (absractFactories.Contains(_rfid))
{
absractFactories.Remove(_rfid);
}
absractFactories.Add(_rfid);
}
else
{
Log.Information($"RFID{item.equipIp}:{item.equipPort};连接失败,时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
}
}
}
}
else
{
Log.Error("RFID配置信息为空");
}
}
catch (Exception e)
{
Log.Error($"RFID初始化连接异常{e.Message}");
}
return absractFactories;
});
}
}
}