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.

107 lines
3.3 KiB
C#

2 months ago
using SlnMesnac.Plc;
using SlnMesnac.Rfid;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
* (c) 2024 WenJY
* CLR4.0.30319.42000
* LAPTOP-E0N2L34V
* SlnMesnac.Business.base
* b00d95c1-a164-43a3-9f34-2a5d2efb3f34
*
* WenJY
* wenjy@mesnac.com
* 2024-04-12 17:36:19
* V1.0.0
*
*
*--------------------------------------------------------------------
*
*
*
*
* V1.0.0
*--------------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
namespace SlnMesnac.Business.@base
{
internal class BaseBusiness
{
private readonly List<PlcAbsractFactory> _plcFactories;
private readonly List<RfidAbsractFactory> _rfidFactories;
public BaseBusiness(List<PlcAbsractFactory> plcFactories, List<RfidAbsractFactory> rfidFactories)
{
_plcFactories = plcFactories;
_rfidFactories = rfidFactories;
}
/// <summary>
/// 根据Key获取PLC连接信息
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
/// <exception cref="InvalidOperationException"></exception>
public PlcAbsractFactory GetPlcByKey(string key)
{
if(_plcFactories == null)
{
throw new ArgumentNullException($"根据Key获取PLC连接信息异常:PLC 连接信息为空");
}
if (string.IsNullOrEmpty(key))
{
throw new ArgumentNullException("根据Key获取PLC连接信息异常:设备Key参数为空");
}
try
{
var info = _plcFactories.Where(x => x.ConfigKey == key).FirstOrDefault();
return info;
}catch(Exception ex)
{
throw new InvalidOperationException($"根据Key获取PLC连接信息异常:{ex.Message}");
}
}
/// <summary>
/// 根据Key获取Rfid连接信息
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
/// <exception cref="InvalidOperationException"></exception>
public RfidAbsractFactory GetRfidByKey(string key)
{
if (_rfidFactories == null)
{
throw new ArgumentNullException($"根据Key获取RFID连接信息异常:PLC 连接信息为空");
}
if (string.IsNullOrEmpty(key))
{
throw new ArgumentNullException("根据Key获取RFID连接信息异常:设备Key参数为空");
}
try
{
var info = _rfidFactories.Where(x => x.ConfigKey == key).FirstOrDefault();
return info;
}
catch (Exception ex)
{
throw new InvalidOperationException($"根据Key获取RFID连接信息异常:{ex.Message}");
}
}
}
}