refactor:删除了DeviceDto,VariableDto,VariableTableDto,改为使用DMS.Core中的实体
This commit is contained in:
@@ -6,6 +6,7 @@ using DMS.Application.Interfaces;
|
||||
using DMS.Application.Models;
|
||||
using DMS.Core.Enums;
|
||||
using DMS.Core.Events;
|
||||
using DMS.Core.Models;
|
||||
using DMS.Infrastructure.Interfaces.Services;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
@@ -30,7 +31,7 @@ public class OptimizedS7BackgroundService : BackgroundService
|
||||
private readonly int _s7PollOnceSleepTimeMs = 50;
|
||||
|
||||
// 存储每个设备的变量按轮询间隔分组
|
||||
private readonly ConcurrentDictionary<int, Dictionary<int, List<VariableDto>>> _variablesByPollingInterval = new();
|
||||
private readonly ConcurrentDictionary<int, Dictionary<int, List<Variable>>> _variablesByPollingInterval = new();
|
||||
|
||||
|
||||
/// <summary>
|
||||
@@ -132,7 +133,7 @@ public class OptimizedS7BackgroundService : BackgroundService
|
||||
_s7ServiceManager.AddDevice(s7Device);
|
||||
|
||||
// 查找设备中所有要轮询的变量
|
||||
var variables = new List<VariableDto>();
|
||||
var variables = new List<Variable>();
|
||||
|
||||
foreach (var variableTable in s7Device.VariableTables)
|
||||
{
|
||||
@@ -203,7 +204,7 @@ public class OptimizedS7BackgroundService : BackgroundService
|
||||
/// <summary>
|
||||
/// 轮询设备的变量
|
||||
/// </summary>
|
||||
private async Task PollVariablesForDeviceAsync(S7DeviceContext context, List<VariableDto> variables,
|
||||
private async Task PollVariablesForDeviceAsync(S7DeviceContext context, List<Variable> variables,
|
||||
CancellationToken stoppingToken)
|
||||
{
|
||||
if (!_appDataStorageService.Devices.TryGetValue(context.Device.Id, out var device))
|
||||
|
||||
@@ -246,7 +246,7 @@ namespace DMS.Infrastructure.Services.S7
|
||||
variable.UpdatedAt = DateTime.Now;
|
||||
|
||||
// 创建VariableDto对象
|
||||
var variableDto = new VariableDto
|
||||
var variableDto = new Variable
|
||||
{
|
||||
Id = variable.Id,
|
||||
Name = variable.Name,
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
using System.Collections.Concurrent;
|
||||
using System.Diagnostics;
|
||||
using DMS.Application.DTOs;
|
||||
using DMS.Application.Events;
|
||||
using DMS.Application.Interfaces;
|
||||
using DMS.Core.Enums;
|
||||
using DMS.Core.Events;
|
||||
using DMS.Core.Models;
|
||||
using DMS.Infrastructure.Interfaces.Services;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NPOI.HSSF.Record;
|
||||
@@ -85,7 +85,7 @@ namespace DMS.Infrastructure.Services.S7
|
||||
/// <summary>
|
||||
/// 添加设备到监控列表
|
||||
/// </summary>
|
||||
public void AddDevice(DeviceDto device)
|
||||
public void AddDevice(DMS.Core.Models.Device device)
|
||||
{
|
||||
if (device == null)
|
||||
throw new ArgumentNullException(nameof(device));
|
||||
@@ -100,7 +100,7 @@ namespace DMS.Infrastructure.Services.S7
|
||||
{
|
||||
Device = device,
|
||||
S7Service = _s7ServiceFactory.CreateService(),
|
||||
Variables = new ConcurrentDictionary<string, VariableDto>(),
|
||||
Variables = new ConcurrentDictionary<string, Variable>(),
|
||||
IsConnected = false
|
||||
};
|
||||
|
||||
@@ -123,7 +123,7 @@ namespace DMS.Infrastructure.Services.S7
|
||||
/// <summary>
|
||||
/// 更新设备变量
|
||||
/// </summary>
|
||||
public void UpdateVariables(int deviceId, List<VariableDto> variables)
|
||||
public void UpdateVariables(int deviceId, List<Variable> variables)
|
||||
{
|
||||
if (_deviceContexts.TryGetValue(deviceId, out var context))
|
||||
{
|
||||
@@ -467,9 +467,9 @@ namespace DMS.Infrastructure.Services.S7
|
||||
/// </summary>
|
||||
public class S7DeviceContext
|
||||
{
|
||||
public DeviceDto Device { get; set; }
|
||||
public DMS.Core.Models.Device Device { get; set; }
|
||||
public IS7Service S7Service { get; set; }
|
||||
public ConcurrentDictionary<string, VariableDto> Variables { get; set; }
|
||||
public ConcurrentDictionary<string, Variable> Variables { get; set; }
|
||||
public bool IsConnected { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user