mirror of
https://gitee.com/ThingsGateway/ThingsGateway.git
synced 2025-10-25 04:33:09 +08:00
Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6510c3e289 | ||
|
|
920e407d05 | ||
|
|
7314c8901d | ||
|
|
4e9f02b48c | ||
|
|
9ae7602cb4 | ||
|
|
aa8aa36aef | ||
|
|
0174f7c6f2 | ||
|
|
df9e7d6ff1 | ||
|
|
b40ca920d3 | ||
|
|
5a4b0a0e93 | ||
|
|
a879edd68b | ||
|
|
62e0a6ee9d | ||
|
|
765e5564d4 | ||
|
|
10eecac19b |
@@ -1,5 +1,5 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Import Project="$(SolutionDir)PackNuget.props" />
|
||||
<Import Project="..\..\PackNuget.props" />
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netstandard2.0;</TargetFrameworks>
|
||||
<Version>$(SourceGeneratorVersion)</Version>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
|
||||
namespace BlazorSetParametersAsyncGenerator;
|
||||
namespace Microsoft.AspNetCore.Components;
|
||||
|
||||
[Generator]
|
||||
public partial class SetParametersAsyncGenerator : ISourceGenerator
|
||||
@@ -11,7 +11,7 @@ public partial class SetParametersAsyncGenerator : ISourceGenerator
|
||||
private string m_DoNotGenerateSetParametersAsyncAttribute = """
|
||||
|
||||
using System;
|
||||
namespace BlazorSetParametersAsyncGenerator
|
||||
namespace Microsoft.AspNetCore.Components
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = true)]
|
||||
internal sealed class DoNotGenerateSetParametersAsyncAttribute : Attribute
|
||||
@@ -25,7 +25,7 @@ public partial class SetParametersAsyncGenerator : ISourceGenerator
|
||||
private string m_GenerateSetParametersAsyncAttribute = """
|
||||
|
||||
using System;
|
||||
namespace BlazorSetParametersAsyncGenerator
|
||||
namespace Microsoft.AspNetCore.Components
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = true)]
|
||||
internal sealed class GenerateSetParametersAsyncAttribute : Attribute
|
||||
@@ -40,7 +40,7 @@ public partial class SetParametersAsyncGenerator : ISourceGenerator
|
||||
private string m_GlobalGenerateSetParametersAsyncAttribute = """
|
||||
|
||||
using System;
|
||||
namespace BlazorSetParametersAsyncGenerator
|
||||
namespace Microsoft.AspNetCore.Components
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = false)]
|
||||
internal sealed class GlobalGenerateSetParametersAsyncAttribute : Attribute
|
||||
@@ -445,8 +445,8 @@ namespace {namespaceName}
|
||||
private static IEnumerable<INamedTypeSymbol> GetCandidateClasses(SyntaxReceiver receiver, GeneratorExecutionContext context)
|
||||
{
|
||||
var compilation = context.Compilation;
|
||||
var positiveAttributeSymbol = compilation.GetTypeByMetadataName("BlazorSetParametersAsyncGenerator.GenerateSetParametersAsyncAttribute");
|
||||
var negativeAttributeSymbol = compilation.GetTypeByMetadataName("BlazorSetParametersAsyncGenerator.DoNotGenerateSetParametersAsyncAttribute");
|
||||
var positiveAttributeSymbol = compilation.GetTypeByMetadataName("Microsoft.AspNetCore.Components.GenerateSetParametersAsyncAttribute");
|
||||
var negativeAttributeSymbol = compilation.GetTypeByMetadataName("Microsoft.AspNetCore.Components.DoNotGenerateSetParametersAsyncAttribute");
|
||||
|
||||
// loop over the candidate methods, and keep the ones that are actually annotated
|
||||
|
||||
@@ -454,7 +454,7 @@ namespace {namespaceName}
|
||||
var assemblyAttributes = compilation.Assembly.GetAttributes();
|
||||
|
||||
var enableAttr = assemblyAttributes.FirstOrDefault(attr =>
|
||||
attr.AttributeClass?.ToDisplayString() == "BlazorSetParametersAsyncGenerator.GlobalGenerateSetParametersAsyncAttribute");
|
||||
attr.AttributeClass?.ToDisplayString() == "Microsoft.AspNetCore.Components.GlobalGenerateSetParametersAsyncAttribute");
|
||||
|
||||
var globalEnable = false;
|
||||
if (enableAttr != null)
|
||||
|
||||
@@ -3,7 +3,7 @@ using Microsoft.CodeAnalysis.Text;
|
||||
|
||||
using System.Text;
|
||||
|
||||
namespace BlazorSetParametersAsyncGenerator
|
||||
namespace Microsoft.AspNetCore.Components
|
||||
{
|
||||
internal static class SourceGeneratorContextExtension
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
|
||||
namespace BlazorSetParametersAsyncGenerator
|
||||
namespace Microsoft.AspNetCore.Components
|
||||
{
|
||||
internal static class StringExtension
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using Microsoft.CodeAnalysis;
|
||||
|
||||
namespace BlazorSetParametersAsyncGenerator
|
||||
namespace Microsoft.AspNetCore.Components
|
||||
{
|
||||
public static class TypeSymbolExtension
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<Import Project="$(SolutionDir)Version.props" />
|
||||
<Import Project="$(SolutionDir)PackNuget.props" />
|
||||
<Import Project="..\..\Version.props" />
|
||||
<Import Project="..\..\PackNuget.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<GenerateDocumentationFile>True</GenerateDocumentationFile>
|
||||
@@ -18,7 +18,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Rougamo.Fody" Version="5.0.0" />
|
||||
<PackageReference Include="Rougamo.Fody" Version="5.0.1" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition=" '$(TargetFramework)' == 'net8.0' ">
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.1" />
|
||||
@@ -41,12 +41,20 @@
|
||||
<ItemGroup>
|
||||
<None Include="..\README.md" Pack="true" PackagePath="\" />
|
||||
<None Include="..\README.zh-CN.md" Pack="true" PackagePath="\" />
|
||||
<None Remove="$(SolutionDir)..\README.md" Pack="false" PackagePath="\" />
|
||||
<None Remove="$(SolutionDir)..\README.zh-CN.md" Pack="false" PackagePath="\" />
|
||||
<None Remove="..\..\..\README.md" Pack="false" PackagePath="\" />
|
||||
<None Remove="..\..\..\README.zh-CN.md" Pack="false" PackagePath="\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ThingsGateway.DB\ThingsGateway.DB.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
<!--<Target Name="Mapster" AfterTargets="AfterBuild">
|
||||
<Exec WorkingDirectory="$(ProjectDir)" Command="dotnet tool restore" />
|
||||
<Exec WorkingDirectory="$(ProjectDir)" Command="dotnet mapster extension -o MapsterGenerator -a "$(TargetDir)$(ProjectName).dll"" />
|
||||
<Exec WorkingDirectory="$(ProjectDir)" Command="dotnet mapster mapper -o MapsterGenerator -a "$(TargetDir)$(ProjectName).dll"" />
|
||||
</Target>-->
|
||||
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -19,4 +19,4 @@ global using System.Diagnostics.CodeAnalysis;
|
||||
global using ThingsGateway.Razor;
|
||||
|
||||
[assembly: SuppressMessage("Reliability", "CA2007", Justification = "<挂起>", Scope = "module")]
|
||||
[assembly: BlazorSetParametersAsyncGenerator.GlobalGenerateSetParametersAsync(true)]
|
||||
[assembly: GlobalGenerateSetParametersAsync(true)]
|
||||
@@ -39,6 +39,7 @@ public partial class SysUserEdit
|
||||
var items = await SysPositionService.SelectorAsync(new PositionSelectorInput() { });
|
||||
Items = PositionUtil.BuildCascaderItemList(items);
|
||||
ModuleSelectedItems = ResourceUtil.BuildModuleSelectList((await SysResourceService.GetAllAsync())).ToList();
|
||||
await InvokeAsync(StateHasChanged);
|
||||
await base.OnInitializedAsync();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Razor">
|
||||
|
||||
<Import Project="$(SolutionDir)Version.props" />
|
||||
<Import Project="$(SolutionDir)PackNuget.props" />
|
||||
<Import Project="..\..\Version.props" />
|
||||
<Import Project="..\..\PackNuget.props" />
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ThingsGateway.Admin.Application\ThingsGateway.Admin.Application.csproj" />
|
||||
@@ -30,8 +30,8 @@
|
||||
<ItemGroup>
|
||||
<None Include="..\README.md" Pack="true" PackagePath="\" />
|
||||
<None Include="..\README.zh-CN.md" Pack="true" PackagePath="\" />
|
||||
<None Remove="$(SolutionDir)..\README.md" Pack="false" PackagePath="\" />
|
||||
<None Remove="$(SolutionDir)..\README.zh-CN.md" Pack="false" PackagePath="\" />
|
||||
<None Remove="..\..\..\README.md" Pack="false" PackagePath="\" />
|
||||
<None Remove="..\..\..\README.zh-CN.md" Pack="false" PackagePath="\" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<Import Project="$(SolutionDir)Version.props" />
|
||||
<Import Project="..\..\Version.props" />
|
||||
|
||||
|
||||
<PropertyGroup>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<Import Project="$(SolutionDir)Version.props" />
|
||||
<Import Project="$(SolutionDir)PackNuget.props" />
|
||||
<Import Project="..\..\Version.props" />
|
||||
<Import Project="..\..\PackNuget.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<GenerateDocumentationFile>True</GenerateDocumentationFile>
|
||||
@@ -11,14 +11,14 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="BootstrapBlazor.TableExport" Version="9.2.5" />
|
||||
<PackageReference Include="BootstrapBlazor.TableExport" Version="9.2.6" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="..\README.md" Pack="true" PackagePath="\" />
|
||||
<None Include="..\README.zh-CN.md" Pack="true" PackagePath="\" />
|
||||
<None Remove="$(SolutionDir)..\README.md" Pack="false" PackagePath="\" />
|
||||
<None Remove="$(SolutionDir)..\README.zh-CN.md" Pack="false" PackagePath="\" />
|
||||
<None Remove="..\..\..\README.md" Pack="false" PackagePath="\" />
|
||||
<None Remove="..\..\..\README.zh-CN.md" Pack="false" PackagePath="\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -15,6 +15,7 @@ using Microsoft.Extensions.Logging;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
using ThingsGateway.NewLife.Caching;
|
||||
using ThingsGateway.NewLife.Log;
|
||||
|
||||
namespace ThingsGateway.Logging;
|
||||
|
||||
@@ -33,7 +34,7 @@ public sealed class DatabaseLoggerProvider : ILoggerProvider, ISupportExternalSc
|
||||
/// <summary>
|
||||
/// 日志消息队列(线程安全)
|
||||
/// </summary>
|
||||
private readonly BlockingCollection<LogMessage> _logMessageQueue = new(12000);
|
||||
private readonly BlockingCollection<LogMessage> _logMessageQueue = new(20000);
|
||||
|
||||
/// <summary>
|
||||
/// 日志作用域提供器
|
||||
@@ -135,7 +136,10 @@ public sealed class DatabaseLoggerProvider : ILoggerProvider, ISupportExternalSc
|
||||
{
|
||||
try
|
||||
{
|
||||
_logMessageQueue.Add(logMsg);
|
||||
if (!_logMessageQueue.TryAdd(logMsg, 5000))
|
||||
{
|
||||
XTrace.Log.Warn($"{nameof(DatabaseLoggerProvider)} queue add fail");
|
||||
}
|
||||
return;
|
||||
}
|
||||
catch (InvalidOperationException) { }
|
||||
|
||||
@@ -14,6 +14,7 @@ using Microsoft.Extensions.Logging;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
using ThingsGateway.NewLife.Caching;
|
||||
using ThingsGateway.NewLife.Log;
|
||||
|
||||
namespace ThingsGateway.Logging;
|
||||
|
||||
@@ -32,7 +33,7 @@ public sealed class FileLoggerProvider : ILoggerProvider, ISupportExternalScope
|
||||
/// <summary>
|
||||
/// 日志消息队列(线程安全)
|
||||
/// </summary>
|
||||
private readonly BlockingCollection<LogMessage> _logMessageQueue = new(12000);
|
||||
private readonly BlockingCollection<LogMessage> _logMessageQueue = new(20000);
|
||||
|
||||
/// <summary>
|
||||
/// 日志作用域提供器
|
||||
@@ -170,8 +171,10 @@ public sealed class FileLoggerProvider : ILoggerProvider, ISupportExternalScope
|
||||
{
|
||||
try
|
||||
{
|
||||
_logMessageQueue.Add(logMsg);
|
||||
return;
|
||||
if (!_logMessageQueue.TryAdd(logMsg, 5000))
|
||||
{
|
||||
XTrace.Log.Warn($"{nameof(DatabaseLoggerProvider)} queue add fail");
|
||||
}
|
||||
}
|
||||
catch (InvalidOperationException) { }
|
||||
catch { }
|
||||
|
||||
@@ -46,6 +46,8 @@ public static class ObjectMapperServiceCollectionExtensions
|
||||
// 获取全局映射配置
|
||||
var config = TypeAdapterConfig.GlobalSettings;
|
||||
|
||||
//config.Compiler = exp => exp.CompileFast();
|
||||
|
||||
// 扫描所有继承 IRegister 接口的对象映射配置
|
||||
if (assemblies?.Length > 0) config.Scan(assemblies);
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ internal sealed partial class SchedulerFactory : ISchedulerFactory
|
||||
/// <summary>
|
||||
/// 作业持久化记录消息队列(线程安全)
|
||||
/// </summary>
|
||||
private readonly BlockingCollection<PersistenceContext> _persistenceMessageQueue = new(12000);
|
||||
private readonly BlockingCollection<PersistenceContext> _persistenceMessageQueue = new(20000);
|
||||
|
||||
/// <summary>
|
||||
/// 不受控的作业 Id 集合
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<Import Project="$(SolutionDir)Version.props" />
|
||||
<Import Project="$(SolutionDir)PackNuget.props" />
|
||||
<Import Project="..\..\Version.props" />
|
||||
<Import Project="..\..\PackNuget.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net8.0;net9.0;</TargetFrameworks>
|
||||
@@ -36,6 +36,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Ben.Demystifier" Version="0.4.1" />
|
||||
<!--<PackageReference Include="FastExpressionCompiler" Version="5.3.0" />-->
|
||||
<PackageReference Include="System.Text.RegularExpressions" Version="4.3.1" />
|
||||
<PackageReference Include="Mapster" Version="7.4.0" />
|
||||
<PackageReference Include="MiniProfiler.AspNetCore.Mvc" Version="4.5.4" />
|
||||
@@ -61,8 +62,8 @@
|
||||
<ItemGroup>
|
||||
<None Include="README.md" Pack="true" PackagePath="\" />
|
||||
<None Include="README.zh-CN.md" Pack="true" PackagePath="\" />
|
||||
<None Remove="$(SolutionDir)..\README.md" Pack="false" PackagePath="\" />
|
||||
<None Remove="$(SolutionDir)..\README.zh-CN.md" Pack="false" PackagePath="\" />
|
||||
<None Remove="..\..\..\README.md" Pack="false" PackagePath="\" />
|
||||
<None Remove="..\..\..\README.zh-CN.md" Pack="false" PackagePath="\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<Import Project="$(SolutionDir)Version.props" />
|
||||
<Import Project="$(SolutionDir)PackNuget.props" />
|
||||
<Import Project="..\..\Version.props" />
|
||||
<Import Project="..\..\PackNuget.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net462;netstandard2.0;net6.0;net6.0-windows;net8.0;net8.0-windows;</TargetFrameworks>
|
||||
@@ -16,8 +16,8 @@
|
||||
<ItemGroup>
|
||||
<None Include="README.md" Pack="true" PackagePath="\" />
|
||||
<None Include="README.zh-CN.md" Pack="true" PackagePath="\" />
|
||||
<None Remove="$(SolutionDir)..\README.md" Pack="false" PackagePath="\" />
|
||||
<None Remove="$(SolutionDir)..\README.zh-CN.md" Pack="false" PackagePath="\" />
|
||||
<None Remove="..\..\..\README.md" Pack="false" PackagePath="\" />
|
||||
<None Remove="..\..\..\README.zh-CN.md" Pack="false" PackagePath="\" />
|
||||
</ItemGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(TargetFramework)'=='net462' or '$(TargetFramework)'=='net5.0-windows' or '$(TargetFramework)'=='net6.0-windows' or '$(TargetFramework)'=='net7.0-windows' or '$(TargetFramework)'=='net8.0-windows'">
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Razor">
|
||||
<Import Project="$(SolutionDir)Version.props" />
|
||||
<Import Project="$(SolutionDir)PackNuget.props" />
|
||||
<Import Project="..\..\Version.props" />
|
||||
<Import Project="..\..\PackNuget.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net8.0;net9.0;</TargetFrameworks>
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace ThingsGateway.Razor;
|
||||
/// <summary>
|
||||
/// 母版页基类
|
||||
/// </summary>
|
||||
[BlazorSetParametersAsyncGenerator.DoNotGenerateSetParametersAsync]
|
||||
[DoNotGenerateSetParametersAsync]
|
||||
public partial class BaseLayout
|
||||
{
|
||||
}
|
||||
|
||||
@@ -18,8 +18,6 @@ namespace ThingsGateway.Extension.Generic;
|
||||
[ThingsGateway.DependencyInjection.SuppressSniffer]
|
||||
public static class GenericExtensions
|
||||
{
|
||||
private static MemoryCache Instance { get; set; } = new MemoryCache();
|
||||
|
||||
/// <summary>
|
||||
/// 把已修改的属性赋值到列表中,并返回字典
|
||||
/// </summary>
|
||||
|
||||
@@ -21,4 +21,4 @@ global using System.Globalization;
|
||||
|
||||
|
||||
[assembly: SuppressMessage("Reliability", "CA2007", Justification = "<挂起>", Scope = "module")]
|
||||
[assembly: BlazorSetParametersAsyncGenerator.GlobalGenerateSetParametersAsync(true)]
|
||||
[assembly: GlobalGenerateSetParametersAsync(true)]
|
||||
@@ -1,12 +1,12 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Razor">
|
||||
<Import Project="$(SolutionDir)Version.props" />
|
||||
<Import Project="$(SolutionDir)PackNuget.props" />
|
||||
<Import Project="..\..\Version.props" />
|
||||
<Import Project="..\..\PackNuget.props" />
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net8.0</TargetFrameworks>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="BootstrapBlazor.FontAwesome" Version="9.0.2" />
|
||||
<PackageReference Include="BootstrapBlazor" Version="9.7.4-beta07" />
|
||||
<PackageReference Include="BootstrapBlazor" Version="9.7.4" />
|
||||
<PackageReference Include="Yitter.IdGenerator" Version="1.0.14" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -20,8 +20,8 @@
|
||||
<ItemGroup>
|
||||
<None Include="..\README.md" Pack="true" PackagePath="\" />
|
||||
<None Include="..\README.zh-CN.md" Pack="true" PackagePath="\" />
|
||||
<None Remove="$(SolutionDir)..\README.md" Pack="false" PackagePath="\" />
|
||||
<None Remove="$(SolutionDir)..\README.zh-CN.md" Pack="false" PackagePath="\" />
|
||||
<None Remove="..\..\..\README.md" Pack="false" PackagePath="\" />
|
||||
<None Remove="..\..\..\README.zh-CN.md" Pack="false" PackagePath="\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<Import Project="$(SolutionDir)Version.props" />
|
||||
<Import Project="$(SolutionDir)PackNuget.props" />
|
||||
<Import Project="..\..\Version.props" />
|
||||
<Import Project="..\..\PackNuget.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<GenerateDocumentationFile>True</GenerateDocumentationFile>
|
||||
@@ -13,8 +13,8 @@
|
||||
<ItemGroup>
|
||||
<None Include="..\README.md" Pack="true" PackagePath="\" />
|
||||
<None Include="..\README.zh-CN.md" Pack="true" PackagePath="\" />
|
||||
<None Remove="$(SolutionDir)..\README.md" Pack="false" PackagePath="\" />
|
||||
<None Remove="$(SolutionDir)..\README.zh-CN.md" Pack="false" PackagePath="\" />
|
||||
<None Remove="..\..\..\README.md" Pack="false" PackagePath="\" />
|
||||
<None Remove="..\..\..\README.zh-CN.md" Pack="false" PackagePath="\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
<Project>
|
||||
|
||||
<PropertyGroup>
|
||||
<PluginVersion>10.8.8</PluginVersion>
|
||||
<ProPluginVersion>10.8.8</ProPluginVersion>
|
||||
<AuthenticationVersion>2.8.0</AuthenticationVersion>
|
||||
<SourceGeneratorVersion>10.8.2</SourceGeneratorVersion>
|
||||
<PluginVersion>10.8.23</PluginVersion>
|
||||
<ProPluginVersion>10.8.23</ProPluginVersion>
|
||||
<AuthenticationVersion>2.8.4</AuthenticationVersion>
|
||||
<SourceGeneratorVersion>10.8.6</SourceGeneratorVersion>
|
||||
<NET8Version>8.0.17</NET8Version>
|
||||
<NET9Version>9.0.6</NET9Version>
|
||||
<SatelliteResourceLanguages>zh-Hans;en-US</SatelliteResourceLanguages>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
@@ -41,7 +42,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="$(SolutionDir)Directory.Build.props" Pack="true" PackagePath="\" />
|
||||
<None Include="$(MSBuildThisFileDirectory)Directory.Build.props" Pack="true" PackagePath="\" />
|
||||
</ItemGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
|
||||
@@ -4,6 +4,6 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="$(SolutionDir)Foundation.props" Pack="true" PackagePath="\" />
|
||||
<None Include="$(MSBuildThisFileDirectory)Foundation.props" Pack="true" PackagePath="\" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Import Project="$(SolutionDir)PackNuget.props" />
|
||||
<Import Project="$(SolutionDir)Version.props" />
|
||||
<Import Project="..\..\PackNuget.props" />
|
||||
<Import Project="..\..\Version.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netstandard2.0;</TargetFrameworks>
|
||||
|
||||
@@ -19,4 +19,4 @@ global using ThingsGateway.Razor;
|
||||
|
||||
[assembly: SuppressMessage("Reliability", "CA2007", Justification = "<挂起>", Scope = "module")]
|
||||
|
||||
[assembly: BlazorSetParametersAsyncGenerator.GlobalGenerateSetParametersAsync(true)]
|
||||
[assembly: GlobalGenerateSetParametersAsync(true)]
|
||||
@@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Razor">
|
||||
|
||||
<Import Project="$(SolutionDir)Version.props" />
|
||||
<Import Project="$(SolutionDir)PackNuget.props" />
|
||||
<Import Project="..\..\Version.props" />
|
||||
<Import Project="..\..\PackNuget.props" />
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net8.0;</TargetFrameworks>
|
||||
<!--<UseRazorSourceGenerator>false</UseRazorSourceGenerator>-->
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<Import Project="$(SolutionDir)PackNuget.props" />
|
||||
<Import Project="..\..\PackNuget.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netstandard2.0;</TargetFrameworks>
|
||||
|
||||
@@ -85,6 +85,7 @@ public static class ChannelOptionsExtensions
|
||||
channelOptions.ThrowIfNull(nameof(IChannelOptions));
|
||||
var channelType = channelOptions.ChannelType;
|
||||
channelType.ThrowIfNull(nameof(ChannelTypeEnum));
|
||||
config.SetMaxCount(channelOptions.MaxClientCount);
|
||||
switch (channelType)
|
||||
{
|
||||
case ChannelTypeEnum.TcpClient:
|
||||
|
||||
@@ -509,18 +509,11 @@ public abstract class DeviceBase : DisposableObject, IDevice
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected virtual async ValueTask<MessageBase> SendThenReturnMessageBaseAsync(ISendMessage command, IClientChannel clientChannel = default, CancellationToken cancellationToken = default)
|
||||
protected virtual ValueTask<MessageBase> SendThenReturnMessageBaseAsync(ISendMessage command, IClientChannel clientChannel = default, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
return await GetResponsedDataAsync(command, clientChannel, Timeout, cancellationToken).ConfigureAwait(false);
|
||||
return GetResponsedDataAsync(command, clientChannel, Timeout, cancellationToken);
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new(ex);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -996,4 +989,6 @@ public abstract class DeviceBase : DisposableObject, IDevice
|
||||
}
|
||||
return a => { };
|
||||
}
|
||||
public abstract ValueTask<OperResult<byte[]>> ReadAsync(object state, CancellationToken cancellationToken = default);
|
||||
|
||||
}
|
||||
|
||||
@@ -466,4 +466,5 @@ public interface IDevice : IDisposable
|
||||
/// <param name="channel">通道</param>
|
||||
/// <param name="deviceLog">单独设备日志</param>
|
||||
void InitChannel(IChannel channel, ILog? deviceLog = null);
|
||||
ValueTask<OperResult<byte[]>> ReadAsync(object state, CancellationToken cancellationToken = default);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Import Project="$(SolutionDir)Foundation.props" />
|
||||
<Import Project="$(SolutionDir)PackNuget.props" />
|
||||
<Import Project="$(SolutionDir)Version.props" />
|
||||
<Import Project="..\..\Foundation.props" />
|
||||
<Import Project="..\..\PackNuget.props" />
|
||||
<Import Project="..\..\Version.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<Description>工业设备通讯协议-基础类库</Description>
|
||||
@@ -10,8 +10,8 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Localization.Abstractions" Version="$(NET9Version)" />
|
||||
<PackageReference Include="TouchSocket" Version="3.1.8" />
|
||||
<PackageReference Include="TouchSocket.SerialPorts" Version="3.1.8" />
|
||||
<PackageReference Include="TouchSocket" Version="3.1.10" />
|
||||
<PackageReference Include="TouchSocket.SerialPorts" Version="3.1.10" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -30,6 +30,11 @@ public interface IVariableSource
|
||||
/// </summary>
|
||||
string RegisterAddress { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 变量地址
|
||||
/// </summary>
|
||||
object AddressObject { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// IntervalTime
|
||||
/// </summary>
|
||||
|
||||
@@ -36,6 +36,8 @@ public class VariableSourceClass : IVariableSource
|
||||
/// </summary>
|
||||
public IEnumerable<IVariable> VariableRuntimes => _variableRuntimes;
|
||||
|
||||
public object AddressObject { get; set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public virtual void AddVariable(IVariable variable)
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Import Project="$(SolutionDir)Version.props" />
|
||||
<Import Project="$(SolutionDir)PackNuget.props" />
|
||||
<Import Project="..\..\Version.props" />
|
||||
<Import Project="..\..\PackNuget.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
|
||||
@@ -8,8 +8,8 @@
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
<None Remove="$(SolutionDir)..\README.md" />
|
||||
<None Remove="$(SolutionDir)..\README.zh-CN.md" />
|
||||
<None Remove="..\..\..\README.md" />
|
||||
<None Remove="..\..\..\README.zh-CN.md" />
|
||||
|
||||
<None Include="README.md" Pack="true" PackagePath="\" />
|
||||
<None Include="README.zh-CN.md" Pack="true" PackagePath="\" />
|
||||
|
||||
@@ -11,4 +11,4 @@
|
||||
|
||||
global using Microsoft.AspNetCore.Components;
|
||||
|
||||
[assembly: BlazorSetParametersAsyncGenerator.GlobalGenerateSetParametersAsync(true)]
|
||||
[assembly: GlobalGenerateSetParametersAsync(true)]
|
||||
@@ -1,6 +1,6 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Razor">
|
||||
<Import Project="$(SolutionDir)Version.props" />
|
||||
<Import Project="$(SolutionDir)PackNuget.props" />
|
||||
<Import Project="..\..\Version.props" />
|
||||
<Import Project="..\..\PackNuget.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
|
||||
@@ -9,8 +9,8 @@
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
<None Remove="$(SolutionDir)..\README.md" />
|
||||
<None Remove="$(SolutionDir)..\README.zh-CN.md" />
|
||||
<None Remove="..\..\..\README.md" />
|
||||
<None Remove="..\..\..\README.zh-CN.md" />
|
||||
|
||||
<None Include="README.md" Pack="true" PackagePath="\" />
|
||||
<None Include="README.zh-CN.md" Pack="true" PackagePath="\" />
|
||||
|
||||
@@ -29,4 +29,13 @@ public class TaskSchedulerLoop
|
||||
}
|
||||
}
|
||||
|
||||
public void Add(IScheduledTask task)
|
||||
{
|
||||
Tasks.Add(task);
|
||||
}
|
||||
public void Remove(IScheduledTask task)
|
||||
{
|
||||
Tasks.Remove(task);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -435,8 +435,10 @@ public abstract class BusinessBaseWithCacheVariableModel<VarModel> : BusinessBas
|
||||
|
||||
try
|
||||
{
|
||||
if (_memoryVarModelsQueue.TryDequeue(out var cacheDBItem))
|
||||
while (_memoryVarModelsQueue.TryDequeue(out var cacheDBItem))
|
||||
{
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
break;
|
||||
var list = cacheDBItem.Value;
|
||||
var data = list.ChunkBetter(_businessPropertyWithCache.SplitSize);
|
||||
foreach (var item in data)
|
||||
|
||||
@@ -127,6 +127,24 @@ public abstract class CollectBase : DriverBase, IRpcDriver
|
||||
LogMessage?.LogWarning(ex, string.Format(AppResource.GetMethodError, ex.Message));
|
||||
}
|
||||
|
||||
|
||||
if (VariableTasks.Count > 0)
|
||||
{
|
||||
foreach (var item in VariableTasks)
|
||||
{
|
||||
item.Stop();
|
||||
TaskSchedulerLoop.Remove(item);
|
||||
}
|
||||
|
||||
VariableTasks = AddVariableTask(cancellationToken);
|
||||
|
||||
foreach (var item in VariableTasks)
|
||||
{
|
||||
TaskSchedulerLoop.Add(item);
|
||||
item.Start();
|
||||
}
|
||||
}
|
||||
|
||||
// 根据标签获取方法信息的局部函数
|
||||
List<VariableMethod> GetMethod(IEnumerable<VariableRuntime> tag)
|
||||
{
|
||||
@@ -165,16 +183,28 @@ public abstract class CollectBase : DriverBase, IRpcDriver
|
||||
return string.Empty;
|
||||
}
|
||||
protected virtual bool VariableSourceReadsEnable => true;
|
||||
|
||||
protected List<IScheduledTask> VariableTasks = new List<IScheduledTask>();
|
||||
protected override List<IScheduledTask> ProtectedGetTasks(CancellationToken cancellationToken)
|
||||
{
|
||||
var tasks = new List<IScheduledTask>();
|
||||
|
||||
var setDeviceStatusTask = new ScheduledSyncTask(3000, SetDeviceStatus, null, LogMessage, cancellationToken);
|
||||
var setDeviceStatusTask = new ScheduledSyncTask(10000, SetDeviceStatus, null, LogMessage, cancellationToken);
|
||||
tasks.Add(setDeviceStatusTask);
|
||||
|
||||
var testOnline = new ScheduledAsyncTask(30000, TestOnline, null, LogMessage, cancellationToken);
|
||||
tasks.Add(testOnline);
|
||||
|
||||
VariableTasks = AddVariableTask(cancellationToken);
|
||||
|
||||
tasks.AddRange(VariableTasks);
|
||||
return tasks;
|
||||
|
||||
}
|
||||
|
||||
protected List<IScheduledTask> AddVariableTask(CancellationToken cancellationToken)
|
||||
{
|
||||
List<IScheduledTask> variableTasks = new();
|
||||
if (VariableSourceReadsEnable)
|
||||
{
|
||||
for (int i = 0; i < CurrentDevice.VariableSourceReads.Count; i++)
|
||||
@@ -182,7 +212,7 @@ public abstract class CollectBase : DriverBase, IRpcDriver
|
||||
var variableSourceRead = CurrentDevice.VariableSourceReads[i];
|
||||
|
||||
var executeTask = ScheduledTaskHelper.GetTask(variableSourceRead.IntervalTime, ReadVariableSource, variableSourceRead, LogMessage, cancellationToken);
|
||||
tasks.Add(executeTask);
|
||||
variableTasks.Add(executeTask);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -192,7 +222,7 @@ public abstract class CollectBase : DriverBase, IRpcDriver
|
||||
var variableMethod = CurrentDevice.ReadVariableMethods[i];
|
||||
|
||||
var executeTask = ScheduledTaskHelper.GetTask(variableMethod.IntervalTime, ReadVariableMed, variableMethod, LogMessage, cancellationToken);
|
||||
tasks.Add(executeTask);
|
||||
variableTasks.Add(executeTask);
|
||||
|
||||
}
|
||||
|
||||
@@ -201,19 +231,31 @@ public abstract class CollectBase : DriverBase, IRpcDriver
|
||||
var variableScriptRead = CurrentDevice.VariableScriptReads[i];
|
||||
|
||||
var executeTask = ScheduledTaskHelper.GetTask(variableScriptRead.IntervalTime, ScriptVariableRun, variableScriptRead, LogMessage, cancellationToken);
|
||||
tasks.Add(executeTask);
|
||||
variableTasks.Add(executeTask);
|
||||
|
||||
}
|
||||
|
||||
return tasks;
|
||||
|
||||
return variableTasks;
|
||||
}
|
||||
|
||||
private void SetDeviceStatus(object? state, CancellationToken cancellationToken)
|
||||
{
|
||||
if (IsConnected())
|
||||
{
|
||||
CurrentDevice.SetDeviceStatus(TimerX.Now);
|
||||
if (CurrentDevice.DeviceStatus == DeviceStatusEnum.OffLine)
|
||||
{
|
||||
if (IdVariableRuntimes.Any(a => a.Value.IsOnline))
|
||||
CurrentDevice.SetDeviceStatus(TimerX.Now, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (IdVariableRuntimes.All(a => !a.Value.IsOnline))
|
||||
CurrentDevice.SetDeviceStatus(TimerX.Now, true);
|
||||
}
|
||||
}
|
||||
else if (IsStarted)
|
||||
{
|
||||
CurrentDevice.SetDeviceStatus(TimerX.Now, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -258,7 +300,7 @@ public abstract class CollectBase : DriverBase, IRpcDriver
|
||||
// 方法调用成功时记录日志并增加成功计数器
|
||||
if (LogMessage?.LogLevel <= TouchSocket.Core.LogLevel.Trace)
|
||||
LogMessage?.Trace(string.Format("{0} - Execute method [{1}] - Succeeded {2}", DeviceName, readVariableMethods.MethodInfo.Name, readResult.Content?.ToSystemTextJsonString()));
|
||||
CurrentDevice.SetDeviceStatus(TimerX.Now, false);
|
||||
CurrentDevice.SetDeviceStatus(TimerX.Now, null);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -281,7 +323,7 @@ public abstract class CollectBase : DriverBase, IRpcDriver
|
||||
}
|
||||
|
||||
readVariableMethods.LastErrorMessage = readResult.ErrorMessage;
|
||||
CurrentDevice.SetDeviceStatus(TimerX.Now, false);
|
||||
CurrentDevice.SetDeviceStatus(TimerX.Now, null);
|
||||
}
|
||||
|
||||
return;
|
||||
@@ -302,6 +344,8 @@ public abstract class CollectBase : DriverBase, IRpcDriver
|
||||
|
||||
var readErrorCount = 0;
|
||||
|
||||
await ReadWriteLock.ReaderLockAsync(cancellationToken).ConfigureAwait(false);
|
||||
|
||||
//if (LogMessage?.LogLevel <= TouchSocket.Core.LogLevel.Trace)
|
||||
// LogMessage?.Trace(string.Format("{0} - Collecting [{1} - {2}]", DeviceName, variableSourceRead?.RegisterAddress, variableSourceRead?.Length));
|
||||
var readResult = await ReadSourceAsync(variableSourceRead, cancellationToken).ConfigureAwait(false);
|
||||
@@ -329,7 +373,7 @@ public abstract class CollectBase : DriverBase, IRpcDriver
|
||||
// 读取成功时记录日志并增加成功计数器
|
||||
if (LogMessage?.LogLevel <= TouchSocket.Core.LogLevel.Trace)
|
||||
LogMessage?.Trace(string.Format("{0} - Collection [{1} - {2}] data succeeded {3}", DeviceName, variableSourceRead?.RegisterAddress, variableSourceRead?.Length, readResult.Content?.ToHexString(' ')));
|
||||
CurrentDevice.SetDeviceStatus(TimerX.Now, false);
|
||||
CurrentDevice.SetDeviceStatus(TimerX.Now, null);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -352,7 +396,7 @@ public abstract class CollectBase : DriverBase, IRpcDriver
|
||||
}
|
||||
|
||||
variableSourceRead.LastErrorMessage = readResult.ErrorMessage;
|
||||
CurrentDevice.SetDeviceStatus(TimerX.Now, true, readResult.ErrorMessage);
|
||||
CurrentDevice.SetDeviceStatus(TimerX.Now, null, readResult.ErrorMessage);
|
||||
var time = DateTime.Now;
|
||||
variableSourceRead.VariableRuntimes.ForEach(a => a.SetValue(null, time, isOnline: false));
|
||||
}
|
||||
@@ -418,7 +462,40 @@ public abstract class CollectBase : DriverBase, IRpcDriver
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
protected async Task Check(Dictionary<VariableRuntime, JToken> writeInfoLists, ConcurrentDictionary<string, OperResult> operResults, CancellationToken cancellationToken)
|
||||
{
|
||||
if (VariableSourceReadsEnable)
|
||||
{
|
||||
// 如果成功,每个变量都读取一次最新值,再次比较写入值
|
||||
var successfulWriteNames = operResults.Where(a => a.Value.IsSuccess).Select(a => a.Key).ToHashSet();
|
||||
|
||||
var groups = writeInfoLists.Select(a => a.Key).Where(a => a.RpcWriteCheck && a.ProtectType != ProtectTypeEnum.WriteOnly && successfulWriteNames.Contains(a.Name) && a.VariableSource != null).GroupBy(a => a.VariableSource as VariableSourceRead).Where(a => a.Key != null).ToList();
|
||||
|
||||
await groups.ParallelForEachAsync(async (varRead, token) =>
|
||||
{
|
||||
var result = await ReadSourceAsync(varRead.Key, token).ConfigureAwait(false);
|
||||
if (result.IsSuccess)
|
||||
{
|
||||
foreach (var item in varRead)
|
||||
{
|
||||
if (!item.Value.Equals(writeInfoLists[item].ToObject(item.Value?.GetType())))
|
||||
{
|
||||
// 如果写入值与读取值不同,则更新操作结果为失败
|
||||
operResults[item.Name] = new OperResult($"The write value is inconsistent with the read value, Write value: {writeInfoLists[item].ToObject(item.Value?.GetType())}, read value: {item.Value}");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var item in varRead)
|
||||
{
|
||||
// 如果写入值与读取值不同,则更新操作结果为失败
|
||||
operResults[item.Name] = new OperResult($"Reading and rechecking resulted in an error: {result.ErrorMessage}", result.Exception);
|
||||
}
|
||||
}
|
||||
}, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
#region 写入方法
|
||||
|
||||
|
||||
@@ -100,7 +100,7 @@ public abstract class CollectFoundationBase : CollectBase
|
||||
LogMessage?.LogWarning(exception, string.Format(AppResource.CollectFail, DeviceName, item?.RegisterAddress, item?.Length, exception.Message));
|
||||
}
|
||||
item.LastErrorMessage = exception.Message;
|
||||
CurrentDevice.SetDeviceStatus(TimerX.Now, true, exception.Message);
|
||||
CurrentDevice.SetDeviceStatus(TimerX.Now, null, exception.Message);
|
||||
var time = DateTime.Now;
|
||||
item.VariableRuntimes.ForEach(a => a.SetValue(null, time, isOnline: false));
|
||||
}
|
||||
@@ -112,7 +112,7 @@ public abstract class CollectFoundationBase : CollectBase
|
||||
LogMessage?.LogWarning(exception, string.Format(AppResource.MethodFail, DeviceName, item.MethodInfo.Name, exception.Message));
|
||||
}
|
||||
item.LastErrorMessage = exception.Message;
|
||||
CurrentDevice.SetDeviceStatus(TimerX.Now, true, exception.Message);
|
||||
CurrentDevice.SetDeviceStatus(TimerX.Now, null, exception.Message);
|
||||
var time = DateTime.Now;
|
||||
item.Variable.SetValue(null, time, isOnline: false);
|
||||
}
|
||||
@@ -133,12 +133,12 @@ public abstract class CollectFoundationBase : CollectBase
|
||||
{
|
||||
try
|
||||
{
|
||||
await ReadWriteLock.ReaderLockAsync(cancellationToken).ConfigureAwait(false);
|
||||
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
return new(new OperationCanceledException());
|
||||
|
||||
// 从协议读取数据
|
||||
var read = await FoundationDevice.ReadAsync(variableSourceRead.RegisterAddress, variableSourceRead.Length, cancellationToken).ConfigureAwait(false);
|
||||
var read = await FoundationDevice.ReadAsync(variableSourceRead.AddressObject, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
// 如果读取成功且有有效内容,则解析结构化内容
|
||||
if (read.IsSuccess)
|
||||
@@ -201,6 +201,8 @@ public abstract class CollectFoundationBase : CollectBase
|
||||
}
|
||||
}, CollectProperties.MaxConcurrentCount, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
await Check(writeInfoLists, operResults, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
// 返回包含操作结果的字典
|
||||
return new Dictionary<string, OperResult>(operResults);
|
||||
}
|
||||
@@ -209,4 +211,5 @@ public abstract class CollectFoundationBase : CollectBase
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -282,7 +282,7 @@ public abstract class DriverBase : DisposableObject, IDriver
|
||||
}
|
||||
|
||||
// 设置设备状态为当前时间
|
||||
CurrentDevice.SetDeviceStatus(TimerX.Now);
|
||||
CurrentDevice.SetDeviceStatus(TimerX.Now, false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -399,6 +399,7 @@ public abstract class DriverBase : DisposableObject, IDriver
|
||||
stringBuilder.Append(" ");
|
||||
if (expireTime.HasValue && (DateTime.Now - expireTime.Value).TotalHours > -72)
|
||||
{
|
||||
stringBuilder.Append(',');
|
||||
stringBuilder.Append(Localizer["ExpireTime", expireTime.Value.ToString("yyyy-MM-dd HH")]);
|
||||
}
|
||||
|
||||
|
||||
@@ -30,9 +30,6 @@ namespace ThingsGateway.Gateway.Application;
|
||||
[SugarIndex("unique_deviceid_variable_name", nameof(Variable.Name), OrderByType.Asc, nameof(Variable.DeviceId), OrderByType.Asc, true)]
|
||||
public class Variable : BaseDataEntity, IValidatableObject
|
||||
{
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 导入验证专用
|
||||
/// </summary>
|
||||
@@ -68,6 +65,8 @@ public class Variable : BaseDataEntity, IValidatableObject
|
||||
private bool lLAlarmEnable;
|
||||
private bool lAlarmEnable;
|
||||
private bool customAlarmEnable;
|
||||
private bool businessGroupUpdateTrigger = true;
|
||||
private bool rpcWriteCheck;
|
||||
|
||||
private object _value;
|
||||
private string name;
|
||||
@@ -143,6 +142,20 @@ public class Variable : BaseDataEntity, IValidatableObject
|
||||
[AutoGenerateColumn(Visible = true, Filterable = true, Sortable = true, Order = 1)]
|
||||
public virtual string BusinessGroup { get => businessGroup; set => businessGroup = value; }
|
||||
|
||||
/// <summary>
|
||||
/// 分组上传触发变量
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnDescription = "分组上传触发变量", IsNullable = true)]
|
||||
[AutoGenerateColumn(Visible = true, Filterable = true, Sortable = true, Order = 1)]
|
||||
public virtual bool BusinessGroupUpdateTrigger { get => businessGroupUpdateTrigger; set => businessGroupUpdateTrigger = value; }
|
||||
|
||||
/// <summary>
|
||||
/// 写入后再次读取检查值是否一致
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnDescription = "写入后再次读取检查值是否一致", IsNullable = true)]
|
||||
[AutoGenerateColumn(Visible = true, Filterable = true, Sortable = true, Order = 1)]
|
||||
public virtual bool RpcWriteCheck { get => rpcWriteCheck; set => rpcWriteCheck = value; }
|
||||
|
||||
/// <summary>
|
||||
/// 描述
|
||||
/// </summary>
|
||||
|
||||
@@ -52,17 +52,7 @@
|
||||
"RulesId": "Name"
|
||||
},
|
||||
|
||||
"ThingsGateway.Management.Authentication": {
|
||||
"AuthName": "AuthName",
|
||||
"Authorized": "Authorized",
|
||||
"ExpireTime": "ExpireTime",
|
||||
"Password": "Password",
|
||||
"Register": "Register",
|
||||
"RegisterStatus": "RegisterStatus",
|
||||
"Unauthorized": "Unauthorized",
|
||||
"Unregister": "Unregister",
|
||||
"UUID": "UUID"
|
||||
},
|
||||
|
||||
"ThingsGateway.Management.AutoUpdateController": {
|
||||
"AutoUpdateController": "AutoUpdate",
|
||||
"Update": "Update"
|
||||
@@ -373,7 +363,7 @@
|
||||
|
||||
"ThingsGateway.Gateway.Application.DriverBase": {
|
||||
"Authorized": "Authorized",
|
||||
"ExpireTime": "ExpireTime",
|
||||
"ExpireTime": "ExpireTime {0}",
|
||||
"Unauthorized": "Unauthorized"
|
||||
},
|
||||
"ThingsGateway.Gateway.Application.ExportString": {
|
||||
@@ -448,6 +438,8 @@
|
||||
"BoolOpenAlarmText": "BoolOpenAlarmText",
|
||||
"BoolOpenRestrainExpressions": "BoolOpenRestrainExpressions",
|
||||
"BusinessGroup": "BusinessGroup",
|
||||
"BusinessGroupUpdateTrigger": "BusinessGroupUpdateTrigger",
|
||||
"RpcWriteCheck": "RpcWriteCheck",
|
||||
"ClearVariable": "Clear Variable",
|
||||
"CollectGroup": "CollectGroup",
|
||||
"CopyVariable": "Copy Variable",
|
||||
@@ -456,7 +448,7 @@
|
||||
"CustomAlarmText": "CustomAlarmText",
|
||||
"CustomRestrainExpressions": "CustomRestrainExpressions",
|
||||
"DataType": "DataType",
|
||||
"DeleteVariable": "Copy Variable",
|
||||
"DeleteVariable": "Delete Variable",
|
||||
"Description": "Description",
|
||||
"DeviceId": "CollectionDevice",
|
||||
"DeviceId.MinValue": "{0} cannot be empty",
|
||||
|
||||
@@ -50,17 +50,7 @@
|
||||
"LogConsole": "日志",
|
||||
"RulesId": "名称"
|
||||
},
|
||||
"ThingsGateway.Management.Authentication": {
|
||||
"AuthName": "公司名称",
|
||||
"Authorized": "已授权",
|
||||
"ExpireTime": "过期时间",
|
||||
"Password": "注册码",
|
||||
"Register": "注册",
|
||||
"RegisterStatus": "注册状态",
|
||||
"Unauthorized": "未授权",
|
||||
"Unregister": "取消注册",
|
||||
"UUID": "唯一编码"
|
||||
},
|
||||
|
||||
"ThingsGateway.Management.AutoUpdateController": {
|
||||
"AutoUpdateController": "程序更新",
|
||||
"Update": "更新"
|
||||
@@ -374,7 +364,7 @@
|
||||
|
||||
"ThingsGateway.Gateway.Application.DriverBase": {
|
||||
"Authorized": "已授权",
|
||||
"ExpireTime": "过期时间",
|
||||
"ExpireTime": "过期时间 {0}",
|
||||
"Unauthorized": "未授权"
|
||||
},
|
||||
"ThingsGateway.Gateway.Application.ExportString": {
|
||||
@@ -449,6 +439,8 @@
|
||||
"BoolOpenAlarmText": "布尔开报警文本",
|
||||
"BoolOpenRestrainExpressions": "布尔开报警约束",
|
||||
"BusinessGroup": "业务组",
|
||||
"BusinessGroupUpdateTrigger": "分组上传触发",
|
||||
"RpcWriteCheck": "写入后再次读取检查值是否一致",
|
||||
"ClearVariable": "清空变量",
|
||||
"CollectGroup": "采集组",
|
||||
"CopyVariable": "复制变量",
|
||||
|
||||
@@ -101,6 +101,9 @@ public class VariableBasicData
|
||||
[System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull)]
|
||||
public string BusinessGroup => VariableRuntime.BusinessGroup;
|
||||
|
||||
/// <inheritdoc cref="Variable.BusinessGroupUpdateTrigger"/>
|
||||
public bool BusinessGroupUpdateTrigger => VariableRuntime.BusinessGroupUpdateTrigger;
|
||||
|
||||
/// <inheritdoc cref="VariableRuntime.DeviceName"/>
|
||||
public string DeviceName => VariableRuntime.DeviceName;
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@ public class VariableSourceRead : IVariableSource
|
||||
/// 读取地址
|
||||
/// </summary>
|
||||
public string RegisterAddress { get; set; }
|
||||
public object AddressObject { get; set; }
|
||||
|
||||
public string IntervalTime { get; set; }
|
||||
|
||||
|
||||
@@ -15,11 +15,8 @@ namespace ThingsGateway.Gateway.Application;
|
||||
public sealed class ChannelThreadOptions : IConfigurableOptions
|
||||
{
|
||||
|
||||
public int MinCycleInterval { get; set; } = 10;
|
||||
public int MaxCycleInterval { get; set; } = 200;
|
||||
public int CheckInterval { get; set; } = 1800000;
|
||||
|
||||
|
||||
public int MaxChannelCount { get; set; } = 1000;
|
||||
public int MaxDeviceCount { get; set; } = 1000;
|
||||
public int MaxVariableCount { get; set; } = 1000000;
|
||||
|
||||
@@ -30,60 +30,6 @@ namespace ThingsGateway.Gateway.Application;
|
||||
internal sealed class DeviceThreadManage : IAsyncDisposable, IDeviceThreadManage
|
||||
{
|
||||
|
||||
#region 动态配置
|
||||
|
||||
/// <summary>
|
||||
/// 线程等待间隔时间
|
||||
/// </summary>
|
||||
public static volatile int CycleInterval = ManageHelper.ChannelThreadOptions.MaxCycleInterval;
|
||||
|
||||
static DeviceThreadManage()
|
||||
{
|
||||
Task.Factory.StartNew(SetCycleInterval, TaskCreationOptions.LongRunning);
|
||||
}
|
||||
|
||||
private static async Task SetCycleInterval()
|
||||
{
|
||||
var appLifetime = App.RootServices!.GetService<IHostApplicationLifetime>()!;
|
||||
var hardwareJob = GlobalData.HardwareJob;
|
||||
|
||||
List<float> cpus = new();
|
||||
while (!appLifetime.ApplicationStopping.IsCancellationRequested)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (hardwareJob?.HardwareInfo?.MachineInfo?.CpuRate == null) continue;
|
||||
cpus.Add((float)(hardwareJob.HardwareInfo.MachineInfo.CpuRate * 100));
|
||||
if (cpus.Count == 1 || cpus.Count > 5)
|
||||
{
|
||||
var avg = cpus.Average();
|
||||
cpus.RemoveAt(0);
|
||||
//Console.WriteLine($"CPU平均值:{avg}");
|
||||
if (avg > 80)
|
||||
{
|
||||
CycleInterval = Math.Max(CycleInterval, (int)(ManageHelper.ChannelThreadOptions.MaxCycleInterval * avg / 100));
|
||||
}
|
||||
else if (avg < 50)
|
||||
{
|
||||
CycleInterval = Math.Min(CycleInterval, ManageHelper.ChannelThreadOptions.MinCycleInterval);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
NewLife.Log.XTrace.WriteException(ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
await Task.Delay(30000, appLifetime?.ApplicationStopping ?? default).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion 动态配置
|
||||
Microsoft.Extensions.Logging.ILogger? _logger;
|
||||
|
||||
/// <summary>
|
||||
@@ -468,6 +414,12 @@ internal sealed class DeviceThreadManage : IAsyncDisposable, IDeviceThreadManage
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (DriverTasks.TryRemove(deviceId, out var task))
|
||||
{
|
||||
task.Stop();
|
||||
}
|
||||
|
||||
// 取消驱动程序的操作
|
||||
if (CancellationTokenSources.TryRemove(deviceId, out var token))
|
||||
{
|
||||
@@ -478,10 +430,6 @@ internal sealed class DeviceThreadManage : IAsyncDisposable, IDeviceThreadManage
|
||||
}
|
||||
}
|
||||
|
||||
if (DriverTasks.TryRemove(deviceId, out var task))
|
||||
{
|
||||
task.Stop();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
@@ -104,12 +104,22 @@ public class ExecuteScriptNode : TextNode, IActuatorNode, IExexcuteExpressionsBa
|
||||
}
|
||||
}
|
||||
|
||||
Task<NodeOutput> IActuatorNode.ExecuteAsync(NodeInput input, CancellationToken cancellationToken)
|
||||
async Task<OperResult<NodeOutput>> IActuatorNode.ExecuteAsync(NodeInput input, CancellationToken cancellationToken)
|
||||
{
|
||||
Logger?.Trace($"Execute script");
|
||||
var exexcuteExpressions = CSharpScriptEngineExtension.Do<IExexcuteExpressions>(Text);
|
||||
exexcuteExpressions.Logger = Logger;
|
||||
return exexcuteExpressions.ExecuteAsync(input, cancellationToken);
|
||||
try
|
||||
{
|
||||
Logger?.Trace($"Execute script");
|
||||
var exexcuteExpressions = CSharpScriptEngineExtension.Do<IExexcuteExpressions>(Text);
|
||||
exexcuteExpressions.Logger = Logger;
|
||||
var data = await exexcuteExpressions.ExecuteAsync(input, cancellationToken).ConfigureAwait(false);
|
||||
return new OperResult<NodeOutput>() { Content = data };
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger?.LogWarning(ex);
|
||||
return new OperResult<NodeOutput>(ex);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -12,22 +12,32 @@ public class VariableRpcNode : VariableNode, IActuatorNode
|
||||
public VariableRpcNode(string id, Point? position = null) : base(id, position)
|
||||
{ Title = "VariableRpcNode"; }
|
||||
|
||||
async Task<NodeOutput> IActuatorNode.ExecuteAsync(NodeInput input, CancellationToken cancellationToken)
|
||||
async Task<OperResult<NodeOutput>> IActuatorNode.ExecuteAsync(NodeInput input, CancellationToken cancellationToken)
|
||||
{
|
||||
if ((!DeviceText.IsNullOrWhiteSpace()) && GlobalData.ReadOnlyDevices.TryGetValue(DeviceText, out var device))
|
||||
try
|
||||
{
|
||||
if (device.ReadOnlyVariableRuntimes.TryGetValue(Text, out var value))
|
||||
|
||||
if ((!DeviceText.IsNullOrWhiteSpace()) && GlobalData.ReadOnlyDevices.TryGetValue(DeviceText, out var device))
|
||||
{
|
||||
var data = await value.RpcAsync(input.JToken.ToString(), $"RulesEngine: {RulesEngineName}", cancellationToken).ConfigureAwait(false);
|
||||
if (data.IsSuccess)
|
||||
Logger?.Trace($" VariableRpcNode - VariableName {Text} : execute success");
|
||||
else
|
||||
Logger?.Warning($" VariableRpcNode - VariableName {Text} : {data.ErrorMessage}");
|
||||
return new NodeOutput() { Value = data };
|
||||
if (device.ReadOnlyVariableRuntimes.TryGetValue(Text, out var value))
|
||||
{
|
||||
var data = await value.RpcAsync(input.JToken.ToString(), $"RulesEngine: {RulesEngineName}", cancellationToken).ConfigureAwait(false);
|
||||
if (data.IsSuccess)
|
||||
Logger?.Trace($" VariableRpcNode - VariableName {Text} : execute success");
|
||||
else
|
||||
Logger?.Warning($" VariableRpcNode - VariableName {Text} : {data.ErrorMessage}");
|
||||
return new OperResult<NodeOutput>() { Content = new NodeOutput() { Value = data } };
|
||||
}
|
||||
}
|
||||
Logger?.Warning($" VariableRpcNode - VariableName {Text} : not found");
|
||||
|
||||
return new OperResult<NodeOutput>() { Content = new NodeOutput() { } };
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger?.LogWarning(ex);
|
||||
return new OperResult<NodeOutput>(ex);
|
||||
}
|
||||
Logger?.Warning($" VariableRpcNode - VariableName {Text} : not found");
|
||||
return new NodeOutput() { };
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -16,12 +16,21 @@ public class DataNode : TextNode, IExpressionNode
|
||||
|
||||
}
|
||||
|
||||
Task<NodeOutput> IExpressionNode.ExecuteAsync(NodeInput input, CancellationToken cancellationToken)
|
||||
Task<OperResult<NodeOutput>> IExpressionNode.ExecuteAsync(NodeInput input, CancellationToken cancellationToken)
|
||||
{
|
||||
var value = Text.GetExpressionsResult(input.Value, Logger);
|
||||
NodeOutput nodeOutput = new();
|
||||
nodeOutput.Value = value;
|
||||
Logger?.Trace($"Data result: {nodeOutput.JToken?.ToString(Newtonsoft.Json.Formatting.Indented)}");
|
||||
return Task.FromResult(nodeOutput);
|
||||
try
|
||||
{
|
||||
var value = Text.GetExpressionsResult(input.Value, Logger);
|
||||
NodeOutput nodeOutput = new();
|
||||
nodeOutput.Value = value;
|
||||
Logger?.Trace($"Data result: {nodeOutput.JToken?.ToString(Newtonsoft.Json.Formatting.Indented)}");
|
||||
return Task.FromResult(new OperResult<NodeOutput>() { Content = nodeOutput });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger?.LogWarning(ex);
|
||||
return Task.FromResult(new OperResult<NodeOutput>(ex));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,11 +10,20 @@ public class DelayNode : NumberNode, IExpressionNode
|
||||
{
|
||||
public DelayNode(string id, Point? position = null) : base(id, position) { Title = "DelayNode"; Placeholder = "DelayNode.Placeholder"; }
|
||||
|
||||
async Task<NodeOutput> IExpressionNode.ExecuteAsync(NodeInput input, CancellationToken cancellationToken)
|
||||
async Task<OperResult<NodeOutput>> IExpressionNode.ExecuteAsync(NodeInput input, CancellationToken cancellationToken)
|
||||
{
|
||||
Logger?.Trace($"Delay {Number} ms");
|
||||
await Task.Delay(Number ?? 0, cancellationToken).ConfigureAwait(false);
|
||||
return new NodeOutput();
|
||||
try
|
||||
{
|
||||
Logger?.Trace($"Delay {Number} ms");
|
||||
await Task.Delay(Number ?? 0, cancellationToken).ConfigureAwait(false);
|
||||
return new OperResult<NodeOutput>() { Content = new NodeOutput() };
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger?.LogWarning(ex);
|
||||
return new OperResult<NodeOutput>(ex);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,11 +13,11 @@ public interface IConditionNode : INode
|
||||
|
||||
public interface IExpressionNode : INode
|
||||
{
|
||||
public Task<NodeOutput> ExecuteAsync(NodeInput input, CancellationToken cancellationToken);
|
||||
public Task<OperResult<NodeOutput>> ExecuteAsync(NodeInput input, CancellationToken cancellationToken);
|
||||
}
|
||||
public interface IActuatorNode : INode
|
||||
{
|
||||
public Task<NodeOutput> ExecuteAsync(NodeInput input, CancellationToken cancellationToken);
|
||||
public Task<OperResult<NodeOutput>> ExecuteAsync(NodeInput input, CancellationToken cancellationToken);
|
||||
}
|
||||
|
||||
public interface ITriggerNode : INode
|
||||
|
||||
@@ -65,7 +65,7 @@ internal sealed class RulesEngineHostedService : BackgroundService, IRulesEngine
|
||||
if (rules.Status)
|
||||
{
|
||||
var data = Init(rules);
|
||||
await Start(data.rulesLog, data.blazorDiagram, TokenSource.Token).ConfigureAwait(false);
|
||||
Start(data.rulesLog, data.blazorDiagram, TokenSource.Token);
|
||||
dispatchService.Dispatch(null);
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ internal sealed class RulesEngineHostedService : BackgroundService, IRulesEngine
|
||||
|
||||
return result;
|
||||
}
|
||||
private static Task Start(RulesLog rulesLog, DefaultDiagram item, CancellationToken cancellationToken)
|
||||
private static void Start(RulesLog rulesLog, DefaultDiagram item, CancellationToken cancellationToken)
|
||||
{
|
||||
rulesLog.Log.Trace("Start");
|
||||
var startNodes = item.Nodes.Where(a => a is IStartNode);
|
||||
@@ -123,7 +123,6 @@ internal sealed class RulesEngineHostedService : BackgroundService, IRulesEngine
|
||||
{
|
||||
_ = Analysis((link.Target.Model as PortModel)?.Parent, new NodeInput(), rulesLog, cancellationToken);
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private static async Task Analysis(NodeModel targetNode, NodeInput input, RulesLog rulesLog, CancellationToken cancellationToken)
|
||||
@@ -152,17 +151,24 @@ internal sealed class RulesEngineHostedService : BackgroundService, IRulesEngine
|
||||
else if (targetNode is IExpressionNode expressionNode)
|
||||
{
|
||||
var nodeOutput = await expressionNode.ExecuteAsync(input, cancellationToken).ConfigureAwait(false);
|
||||
foreach (var link in targetNode.PortLinks.Where(a => ((a.Target.Model as PortModel)?.Parent) != targetNode))
|
||||
if (nodeOutput.IsSuccess)
|
||||
{
|
||||
await Analysis((link.Target.Model as PortModel)?.Parent, new NodeInput() { Value = nodeOutput.Value, }, rulesLog, cancellationToken).ConfigureAwait(false);
|
||||
foreach (var link in targetNode.PortLinks.Where(a => ((a.Target.Model as PortModel)?.Parent) != targetNode))
|
||||
{
|
||||
await Analysis((link.Target.Model as PortModel)?.Parent, new NodeInput() { Value = nodeOutput.Content.Value, }, rulesLog, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else if (targetNode is IActuatorNode actuatorNode)
|
||||
{
|
||||
var nodeOutput = await actuatorNode.ExecuteAsync(input, cancellationToken).ConfigureAwait(false);
|
||||
foreach (var link in targetNode.PortLinks.Where(a => ((a.Target.Model as PortModel)?.Parent) != targetNode))
|
||||
if (nodeOutput.IsSuccess)
|
||||
{
|
||||
await Analysis((link.Target.Model as PortModel)?.Parent, new NodeInput() { Value = nodeOutput.Value }, rulesLog, cancellationToken).ConfigureAwait(false);
|
||||
foreach (var link in targetNode.PortLinks.Where(a => ((a.Target.Model as PortModel)?.Parent) != targetNode))
|
||||
{
|
||||
await Analysis((link.Target.Model as PortModel)?.Parent, new NodeInput() { Value = nodeOutput.Content.Value }, rulesLog, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (targetNode is ITriggerNode triggerNode)
|
||||
@@ -200,11 +206,10 @@ internal sealed class RulesEngineHostedService : BackgroundService, IRulesEngine
|
||||
foreach (var rules in Rules.Where(a => a.Status))
|
||||
{
|
||||
var item = Init(rules);
|
||||
await Start(item.rulesLog, item.blazorDiagram, cancellationToken).ConfigureAwait(false);
|
||||
Start(item.rulesLog, item.blazorDiagram, cancellationToken);
|
||||
}
|
||||
dispatchService.Dispatch(null);
|
||||
|
||||
|
||||
_ = Task.Factory.StartNew(async (state) =>
|
||||
{
|
||||
if (state is not Dictionary<RulesLog, Diagram> diagrams)
|
||||
|
||||
@@ -176,20 +176,20 @@ public class VariableRuntimeService : IVariableRuntimeService
|
||||
var datas = await GlobalData.VariableService.InsertTestDataAsync(testVariableCount, testDeviceCount, slaveUrl, businessEnable).ConfigureAwait(false);
|
||||
|
||||
{
|
||||
var newChannelRuntimes = (datas.Item1).Adapt<List<ChannelRuntime>>();
|
||||
var newChannelRuntimes = datas.Item1.Adapt<List<ChannelRuntime>>();
|
||||
|
||||
//批量修改之后,需要重新加载通道
|
||||
RuntimeServiceHelper.Init(newChannelRuntimes);
|
||||
|
||||
{
|
||||
|
||||
var newDeviceRuntimes = (datas.Item2).Adapt<List<DeviceRuntime>>();
|
||||
var newDeviceRuntimes = datas.Item2.Adapt<List<DeviceRuntime>>();
|
||||
|
||||
RuntimeServiceHelper.Init(newDeviceRuntimes);
|
||||
|
||||
}
|
||||
{
|
||||
var newVariableRuntimes = (datas.Item3).Adapt<List<VariableRuntime>>();
|
||||
var newVariableRuntimes = datas.Item3.Adapt<List<VariableRuntime>>();
|
||||
RuntimeServiceHelper.Init(newVariableRuntimes);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<Import Project="$(SolutionDir)Version.props" />
|
||||
<Import Project="$(SolutionDir)PackNuget.props" />
|
||||
<Import Project="..\..\Version.props" />
|
||||
<Import Project="..\..\PackNuget.props" />
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net8.0;</TargetFrameworks>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Portable.BouncyCastle" Version="1.9.0" />
|
||||
<PackageReference Include="Rougamo.Fody" Version="5.0.0" />
|
||||
<PackageReference Include="TouchSocket.Dmtp" Version="3.1.8" />
|
||||
<PackageReference Include="TouchSocket.WebApi.Swagger" Version="3.1.8" />
|
||||
<PackageReference Include="Rougamo.Fody" Version="5.0.1" />
|
||||
<PackageReference Include="TouchSocket.Dmtp" Version="3.1.10" />
|
||||
<PackageReference Include="TouchSocket.WebApi.Swagger" Version="3.1.10" />
|
||||
<PackageReference Include="ThingsGateway.Authentication" Version="$(AuthenticationVersion)" />
|
||||
<!--<ProjectReference Include="..\..\PluginPro\ThingsGateway.Authentication\ThingsGateway.Authentication.csproj" />-->
|
||||
|
||||
|
||||
@@ -20,4 +20,4 @@ global using ThingsGateway.Razor;
|
||||
|
||||
[assembly: SuppressMessage("Reliability", "CA2007", Justification = "<挂起>", Scope = "module")]
|
||||
|
||||
[assembly: BlazorSetParametersAsyncGenerator.GlobalGenerateSetParametersAsync(true)]
|
||||
[assembly: GlobalGenerateSetParametersAsync(true)]
|
||||
@@ -1,4 +1,34 @@
|
||||
{
|
||||
"ThingsGateway.Gateway.Razor.ValueTransformType": {
|
||||
"None": "None",
|
||||
"Linear": "Linear",
|
||||
"Sqrt": "Sqrt"
|
||||
},
|
||||
|
||||
"ThingsGateway.Gateway.Razor.ValueTransformConfig": {
|
||||
"TransformType": "TransformType",
|
||||
"MinMax": "MinMax",
|
||||
"ClampToRawRange": "ClampToRawRange",
|
||||
"DecimalPlaces": "DecimalPlaces",
|
||||
"RawMin": "RawMin",
|
||||
"RawMax": "RawMax",
|
||||
"ActualMin": "ActualMin",
|
||||
"ActualMax": "ActualMax"
|
||||
},
|
||||
|
||||
|
||||
"ThingsGateway.Management.Authentication": {
|
||||
"AuthName": "AuthName",
|
||||
"Authorized": "Authorized",
|
||||
"ExpireTime": "ExpireTime",
|
||||
"Password": "Password",
|
||||
"Register": "Register",
|
||||
"RegisterStatus": "RegisterStatus",
|
||||
"Unauthorized": "Unauthorized",
|
||||
"Unregister": "Unregister",
|
||||
"UUID": "UUID"
|
||||
},
|
||||
|
||||
"ThingsGateway.Gateway.Razor._Imports": {
|
||||
|
||||
"Actuator": "Actuator",
|
||||
|
||||
@@ -1,4 +1,32 @@
|
||||
{
|
||||
"ThingsGateway.Gateway.Razor.ValueTransformType": {
|
||||
"None": "无",
|
||||
"Linear": "线性",
|
||||
"Sqrt": "开方"
|
||||
},
|
||||
"ThingsGateway.Gateway.Razor.ValueTransformConfig": {
|
||||
"TransformType": "转换方式",
|
||||
"MinMax": "最小最大值",
|
||||
"ClampToRawRange": "限制范围",
|
||||
"DecimalPlaces": "保留小数位",
|
||||
"RawMin": "原始最小值",
|
||||
"RawMax": "原始最大值",
|
||||
"ActualMin": "实际最小值",
|
||||
"ActualMax": "实际最大值"
|
||||
},
|
||||
|
||||
"ThingsGateway.Management.Authentication": {
|
||||
"AuthName": "公司名称",
|
||||
"Authorized": "已授权",
|
||||
"ExpireTime": "过期时间",
|
||||
"Password": "注册码",
|
||||
"Register": "注册",
|
||||
"RegisterStatus": "注册状态",
|
||||
"Unauthorized": "未授权",
|
||||
"Unregister": "取消注册",
|
||||
"UUID": "唯一编码"
|
||||
},
|
||||
|
||||
"ThingsGateway.Gateway.Razor._Imports": {
|
||||
|
||||
"Actuator": "执行",
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
<span style="color:var(--bs-body-color)" class="text-h6 mb-2">@GatewayLocalizer["DeviceList"]</span>
|
||||
|
||||
<ContextMenuZone title="Right click operation">
|
||||
<TreeView TItem="ChannelDeviceTreeItem" Items="Items" ShowIcon="false" ShowSearch IsAccordion=false IsVirtualize="true" OnTreeItemClick="OnTreeItemClick" OnSearchAsync="OnClickSearch" ModelEqualityComparer=ModelEqualityComparer>
|
||||
<TreeView TItem="ChannelDeviceTreeItem" Items="Items" ShowIcon="false" ShowSearch IsAccordion=false IsVirtualize="true" OnTreeItemClick="OnTreeItemClick" OnSearchAsync="OnClickSearch" ModelEqualityComparer=ModelEqualityComparer>
|
||||
|
||||
</TreeView>
|
||||
|
||||
|
||||
@@ -1469,27 +1469,22 @@ EventCallback.Factory.Create<MouseEventArgs>(this, async e =>
|
||||
|
||||
private static bool ModelEqualityComparer(ChannelDeviceTreeItem x, ChannelDeviceTreeItem y)
|
||||
{
|
||||
if (x.ChannelDevicePluginType == y.ChannelDevicePluginType)
|
||||
{
|
||||
if (x.ChannelDevicePluginType == ChannelDevicePluginTypeEnum.Device)
|
||||
{
|
||||
return x.DeviceRuntime.Id == y.DeviceRuntime.Id; ;
|
||||
}
|
||||
else if (x.ChannelDevicePluginType == ChannelDevicePluginTypeEnum.PluginType)
|
||||
{
|
||||
return x.PluginType == y.PluginType;
|
||||
if (x.ChannelDevicePluginType != y.ChannelDevicePluginType)
|
||||
return false;
|
||||
|
||||
}
|
||||
else if (x.ChannelDevicePluginType == ChannelDevicePluginTypeEnum.Channel)
|
||||
{
|
||||
switch (x.ChannelDevicePluginType)
|
||||
{
|
||||
case ChannelDevicePluginTypeEnum.Device:
|
||||
return x.DeviceRuntime.Id == y.DeviceRuntime.Id;
|
||||
case ChannelDevicePluginTypeEnum.PluginType:
|
||||
return x.PluginType == y.PluginType;
|
||||
case ChannelDevicePluginTypeEnum.Channel:
|
||||
return x.ChannelRuntime.Id == y.ChannelRuntime.Id;
|
||||
}
|
||||
else if (x.ChannelDevicePluginType == ChannelDevicePluginTypeEnum.PluginName)
|
||||
{
|
||||
case ChannelDevicePluginTypeEnum.PluginName:
|
||||
return x.PluginName == y.PluginName;
|
||||
}
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
private bool Disposed;
|
||||
protected override ValueTask DisposeAsync(bool disposing)
|
||||
|
||||
@@ -31,27 +31,22 @@ public class ChannelDeviceTreeItem : IEqualityComparer<ChannelDeviceTreeItem>
|
||||
{
|
||||
if (obj is ChannelDeviceTreeItem item)
|
||||
{
|
||||
if (ChannelDevicePluginType == item.ChannelDevicePluginType)
|
||||
if (ChannelDevicePluginType != item.ChannelDevicePluginType)
|
||||
return false;
|
||||
|
||||
switch (ChannelDevicePluginType)
|
||||
{
|
||||
if (ChannelDevicePluginType == ChannelDevicePluginTypeEnum.Device)
|
||||
{
|
||||
case ChannelDevicePluginTypeEnum.Device:
|
||||
return DeviceRuntime == item.DeviceRuntime;
|
||||
}
|
||||
else if (ChannelDevicePluginType == ChannelDevicePluginTypeEnum.PluginType)
|
||||
{
|
||||
case ChannelDevicePluginTypeEnum.PluginType:
|
||||
return PluginType == item.PluginType;
|
||||
|
||||
}
|
||||
else if (ChannelDevicePluginType == ChannelDevicePluginTypeEnum.Channel)
|
||||
{
|
||||
case ChannelDevicePluginTypeEnum.Channel:
|
||||
return ChannelRuntime == item.ChannelRuntime;
|
||||
}
|
||||
else if (ChannelDevicePluginType == ChannelDevicePluginTypeEnum.PluginName)
|
||||
{
|
||||
case ChannelDevicePluginTypeEnum.PluginName:
|
||||
return PluginName == item.PluginName;
|
||||
}
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
return false;
|
||||
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
|
||||
// 此代码版权(除特别声明外的代码)归作者本人Diego所有
|
||||
// 源代码使用协议遵循本仓库的开源协议及附加协议
|
||||
// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
|
||||
// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
|
||||
// 使用文档:https://thingsgateway.cn/
|
||||
// QQ群:605534569
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace ThingsGateway.Gateway.Razor;
|
||||
|
||||
public class ValueTransformConfig
|
||||
{
|
||||
/// <summary>
|
||||
/// 保留小数位
|
||||
/// </summary>
|
||||
public int DecimalPlaces { get; set; } = 2;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 限制范围
|
||||
/// </summary>
|
||||
public bool ClampToRawRange { get; set; }
|
||||
|
||||
public ValueTransformType TransformType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 原始低
|
||||
/// </summary>
|
||||
public decimal RawMin { get; set; }
|
||||
/// <summary>
|
||||
/// 原始高
|
||||
/// </summary>
|
||||
public decimal RawMax { get; set; }
|
||||
/// <summary>
|
||||
/// 实际低
|
||||
/// </summary>
|
||||
public decimal ActualMin { get; set; }
|
||||
/// <summary>
|
||||
/// 实际高
|
||||
/// </summary>
|
||||
public decimal ActualMax { get; set; }
|
||||
|
||||
|
||||
}
|
||||
|
||||
public enum ValueTransformType
|
||||
{
|
||||
/// <summary>
|
||||
/// 不转换,仅保留小数位
|
||||
/// </summary>
|
||||
None,
|
||||
/// <summary>
|
||||
/// 线性转换
|
||||
/// </summary>
|
||||
Linear,
|
||||
/// <summary>
|
||||
/// 开方转换
|
||||
/// </summary>
|
||||
Sqrt
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
@namespace ThingsGateway.Gateway.Razor
|
||||
@using ThingsGateway.Admin.Application
|
||||
@using ThingsGateway.Admin.Razor
|
||||
@using ThingsGateway.Foundation
|
||||
@using ThingsGateway.Gateway.Application
|
||||
@inherits ComponentDefault
|
||||
|
||||
<ValidateForm class="p-4 h-100" Model="@ValueTransformConfig" OnValidSubmit="OnSave">
|
||||
<EditorForm AutoGenerateAllItem="false" RowType=RowType.Inline ItemsPerRow=1 LabelWidth=150 Model="ValueTransformConfig">
|
||||
|
||||
<FieldItems>
|
||||
|
||||
<EditorItem @bind-Field="@context.TransformType" GroupName=@(ValueTransformConfigLocalizer["TransformType"]) Cols="4" />
|
||||
<EditorItem @bind-Field="@context.ClampToRawRange" GroupName=@(ValueTransformConfigLocalizer["TransformType"]) Cols="4" />
|
||||
<EditorItem @bind-Field="@context.DecimalPlaces" GroupName=@(ValueTransformConfigLocalizer["TransformType"]) Cols="4" />
|
||||
|
||||
|
||||
<EditorItem @bind-Field="@context.RawMin" GroupName=@(ValueTransformConfigLocalizer["MinMax"]) GroupOrder=2 Cols="6" />
|
||||
<EditorItem @bind-Field="@context.RawMax" GroupName=@(ValueTransformConfigLocalizer["MinMax"]) GroupOrder=2 Cols="6" />
|
||||
<EditorItem @bind-Field="@context.ActualMin" GroupName=@(ValueTransformConfigLocalizer["MinMax"]) GroupOrder=2 Cols="6" />
|
||||
<EditorItem @bind-Field="@context.ActualMax" GroupName=@(ValueTransformConfigLocalizer["MinMax"]) GroupOrder=2 Cols="6" />
|
||||
|
||||
|
||||
</FieldItems>
|
||||
<Buttons>
|
||||
<Button ButtonType="ButtonType.Submit" Icon="fa-solid fa-floppy-disk" IsAsync Text=@RazorLocalizer["Save"] />
|
||||
</Buttons>
|
||||
</EditorForm>
|
||||
|
||||
</ValidateForm>
|
||||
|
||||
@@ -0,0 +1,215 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
|
||||
// 此代码版权(除特别声明外的代码)归作者本人Diego所有
|
||||
// 源代码使用协议遵循本仓库的开源协议及附加协议
|
||||
// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
|
||||
// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
|
||||
// 使用文档:https://thingsgateway.cn/
|
||||
// QQ群:605534569
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
using Microsoft.AspNetCore.Components.Forms;
|
||||
|
||||
using System.Globalization;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
using ThingsGateway.NewLife.Extension;
|
||||
|
||||
namespace ThingsGateway.Gateway.Razor;
|
||||
|
||||
public partial class ValueTransformConfigPage
|
||||
{
|
||||
private ValueTransformConfig ValueTransformConfig = new();
|
||||
|
||||
[Inject]
|
||||
[NotNull]
|
||||
private IStringLocalizer<ValueTransformConfig>? ValueTransformConfigLocalizer { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public string Expressions { get; set; }
|
||||
|
||||
|
||||
[Parameter]
|
||||
public EventCallback<string> ExpressionsChanged { get; set; }
|
||||
|
||||
public static bool TryParseLinearFormula(string formula, out ValueTransformConfig config)
|
||||
{
|
||||
config = new ValueTransformConfig();
|
||||
var dec = @"[\d]+(?:\.[\d]+)?";
|
||||
|
||||
try
|
||||
{
|
||||
// None + clamp actual
|
||||
var m = Regex.Match(formula, $@"^Math\.Round\(\s*
|
||||
Math\.Min\(\s*
|
||||
Math\.Max\(\s*
|
||||
raw\.ToDecimal\(\)\s*,\s*({dec})\s*\)\s*,\s*({dec})\s*\)\s*,\s*(\d+)\s*\)$", RegexOptions.IgnorePatternWhitespace);
|
||||
if (m.Success)
|
||||
{
|
||||
config.TransformType = ValueTransformType.None;
|
||||
config.ClampToRawRange = true;
|
||||
config.ActualMin = decimal.Parse(m.Groups[1].Value);
|
||||
config.ActualMax = decimal.Parse(m.Groups[2].Value);
|
||||
config.DecimalPlaces = int.Parse(m.Groups[3].Value);
|
||||
return true;
|
||||
}
|
||||
|
||||
// None pure
|
||||
m = Regex.Match(formula, $@"^Math\.Round\(\s*raw\.ToDecimal\(\)\s*,\s*(\d+)\s*\)$");
|
||||
if (m.Success)
|
||||
{
|
||||
config.TransformType = ValueTransformType.None;
|
||||
config.ClampToRawRange = false;
|
||||
config.DecimalPlaces = int.Parse(m.Groups[1].Value);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Linear + clamp actual
|
||||
|
||||
m = Regex.Match(formula, $@"^Math\.Round\(\s*
|
||||
Math\.Min\(\s*
|
||||
Math\.Max\(\s*
|
||||
\(\(raw\.ToDecimal\(\)\s*-\s*({dec})\)\s*/\s*
|
||||
\(({dec})\s*-\s*({dec})\)\s*\*\s*
|
||||
\(({dec})\s*-\s*({dec})\)\s*\+\s*
|
||||
({dec})\)\s*,\s*({dec})\)\s*,\s*({dec})\)\s*,\s*(\d+)\s*\)$", RegexOptions.IgnorePatternWhitespace);
|
||||
if (m.Success)
|
||||
{
|
||||
config.TransformType = ValueTransformType.Linear;
|
||||
config.ClampToRawRange = true;
|
||||
config.RawMin = decimal.Parse(m.Groups[1].Value);
|
||||
config.RawMax = decimal.Parse(m.Groups[2].Value);
|
||||
config.ActualMax = decimal.Parse(m.Groups[4].Value);
|
||||
config.ActualMin = decimal.Parse(m.Groups[5].Value);
|
||||
config.DecimalPlaces = int.Parse(m.Groups[9].Value);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Linear pure
|
||||
m = Regex.Match(formula, $@"^Math\.Round\(\s*
|
||||
\(\(raw\.ToDecimal\(\)\s*-\s*({dec})\)\s*/\s*
|
||||
\(({dec})\s*-\s*({dec})\)\s*\*\s*
|
||||
\(({dec})\s*-\s*({dec})\)\s*\+\s*({dec})\)\s*,\s*(\d+)\s*\)$", RegexOptions.IgnorePatternWhitespace);
|
||||
|
||||
if (m.Success)
|
||||
{
|
||||
config.TransformType = ValueTransformType.Linear;
|
||||
config.ClampToRawRange = false;
|
||||
config.RawMin = decimal.Parse(m.Groups[1].Value); // raw减数(0)
|
||||
config.RawMax = decimal.Parse(m.Groups[2].Value); // 分母第一个数(10)
|
||||
config.ActualMax = decimal.Parse(m.Groups[4].Value); // 乘数第一个数(1)
|
||||
config.ActualMin = decimal.Parse(m.Groups[6].Value); // 加数(0)
|
||||
config.DecimalPlaces = int.Parse(m.Groups[7].Value); // 小数位(2)
|
||||
return true;
|
||||
}
|
||||
|
||||
// Sqrt + clamp actual
|
||||
m = Regex.Match(formula, $@"^Math\.Round\(\s*
|
||||
Math\.Min\(\s*
|
||||
Math\.Max\(\s*
|
||||
Math\.Sqrt\(Math\.Max\(raw\.ToDecimal\(\),\s*0\)\)\s*\*\s*({dec})\s*,\s*({dec})\)\s*,\s*({dec})\)\s*,\s*(\d+)\s*\)$", RegexOptions.IgnorePatternWhitespace);
|
||||
if (m.Success)
|
||||
{
|
||||
config.TransformType = ValueTransformType.Sqrt;
|
||||
config.ClampToRawRange = true;
|
||||
config.ActualMax = decimal.Parse(m.Groups[1].Value);
|
||||
config.ActualMin = decimal.Parse(m.Groups[2].Value);
|
||||
config.DecimalPlaces = int.Parse(m.Groups[4].Value);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Sqrt pure
|
||||
m = Regex.Match(formula, $@"^Math\.Round\(\s*
|
||||
Math\.Sqrt\(Math\.Max\(raw\.ToDecimal\(\),\s*0\)\)\s*\*\s*({dec})\s*,\s*(\d+)\s*\)$", RegexOptions.IgnorePatternWhitespace);
|
||||
if (m.Success)
|
||||
{
|
||||
config.TransformType = ValueTransformType.Sqrt;
|
||||
config.ClampToRawRange = false;
|
||||
config.DecimalPlaces = int.Parse(m.Groups[2].Value);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// ignore
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static string GenerateFormula(ValueTransformConfig config)
|
||||
{
|
||||
// 只有 ClampToRawRange 为 true 时才包裹实际值范围限制
|
||||
string clampActual(string expr)
|
||||
{
|
||||
if (config.ClampToRawRange)
|
||||
return $"Math.Min(Math.Max({expr}, {config.ActualMin}), {config.ActualMax})";
|
||||
else
|
||||
return expr;
|
||||
}
|
||||
|
||||
string rawExpr = "raw.ToDecimal()"; // 这里不做 raw clamp
|
||||
|
||||
switch (config.TransformType)
|
||||
{
|
||||
case ValueTransformType.None:
|
||||
return $"Math.Round({clampActual(rawExpr)}, {config.DecimalPlaces})";
|
||||
|
||||
case ValueTransformType.Linear:
|
||||
var linearExpr = $"(({rawExpr} - {config.RawMin}) / ({config.RawMax} - {config.RawMin}) * ({config.ActualMax} - {config.ActualMin}) + {config.ActualMin})";
|
||||
return $"Math.Round({clampActual(linearExpr)}, {config.DecimalPlaces})";
|
||||
|
||||
case ValueTransformType.Sqrt:
|
||||
var sqrtExpr = $"Math.Sqrt(Math.Max({rawExpr}, 0)) * {config.ActualMax}";
|
||||
return $"Math.Round({clampActual(sqrtExpr)}, {config.DecimalPlaces})";
|
||||
|
||||
default:
|
||||
throw new NotSupportedException($"Unsupported transform type: {config.TransformType}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected override void OnParametersSet()
|
||||
{
|
||||
if (!Expressions.IsNullOrWhiteSpace())
|
||||
{
|
||||
if (TryParseLinearFormula(Expressions, out var config))
|
||||
{
|
||||
ValueTransformConfig = config;
|
||||
}
|
||||
}
|
||||
base.OnParametersSet();
|
||||
}
|
||||
|
||||
#region 修改
|
||||
[CascadingParameter]
|
||||
private Func<Task>? OnCloseAsync { get; set; }
|
||||
|
||||
|
||||
|
||||
private async Task OnSave(EditContext editContext)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = GenerateFormula(ValueTransformConfig);
|
||||
Expressions = result;
|
||||
if (ExpressionsChanged.HasDelegate)
|
||||
{
|
||||
await ExpressionsChanged.InvokeAsync(result);
|
||||
}
|
||||
else
|
||||
{
|
||||
Expressions = result;
|
||||
}
|
||||
if (OnCloseAsync != null)
|
||||
await OnCloseAsync();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await ToastService.Warn(ex);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion 修改
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
.appconfig ::deep .tabs-body-content {
|
||||
height: 100% !important;
|
||||
}
|
||||
|
||||
.appconfig {
|
||||
height: 100% !important;
|
||||
}
|
||||
@@ -28,225 +28,247 @@
|
||||
RenderFragment renderFragment =>
|
||||
@<Tab>
|
||||
|
||||
<TabItem Text=@GatewayLocalizer["VariableInformation"]>
|
||||
<TabItem Text=@GatewayLocalizer["VariableInformation"]>
|
||||
|
||||
<EditorForm class="p-2" AutoGenerateAllItem="false" RowType=RowType.Inline ItemsPerRow=2 LabelWidth=200 Model="Model">
|
||||
<EditorForm class="p-2" AutoGenerateAllItem="false" RowType=RowType.Inline ItemsPerRow=2 LabelWidth=200 Model="Model">
|
||||
|
||||
<FieldItems>
|
||||
<EditorItem TValue="string" TModel="Variable" @bind-Field="@context.Name">
|
||||
<EditTemplate Context="value">
|
||||
<div class="col-12">
|
||||
<h6>@GatewayLocalizer["BasicInformation"]</h6>
|
||||
</div>
|
||||
</EditTemplate>
|
||||
</EditorItem>
|
||||
<FieldItems>
|
||||
<EditorItem TValue="string" TModel="Variable" @bind-Field="@context.Name">
|
||||
<EditTemplate Context="value">
|
||||
<div class="col-12">
|
||||
<h6>@GatewayLocalizer["BasicInformation"]</h6>
|
||||
</div>
|
||||
</EditTemplate>
|
||||
</EditorItem>
|
||||
|
||||
<EditorItem @bind-Field="@context.Name" Readonly=BatchEditEnable />
|
||||
<EditorItem @bind-Field="@context.Name" Readonly=BatchEditEnable />
|
||||
|
||||
<EditorItem @bind-Field="@context.Description" />
|
||||
<EditorItem @bind-Field="@context.CollectGroup" />
|
||||
<EditorItem @bind-Field="@context.BusinessGroup" />
|
||||
<EditorItem @bind-Field="@context.Description" />
|
||||
<EditorItem @bind-Field="@context.CollectGroup" />
|
||||
<EditorItem @bind-Field="@context.BusinessGroup" />
|
||||
<EditorItem @bind-Field="@context.BusinessGroupUpdateTrigger" />
|
||||
<EditorItem @bind-Field="@context.RpcWriteCheck" />
|
||||
|
||||
<EditorItem @bind-Field="@context.Unit" />
|
||||
<EditorItem @bind-Field="@context.ProtectType" />
|
||||
<EditorItem @bind-Field="@context.Enable" />
|
||||
<EditorItem @bind-Field="@context.RpcWriteEnable" />
|
||||
<EditorItem @bind-Field="@context.Unit" />
|
||||
<EditorItem @bind-Field="@context.ProtectType" />
|
||||
<EditorItem @bind-Field="@context.Enable" />
|
||||
<EditorItem @bind-Field="@context.RpcWriteEnable" />
|
||||
|
||||
<EditorItem @bind-Field="@context.InitValue">
|
||||
<EditTemplate Context="value">
|
||||
<div class="col-12 col-md-6 ">
|
||||
<BootstrapInput @bind-Value="@value.InitValue" DisplayText="@(context.Description(a=>a.InitValue))" ShowLabel="true" Formatter=@(JsonFormatter) />
|
||||
</div>
|
||||
</EditTemplate>
|
||||
</EditorItem>
|
||||
<EditorItem @bind-Field="@context.InitValue">
|
||||
<EditTemplate Context="value">
|
||||
<div class="col-12 col-md-6 ">
|
||||
<BootstrapInput @bind-Value="@value.InitValue" DisplayText="@(context.Description(a => a.InitValue))" ShowLabel="true" Formatter=@(JsonFormatter) />
|
||||
</div>
|
||||
</EditTemplate>
|
||||
</EditorItem>
|
||||
|
||||
<EditorItem @bind-Field="@context.SaveValue" />
|
||||
<EditorItem @bind-Field="@context.SaveValue" />
|
||||
|
||||
<EditorItem TValue="string" TModel="Variable" @bind-Field="@context.Name">
|
||||
<EditTemplate Context="value">
|
||||
<div class="col-12">
|
||||
<h6>@GatewayLocalizer["Connection"]</h6>
|
||||
</div>
|
||||
</EditTemplate>
|
||||
</EditorItem>
|
||||
<EditorItem TValue="string" TModel="Variable" @bind-Field="@context.Name">
|
||||
<EditTemplate Context="value">
|
||||
<div class="col-12">
|
||||
<h6>@GatewayLocalizer["Connection"]</h6>
|
||||
</div>
|
||||
</EditTemplate>
|
||||
</EditorItem>
|
||||
|
||||
<EditorItem @bind-Field="@context.DeviceId">
|
||||
<EditTemplate Context="value">
|
||||
<div class="col-12 col-md-6 ">
|
||||
<BootstrapInputGroup>
|
||||
<Select IsVirtualize @bind-Value="@value.DeviceId" DefaultVirtualizeItemText=@(GlobalData.ReadOnlyIdDevices.TryGetValue(value.DeviceId,out var deviceRuntime)?deviceRuntime.Name:string.Empty) IsDisabled=BatchEditEnable Items="@CollectDeviceItems" OnSelectedItemChanged=OnDeviceChanged ShowSearch="true" ShowLabel="true" />
|
||||
<Button class="text-end" Icon="fa-solid fa-plus" OnClick="AddDevice" IsDisabled=BatchEditEnable></Button>
|
||||
</BootstrapInputGroup>
|
||||
</div>
|
||||
</EditTemplate>
|
||||
</EditorItem>
|
||||
<EditorItem @bind-Field="@context.DeviceId">
|
||||
<EditTemplate Context="value">
|
||||
<div class="col-12 col-md-6 ">
|
||||
<BootstrapInputGroup>
|
||||
<Select IsVirtualize @bind-Value="@value.DeviceId" DefaultVirtualizeItemText=@(GlobalData.ReadOnlyIdDevices.TryGetValue(value.DeviceId, out var deviceRuntime) ? deviceRuntime.Name : string.Empty) IsDisabled=BatchEditEnable Items="@CollectDeviceItems" OnSelectedItemChanged=OnDeviceChanged ShowSearch="true" ShowLabel="true" />
|
||||
<Button class="text-end" Icon="fa-solid fa-plus" OnClick="AddDevice" IsDisabled=BatchEditEnable></Button>
|
||||
</BootstrapInputGroup>
|
||||
</div>
|
||||
</EditTemplate>
|
||||
</EditorItem>
|
||||
|
||||
<EditorItem @bind-Field="@context.DataType" />
|
||||
<EditorItem @bind-Field="@context.IntervalTime" />
|
||||
<EditorItem @bind-Field="@context.DataType" />
|
||||
<EditorItem @bind-Field="@context.IntervalTime" />
|
||||
|
||||
<EditorItem @bind-Field="@context.OtherMethod">
|
||||
<EditTemplate Context="value">
|
||||
<div class="col-12 col-md-6">
|
||||
<Select IsVirtualize DefaultVirtualizeItemText=@(OtherMethods.TryGetValue(value.OtherMethod??string.Empty,out var desc)?desc:value.OtherMethod) @bind-Value="@value.OtherMethod" Items="@OtherMethodSelectedItems" ShowSearch="true" />
|
||||
</div>
|
||||
</EditTemplate>
|
||||
</EditorItem>
|
||||
<EditorItem @bind-Field="@context.OtherMethod">
|
||||
<EditTemplate Context="value">
|
||||
<div class="col-12 col-md-6">
|
||||
<Select IsVirtualize DefaultVirtualizeItemText=@(OtherMethods.TryGetValue(value.OtherMethod ?? string.Empty, out var desc) ? desc : value.OtherMethod) @bind-Value="@value.OtherMethod" Items="@OtherMethodSelectedItems" ShowSearch="true" />
|
||||
</div>
|
||||
</EditTemplate>
|
||||
</EditorItem>
|
||||
|
||||
<EditorItem @bind-Field="@context.RegisterAddress">
|
||||
<EditTemplate Context="value">
|
||||
<div class="col-12">
|
||||
<BootstrapInputGroup>
|
||||
@if(GlobalData.ReadOnlyIdDevices.TryGetValue(value.DeviceId,out var device)&&device.Driver is CollectBase collectBase)
|
||||
{
|
||||
<Textarea rows="1" title=@collectBase.GetAddressDescription() @bind-Value="value.RegisterAddress" ShowLabel="true"></Textarea>
|
||||
}
|
||||
else
|
||||
<EditorItem @bind-Field="@context.RegisterAddress">
|
||||
<EditTemplate Context="value">
|
||||
<div class="col-12">
|
||||
<BootstrapInputGroup>
|
||||
@if(GlobalData.ReadOnlyIdDevices.TryGetValue(value.DeviceId,out var device)&&device.Driver is CollectBase collectBase)
|
||||
{
|
||||
<Textarea rows="1" title=@collectBase.GetAddressDescription() @bind-Value="value.RegisterAddress" ShowLabel="true"></Textarea>
|
||||
}
|
||||
else
|
||||
{
|
||||
<Textarea rows="1" @bind-Value="value.RegisterAddress" ShowLabel="true"></Textarea>
|
||||
}
|
||||
<Button IsDisabled=@(AddressUIType==null) Icon="fa-solid fa-bars" OnClick="ShowAddressUI"></Button>
|
||||
</BootstrapInputGroup>
|
||||
</div>
|
||||
</EditTemplate>
|
||||
</EditorItem>
|
||||
<EditorItem @bind-Field="@context.ArrayLength" />
|
||||
<Button IsDisabled=@(AddressUIType == null) Icon="fa-solid fa-bars" OnClick="ShowAddressUI"></Button>
|
||||
</BootstrapInputGroup>
|
||||
</div>
|
||||
</EditTemplate>
|
||||
</EditorItem>
|
||||
<EditorItem @bind-Field="@context.ArrayLength" />
|
||||
|
||||
<EditorItem @bind-Field="@context.ReadExpressions" Rows="1" />
|
||||
<EditorItem @bind-Field="@context.WriteExpressions" Rows="1" />
|
||||
<EditorItem @bind-Field="@context.ReadExpressions">
|
||||
<EditTemplate Context="value">
|
||||
<div class="col-12">
|
||||
<BootstrapInputGroup>
|
||||
|
||||
<Textarea rows="1" @bind-Value="value.ReadExpressions" ShowLabel="true"></Textarea>
|
||||
<Button Icon="fa-solid fa-bars" OnClick="() => ShowExpressionsUI(true)"></Button>
|
||||
</BootstrapInputGroup>
|
||||
</div>
|
||||
</EditTemplate>
|
||||
</EditorItem>
|
||||
<EditorItem @bind-Field="@context.WriteExpressions">
|
||||
<EditTemplate Context="value">
|
||||
<div class="col-12">
|
||||
<BootstrapInputGroup>
|
||||
|
||||
<Textarea rows="1" @bind-Value="value.WriteExpressions" ShowLabel="true"></Textarea>
|
||||
<Button Icon="fa-solid fa-bars" OnClick="() => ShowExpressionsUI(false)"></Button>
|
||||
</BootstrapInputGroup>
|
||||
</div>
|
||||
</EditTemplate>
|
||||
</EditorItem>
|
||||
|
||||
|
||||
<EditorItem TValue="string" TModel="Variable" @bind-Field="@context.Description">
|
||||
<EditTemplate Context="value">
|
||||
<div class="col-12">
|
||||
<h6>@GatewayLocalizer["Remark"]</h6>
|
||||
</div>
|
||||
</EditTemplate>
|
||||
</EditorItem>
|
||||
<EditorItem @bind-Field="@context.Remark1" />
|
||||
<EditorItem @bind-Field="@context.Remark2" />
|
||||
<EditorItem @bind-Field="@context.Remark3" />
|
||||
<EditorItem @bind-Field="@context.Remark4" />
|
||||
<EditorItem @bind-Field="@context.Remark5" />
|
||||
<EditorItem TValue="string" TModel="Variable" @bind-Field="@context.Description">
|
||||
<EditTemplate Context="value">
|
||||
<div class="col-12">
|
||||
<h6>@GatewayLocalizer["Remark"]</h6>
|
||||
</div>
|
||||
</EditTemplate>
|
||||
</EditorItem>
|
||||
<EditorItem @bind-Field="@context.Remark1" />
|
||||
<EditorItem @bind-Field="@context.Remark2" />
|
||||
<EditorItem @bind-Field="@context.Remark3" />
|
||||
<EditorItem @bind-Field="@context.Remark4" />
|
||||
<EditorItem @bind-Field="@context.Remark5" />
|
||||
|
||||
</FieldItems>
|
||||
</FieldItems>
|
||||
|
||||
</EditorForm>
|
||||
</TabItem>
|
||||
</EditorForm>
|
||||
</TabItem>
|
||||
|
||||
<TabItem Text=@GatewayLocalizer["AlarmInformation"]>
|
||||
<EditorForm class="p-2" AutoGenerateAllItem="false" RowType=RowType.Inline ItemsPerRow=2 LabelWidth=250 Model="Model">
|
||||
<FieldItems>
|
||||
<TabItem Text=@GatewayLocalizer["AlarmInformation"]>
|
||||
<EditorForm class="p-2" AutoGenerateAllItem="false" RowType=RowType.Inline ItemsPerRow=2 LabelWidth=250 Model="Model">
|
||||
<FieldItems>
|
||||
|
||||
<EditorItem @bind-Field="@context.BoolCloseAlarmText" />
|
||||
<EditorItem @bind-Field="@context.BoolCloseRestrainExpressions" />
|
||||
<EditorItem @bind-Field="@context.BoolCloseAlarmEnable" Rows="1" />
|
||||
<EditorItem @bind-Field="@context.BoolOpenAlarmText" />
|
||||
<EditorItem @bind-Field="@context.BoolOpenRestrainExpressions" />
|
||||
<EditorItem @bind-Field="@context.BoolOpenAlarmEnable" Rows="1" />
|
||||
<EditorItem @bind-Field="@context.HHAlarmText" />
|
||||
<EditorItem @bind-Field="@context.HHAlarmCode" />
|
||||
<EditorItem @bind-Field="@context.HHRestrainExpressions" />
|
||||
<EditorItem @bind-Field="@context.HHAlarmEnable" />
|
||||
<EditorItem @bind-Field="@context.HAlarmText" />
|
||||
<EditorItem @bind-Field="@context.HAlarmCode" />
|
||||
<EditorItem @bind-Field="@context.HRestrainExpressions" />
|
||||
<EditorItem @bind-Field="@context.HAlarmEnable" />
|
||||
<EditorItem @bind-Field="@context.LAlarmText" />
|
||||
<EditorItem @bind-Field="@context.LAlarmCode" />
|
||||
<EditorItem @bind-Field="@context.LRestrainExpressions" />
|
||||
<EditorItem @bind-Field="@context.LAlarmEnable" />
|
||||
<EditorItem @bind-Field="@context.LLAlarmText" />
|
||||
<EditorItem @bind-Field="@context.LLAlarmCode" />
|
||||
<EditorItem @bind-Field="@context.LLRestrainExpressions" />
|
||||
<EditorItem @bind-Field="@context.LLAlarmEnable" />
|
||||
<EditorItem @bind-Field="@context.CustomAlarmText" />
|
||||
<EditorItem @bind-Field="@context.CustomAlarmCode" />
|
||||
<EditorItem @bind-Field="@context.CustomRestrainExpressions" />
|
||||
<EditorItem @bind-Field="@context.CustomAlarmEnable" />
|
||||
<EditorItem @bind-Field="@context.AlarmDelay" />
|
||||
</FieldItems>
|
||||
</EditorForm>
|
||||
</TabItem>
|
||||
@if(!BatchEditEnable)
|
||||
{
|
||||
<EditorItem @bind-Field="@context.BoolCloseAlarmText" />
|
||||
<EditorItem @bind-Field="@context.BoolCloseRestrainExpressions" />
|
||||
<EditorItem @bind-Field="@context.BoolCloseAlarmEnable" Rows="1" />
|
||||
<EditorItem @bind-Field="@context.BoolOpenAlarmText" />
|
||||
<EditorItem @bind-Field="@context.BoolOpenRestrainExpressions" />
|
||||
<EditorItem @bind-Field="@context.BoolOpenAlarmEnable" Rows="1" />
|
||||
<EditorItem @bind-Field="@context.HHAlarmText" />
|
||||
<EditorItem @bind-Field="@context.HHAlarmCode" />
|
||||
<EditorItem @bind-Field="@context.HHRestrainExpressions" />
|
||||
<EditorItem @bind-Field="@context.HHAlarmEnable" />
|
||||
<EditorItem @bind-Field="@context.HAlarmText" />
|
||||
<EditorItem @bind-Field="@context.HAlarmCode" />
|
||||
<EditorItem @bind-Field="@context.HRestrainExpressions" />
|
||||
<EditorItem @bind-Field="@context.HAlarmEnable" />
|
||||
<EditorItem @bind-Field="@context.LAlarmText" />
|
||||
<EditorItem @bind-Field="@context.LAlarmCode" />
|
||||
<EditorItem @bind-Field="@context.LRestrainExpressions" />
|
||||
<EditorItem @bind-Field="@context.LAlarmEnable" />
|
||||
<EditorItem @bind-Field="@context.LLAlarmText" />
|
||||
<EditorItem @bind-Field="@context.LLAlarmCode" />
|
||||
<EditorItem @bind-Field="@context.LLRestrainExpressions" />
|
||||
<EditorItem @bind-Field="@context.LLAlarmEnable" />
|
||||
<EditorItem @bind-Field="@context.CustomAlarmText" />
|
||||
<EditorItem @bind-Field="@context.CustomAlarmCode" />
|
||||
<EditorItem @bind-Field="@context.CustomRestrainExpressions" />
|
||||
<EditorItem @bind-Field="@context.CustomAlarmEnable" />
|
||||
<EditorItem @bind-Field="@context.AlarmDelay" />
|
||||
</FieldItems>
|
||||
</EditorForm>
|
||||
</TabItem>
|
||||
@if (!BatchEditEnable)
|
||||
{
|
||||
<TabItem Text=@GatewayLocalizer["PluginInformation"]>
|
||||
<div class="min-height-500 px-4">
|
||||
<div class="row g-2 mx-1 form-inline">
|
||||
|
||||
<div class="col-12 col-md-8">
|
||||
<Select SkipValidate IsVirtualize DefaultVirtualizeItemText=@(GlobalData.ReadOnlyIdDevices.TryGetValue(ChoiceBusinessDeviceId,out var deviceRuntime)?deviceRuntime.Name:string.Empty) @bind-Value="@ChoiceBusinessDeviceId" Items="@BusinessDeviceItems" ShowSearch="true" ShowLabel="true" />
|
||||
<Select SkipValidate IsVirtualize DefaultVirtualizeItemText=@(GlobalData.ReadOnlyIdDevices.TryGetValue(ChoiceBusinessDeviceId, out var deviceRuntime) ? deviceRuntime.Name : string.Empty) @bind-Value="@ChoiceBusinessDeviceId" Items="@BusinessDeviceItems" ShowSearch="true" ShowLabel="true" />
|
||||
</div>
|
||||
<div class="col-12 col-md-4">
|
||||
<Button OnClick="async() =>{
|
||||
|
||||
await RefreshBusinessPropertyClickAsync(ChoiceBusinessDeviceId);
|
||||
foreach (var item in Model.VariablePropertyModels)
|
||||
{
|
||||
if(item.Value!=null)
|
||||
{
|
||||
item.Value.ValidateForm=null;
|
||||
}
|
||||
}
|
||||
}">
|
||||
@GatewayLocalizer["RefreshBusinessProperty"]
|
||||
</Button>
|
||||
</div>
|
||||
await RefreshBusinessPropertyClickAsync(ChoiceBusinessDeviceId);
|
||||
foreach (var item in Model.VariablePropertyModels)
|
||||
{
|
||||
if (item.Value != null)
|
||||
{
|
||||
item.Value.ValidateForm = null;
|
||||
}
|
||||
}
|
||||
}">
|
||||
@GatewayLocalizer["RefreshBusinessProperty"]
|
||||
</Button>
|
||||
</div>
|
||||
@if (Model.VariablePropertyModels != null)
|
||||
</div>
|
||||
@if (Model.VariablePropertyModels != null)
|
||||
{
|
||||
@foreach (var a in Model.VariablePropertyModels)
|
||||
{
|
||||
{
|
||||
|
||||
var item = a;
|
||||
var item = a;
|
||||
|
||||
var custom = VariablePropertyRenderFragments.TryGetValue(item.Key, out var renderFragment);
|
||||
var custom = VariablePropertyRenderFragments.TryGetValue(item.Key, out var renderFragment);
|
||||
|
||||
if (!custom)
|
||||
{
|
||||
var has = VariablePropertyEditors.TryGetValue(item.Key, out var items);
|
||||
if (has)
|
||||
{
|
||||
if (!custom)
|
||||
{
|
||||
var has = VariablePropertyEditors.TryGetValue(item.Key, out var items);
|
||||
if (has)
|
||||
{
|
||||
|
||||
|
||||
<Card IsShadow=true class="m-2 flex-fill" Color="Color.Primary">
|
||||
<HeaderTemplate>
|
||||
@{
|
||||
GlobalData.ReadOnlyIdDevices.TryGetValue(item.Key, out var items);
|
||||
<Card IsShadow=true class="m-2 flex-fill" Color="Color.Primary">
|
||||
<HeaderTemplate>
|
||||
@{
|
||||
GlobalData.ReadOnlyIdDevices.TryGetValue(item.Key, out var items);
|
||||
}
|
||||
<div class="flex-fill">
|
||||
@($"{items.Name} - {PluginServiceUtil.GetFileNameAndTypeName(items?.PluginName).TypeName}")
|
||||
</div>
|
||||
|
||||
<Button OnClick=@((a)=>
|
||||
{
|
||||
Model.VariablePropertyModels.TryRemove(item.Key, out _);
|
||||
}) class="mx-2" Color="Color.None" style="color: var(--bs-card-titlecolor);" Icon=@("fas fa-delete-left") />
|
||||
|
||||
</HeaderTemplate>
|
||||
|
||||
<BodyTemplate>
|
||||
|
||||
<ValidateForm Model="item.Value.Value" @ref=item.Value.ValidateForm
|
||||
@key=@($"VariableEditValidateForm{item.Key}{Model.Id}{item.Value.Value.GetType().TypeHandle.Value}")
|
||||
Id=@($"VariableEditValidateForm{item.Key}{Model.Id}{item.Value.Value.GetType().TypeHandle.Value}")>
|
||||
|
||||
<EditorFormObject class="p-2" Items=items AutoGenerateAllItem="false" RowType=RowType.Inline ItemsPerRow=2 ShowLabelTooltip=true LabelWidth=150 Model="item.Value.Value" @key=@($"VariableEditEditorFormObject{item.Key}{Model.Id}{item.Value.Value.GetType().TypeHandle.Value}")>
|
||||
|
||||
</EditorFormObject>
|
||||
</ValidateForm>
|
||||
</BodyTemplate>
|
||||
</Card>
|
||||
}
|
||||
<div class="flex-fill">
|
||||
@($"{items.Name} - {PluginServiceUtil.GetFileNameAndTypeName(items?.PluginName).TypeName}")
|
||||
</div>
|
||||
|
||||
<Button OnClick=@((a)=>
|
||||
{
|
||||
Model.VariablePropertyModels.TryRemove(item.Key,out _);
|
||||
}) class="mx-2" Color="Color.None" style="color: var(--bs-card-titlecolor);" Icon=@("fas fa-delete-left") />
|
||||
|
||||
</HeaderTemplate>
|
||||
|
||||
<BodyTemplate>
|
||||
|
||||
<ValidateForm Model="item.Value.Value" @ref=item.Value.ValidateForm
|
||||
@key=@($"VariableEditValidateForm{item.Key}{Model.Id}{item.Value.Value.GetType().TypeHandle.Value}")
|
||||
Id=@($"VariableEditValidateForm{item.Key}{Model.Id}{item.Value.Value.GetType().TypeHandle.Value}")>
|
||||
|
||||
<EditorFormObject class="p-2" Items=items AutoGenerateAllItem="false" RowType=RowType.Inline ItemsPerRow=2 ShowLabelTooltip=true LabelWidth=150 Model="item.Value.Value" @key=@($"VariableEditEditorFormObject{item.Key}{Model.Id}{item.Value.Value.GetType().TypeHandle.Value}")>
|
||||
|
||||
</EditorFormObject>
|
||||
</ValidateForm>
|
||||
</BodyTemplate>
|
||||
</Card>
|
||||
}
|
||||
else
|
||||
{
|
||||
@renderFragment
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@renderFragment
|
||||
}
|
||||
}
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</TabItem>
|
||||
</TabItem>
|
||||
}
|
||||
</Tab>;
|
||||
</Tab>;
|
||||
}
|
||||
@@ -163,7 +163,37 @@ public partial class VariableEditComponent
|
||||
op.Component = AddressDynamicComponent;
|
||||
await DialogService.Show(op);
|
||||
}
|
||||
|
||||
[Inject]
|
||||
IStringLocalizer<Variable> VariableLocalizer { get; set; }
|
||||
private async Task ShowExpressionsUI(bool read)
|
||||
{
|
||||
var op = new DialogOption()
|
||||
{
|
||||
IsScrolling = false,
|
||||
ShowMaximizeButton = true,
|
||||
Size = Size.Large,
|
||||
Title = $"{Model.Name} {(read ? VariableLocalizer[nameof(Variable.ReadExpressions)] : VariableLocalizer[nameof(Variable.WriteExpressions)])}",
|
||||
ShowFooter = false,
|
||||
ShowCloseButton = false,
|
||||
BodyTemplate = BootstrapDynamicComponent.CreateComponent<ValueTransformConfigPage>(new Dictionary<string, object?>
|
||||
{
|
||||
{nameof(ValueTransformConfigPage.ExpressionsChanged), EventCallback.Factory.Create<string>(this,a =>
|
||||
{
|
||||
if(read)
|
||||
{
|
||||
Model.ReadExpressions = a;
|
||||
}
|
||||
else
|
||||
{
|
||||
Model.WriteExpressions=a;
|
||||
}
|
||||
})
|
||||
},
|
||||
{nameof(ValueTransformConfigPage.Expressions),read?Model.ReadExpressions:Model.WriteExpressions },
|
||||
}).Render(),
|
||||
};
|
||||
await DialogService.Show(op);
|
||||
}
|
||||
|
||||
[Inject]
|
||||
private IStringLocalizer<Device> DeviceLocalizer { get; set; }
|
||||
|
||||
@@ -35,6 +35,8 @@
|
||||
<TableColumn @bind-Field="@context.Name" ShowTips=true Filterable=true Sortable=true Visible=true />
|
||||
<TableColumn @bind-Field="@context.Description" ShowTips=true Filterable=true Sortable=true Visible=true />
|
||||
<TableColumn @bind-Field="@context.BusinessGroup" ShowTips=true Filterable=true Sortable=true Visible=true />
|
||||
<TableColumn @bind-Field="@context.BusinessGroupUpdateTrigger" ShowTips=true Filterable=true Sortable=true Visible=false />
|
||||
<TableColumn @bind-Field="@context.RpcWriteCheck" ShowTips=true Filterable=true Sortable=true Visible=false />
|
||||
|
||||
<TableColumn @bind-Field="@context.Enable" Filterable=true Sortable=true Visible="false" />
|
||||
<TableColumn Field="@context.ChangeTime" ShowTips=true FieldExpression=@(()=>context.ChangeTime) Filterable=true Sortable=true Visible=false />
|
||||
|
||||
@@ -44,9 +44,17 @@ namespace ThingsGateway.Gateway.Razor
|
||||
if(Node is IConditionNode conditionNode)
|
||||
return (await conditionNode.ExecuteAsync(new NodeInput(){Value=a==null?a:JToken.Parse(a??string.Empty) },default).ConfigureAwait(false)).ToString();
|
||||
if(Node is IExpressionNode expressionNode)
|
||||
return (await expressionNode.ExecuteAsync(new NodeInput(){Value=a==null?a:JToken.Parse(a??string.Empty) },default).ConfigureAwait(false)).JToken?.ToString();
|
||||
{
|
||||
var data=await expressionNode.ExecuteAsync(new NodeInput(){Value=a==null?a:JToken.Parse(a??string.Empty) },default).ConfigureAwait(false);
|
||||
|
||||
return data.IsSuccess? data.Content.JToken?.ToString()??string.Empty: data.ToString();
|
||||
}
|
||||
if(Node is IActuatorNode actuatorNode)
|
||||
return (await actuatorNode.ExecuteAsync(new NodeInput(){Value=a==null?a:JToken.Parse(a??string.Empty) },default).ConfigureAwait(false)).JToken?.ToString();
|
||||
{
|
||||
var data=await actuatorNode.ExecuteAsync(new NodeInput(){Value=a==null?a:JToken.Parse(a??string.Empty) },default).ConfigureAwait(false);
|
||||
|
||||
return data.IsSuccess? data.Content.JToken?.ToString()??string.Empty: data.ToString();
|
||||
}
|
||||
return string.Empty;
|
||||
}) },
|
||||
{nameof(ScriptEdit.Script),Node.Text },
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Razor">
|
||||
<Import Project="$(SolutionDir)Version.props" />
|
||||
<Import Project="$(SolutionDir)PackNuget.props" />
|
||||
<Import Project="..\..\Version.props" />
|
||||
<Import Project="..\..\PackNuget.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net8.0;</TargetFrameworks>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<PropertyGroup>
|
||||
|
||||
<GenerateDocumentationFile>True</GenerateDocumentationFile>
|
||||
<PackageOutputPath>$(SolutionDir)..\..\nupkgs</PackageOutputPath>
|
||||
<PackageOutputPath>$(MSBuildThisFileDirectory)..\..\nupkgs</PackageOutputPath>
|
||||
<PackageVersion>$(Version)</PackageVersion>
|
||||
<PackageTags>ThingsGateway;Diego;Blazor;IOT;设备采集;边缘网关;物联网</PackageTags>
|
||||
<PackageProjectUrl>https://gitee.com/diego2098/ThingsGateway</PackageProjectUrl>
|
||||
@@ -19,13 +19,13 @@
|
||||
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="$(SolutionDir)PackNuget.props" Pack="true" PackagePath="\" />
|
||||
<None Include="$(MSBuildThisFileDirectory)PackNuget.props" Pack="true" PackagePath="\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="$(SolutionDir)..\README.md" Pack="true" PackagePath="\" />
|
||||
<None Include="$(SolutionDir)..\README.zh-CN.md" Pack="true" PackagePath="\" />
|
||||
<None Include="$(SolutionDir)..\LICENSE" Pack="true" PackagePath="\" />
|
||||
<None Include="$(SolutionDir)..\icon.png" Pack="true" PackagePath="\" />
|
||||
<None Include="$(MSBuildThisFileDirectory)..\README.md" Pack="true" PackagePath="\" />
|
||||
<None Include="$(MSBuildThisFileDirectory)..\README.zh-CN.md" Pack="true" PackagePath="\" />
|
||||
<None Include="$(MSBuildThisFileDirectory)..\LICENSE" Pack="true" PackagePath="\" />
|
||||
<None Include="$(MSBuildThisFileDirectory)..\icon.png" Pack="true" PackagePath="\" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
@@ -6,10 +6,6 @@
|
||||
"Url": "/",
|
||||
"Text": "首页"
|
||||
},
|
||||
{
|
||||
"Url": "/des",
|
||||
"Text": "DES"
|
||||
},
|
||||
{
|
||||
"Text": "Modbus",
|
||||
"Items": [
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Razor">
|
||||
<Import Project="$(SolutionDir)Version.props" />
|
||||
<Import Project="..\..\Version.props" />
|
||||
|
||||
|
||||
<PropertyGroup>
|
||||
|
||||
@@ -12,4 +12,4 @@ global using Microsoft.AspNetCore.Components;
|
||||
|
||||
global using ThingsGateway.Razor;
|
||||
|
||||
[assembly: BlazorSetParametersAsyncGenerator.GlobalGenerateSetParametersAsync(true)]
|
||||
[assembly: GlobalGenerateSetParametersAsync(true)]
|
||||
@@ -1,6 +1,6 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Razor">
|
||||
<Import Project="$(SolutionDir)Version.props" />
|
||||
<Import Project="$(SolutionDir)PackNuget.props" />
|
||||
<Import Project="..\..\Version.props" />
|
||||
<Import Project="..\..\PackNuget.props" />
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net8.0;</TargetFrameworks>
|
||||
<!--<UseRazorSourceGenerator>false</UseRazorSourceGenerator>-->
|
||||
|
||||
@@ -44,7 +44,7 @@ public class Dlt645_2007Master : DtuServiceDeviceBase
|
||||
/// <param name="dateTime">时间</param>
|
||||
/// <param name="cancellationToken">取消令箭</param>
|
||||
/// <returns></returns>
|
||||
public async ValueTask<OperResult> BroadcastTimeAsync(DateTime dateTime, CancellationToken cancellationToken = default)
|
||||
public ValueTask<OperResult> BroadcastTimeAsync(DateTime dateTime, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -53,40 +53,30 @@ public class Dlt645_2007Master : DtuServiceDeviceBase
|
||||
dAddress.Station = str.HexStringToBytes();
|
||||
dAddress.DataId = "999999999999".HexStringToBytes();
|
||||
|
||||
return await Dlt645SendAsync(dAddress, ControlCode.BroadcastTime, FEHead, cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
return Dlt645SendAsync(dAddress, ControlCode.BroadcastTime, FEHead, cancellationToken: cancellationToken);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new OperResult(ex);
|
||||
return EasyValueTask.FromResult(new OperResult(ex));
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public async ValueTask<OperResult<byte[]>> Dlt645RequestAsync(Dlt645_2007Address dAddress, ControlCode controlCode, string feHead, byte[] codes = default, string[] datas = default, CancellationToken cancellationToken = default)
|
||||
public ValueTask<OperResult<byte[]>> Dlt645RequestAsync(Dlt645_2007Address dAddress, ControlCode controlCode, string feHead, byte[] codes = default, string[] datas = default, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
return await SendThenReturnAsync(GetSendMessage(dAddress, controlCode, feHead, codes, datas), cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new OperResult<byte[]>(ex);
|
||||
}
|
||||
|
||||
return SendThenReturnAsync(GetSendMessage(dAddress, controlCode, feHead, codes, datas), cancellationToken);
|
||||
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public async ValueTask<OperResult> Dlt645SendAsync(Dlt645_2007Address dAddress, ControlCode controlCode, string feHead, byte[] codes = default, string[] datas = default, CancellationToken cancellationToken = default)
|
||||
public ValueTask<OperResult> Dlt645SendAsync(Dlt645_2007Address dAddress, ControlCode controlCode, string feHead, byte[] codes = default, string[] datas = default, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
return await SendAsync(GetSendMessage(dAddress, controlCode, feHead, codes, datas), cancellationToken).ConfigureAwait(false);
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new OperResult<byte[]>(ex);
|
||||
}
|
||||
return SendAsync(GetSendMessage(dAddress, controlCode, feHead, codes, datas), cancellationToken);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -147,7 +137,7 @@ public class Dlt645_2007Master : DtuServiceDeviceBase
|
||||
/// <inheritdoc/>
|
||||
public override List<T> LoadSourceRead<T>(IEnumerable<IVariable> deviceVariables, int maxPack, string defaultIntervalTime)
|
||||
{
|
||||
return PackHelper.LoadSourceRead<T>(this, deviceVariables, maxPack, defaultIntervalTime);
|
||||
return PackHelper.LoadSourceRead<T>(this, deviceVariables, maxPack, Station, defaultIntervalTime);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
@@ -163,7 +153,19 @@ public class Dlt645_2007Master : DtuServiceDeviceBase
|
||||
return EasyValueTask.FromResult(new OperResult<byte[]>(ex));
|
||||
}
|
||||
}
|
||||
public override ValueTask<OperResult<byte[]>> ReadAsync(object state, CancellationToken cancellationToken = default)
|
||||
{
|
||||
|
||||
if (state is Dlt645_2007Address dlt645_2007Address)
|
||||
{
|
||||
return Dlt645RequestAsync(dlt645_2007Address, ControlCode.Read, FEHead, cancellationToken: cancellationToken);
|
||||
}
|
||||
else
|
||||
{
|
||||
return EasyValueTask.FromResult(new OperResult<byte[]>(new ArgumentException("State must be of type Dlt645_2007Address", nameof(state))));
|
||||
}
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// 读取通信地址
|
||||
/// </summary>
|
||||
@@ -231,16 +233,16 @@ public class Dlt645_2007Master : DtuServiceDeviceBase
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override async ValueTask<OperResult> WriteAsync(string address, string value, IThingsGatewayBitConverter bitConverter = null, CancellationToken cancellationToken = default)
|
||||
public override ValueTask<OperResult> WriteAsync(string address, string value, IThingsGatewayBitConverter bitConverter = null, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
string[] strArray = value.SplitStringBySemicolon();
|
||||
return await WriteAsync(address, value, bitConverter, cancellationToken).ConfigureAwait(false);
|
||||
return WriteAsync(address, value, bitConverter, cancellationToken);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new OperResult<byte[]>(ex);
|
||||
return EasyValueTask.FromResult(new OperResult(ex));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,9 +18,10 @@ internal static class PackHelper
|
||||
/// <param name="device"></param>
|
||||
/// <param name="deviceVariables"></param>
|
||||
/// <param name="maxPack">最大打包长度</param>
|
||||
/// <param name="station">station</param>
|
||||
/// <param name="defaultIntervalTime">默认间隔时间</param>
|
||||
/// <returns></returns>
|
||||
public static List<T> LoadSourceRead<T>(IDevice device, IEnumerable<IVariable> deviceVariables, int maxPack, string defaultIntervalTime) where T : IVariableSource, new()
|
||||
public static List<T> LoadSourceRead<T>(IDevice device, IEnumerable<IVariable> deviceVariables, int maxPack, string station, string defaultIntervalTime) where T : IVariableSource, new()
|
||||
{
|
||||
var byteConverter = device.ThingsGatewayBitConverter;
|
||||
var result = new List<T>();
|
||||
@@ -42,6 +43,7 @@ internal static class PackHelper
|
||||
var r = new T()
|
||||
{
|
||||
RegisterAddress = item.Key!,
|
||||
AddressObject = Dlt645_2007Address.ParseFrom(item.Key, station),
|
||||
Length = 1,
|
||||
IntervalTime = string.IsNullOrWhiteSpace(item.FirstOrDefault().IntervalTime) ? defaultIntervalTime : item.FirstOrDefault().IntervalTime,
|
||||
};
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<Import Project="$(SolutionDir)Foundation.props" />
|
||||
<Import Project="$(SolutionDir)PackNuget.props" />
|
||||
<Import Project="$(SolutionDir)Version.props" />
|
||||
<Import Project="..\..\Foundation.props" />
|
||||
<Import Project="..\..\PackNuget.props" />
|
||||
<Import Project="..\..\Version.props" />
|
||||
<PropertyGroup>
|
||||
<Description>工业设备通讯协议-Dlt645协议</Description>
|
||||
<GenerateDocumentationFile>True</GenerateDocumentationFile>
|
||||
|
||||
@@ -167,6 +167,7 @@ public static class PackHelper
|
||||
IntervalTime = intervalTime,
|
||||
// 将当前组打包地址中的起始地址作为实际打包报文中的起始地址
|
||||
RegisterAddress = startAddress.ToString(),
|
||||
AddressObject = new ModbusAddress(startAddress) { Length = (ushort)sourceLen },
|
||||
Length = sourceLen.ToInt()
|
||||
};
|
||||
|
||||
|
||||
@@ -98,31 +98,64 @@ public partial class ModbusMaster : DtuServiceDeviceBase, IModbusAddress
|
||||
return PackHelper.LoadSourceRead<T>(this, deviceVariables, maxPack, defaultIntervalTime, Station);
|
||||
}
|
||||
|
||||
public async ValueTask<OperResult<byte[]>> ModbusRequestAsync(ModbusAddress mAddress, bool read, CancellationToken cancellationToken = default)
|
||||
public override ValueTask<OperResult<byte[]>> ReadAsync(object state, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
return await SendThenReturnAsync(GetSendMessage(mAddress, read),
|
||||
cancellationToken).ConfigureAwait(false);
|
||||
if (state is ModbusAddress mAddress)
|
||||
{
|
||||
return ModbusReadAsync(mAddress, cancellationToken);
|
||||
}
|
||||
else
|
||||
{
|
||||
return EasyValueTask.FromResult(new OperResult<byte[]>(new ArgumentException("State must be of type ModbusAddress", nameof(state))));
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new OperResult<byte[]>(ex);
|
||||
return EasyValueTask.FromResult(new OperResult<byte[]>(ex));
|
||||
}
|
||||
}
|
||||
|
||||
public ValueTask<OperResult<byte[]>> ModbusReadAsync(ModbusAddress mAddress, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
return SendThenReturnAsync(GetSendMessage(mAddress, true),
|
||||
cancellationToken);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return EasyValueTask.FromResult(new OperResult<byte[]>(ex));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public ValueTask<OperResult<byte[]>> ModbusRequestAsync(ModbusAddress mAddress, bool read, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
return SendThenReturnAsync(GetSendMessage(mAddress, read),
|
||||
cancellationToken);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return EasyValueTask.FromResult(new OperResult<byte[]>(ex));
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override async ValueTask<OperResult<byte[]>> ReadAsync(string address, int length, CancellationToken cancellationToken = default)
|
||||
public override ValueTask<OperResult<byte[]>> ReadAsync(string address, int length, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
var mAddress = GetModbusAddress(address, Station);
|
||||
mAddress.Length = (ushort)length;
|
||||
return await ModbusRequestAsync(mAddress, true, cancellationToken).ConfigureAwait(false);
|
||||
return ModbusRequestAsync(mAddress, true, cancellationToken);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new OperResult<byte[]>(ex);
|
||||
return EasyValueTask.FromResult(new OperResult<byte[]>(ex));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -310,6 +310,34 @@ public class ModbusSlave : DeviceBase, IModbusAddress
|
||||
return EasyValueTask.FromResult(new OperResult<byte[]>(result));
|
||||
}
|
||||
}
|
||||
|
||||
public override ValueTask<OperResult<byte[]>> ReadAsync(object state, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (state is ModbusAddress mAddress)
|
||||
{
|
||||
var result = ModbusRequest(mAddress, true, cancellationToken);
|
||||
if (result.IsSuccess)
|
||||
{
|
||||
return EasyValueTask.FromResult(new OperResult<byte[]>() { Content = result.Content.ToArray() });
|
||||
}
|
||||
else
|
||||
{
|
||||
return EasyValueTask.FromResult(new OperResult<byte[]>(result));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return EasyValueTask.FromResult(new OperResult<byte[]>(new ArgumentException("State must be of type ModbusAddress", nameof(state))));
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return EasyValueTask.FromResult(new OperResult<byte[]>(ex));
|
||||
}
|
||||
}
|
||||
|
||||
public virtual ModbusAddress GetModbusAddress(string address, byte? station, bool isCache = true)
|
||||
{
|
||||
var mAddress = ModbusAddress.ParseFrom(address, station, isCache);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<Import Project="$(SolutionDir)Foundation.props" />
|
||||
<Import Project="$(SolutionDir)PackNuget.props" />
|
||||
<Import Project="$(SolutionDir)Version.props" />
|
||||
<Import Project="..\..\Foundation.props" />
|
||||
<Import Project="..\..\PackNuget.props" />
|
||||
<Import Project="..\..\Version.props" />
|
||||
<PropertyGroup>
|
||||
<Description>工业设备通讯协议-Modbus协议</Description>
|
||||
<GenerateDocumentationFile>True</GenerateDocumentationFile>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<Import Project="$(SolutionDir)PackNuget.props" />
|
||||
<Import Project="$(SolutionDir)Version.props" />
|
||||
<Import Project="..\..\PackNuget.props" />
|
||||
<Import Project="..\..\Version.props" />
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net462;netstandard2.0;net6.0;</TargetFrameworks>
|
||||
<Description>工业设备通讯协议-OpcDa协议</Description>
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
|
||||
<Import Project="$(SolutionDir)PackNuget.props" />
|
||||
<Import Project="$(SolutionDir)Version.props" />
|
||||
<Import Project="..\..\PackNuget.props" />
|
||||
<Import Project="..\..\Version.props" />
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net48;netstandard2.1;net6.0;</TargetFrameworks>
|
||||
<Description>工业设备通讯协议-OpcUa协议</Description>
|
||||
|
||||
@@ -230,6 +230,7 @@ internal static class PackHelper
|
||||
{
|
||||
IntervalTime = intervalTime, // 设置时间戳
|
||||
RegisterAddress = tempAddresses.OrderBy(it => it.AddressStart).First().ToString(), // 获取地址并按地址排序
|
||||
AddressObject = new SiemensS7Address(tempAddresses.OrderBy(it => it.AddressStart).First()) { Length = sourceLen },
|
||||
Length = sourceLen // 设置源长度
|
||||
};
|
||||
|
||||
|
||||
@@ -139,27 +139,36 @@ public partial class SiemensS7Master : DeviceBase
|
||||
{
|
||||
int num = 0;
|
||||
var addressLen = sAddress.Length == 0 ? 1 : sAddress.Length;
|
||||
while (num < addressLen)
|
||||
var start = sAddress.AddressStart;
|
||||
try
|
||||
{
|
||||
//pdu长度,重复生成报文,直至全部生成
|
||||
int len = Math.Min(addressLen - num, PduLength);
|
||||
sAddress.Length = len;
|
||||
|
||||
var result = await SendThenReturnAsync(new S7Send([sAddress], true), cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
if (!result.IsSuccess) return result;
|
||||
|
||||
byteBlock.Write(result.Content);
|
||||
num += len;
|
||||
|
||||
if (sAddress.DataCode == S7Area.TM || sAddress.DataCode == S7Area.CT)
|
||||
while (num < addressLen)
|
||||
{
|
||||
sAddress.AddressStart += len / 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
sAddress.AddressStart += len * 8;
|
||||
//pdu长度,重复生成报文,直至全部生成
|
||||
int len = Math.Min(addressLen - num, PduLength);
|
||||
sAddress.Length = len;
|
||||
var result = await SendThenReturnAsync(new S7Send([sAddress], true), cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
if (!result.IsSuccess) return result;
|
||||
|
||||
byteBlock.Write(result.Content);
|
||||
num += len;
|
||||
|
||||
if (sAddress.DataCode == S7Area.TM || sAddress.DataCode == S7Area.CT)
|
||||
{
|
||||
sAddress.AddressStart += len / 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
sAddress.AddressStart += len * 8;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
sAddress.AddressStart = start;
|
||||
}
|
||||
}
|
||||
|
||||
return new OperResult<byte[]>() { Content = byteBlock.ToArray() };
|
||||
@@ -298,6 +307,26 @@ public partial class SiemensS7Master : DeviceBase
|
||||
}
|
||||
}
|
||||
|
||||
public override ValueTask<OperResult<byte[]>> ReadAsync(object state, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (state is SiemensS7Address sAddress)
|
||||
{
|
||||
return S7ReadAsync([sAddress], cancellationToken);
|
||||
}
|
||||
else
|
||||
{
|
||||
return EasyValueTask.FromResult(new OperResult<byte[]>(new ArgumentException("State must be of type SiemensS7Address", nameof(state))));
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return EasyValueTask.FromResult(new OperResult<byte[]>(ex));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override async ValueTask<OperResult> WriteAsync(string address, byte[] value, DataTypeEnum dataType, CancellationToken cancellationToken = default)
|
||||
{
|
||||
@@ -341,6 +370,7 @@ public partial class SiemensS7Master : DeviceBase
|
||||
{
|
||||
try
|
||||
{
|
||||
SetDataAdapter(channel);
|
||||
AutoConnect = false;
|
||||
var ISO_CR = SiemensHelper.ISO_CR;
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<Import Project="$(SolutionDir)Foundation.props" />
|
||||
<Import Project="$(SolutionDir)PackNuget.props" />
|
||||
<Import Project="$(SolutionDir)Version.props" />
|
||||
<Import Project="..\..\Foundation.props" />
|
||||
<Import Project="..\..\PackNuget.props" />
|
||||
<Import Project="..\..\Version.props" />
|
||||
<PropertyGroup>
|
||||
<Description>工业设备通讯协议-SiemensS7协议</Description>
|
||||
<GenerateDocumentationFile>True</GenerateDocumentationFile>
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace ThingsGateway.Plugin.QuestDB;
|
||||
/// <summary>
|
||||
/// QuestDBProducer
|
||||
/// </summary>
|
||||
public partial class QuestDBProducer : BusinessBaseWithCacheIntervalVariableModel<QuestDBHistoryValue>, IDBHistoryValueService
|
||||
public partial class QuestDBProducer : BusinessBaseWithCacheIntervalVariableModel<VariableBasicData>, IDBHistoryValueService
|
||||
{
|
||||
internal readonly RealDBProducerProperty _driverPropertys = new();
|
||||
private readonly QuestDBProducerVariableProperty _variablePropertys = new();
|
||||
|
||||
@@ -23,11 +23,11 @@ namespace ThingsGateway.Plugin.QuestDB;
|
||||
/// <summary>
|
||||
/// RabbitMQProducer
|
||||
/// </summary>
|
||||
public partial class QuestDBProducer : BusinessBaseWithCacheIntervalVariableModel<QuestDBHistoryValue>
|
||||
public partial class QuestDBProducer : BusinessBaseWithCacheIntervalVariableModel<VariableBasicData>
|
||||
{
|
||||
private TypeAdapterConfig _config;
|
||||
|
||||
protected override ValueTask<OperResult> UpdateVarModel(IEnumerable<CacheDBItem<QuestDBHistoryValue>> item, CancellationToken cancellationToken)
|
||||
protected override ValueTask<OperResult> UpdateVarModel(IEnumerable<CacheDBItem<VariableBasicData>> item, CancellationToken cancellationToken)
|
||||
{
|
||||
return UpdateVarModel(item.Select(a => a.Value).OrderBy(a => a.Id), cancellationToken);
|
||||
}
|
||||
@@ -41,7 +41,7 @@ public partial class QuestDBProducer : BusinessBaseWithCacheIntervalVariableMode
|
||||
UpdateVariable(variableRuntime, variable);
|
||||
base.VariableChange(variableRuntime, variable);
|
||||
}
|
||||
protected override ValueTask<OperResult> UpdateVarModels(IEnumerable<QuestDBHistoryValue> item, CancellationToken cancellationToken)
|
||||
protected override ValueTask<OperResult> UpdateVarModels(IEnumerable<VariableBasicData> item, CancellationToken cancellationToken)
|
||||
{
|
||||
return UpdateVarModel(item, cancellationToken);
|
||||
}
|
||||
@@ -56,18 +56,18 @@ public partial class QuestDBProducer : BusinessBaseWithCacheIntervalVariableMode
|
||||
|
||||
foreach (var group in varGroup)
|
||||
{
|
||||
AddQueueVarModel(new CacheDBItem<List<QuestDBHistoryValue>>(group.Adapt<List<QuestDBHistoryValue>>(_config)));
|
||||
AddQueueVarModel(new CacheDBItem<List<VariableBasicData>>(group.ToList()));
|
||||
}
|
||||
foreach (var variable in varList)
|
||||
{
|
||||
AddQueueVarModel(new CacheDBItem<QuestDBHistoryValue>(variable.Adapt<QuestDBHistoryValue>(_config)));
|
||||
AddQueueVarModel(new CacheDBItem<VariableBasicData>(variable));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var variable in variables)
|
||||
{
|
||||
AddQueueVarModel(new CacheDBItem<QuestDBHistoryValue>(variable.Adapt<QuestDBHistoryValue>(_config)));
|
||||
AddQueueVarModel(new CacheDBItem<VariableBasicData>(variable));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -75,18 +75,18 @@ public partial class QuestDBProducer : BusinessBaseWithCacheIntervalVariableMode
|
||||
|
||||
private void UpdateVariable(VariableRuntime variableRuntime, VariableBasicData variable)
|
||||
{
|
||||
if (_driverPropertys.GroupUpdate && !variable.BusinessGroup.IsNullOrEmpty() && VariableRuntimeGroups.TryGetValue(variable.BusinessGroup, out var variableRuntimeGroup))
|
||||
if (_driverPropertys.GroupUpdate && variable.BusinessGroupUpdateTrigger && !variable.BusinessGroup.IsNullOrEmpty() && VariableRuntimeGroups.TryGetValue(variable.BusinessGroup, out var variableRuntimeGroup))
|
||||
{
|
||||
|
||||
AddQueueVarModel(new CacheDBItem<List<QuestDBHistoryValue>>(variableRuntimeGroup.Adapt<List<QuestDBHistoryValue>>(_config)));
|
||||
AddQueueVarModel(new CacheDBItem<List<VariableBasicData>>(variableRuntimeGroup.Adapt<List<VariableBasicData>>(_config)));
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
AddQueueVarModel(new CacheDBItem<QuestDBHistoryValue>(variableRuntime.Adapt<QuestDBHistoryValue>(_config)));
|
||||
AddQueueVarModel(new CacheDBItem<VariableBasicData>(variable));
|
||||
}
|
||||
}
|
||||
private async ValueTask<OperResult> UpdateVarModel(IEnumerable<QuestDBHistoryValue> item, CancellationToken cancellationToken)
|
||||
private async ValueTask<OperResult> UpdateVarModel(IEnumerable<VariableBasicData> item, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await InserableAsync(item.WhereIf(_driverPropertys.OnlineFilter, a => a.IsOnline == true).ToList(), cancellationToken).ConfigureAwait(false);
|
||||
if (success != result.IsSuccess)
|
||||
@@ -101,7 +101,7 @@ public partial class QuestDBProducer : BusinessBaseWithCacheIntervalVariableMode
|
||||
|
||||
#region 方法
|
||||
|
||||
private async ValueTask<OperResult> InserableAsync(List<QuestDBHistoryValue> dbInserts, CancellationToken cancellationToken)
|
||||
private async ValueTask<OperResult> InserableAsync(List<VariableBasicData> dbInserts, CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -118,8 +118,8 @@ public partial class QuestDBProducer : BusinessBaseWithCacheIntervalVariableMode
|
||||
{
|
||||
Stopwatch stopwatch = new();
|
||||
stopwatch.Start();
|
||||
|
||||
var result = await _db.Insertable(dbInserts).AS(_driverPropertys.TableName).ExecuteCommandAsync(cancellationToken).ConfigureAwait(false);//不要加分表
|
||||
var data = dbInserts.Adapt<List<QuestDBHistoryValue>>();
|
||||
var result = await _db.Insertable(data).AS(_driverPropertys.TableName).ExecuteCommandAsync(cancellationToken).ConfigureAwait(false);//不要加分表
|
||||
stopwatch.Stop();
|
||||
|
||||
//var result = await db.Insertable(dbInserts).SplitTable().ExecuteCommandAsync().ConfigureAwait(false);
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace ThingsGateway.Plugin.SqlDB;
|
||||
/// <summary>
|
||||
/// SqlDBProducer
|
||||
/// </summary>
|
||||
public partial class SqlDBProducer : BusinessBaseWithCacheIntervalVariableModel<SQLHistoryValue>, IDBHistoryValueService
|
||||
public partial class SqlDBProducer : BusinessBaseWithCacheIntervalVariableModel<VariableBasicData>, IDBHistoryValueService
|
||||
{
|
||||
internal readonly SqlDBProducerProperty _driverPropertys = new();
|
||||
private readonly SqlDBProducerVariableProperty _variablePropertys = new();
|
||||
@@ -236,7 +236,7 @@ public partial class SqlDBProducer : BusinessBaseWithCacheIntervalVariableModel<
|
||||
var varList = RealTimeVariables.ToListWithDequeue();
|
||||
if (varList.Count > 0)
|
||||
{
|
||||
var result = await UpdateAsync(varList.Adapt<List<SQLRealValue>>(), cancellationToken).ConfigureAwait(false);
|
||||
var result = await UpdateAsync(varList, cancellationToken).ConfigureAwait(false);
|
||||
if (success != result.IsSuccess)
|
||||
{
|
||||
if (!result.IsSuccess)
|
||||
|
||||
@@ -24,13 +24,13 @@ namespace ThingsGateway.Plugin.SqlDB;
|
||||
/// <summary>
|
||||
/// SqlDBProducer
|
||||
/// </summary>
|
||||
public partial class SqlDBProducer : BusinessBaseWithCacheIntervalVariableModel<SQLHistoryValue>
|
||||
public partial class SqlDBProducer : BusinessBaseWithCacheIntervalVariableModel<VariableBasicData>
|
||||
{
|
||||
private TypeAdapterConfig _config;
|
||||
private volatile bool _initRealData;
|
||||
private ConcurrentDictionary<long, VariableBasicData> RealTimeVariables { get; } = new ConcurrentDictionary<long, VariableBasicData>();
|
||||
|
||||
protected override ValueTask<OperResult> UpdateVarModel(IEnumerable<CacheDBItem<SQLHistoryValue>> item, CancellationToken cancellationToken)
|
||||
protected override ValueTask<OperResult> UpdateVarModel(IEnumerable<CacheDBItem<VariableBasicData>> item, CancellationToken cancellationToken)
|
||||
{
|
||||
return UpdateVarModel(item.Select(a => a.Value).OrderBy(a => a.Id), cancellationToken);
|
||||
}
|
||||
@@ -48,7 +48,7 @@ public partial class SqlDBProducer : BusinessBaseWithCacheIntervalVariableModel<
|
||||
UpdateVariable(variableRuntime, variable);
|
||||
base.VariableChange(variableRuntime, variable);
|
||||
}
|
||||
protected override ValueTask<OperResult> UpdateVarModels(IEnumerable<SQLHistoryValue> item, CancellationToken cancellationToken)
|
||||
protected override ValueTask<OperResult> UpdateVarModels(IEnumerable<VariableBasicData> item, CancellationToken cancellationToken)
|
||||
{
|
||||
return UpdateVarModel(item, cancellationToken);
|
||||
}
|
||||
@@ -62,18 +62,18 @@ public partial class SqlDBProducer : BusinessBaseWithCacheIntervalVariableModel<
|
||||
|
||||
foreach (var group in varGroup)
|
||||
{
|
||||
AddQueueVarModel(new CacheDBItem<List<SQLHistoryValue>>(group.Adapt<List<SQLHistoryValue>>(_config)));
|
||||
AddQueueVarModel(new CacheDBItem<List<VariableBasicData>>(group.ToList()));
|
||||
}
|
||||
foreach (var variable in varList)
|
||||
{
|
||||
AddQueueVarModel(new CacheDBItem<SQLHistoryValue>(variable.Adapt<SQLHistoryValue>(_config)));
|
||||
AddQueueVarModel(new CacheDBItem<VariableBasicData>(variable));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var variable in variables)
|
||||
{
|
||||
AddQueueVarModel(new CacheDBItem<SQLHistoryValue>(variable.Adapt<SQLHistoryValue>(_config)));
|
||||
AddQueueVarModel(new CacheDBItem<VariableBasicData>(variable));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -82,15 +82,15 @@ public partial class SqlDBProducer : BusinessBaseWithCacheIntervalVariableModel<
|
||||
{
|
||||
if (_driverPropertys.IsHistoryDB)
|
||||
{
|
||||
if (_driverPropertys.GroupUpdate && !variable.BusinessGroup.IsNullOrEmpty() && VariableRuntimeGroups.TryGetValue(variable.BusinessGroup, out var variableRuntimeGroup))
|
||||
if (_driverPropertys.GroupUpdate && variable.BusinessGroupUpdateTrigger && !variable.BusinessGroup.IsNullOrEmpty() && VariableRuntimeGroups.TryGetValue(variable.BusinessGroup, out var variableRuntimeGroup))
|
||||
{
|
||||
|
||||
AddQueueVarModel(new CacheDBItem<List<SQLHistoryValue>>(variableRuntimeGroup.Adapt<List<SQLHistoryValue>>(_config)));
|
||||
AddQueueVarModel(new CacheDBItem<List<VariableBasicData>>(variableRuntimeGroup.Adapt<List<VariableBasicData>>(_config)));
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
AddQueueVarModel(new CacheDBItem<SQLHistoryValue>(variableRuntime.Adapt<SQLHistoryValue>(_config)));
|
||||
AddQueueVarModel(new CacheDBItem<VariableBasicData>(variable));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ public partial class SqlDBProducer : BusinessBaseWithCacheIntervalVariableModel<
|
||||
}
|
||||
|
||||
|
||||
private async ValueTask<OperResult> UpdateVarModel(IEnumerable<SQLHistoryValue> item, CancellationToken cancellationToken)
|
||||
private async ValueTask<OperResult> UpdateVarModel(IEnumerable<VariableBasicData> item, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await InserableAsync(item.WhereIf(_driverPropertys.OnlineFilter, a => a.IsOnline == true).ToList(), cancellationToken).ConfigureAwait(false);
|
||||
if (success != result.IsSuccess)
|
||||
@@ -116,7 +116,7 @@ public partial class SqlDBProducer : BusinessBaseWithCacheIntervalVariableModel<
|
||||
|
||||
#region 方法
|
||||
|
||||
private async ValueTask<OperResult> InserableAsync(List<SQLHistoryValue> dbInserts, CancellationToken cancellationToken)
|
||||
private async ValueTask<OperResult> InserableAsync(List<VariableBasicData> dbInserts, CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -134,8 +134,8 @@ public partial class SqlDBProducer : BusinessBaseWithCacheIntervalVariableModel<
|
||||
{
|
||||
Stopwatch stopwatch = new();
|
||||
stopwatch.Start();
|
||||
var result = await _db.Fastest<SQLHistoryValue>().PageSize(50000).SplitTable().BulkCopyAsync(dbInserts).ConfigureAwait(false);
|
||||
//var result = await db.Insertable(dbInserts).SplitTable().ExecuteCommandAsync().ConfigureAwait(false);
|
||||
var data = dbInserts.Adapt<List<SQLHistoryValue>>(_config);
|
||||
var result = await _db.Fastest<SQLHistoryValue>().PageSize(50000).SplitTable().BulkCopyAsync(data).ConfigureAwait(false);
|
||||
stopwatch.Stop();
|
||||
if (result > 0)
|
||||
{
|
||||
@@ -152,7 +152,7 @@ public partial class SqlDBProducer : BusinessBaseWithCacheIntervalVariableModel<
|
||||
}
|
||||
}
|
||||
|
||||
private async ValueTask<OperResult> UpdateAsync(List<SQLRealValue> datas, CancellationToken cancellationToken)
|
||||
private async ValueTask<OperResult> UpdateAsync(List<VariableBasicData> datas, CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -190,7 +190,8 @@ public partial class SqlDBProducer : BusinessBaseWithCacheIntervalVariableModel<
|
||||
Stopwatch stopwatch = new();
|
||||
stopwatch.Start();
|
||||
|
||||
var result = await _db.Fastest<SQLRealValue>().AS(_driverPropertys.ReadDBTableName).PageSize(100000).BulkUpdateAsync(datas).ConfigureAwait(false);
|
||||
var data = datas.Adapt<List<SQLRealValue>>(_config);
|
||||
var result = await _db.Fastest<SQLRealValue>().AS(_driverPropertys.ReadDBTableName).PageSize(100000).BulkUpdateAsync(data).ConfigureAwait(false);
|
||||
|
||||
stopwatch.Stop();
|
||||
if (result > 0)
|
||||
|
||||
@@ -43,7 +43,7 @@ public partial class SqlHistoryAlarm : BusinessBaseWithCacheVariableModel<Histor
|
||||
|
||||
protected override async Task InitChannelAsync(IChannel? channel, CancellationToken cancellationToken)
|
||||
{
|
||||
_db = BusinessDatabaseUtil.GetDb(_driverPropertys.DbType, _driverPropertys.BigTextConnectStr);
|
||||
_db = BusinessDatabaseUtil.GetDb((DbType)_driverPropertys.DbType, _driverPropertys.BigTextConnectStr);
|
||||
|
||||
_config.ForType<AlarmVariable, HistoryAlarm>().Map(dest => dest.Id, (src) => CommonUtils.GetSingleId());
|
||||
GlobalData.AlarmChangedEvent -= AlarmWorker_OnAlarmChanged;
|
||||
@@ -112,7 +112,7 @@ public partial class SqlHistoryAlarm : BusinessBaseWithCacheVariableModel<Histor
|
||||
|
||||
internal ISugarQueryable<HistoryAlarm> Query(DBHistoryAlarmPageInput input)
|
||||
{
|
||||
using var db = BusinessDatabaseUtil.GetDb(_driverPropertys.DbType, _driverPropertys.BigTextConnectStr);
|
||||
using var db = BusinessDatabaseUtil.GetDb((DbType)_driverPropertys.DbType, _driverPropertys.BigTextConnectStr);
|
||||
var query = db.Queryable<HistoryAlarm>().AS(_driverPropertys.TableName)
|
||||
.WhereIF(input.StartTime != null, a => a.EventTime >= input.StartTime)
|
||||
.WhereIF(input.EndTime != null, a => a.EventTime <= input.EndTime)
|
||||
@@ -132,7 +132,7 @@ public partial class SqlHistoryAlarm : BusinessBaseWithCacheVariableModel<Histor
|
||||
|
||||
internal async Task<QueryData<HistoryAlarm>> QueryData(QueryPageOptions option)
|
||||
{
|
||||
using var db = BusinessDatabaseUtil.GetDb(_driverPropertys.DbType, _driverPropertys.BigTextConnectStr);
|
||||
using var db = BusinessDatabaseUtil.GetDb((DbType)_driverPropertys.DbType, _driverPropertys.BigTextConnectStr);
|
||||
var ret = new QueryData<HistoryAlarm>()
|
||||
{
|
||||
IsSorted = option.SortOrder != SortOrder.Unset,
|
||||
|
||||
@@ -13,7 +13,7 @@ using Mapster;
|
||||
using System.Diagnostics;
|
||||
|
||||
using ThingsGateway.Foundation;
|
||||
using ThingsGateway.NewLife.Threading;
|
||||
using ThingsGateway.Plugin.DB;
|
||||
|
||||
using TouchSocket.Core;
|
||||
|
||||
@@ -56,38 +56,6 @@ public partial class SqlHistoryAlarm : BusinessBaseWithCacheVariableModel<Histor
|
||||
}
|
||||
}
|
||||
|
||||
private async ValueTask<OperResult> InserableAsync(List<HistoryAlarm> dbInserts, CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
int result = 0;
|
||||
//.SplitTable()
|
||||
Stopwatch stopwatch = new();
|
||||
stopwatch.Start();
|
||||
|
||||
if (_db.CurrentConnectionConfig.DbType == SqlSugar.DbType.QuestDB)
|
||||
result = await _db.Insertable(dbInserts).AS(_driverPropertys.TableName).ExecuteCommandAsync(cancellationToken).ConfigureAwait(false);//不要加分表
|
||||
else
|
||||
result = await _db.Fastest<HistoryAlarm>().AS(_driverPropertys.TableName).PageSize(50000).BulkCopyAsync(dbInserts).ConfigureAwait(false);
|
||||
|
||||
|
||||
stopwatch.Stop();
|
||||
//var result = await db.Insertable(dbInserts).SplitTable().ExecuteCommandAsync().ConfigureAwait(false);
|
||||
if (result > 0)
|
||||
{
|
||||
CurrentDevice.SetDeviceStatus(TimerX.Now, false);
|
||||
LogMessage?.Trace($"Count:{dbInserts.Count},watchTime: {stopwatch.ElapsedMilliseconds} ms");
|
||||
}
|
||||
return OperResult.Success;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
CurrentDevice.SetDeviceStatus(TimerX.Now, true);
|
||||
return new OperResult(ex);
|
||||
}
|
||||
}
|
||||
|
||||
private async ValueTask<OperResult> UpdateT(IEnumerable<HistoryAlarm> item, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await InserableAsync(item.ToList(), cancellationToken).ConfigureAwait(false);
|
||||
@@ -100,4 +68,51 @@ public partial class SqlHistoryAlarm : BusinessBaseWithCacheVariableModel<Histor
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private async ValueTask<OperResult> InserableAsync(List<HistoryAlarm> dbInserts, CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
_db.Ado.CancellationToken = cancellationToken;
|
||||
if (!_driverPropertys.BigTextScriptHistoryTable.IsNullOrEmpty())
|
||||
{
|
||||
var getDeviceModel = CSharpScriptEngineExtension.Do<DynamicSQLBase>(_driverPropertys.BigTextScriptHistoryTable);
|
||||
|
||||
getDeviceModel.Logger = LogMessage;
|
||||
|
||||
await getDeviceModel.DBInsertable(_db, dbInserts, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
int result = 0;
|
||||
//.SplitTable()
|
||||
Stopwatch stopwatch = new();
|
||||
stopwatch.Start();
|
||||
|
||||
if (_db.CurrentConnectionConfig.DbType == SqlSugar.DbType.QuestDB)
|
||||
result = await _db.Insertable(dbInserts).AS(_driverPropertys.TableName).ExecuteCommandAsync(cancellationToken).ConfigureAwait(false);
|
||||
else
|
||||
result = await _db.Fastest<HistoryAlarm>().AS(_driverPropertys.TableName).PageSize(50000).BulkCopyAsync(dbInserts).ConfigureAwait(false);
|
||||
|
||||
stopwatch.Stop();
|
||||
//var result = await db.Insertable(dbInserts).SplitTable().ExecuteCommandAsync().ConfigureAwait(false);
|
||||
if (result > 0)
|
||||
{
|
||||
LogMessage?.Trace($"Count:{dbInserts.Count},watchTime: {stopwatch.ElapsedMilliseconds} ms");
|
||||
}
|
||||
return OperResult.Success;
|
||||
}
|
||||
|
||||
|
||||
return OperResult.Success;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new OperResult(ex);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -12,7 +12,8 @@ using BootstrapBlazor.Components;
|
||||
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
using ThingsGateway.SqlSugar;
|
||||
using ThingsGateway.Plugin.SqlDB;
|
||||
|
||||
|
||||
namespace ThingsGateway.Plugin.SqlHistoryAlarm;
|
||||
|
||||
@@ -23,15 +24,21 @@ public class SqlHistoryAlarmProperty : BusinessPropertyWithCache
|
||||
{
|
||||
[DynamicProperty]
|
||||
public DbType DbType { get; set; } = DbType.SqlServer;
|
||||
|
||||
[DynamicProperty]
|
||||
[Required]
|
||||
public string TableName { get; set; } = "historyAlarm";
|
||||
[DynamicProperty]
|
||||
[Required]
|
||||
[AutoGenerateColumn(ComponentType = typeof(Textarea), Rows = 1)]
|
||||
public string BigTextConnectStr { get; set; } = "server=.;uid=sa;pwd=111111;database=test;";
|
||||
|
||||
/// <summary>
|
||||
/// 历史表脚本
|
||||
/// </summary>
|
||||
[DynamicProperty]
|
||||
[Required]
|
||||
public string TableName { get; set; } = "historyAlarm";
|
||||
[AutoGenerateColumn(Visible = true, IsVisibleWhenEdit = false, IsVisibleWhenAdd = false)]
|
||||
public string? BigTextScriptHistoryTable { get; set; }
|
||||
|
||||
|
||||
public override bool OnlineFilter { get; set; } = false;
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace ThingsGateway.Plugin.TDengineDB;
|
||||
/// <summary>
|
||||
/// TDengineDBProducer
|
||||
/// </summary>
|
||||
public partial class TDengineDBProducer : BusinessBaseWithCacheIntervalVariableModel<TDengineDBHistoryValue>, IDBHistoryValueService
|
||||
public partial class TDengineDBProducer : BusinessBaseWithCacheIntervalVariableModel<VariableBasicData>, IDBHistoryValueService
|
||||
{
|
||||
internal readonly RealDBProducerProperty _driverPropertys = new()
|
||||
{
|
||||
|
||||
@@ -26,11 +26,11 @@ namespace ThingsGateway.Plugin.TDengineDB;
|
||||
/// <summary>
|
||||
/// RabbitMQProducer
|
||||
/// </summary>
|
||||
public partial class TDengineDBProducer : BusinessBaseWithCacheIntervalVariableModel<TDengineDBHistoryValue>
|
||||
public partial class TDengineDBProducer : BusinessBaseWithCacheIntervalVariableModel<VariableBasicData>
|
||||
{
|
||||
private TypeAdapterConfig _config;
|
||||
|
||||
protected override ValueTask<OperResult> UpdateVarModel(IEnumerable<CacheDBItem<TDengineDBHistoryValue>> item, CancellationToken cancellationToken)
|
||||
protected override ValueTask<OperResult> UpdateVarModel(IEnumerable<CacheDBItem<VariableBasicData>> item, CancellationToken cancellationToken)
|
||||
{
|
||||
return UpdateVarModel(item.Select(a => a.Value).OrderBy(a => a.Id), cancellationToken);
|
||||
}
|
||||
@@ -46,7 +46,7 @@ public partial class TDengineDBProducer : BusinessBaseWithCacheIntervalVariableM
|
||||
UpdateVariable(variableRuntime, variable);
|
||||
base.VariableChange(variableRuntime, variable);
|
||||
}
|
||||
protected override ValueTask<OperResult> UpdateVarModels(IEnumerable<TDengineDBHistoryValue> item, CancellationToken cancellationToken)
|
||||
protected override ValueTask<OperResult> UpdateVarModels(IEnumerable<VariableBasicData> item, CancellationToken cancellationToken)
|
||||
{
|
||||
return UpdateVarModel(item, cancellationToken);
|
||||
}
|
||||
@@ -59,36 +59,36 @@ public partial class TDengineDBProducer : BusinessBaseWithCacheIntervalVariableM
|
||||
|
||||
foreach (var group in varGroup)
|
||||
{
|
||||
AddQueueVarModel(new CacheDBItem<List<TDengineDBHistoryValue>>(group.Adapt<List<TDengineDBHistoryValue>>(_config)));
|
||||
AddQueueVarModel(new CacheDBItem<List<VariableBasicData>>(group.ToList()));
|
||||
}
|
||||
foreach (var variable in varList)
|
||||
{
|
||||
AddQueueVarModel(new CacheDBItem<TDengineDBHistoryValue>(variable.Adapt<TDengineDBHistoryValue>(_config)));
|
||||
AddQueueVarModel(new CacheDBItem<VariableBasicData>(variable));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var variable in variables)
|
||||
{
|
||||
AddQueueVarModel(new CacheDBItem<TDengineDBHistoryValue>(variable.Adapt<TDengineDBHistoryValue>(_config)));
|
||||
AddQueueVarModel(new CacheDBItem<VariableBasicData>(variable));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateVariable(VariableRuntime variableRuntime, VariableBasicData variable)
|
||||
{
|
||||
if (_driverPropertys.GroupUpdate && !variable.BusinessGroup.IsNullOrEmpty() && VariableRuntimeGroups.TryGetValue(variable.BusinessGroup, out var variableRuntimeGroup))
|
||||
if (_driverPropertys.GroupUpdate && variable.BusinessGroupUpdateTrigger && !variable.BusinessGroup.IsNullOrEmpty() && VariableRuntimeGroups.TryGetValue(variable.BusinessGroup, out var variableRuntimeGroup))
|
||||
{
|
||||
|
||||
AddQueueVarModel(new CacheDBItem<List<TDengineDBHistoryValue>>(variableRuntimeGroup.Adapt<List<TDengineDBHistoryValue>>(_config)));
|
||||
AddQueueVarModel(new CacheDBItem<List<VariableBasicData>>(variableRuntimeGroup.Adapt<List<VariableBasicData>>(_config)));
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
AddQueueVarModel(new CacheDBItem<TDengineDBHistoryValue>(variableRuntime.Adapt<TDengineDBHistoryValue>(_config)));
|
||||
AddQueueVarModel(new CacheDBItem<VariableBasicData>(variable));
|
||||
}
|
||||
}
|
||||
private async ValueTask<OperResult> UpdateVarModel(IEnumerable<TDengineDBHistoryValue> item, CancellationToken cancellationToken)
|
||||
private async ValueTask<OperResult> UpdateVarModel(IEnumerable<VariableBasicData> item, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await InserableAsync(item.WhereIf(_driverPropertys.OnlineFilter, a => a.IsOnline == true).ToList(), cancellationToken).ConfigureAwait(false);
|
||||
if (success != result.IsSuccess)
|
||||
@@ -103,7 +103,7 @@ public partial class TDengineDBProducer : BusinessBaseWithCacheIntervalVariableM
|
||||
|
||||
#region 方法
|
||||
|
||||
private async ValueTask<OperResult> InserableAsync(List<TDengineDBHistoryValue> dbInserts, CancellationToken cancellationToken)
|
||||
private async ValueTask<OperResult> InserableAsync(List<VariableBasicData> dbInserts, CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Razor">
|
||||
<Import Project="$(SolutionDir)Version.props" />
|
||||
<Import Project="$(SolutionDir)PackNuget.props" />
|
||||
<Import Project="..\..\Version.props" />
|
||||
<Import Project="..\..\PackNuget.props" />
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net8.0;</TargetFrameworks>
|
||||
</PropertyGroup>
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user