|
|
|
|
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 保留所有权利。
|
|
|
|
|
* CLR版本:4.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);
|
|
|
|
|
_rfid.ip = item.equipIp;
|
|
|
|
|
_rfid.port = 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);
|
|
|
|
|
}
|
|
|
|
|
_rfid.IsConnected = true;
|
|
|
|
|
absractFactories.Add(_rfid);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
_rfid.IsConnected = false;
|
|
|
|
|
absractFactories.Add(_rfid);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Log.Error("RFID配置信息为空");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Log.Error($"RFID初始化连接异常:{e.Message}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return absractFactories;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|