wanshenmean
19 小时以前 627371d0ffdf50239313f2c86d022a0c5c69550d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using SqlSugar;
using System.Collections.Concurrent;
 
namespace WIDESEAWCS_QuartzJob
{
    /// <summary>
    /// 静态变量存储区,可使用静态变量,也可注入使用
    /// </summary>
    public class Storage
    {
        /// <summary>
        /// 已连接设备对象集合(线程安全)
        /// </summary>
        public static ConcurrentBag<IDevice> Devices = new ConcurrentBag<IDevice>();
 
        /// <summary>
        /// 设备对象
        /// </summary>
        public List<IDevice> Pro_Devices { get; set; }
 
        /// <summary>
        /// 构造函数
        /// </summary>
        public Storage()
        {
            Pro_Devices = new List<IDevice>();
        }
 
        /// <summary>
        /// 获取设备
        /// </summary>
        /// <param name="deviceCode">设备编码</param>
        /// <returns>设备实例,未找到返回 null</returns>
        public IDevice? GetDevice(string deviceCode)
        {
            return Pro_Devices.FirstOrDefault(x => x.DeviceCode == deviceCode);
        }
 
        /// <summary>
        /// 获取设备
        /// </summary>
        /// <param name="deviceCodes">设备编码列表</param>
        /// <returns>匹配的设备列表</returns>
        public List<IDevice> GetDevices(List<string> deviceCodes)
        {
            return Pro_Devices.Where(x => deviceCodes.Contains(x.DeviceCode)).ToList();
        }
    }
}