增加变量运行态 CollectVariableRuntime 所在设备属性

This commit is contained in:
2248356998 qq.com
2023-06-15 16:50:08 +08:00
parent c2cfc42ba4
commit 2b36a99720
5 changed files with 34 additions and 27 deletions

View File

@@ -229,23 +229,35 @@ public class CollectDeviceService : DbRepository<CollectDevice>, ICollectDeviceS
device.PluginName = pluginName;
device.DeviceVariableRunTimes = collectVariableRunTimes.Where(a => a.DeviceId == device.Id).ToList();
}
ParallelOptions options = new ParallelOptions();
options.MaxDegreeOfParallelism = Environment.ProcessorCount / 2;
Parallel.ForEach(collectVariableRunTimes, options, variable =>
{
variable.CollectDeviceRunTime = runtime.FirstOrDefault(a => a.Id == variable.DeviceId);
variable.DeviceName = runtime.FirstOrDefault(a => a.Id == variable.DeviceId).Name;
});
return runtime;
}
else
{
var devices = GetCacheList().Where(a => a.Enable).ToList();
devices = devices.Where(it => it.Id == devId).ToList();
var runtime = devices.Adapt<List<CollectDeviceRunTime>>();
var device = GetCacheList().Where(a => a.Enable).ToList().FirstOrDefault(it => it.Id == devId);
var runtime = device.Adapt<CollectDeviceRunTime>();
using var serviceScope = _scopeFactory.CreateScope();
var variableService = serviceScope.ServiceProvider.GetService<IVariableService>();
foreach (var device in runtime)
var pluginName = _driverPluginService.GetNameById(device.PluginId);
var collectVariableRunTimes = await variableService.GetCollectDeviceVariableRuntimeAsync(devId);
runtime.PluginName = pluginName;
runtime.DeviceVariableRunTimes = collectVariableRunTimes;
ParallelOptions options = new ParallelOptions();
options.MaxDegreeOfParallelism = Environment.ProcessorCount / 2;
Parallel.ForEach(collectVariableRunTimes, options, variable =>
{
var pluginName = _driverPluginService.GetNameById(device.PluginId);
var collectVariableRunTimes = await variableService.GetCollectDeviceVariableRuntimeAsync(devId);
device.PluginName = pluginName;
device.DeviceVariableRunTimes = collectVariableRunTimes;
}
return runtime;
variable.CollectDeviceRunTime = runtime;
variable.DeviceName = runtime.Name;
});
return new() { runtime };
}

View File

@@ -192,26 +192,12 @@ public class VariableService : DbRepository<CollectDeviceVariable>, IVariableSer
{
var deviceVariables = await GetListAsync();
var runtime = deviceVariables.Adapt<List<CollectVariableRunTime>>();
ParallelOptions options = new ParallelOptions();
options.MaxDegreeOfParallelism = Environment.ProcessorCount / 2;
Parallel.ForEach(runtime, options, device =>
{
var deviceName = _collectDeviceService.GetNameById(device.DeviceId);
device.DeviceName = deviceName;
});
return runtime;
}
else
{
var deviceVariables = await GetListAsync(a => a.DeviceId == devId);
var runtime = deviceVariables.Adapt<List<CollectVariableRunTime>>();
ParallelOptions options = new ParallelOptions();
options.MaxDegreeOfParallelism = Environment.ProcessorCount / 2;
Parallel.ForEach(runtime, options, device =>
{
var deviceName = _collectDeviceService.GetNameById(device.DeviceId);
device.DeviceName = deviceName;
});
return runtime;
}

View File

@@ -49,6 +49,14 @@ public class CollectVariableRunTime : CollectDeviceVariable
}
}
/// <summary>
/// 所在采集设备
/// </summary>
[Newtonsoft.Json.JsonIgnore]
[System.Text.Json.Serialization.JsonIgnore]
[Description("采集设备")]
public CollectDeviceRunTime CollectDeviceRunTime { get; set; }
/// <summary>
/// 原始值
/// </summary>

View File

@@ -179,6 +179,7 @@
datas.RemoveWhere(it => it.Value == nameof(CollectVariableRunTime.DataType));
datas.RemoveWhere(it => it.Value == nameof(CollectVariableRunTime.EventTime));
datas.RemoveWhere(it => it.Value == nameof(CollectVariableRunTime.EventTypeEnum));
datas.RemoveWhere(it => it.Value == nameof(CollectVariableRunTime.CollectDeviceRunTime));
datas.RemoveWhere(it => it.Value.Contains("His"));
datas.RemoveWhere(it => it.Value.Contains("Alarm"));

View File

@@ -7,17 +7,17 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
<DeleteExistingFiles>true</DeleteExistingFiles>
<ExcludeApp_Data>false</ExcludeApp_Data>
<LaunchSiteAfterPublish>true</LaunchSiteAfterPublish>
<LastUsedBuildConfiguration>KINGVIEW</LastUsedBuildConfiguration>
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<PublishProvider>FileSystem</PublishProvider>
<PublishUrl>bin\KINGVIEW\net6.0\publish\win-64</PublishUrl>
<PublishUrl>bin\Release\net6.0\publish\win-64</PublishUrl>
<WebPublishMethod>FileSystem</WebPublishMethod>
<_TargetId>Folder</_TargetId>
<SiteUrlToLaunchAfterPublish />
<TargetFramework>net6.0</TargetFramework>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<ProjectGuid>5fea231a-5d22-428d-a0fa-814dbc3091c1</ProjectGuid>
<SelfContained>false</SelfContained>
<SelfContained>true</SelfContained>
<PublishSingleFile>false</PublishSingleFile>
<PublishReadyToRun>false</PublishReadyToRun>
</PropertyGroup>