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.
crop/SlnMesnac.Business/base/BaseBusiness.cs

78 lines
2.1 KiB
C#

7 months ago
using SlnMesnac.Plc;
7 months ago
7 months ago
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;
7 months ago
7 months ago
7 months ago
public BaseBusiness(List<PlcAbsractFactory> plcFactories)
7 months ago
{
_plcFactories = plcFactories;
7 months ago
7 months ago
}
/// <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}");
}
}
7 months ago
7 months ago
}
}