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#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using SlnMesnac.Plc;
using SlnMesnac.Rfid;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
* 版权所有 (c) 2024 WenJY 保留所有权利。
* CLR版本4.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}");
}
}
}
}