10.8.0
This commit is contained in:
		| @@ -0,0 +1,6 @@ | |||||||
|  | ## Release 1.0 | ||||||
|  |  | ||||||
|  | ### New Rules | ||||||
|  | Rule ID | Category | Severity | Notes | ||||||
|  | --------|----------|----------|-------------------- | ||||||
|  | TG0001 | Conflict | Error | SetParametersAsyncGenerator | ||||||
| @@ -0,0 +1,32 @@ | |||||||
|  | <Project Sdk="Microsoft.NET.Sdk"> | ||||||
|  | 	<Import Project="$(SolutionDir)PackNuget.props" /> | ||||||
|  | 	<PropertyGroup> | ||||||
|  | 		<TargetFrameworks>netstandard2.0;</TargetFrameworks> | ||||||
|  | 		<Version>$(SourceGeneratorVersion)</Version> | ||||||
|  | 		<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules> | ||||||
|  | 		<NoPackageAnalysis>true</NoPackageAnalysis> | ||||||
|  | 		<SignAssembly>false</SignAssembly> | ||||||
|  |  | ||||||
|  | 		<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles> | ||||||
|  | 		<IncludeBuildOutput>false</IncludeBuildOutput> | ||||||
|  | 		<!-- 避免 DLL 被打包到 lib/ --> | ||||||
|  | 		<EnableSourceGenerator>true</EnableSourceGenerator> | ||||||
|  | 		<!-- 可选 --> | ||||||
|  |  | ||||||
|  | 		 | ||||||
|  | 	</PropertyGroup> | ||||||
|  |  | ||||||
|  | 	<ItemGroup> | ||||||
|  | 		<None Include="$(OutputPath)\$(TargetFileName)" Pack="true" | ||||||
|  | 			  PackagePath="analyzers/dotnet/cs" Visible="false" /> | ||||||
|  | 	</ItemGroup> | ||||||
|  | 	 | ||||||
|  |  | ||||||
|  | 	<ItemGroup> | ||||||
|  | 		<AdditionalFiles Include="AnalyzerReleases.Shipped.md" /> | ||||||
|  | 	</ItemGroup> | ||||||
|  |  | ||||||
|  | 	<ItemGroup> | ||||||
|  | 		<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.9.0" PrivateAssets="all" /> | ||||||
|  | 	</ItemGroup> | ||||||
|  | </Project> | ||||||
| @@ -0,0 +1,9 @@ | |||||||
|  | //------------------------------------------------------------------------------ | ||||||
|  | //  此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充 | ||||||
|  | //  此代码版权(除特别声明外的代码)归作者本人Diego所有 | ||||||
|  | //  源代码使用协议遵循本仓库的开源协议及附加协议 | ||||||
|  | //  Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway | ||||||
|  | //  Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway | ||||||
|  | //  使用文档:https://thingsgateway.cn/ | ||||||
|  | //  QQ群:605534569 | ||||||
|  | //------------------------------------------------------------------------------ | ||||||
| @@ -0,0 +1,534 @@ | |||||||
|  | using Microsoft.CodeAnalysis; | ||||||
|  | using Microsoft.CodeAnalysis.CSharp; | ||||||
|  | using Microsoft.CodeAnalysis.CSharp.Syntax; | ||||||
|  |  | ||||||
|  | namespace BlazorSetParametersAsyncGenerator; | ||||||
|  |  | ||||||
|  | [Generator] | ||||||
|  | public partial class SetParametersAsyncGenerator : ISourceGenerator | ||||||
|  | { | ||||||
|  |  | ||||||
|  |     private string m_DoNotGenerateSetParametersAsyncAttribute = """ | ||||||
|  |          | ||||||
|  |         using System; | ||||||
|  |         namespace BlazorSetParametersAsyncGenerator | ||||||
|  |         { | ||||||
|  |             [AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = true)] | ||||||
|  |             internal sealed class DoNotGenerateSetParametersAsyncAttribute : Attribute | ||||||
|  |             { | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |  | ||||||
|  |         """ | ||||||
|  |         ; | ||||||
|  |     private string m_GenerateSetParametersAsyncAttribute = """ | ||||||
|  |          | ||||||
|  |         using System; | ||||||
|  |         namespace BlazorSetParametersAsyncGenerator | ||||||
|  |         { | ||||||
|  |             [AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = true)] | ||||||
|  |             internal sealed class GenerateSetParametersAsyncAttribute : Attribute | ||||||
|  |             { | ||||||
|  |                 public bool RequireExactMatch { get; set; } | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |  | ||||||
|  |         """ | ||||||
|  |         ; | ||||||
|  |     private string m_GlobalGenerateSetParametersAsyncAttribute = """ | ||||||
|  |          | ||||||
|  |         using System; | ||||||
|  |         namespace BlazorSetParametersAsyncGenerator | ||||||
|  |         { | ||||||
|  |             [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = false)] | ||||||
|  |             internal sealed class GlobalGenerateSetParametersAsyncAttribute : Attribute | ||||||
|  |             { | ||||||
|  |                 public bool Enable { get; } | ||||||
|  |  | ||||||
|  |                 public GlobalGenerateSetParametersAsyncAttribute(bool enable = true) | ||||||
|  |                 { | ||||||
|  |                     Enable = enable; | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |  | ||||||
|  |         """ | ||||||
|  |         ; | ||||||
|  |  | ||||||
|  |     private static readonly DiagnosticDescriptor ParameterNameConflict = new DiagnosticDescriptor( | ||||||
|  |         id: "TG0001", | ||||||
|  |         title: "Parameter name conflict", | ||||||
|  |         messageFormat: "Parameter names are case insensitive. {0} conflicts with {1}.", | ||||||
|  |         category: "Conflict", | ||||||
|  |         defaultSeverity: DiagnosticSeverity.Error, | ||||||
|  |         isEnabledByDefault: true, | ||||||
|  |         description: "Parameter names must be case insensitive to be usable in routes. Rename the parameter to not be in conflict with other parameters."); | ||||||
|  |  | ||||||
|  |     public void Initialize(GeneratorInitializationContext context) | ||||||
|  |     { | ||||||
|  |         context.RegisterForPostInitialization(a => | ||||||
|  |         { | ||||||
|  |             a.AddSource(nameof(m_DoNotGenerateSetParametersAsyncAttribute), m_DoNotGenerateSetParametersAsyncAttribute); | ||||||
|  |             a.AddSource(nameof(m_GenerateSetParametersAsyncAttribute), m_GenerateSetParametersAsyncAttribute); | ||||||
|  |             a.AddSource(nameof(m_GlobalGenerateSetParametersAsyncAttribute), m_GlobalGenerateSetParametersAsyncAttribute); | ||||||
|  |         }); | ||||||
|  |  | ||||||
|  |         // Register a syntax receiver that will be created for each generation pass | ||||||
|  |         context.RegisterForSyntaxNotifications(() => new SyntaxReceiver()); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public void Execute(GeneratorExecutionContext context) | ||||||
|  |     { | ||||||
|  |         // https://github.com/dotnet/AspNetCore.Docs/blob/1e199f340780f407a685695e6c4d953f173fa891/aspnetcore/blazor/webassembly-performance-best-practices.md#implement-setparametersasync-manually | ||||||
|  |         if (context.SyntaxReceiver is not SyntaxReceiver receiver) | ||||||
|  |         { | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         var candidate_classes = GetCandidateClasses(receiver, context); | ||||||
|  |  | ||||||
|  |         foreach (var class_symbol in candidate_classes.Distinct(SymbolEqualityComparer.Default).Cast<INamedTypeSymbol>()) | ||||||
|  |         { | ||||||
|  |             GenerateSetParametersAsyncMethod(context, class_symbol); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     private static void GenerateSetParametersAsyncMethod(GeneratorExecutionContext context, INamedTypeSymbol class_symbol) | ||||||
|  |     { | ||||||
|  |         var force_exact_match = class_symbol.GetAttributes().Any(a => a.NamedArguments.Any(na => na.Key == "RequireExactMatch" && na.Value.Value is bool v && v)); | ||||||
|  |         var namespaceName = class_symbol.ContainingNamespace.ToDisplayString(); | ||||||
|  |         var type_kind = class_symbol.TypeKind switch { TypeKind.Class => "class", TypeKind.Interface => "interface", _ => "struct" }; | ||||||
|  |         var type_parameters = string.Join(", ", class_symbol.TypeArguments.Select(t => t.Name)); | ||||||
|  |         type_parameters = string.IsNullOrEmpty(type_parameters) ? type_parameters : "<" + type_parameters + ">"; | ||||||
|  |         context.AddCode(class_symbol.ToDisplayString() + "_override.cs", $@" | ||||||
|  | using Microsoft.AspNetCore.Components; | ||||||
|  | using System.Collections.Generic; | ||||||
|  | using System.Threading.Tasks; | ||||||
|  |  | ||||||
|  | #pragma warning disable CA2007 | ||||||
|  | #pragma warning disable CS0162 | ||||||
|  | #pragma warning disable CS8632 | ||||||
|  | namespace {namespaceName} | ||||||
|  | {{ | ||||||
|  |     public partial class {class_symbol.Name}{type_parameters} | ||||||
|  |     {{ | ||||||
|  |         private bool _initialized; | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// <inheritdoc/> | ||||||
|  |         /// </summary> | ||||||
|  |         public override Task SetParametersAsync(ParameterView parameters) | ||||||
|  |         {{ | ||||||
|  |             Dictionary<string,object?> parameterValues = new(); | ||||||
|  |             foreach (var parameter in parameters) | ||||||
|  |             {{ | ||||||
|  |               if(BlazorImplementation__WriteSingleParameter(parameter.Name, parameter.Value)==false) | ||||||
|  |               {{ | ||||||
|  |                   // 如果没有处理参数,则添加到参数列表中 | ||||||
|  |                   parameterValues.Add(parameter.Name, parameter.Value); | ||||||
|  |               }} | ||||||
|  |             }} | ||||||
|  |              | ||||||
|  |             if(parameterValues.Count > 0) | ||||||
|  |             {{ | ||||||
|  |                 parameters.SetParameterProperties(this); | ||||||
|  |             }} | ||||||
|  |             if (!_initialized) | ||||||
|  |             {{ | ||||||
|  |                 _initialized = true; | ||||||
|  |  | ||||||
|  |                 return RunInitAndSetParametersAsync(); | ||||||
|  |             }} | ||||||
|  |             else | ||||||
|  |             {{ | ||||||
|  |                 return CallOnParametersSetAsync(); | ||||||
|  |             }} | ||||||
|  |         }} | ||||||
|  |  | ||||||
|  |         // We do not want the debugger to consider NavigationExceptions caught by this method as user-unhandled. | ||||||
|  |     #if NET9_0_OR_GREATER | ||||||
|  |         [System.Diagnostics.DebuggerDisableUserUnhandledExceptions] | ||||||
|  |     #endif | ||||||
|  |         private async Task RunInitAndSetParametersAsync() | ||||||
|  |         {{ | ||||||
|  |             Task task; | ||||||
|  |  | ||||||
|  |             try | ||||||
|  |             {{ | ||||||
|  |                 OnInitialized(); | ||||||
|  |                 task = OnInitializedAsync(); | ||||||
|  |             }} | ||||||
|  |             catch (Exception ex) when (ex is not NavigationException) | ||||||
|  |             {{ | ||||||
|  |                 throw; | ||||||
|  |             }} | ||||||
|  |  | ||||||
|  |             if (task.Status != TaskStatus.RanToCompletion && task.Status != TaskStatus.Canceled) | ||||||
|  |             {{ | ||||||
|  |                 // Call state has changed here so that we render after the sync part of OnInitAsync has run | ||||||
|  |                 // and wait for it to finish before we continue. If no async work has been done yet, we want | ||||||
|  |                 // to defer calling StateHasChanged up until the first bit of async code happens or until | ||||||
|  |                 // the end. Additionally, we want to avoid calling StateHasChanged if no | ||||||
|  |                 // async work is to be performed. | ||||||
|  |                 StateHasChanged(); | ||||||
|  |  | ||||||
|  |                 try | ||||||
|  |                 {{ | ||||||
|  |                     await task; | ||||||
|  |                 }} | ||||||
|  |                 catch // avoiding exception filters for AOT runtime support | ||||||
|  |                 {{ | ||||||
|  |                     // Ignore exceptions from task cancellations. | ||||||
|  |                     // Awaiting a canceled task may produce either an OperationCanceledException (if produced as a consequence of | ||||||
|  |                     // CancellationToken.ThrowIfCancellationRequested()) or a TaskCanceledException (produced as a consequence of awaiting Task.FromCanceled). | ||||||
|  |                     // It's much easier to check the state of the Task (i.e. Task.IsCanceled) rather than catch two distinct exceptions. | ||||||
|  |                     if (!task.IsCanceled) | ||||||
|  |                     {{ | ||||||
|  |                         throw; | ||||||
|  |                     }} | ||||||
|  |                 }} | ||||||
|  |  | ||||||
|  |                 // Don't call StateHasChanged here. CallOnParametersSetAsync should handle that for us. | ||||||
|  |             }} | ||||||
|  |  | ||||||
|  |             await CallOnParametersSetAsync(); | ||||||
|  |         }} | ||||||
|  |  | ||||||
|  |         // We do not want the debugger to consider NavigationExceptions caught by this method as user-unhandled. | ||||||
|  |     #if NET9_0_OR_GREATER | ||||||
|  |         [System.Diagnostics.DebuggerDisableUserUnhandledExceptions] | ||||||
|  |     #endif | ||||||
|  |         private Task CallOnParametersSetAsync() | ||||||
|  |         {{ | ||||||
|  |             Task task; | ||||||
|  |  | ||||||
|  |             try | ||||||
|  |             {{ | ||||||
|  |                 OnParametersSet(); | ||||||
|  |                 task = OnParametersSetAsync(); | ||||||
|  |             }} | ||||||
|  |             catch (Exception ex) when (ex is not NavigationException) | ||||||
|  |             {{ | ||||||
|  |     #if NET9_0_OR_GREATER | ||||||
|  |                 System.Diagnostics.Debugger.BreakForUserUnhandledException(ex); | ||||||
|  |     #endif | ||||||
|  |                 throw; | ||||||
|  |             }} | ||||||
|  |  | ||||||
|  |             // If no async work is to be performed, i.e. the task has already ran to completion | ||||||
|  |             // or was canceled by the time we got to inspect it, avoid going async and re-invoking | ||||||
|  |             // StateHasChanged at the culmination of the async work. | ||||||
|  |             var shouldAwaitTask = task.Status != TaskStatus.RanToCompletion && | ||||||
|  |                 task.Status != TaskStatus.Canceled; | ||||||
|  |  | ||||||
|  |             // We always call StateHasChanged here as we want to trigger a rerender after OnParametersSet and | ||||||
|  |             // the synchronous part of OnParametersSetAsync has run. | ||||||
|  |             StateHasChanged(); | ||||||
|  |  | ||||||
|  |             return shouldAwaitTask ? | ||||||
|  |                 CallStateHasChangedOnAsyncCompletion(task) : | ||||||
|  |                 Task.CompletedTask; | ||||||
|  |         }} | ||||||
|  |  | ||||||
|  |         // We do not want the debugger to stop more than once per user-unhandled exception. | ||||||
|  |     #if NET9_0_OR_GREATER | ||||||
|  |         [System.Diagnostics.DebuggerDisableUserUnhandledExceptions] | ||||||
|  |     #endif | ||||||
|  |         private async Task CallStateHasChangedOnAsyncCompletion(Task task) | ||||||
|  |         {{ | ||||||
|  |             try | ||||||
|  |             {{ | ||||||
|  |                 await task; | ||||||
|  |             }} | ||||||
|  |             catch // avoiding exception filters for AOT runtime support | ||||||
|  |             {{ | ||||||
|  |                 // Ignore exceptions from task cancellations, but don't bother issuing a state change. | ||||||
|  |                 if (task.IsCanceled) | ||||||
|  |                 {{ | ||||||
|  |                     return; | ||||||
|  |                 }} | ||||||
|  |  | ||||||
|  |                 throw; | ||||||
|  |             }} | ||||||
|  |  | ||||||
|  |             StateHasChanged(); | ||||||
|  |         }} | ||||||
|  |  | ||||||
|  |     }} | ||||||
|  | }} | ||||||
|  | #pragma warning restore CS8632 | ||||||
|  | #pragma warning restore CS0162 | ||||||
|  | #pragma warning restore CA2007 | ||||||
|  | "); | ||||||
|  |         var bases = class_symbol.GetTypeHierarchy().Where(t => !SymbolEqualityComparer.Default.Equals(t, class_symbol)); | ||||||
|  |         var members = class_symbol.GetMembers() // members of the type itself | ||||||
|  |             .Concat(bases.SelectMany(t => t.GetMembers().Where(m => m.DeclaredAccessibility != Accessibility.Private))) // plus accessible members of any base | ||||||
|  |             .Distinct(SymbolEqualityComparer.Default); | ||||||
|  |         var property_symbols = members.OfType<IPropertySymbol>(); | ||||||
|  |         var writable_property_symbols = property_symbols.Where(ps => | ||||||
|  |             !ps.IsReadOnly || ps.GetAttributes().Any(a => | ||||||
|  |                 a.AttributeClass?.Name is "CascadingParameter" or "CascadingParameterAttribute") | ||||||
|  |         ); | ||||||
|  |  | ||||||
|  |         var parameter_symbols = writable_property_symbols | ||||||
|  |             .Where(ps => ps.GetAttributes().Any(a => false | ||||||
|  |             || a.AttributeClass.Name == "Parameter" | ||||||
|  |             || a.AttributeClass.Name == "ParameterAttribute" | ||||||
|  |             || a.AttributeClass.Name == "CascadingParameter" | ||||||
|  |             || a.AttributeClass.Name == "CascadingParameterAttribute" | ||||||
|  |  | ||||||
|  |         )); | ||||||
|  |         var name_conflicts = parameter_symbols.GroupBy(ps => ps.Name.ToLowerInvariant()).Where(g => g.Count() > 1); | ||||||
|  |         foreach (var conflict in name_conflicts) | ||||||
|  |         { | ||||||
|  |             var key = conflict.Key; | ||||||
|  |             var conflicting_parameters = conflict.ToList(); | ||||||
|  |             foreach (var parameter in conflicting_parameters) | ||||||
|  |             { | ||||||
|  |                 var this_name = parameter.Name; | ||||||
|  |                 var conflicting_name = conflicting_parameters.Select(p => p.Name).FirstOrDefault(n => n != this_name); | ||||||
|  |                 foreach (var location in parameter.Locations) | ||||||
|  |                 { | ||||||
|  |                     context.ReportDiagnostic(Diagnostic.Create(ParameterNameConflict, location, this_name, conflicting_name)); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |         var all = parameter_symbols.ToList(); | ||||||
|  |         var catch_all_parameter = parameter_symbols.FirstOrDefault(p => | ||||||
|  |         { | ||||||
|  |             var parameter_attr = p.GetAttributes().FirstOrDefault(a => a.AttributeClass!.Name.StartsWith("Parameter")); | ||||||
|  |             return parameter_attr?.NamedArguments.Any(n => n.Key == "CaptureUnmatchedValues" && n.Value.Value is bool v && v) == true; | ||||||
|  |         }); | ||||||
|  |         var lower_case_match_cases = parameter_symbols.Except(new[] { catch_all_parameter }).Select(p => $"case \"{p.Name.ToLowerInvariant()}\": this.{p.Name} = ({p.Type.ToDisplayString()}) value; break;"); | ||||||
|  |         var lower_case_match_default = catch_all_parameter == null ? @"default: {return false;}" : $@" | ||||||
|  | default: | ||||||
|  | {{ | ||||||
|  |     this.{catch_all_parameter.Name} ??= new System.Collections.Generic.Dictionary<string, object>(); | ||||||
|  |     var writable_dict = this.{catch_all_parameter.Name}; | ||||||
|  |     if (!writable_dict.TryAdd(name, value)) | ||||||
|  |     {{ | ||||||
|  |         writable_dict[name] = value; | ||||||
|  |     }} | ||||||
|  |     break; | ||||||
|  | }}"; | ||||||
|  |  | ||||||
|  |         var exact_match_cases = parameter_symbols.Except(new[] { catch_all_parameter }).Select(p => $"case \"{p!.Name}\": this.{p.Name} = ({p.Type.ToDisplayString()}) value; break;"); | ||||||
|  |         string exact_match_default; | ||||||
|  |         if (force_exact_match) | ||||||
|  |         { | ||||||
|  |             if (catch_all_parameter == null) // exact matches are forced, and we do not have a catch-all parameter, therefore we need to throw on unmatched parameter | ||||||
|  |             { | ||||||
|  |                 exact_match_default = @"default: { return false;"; | ||||||
|  |             } | ||||||
|  |             else // exact matches are forced, and we DO have a catch-all parameter, therefore we simply add that unmatched parameter to the dictionary | ||||||
|  |             { | ||||||
|  |                 exact_match_default = $@" | ||||||
|  | default: | ||||||
|  | {{ | ||||||
|  |     this.{catch_all_parameter.Name} ??= new System.Collections.Generic.Dictionary<string, object>(); | ||||||
|  |     var writable_dict = this.{catch_all_parameter.Name}; | ||||||
|  |     if (!writable_dict.TryAdd(name, value)) | ||||||
|  |     {{ | ||||||
|  |         writable_dict[name] = value; | ||||||
|  |     }} | ||||||
|  |     break; | ||||||
|  | }}"; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |         else | ||||||
|  |         { | ||||||
|  |             // exact matches are not forced, so if there is no exact match, we fall back to compare it in lower case | ||||||
|  |             exact_match_default = $@" | ||||||
|  | default: | ||||||
|  | {{ | ||||||
|  |     switch (name.ToLowerInvariant()) | ||||||
|  |     {{ | ||||||
|  |         {string.Join("\n", lower_case_match_cases)} | ||||||
|  |         {lower_case_match_default} | ||||||
|  |     }} | ||||||
|  |     break; | ||||||
|  | }} | ||||||
|  | "; | ||||||
|  |         } | ||||||
|  |         context.AddCode(class_symbol.ToDisplayString() + "_implementation.cs", $@" | ||||||
|  | using System; | ||||||
|  |  | ||||||
|  | #pragma warning disable CS0162 | ||||||
|  | #pragma warning disable CS0618 | ||||||
|  | #pragma warning disable CS8632 | ||||||
|  | namespace {namespaceName} | ||||||
|  | {{ | ||||||
|  |     public partial class {class_symbol.Name}{type_parameters} | ||||||
|  |     {{ | ||||||
|  |  | ||||||
|  |         private bool BlazorImplementation__WriteSingleParameter(string name, object value) | ||||||
|  |         {{ | ||||||
|  |             if(name != ""Body"") | ||||||
|  |             {{ | ||||||
|  |  | ||||||
|  |                 switch (name) | ||||||
|  |                 {{ | ||||||
|  |                     {string.Join("\n", exact_match_cases)} | ||||||
|  |                     {exact_match_default} | ||||||
|  |                 }} | ||||||
|  |                 return true; | ||||||
|  |             }} | ||||||
|  |            return false; | ||||||
|  |          }} | ||||||
|  |     }} | ||||||
|  | }} | ||||||
|  | #pragma warning restore CS8632 | ||||||
|  | #pragma warning restore CS0618 | ||||||
|  | #pragma warning restore CS0162"); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     private static bool HasUserDefinedSetParametersAsync(INamedTypeSymbol classSymbol) | ||||||
|  |     { | ||||||
|  |         return classSymbol | ||||||
|  |             .GetMembers("SetParametersAsync") | ||||||
|  |             .OfType<IMethodSymbol>() | ||||||
|  |             .Any(m => | ||||||
|  |                 m.Parameters.Length == 1 && | ||||||
|  |                 m.Parameters[0].Type.ToDisplayString() == "Microsoft.AspNetCore.Components.ParameterView" && | ||||||
|  |                 m.DeclaredAccessibility == Accessibility.Public && | ||||||
|  |                 !m.IsStatic); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |  | ||||||
|  |     private static bool IsPartial(INamedTypeSymbol symbol) | ||||||
|  |     { | ||||||
|  |         return symbol.DeclaringSyntaxReferences | ||||||
|  |             .Select(r => r.GetSyntax()) | ||||||
|  |             .OfType<ClassDeclarationSyntax>() | ||||||
|  |             .Any(c => c.Modifiers.Any(m => m.IsKind(SyntaxKind.PartialKeyword))); | ||||||
|  |     } | ||||||
|  |     private static bool IsComponent(ClassDeclarationSyntax classDeclarationSyntax, INamedTypeSymbol symbol, Compilation compilation) | ||||||
|  |     { | ||||||
|  |         if (HasUserDefinedSetParametersAsync(symbol)) | ||||||
|  |         { | ||||||
|  |             // 用户自己写了方法,不生成 | ||||||
|  |             return false; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         if (!IsPartial(symbol)) | ||||||
|  |         { | ||||||
|  |             return false; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         if (classDeclarationSyntax.SyntaxTree.FilePath.EndsWith(".razor") || classDeclarationSyntax.SyntaxTree.FilePath.EndsWith(".razor.cs")) | ||||||
|  |         { | ||||||
|  |             return true; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |         var iComponent = compilation.GetTypeByMetadataName("Microsoft.AspNetCore.Components.IComponent"); | ||||||
|  |         var componentBase = compilation.GetTypeByMetadataName("Microsoft.AspNetCore.Components.ComponentBase"); | ||||||
|  |         if (iComponent == null || componentBase == null) | ||||||
|  |             return false; | ||||||
|  |  | ||||||
|  |         if (SymbolEqualityComparer.Default.Equals(symbol, iComponent)) | ||||||
|  |             return true; | ||||||
|  |         if (SymbolEqualityComparer.Default.Equals(symbol, componentBase)) | ||||||
|  |             return true; | ||||||
|  |  | ||||||
|  |         return false; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /// <summary> | ||||||
|  |     /// Enumerate methods with at least one Group attribute | ||||||
|  |     /// </summary> | ||||||
|  |     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"); | ||||||
|  |  | ||||||
|  |         // loop over the candidate methods, and keep the ones that are actually annotated | ||||||
|  |  | ||||||
|  |         // 找特性 | ||||||
|  |         var assemblyAttributes = compilation.Assembly.GetAttributes(); | ||||||
|  |  | ||||||
|  |         var enableAttr = assemblyAttributes.FirstOrDefault(attr => | ||||||
|  |             attr.AttributeClass?.ToDisplayString() == "BlazorSetParametersAsyncGenerator.GlobalGenerateSetParametersAsyncAttribute"); | ||||||
|  |  | ||||||
|  |         var globalEnable = false; | ||||||
|  |         if (enableAttr != null) | ||||||
|  |         { | ||||||
|  |             var arg = enableAttr.ConstructorArguments.FirstOrDefault(); | ||||||
|  |             if (arg.Value is bool b) | ||||||
|  |                 globalEnable = b; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         foreach (ClassDeclarationSyntax class_declaration in receiver.CandidateClasses) | ||||||
|  |         { | ||||||
|  |             var model = compilation.GetSemanticModel(class_declaration.SyntaxTree); | ||||||
|  |             var class_symbol = model.GetDeclaredSymbol(class_declaration); | ||||||
|  |             if (class_symbol is null) | ||||||
|  |             { | ||||||
|  |                 continue; | ||||||
|  |             } | ||||||
|  |             if (class_symbol.Name == "_Imports") | ||||||
|  |             { | ||||||
|  |                 continue; | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             // 是否拒绝生成 | ||||||
|  |             var hasNegative = class_symbol.GetAttributes().Any(ad => | ||||||
|  |                 ad.AttributeClass?.Equals(negativeAttributeSymbol, SymbolEqualityComparer.Default) == true); | ||||||
|  |  | ||||||
|  |             if (hasNegative) | ||||||
|  |                 continue; | ||||||
|  |  | ||||||
|  |  | ||||||
|  |             if (IsComponent(class_declaration, class_symbol, compilation)) | ||||||
|  |             { | ||||||
|  |                 if (globalEnable) | ||||||
|  |                 { | ||||||
|  |                     yield return class_symbol; | ||||||
|  |                 } | ||||||
|  |                 else | ||||||
|  |                 { | ||||||
|  |                     // 必须显式标注 Positive Attribute | ||||||
|  |                     var hasPositive = class_symbol.GetAttributes().Any(ad => | ||||||
|  |                         ad.AttributeClass?.Equals(positiveAttributeSymbol, SymbolEqualityComparer.Default) == true); | ||||||
|  |  | ||||||
|  |                     if (hasPositive) | ||||||
|  |                         yield return class_symbol; | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |             else | ||||||
|  |             { | ||||||
|  |  | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /// <summary> | ||||||
|  |     /// Created on demand before each generation pass | ||||||
|  |     /// </summary> | ||||||
|  |     internal class SyntaxReceiver : ISyntaxReceiver | ||||||
|  |     { | ||||||
|  |         public List<ClassDeclarationSyntax> CandidateClasses { get; } = new List<ClassDeclarationSyntax>(); | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Called for every syntax node in the compilation, we can inspect the nodes and save any information useful for generation | ||||||
|  |         /// </summary> | ||||||
|  |         public void OnVisitSyntaxNode(SyntaxNode syntax_node) | ||||||
|  |         { | ||||||
|  |             // any class with at least one attribute is a candidate for property generation | ||||||
|  |             if (syntax_node is ClassDeclarationSyntax classDeclarationSyntax) | ||||||
|  |             { | ||||||
|  |                 CandidateClasses.Add(classDeclarationSyntax); | ||||||
|  |             } | ||||||
|  |             else | ||||||
|  |             { | ||||||
|  |  | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -0,0 +1,15 @@ | |||||||
|  | using Microsoft.CodeAnalysis; | ||||||
|  | using Microsoft.CodeAnalysis.Text; | ||||||
|  |  | ||||||
|  | using System.Text; | ||||||
|  |  | ||||||
|  | namespace BlazorSetParametersAsyncGenerator | ||||||
|  | { | ||||||
|  |     internal static class SourceGeneratorContextExtension | ||||||
|  |     { | ||||||
|  |         public static void AddCode(this GeneratorExecutionContext context, string hint_name, string code) | ||||||
|  |         { | ||||||
|  |             context.AddSource(hint_name.Replace("<", "_").Replace(">", "_"), SourceText.From(code, Encoding.UTF8)); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -0,0 +1,13 @@ | |||||||
|  | using Microsoft.CodeAnalysis; | ||||||
|  | using Microsoft.CodeAnalysis.CSharp; | ||||||
|  |  | ||||||
|  | namespace BlazorSetParametersAsyncGenerator | ||||||
|  | { | ||||||
|  |     internal static class StringExtension | ||||||
|  |     { | ||||||
|  |         public static string NormalizeWhitespace(this string code) | ||||||
|  |         { | ||||||
|  |             return CSharpSyntaxTree.ParseText(code).GetRoot().NormalizeWhitespace().ToFullString(); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -0,0 +1,19 @@ | |||||||
|  | using Microsoft.CodeAnalysis; | ||||||
|  |  | ||||||
|  | namespace BlazorSetParametersAsyncGenerator | ||||||
|  | { | ||||||
|  |     public static class TypeSymbolExtension | ||||||
|  |     { | ||||||
|  |         public static IEnumerable<INamedTypeSymbol> GetTypeHierarchy(this INamedTypeSymbol symbol) | ||||||
|  |         { | ||||||
|  |             yield return symbol; | ||||||
|  |             if (symbol.BaseType != null) | ||||||
|  |             { | ||||||
|  |                 foreach (var type in GetTypeHierarchy(symbol.BaseType)) | ||||||
|  |                 { | ||||||
|  |                     yield return type; | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -0,0 +1,49 @@ | |||||||
|  | param($installPath, $toolsPath, $package, $project) | ||||||
|  |  | ||||||
|  | $analyzersPaths = Join-Path (Join-Path (Split-Path -Path $toolsPath -Parent) "analyzers" ) * -Resolve | ||||||
|  |  | ||||||
|  | foreach($analyzersPath in $analyzersPaths) | ||||||
|  | { | ||||||
|  |     # Install the language agnostic analyzers. | ||||||
|  |     if (Test-Path $analyzersPath) | ||||||
|  |     { | ||||||
|  |         foreach ($analyzerFilePath in Get-ChildItem $analyzersPath -Filter *.dll) | ||||||
|  |         { | ||||||
|  |             if($project.Object.AnalyzerReferences) | ||||||
|  |             { | ||||||
|  |                 $project.Object.AnalyzerReferences.Add($analyzerFilePath.FullName) | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | # $project.Type gives the language name like (C# or VB.NET) | ||||||
|  | $languageFolder = "" | ||||||
|  | if($project.Type -eq "C#") | ||||||
|  | { | ||||||
|  |     $languageFolder = "cs" | ||||||
|  | } | ||||||
|  | if($project.Type -eq "VB.NET") | ||||||
|  | { | ||||||
|  |     $languageFolder = "vb" | ||||||
|  | } | ||||||
|  | if($languageFolder -eq "") | ||||||
|  | { | ||||||
|  |     return | ||||||
|  | } | ||||||
|  |  | ||||||
|  | foreach($analyzersPath in $analyzersPaths) | ||||||
|  | { | ||||||
|  |     # Install language specific analyzers. | ||||||
|  |     $languageAnalyzersPath = join-path $analyzersPath $languageFolder | ||||||
|  |     if (Test-Path $languageAnalyzersPath) | ||||||
|  |     { | ||||||
|  |         foreach ($analyzerFilePath in Get-ChildItem $languageAnalyzersPath -Filter *.dll) | ||||||
|  |         { | ||||||
|  |             if($project.Object.AnalyzerReferences) | ||||||
|  |             { | ||||||
|  |                 $project.Object.AnalyzerReferences.Add($analyzerFilePath.FullName) | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -0,0 +1,56 @@ | |||||||
|  | param($installPath, $toolsPath, $package, $project) | ||||||
|  |  | ||||||
|  | $analyzersPaths = Join-Path (Join-Path (Split-Path -Path $toolsPath -Parent) "analyzers" ) * -Resolve | ||||||
|  |  | ||||||
|  | foreach($analyzersPath in $analyzersPaths) | ||||||
|  | { | ||||||
|  |     # Uninstall the language agnostic analyzers. | ||||||
|  |     if (Test-Path $analyzersPath) | ||||||
|  |     { | ||||||
|  |         foreach ($analyzerFilePath in Get-ChildItem $analyzersPath -Filter *.dll) | ||||||
|  |         { | ||||||
|  |             if($project.Object.AnalyzerReferences) | ||||||
|  |             { | ||||||
|  |                 $project.Object.AnalyzerReferences.Remove($analyzerFilePath.FullName) | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | # $project.Type gives the language name like (C# or VB.NET) | ||||||
|  | $languageFolder = "" | ||||||
|  | if($project.Type -eq "C#") | ||||||
|  | { | ||||||
|  |     $languageFolder = "cs" | ||||||
|  | } | ||||||
|  | if($project.Type -eq "VB.NET") | ||||||
|  | { | ||||||
|  |     $languageFolder = "vb" | ||||||
|  | } | ||||||
|  | if($languageFolder -eq "") | ||||||
|  | { | ||||||
|  |     return | ||||||
|  | } | ||||||
|  |  | ||||||
|  | foreach($analyzersPath in $analyzersPaths) | ||||||
|  | { | ||||||
|  |     # Uninstall language specific analyzers. | ||||||
|  |     $languageAnalyzersPath = join-path $analyzersPath $languageFolder | ||||||
|  |     if (Test-Path $languageAnalyzersPath) | ||||||
|  |     { | ||||||
|  |         foreach ($analyzerFilePath in Get-ChildItem $languageAnalyzersPath -Filter *.dll) | ||||||
|  |         { | ||||||
|  |             if($project.Object.AnalyzerReferences) | ||||||
|  |             { | ||||||
|  |                 try | ||||||
|  |                 { | ||||||
|  |                     $project.Object.AnalyzerReferences.Remove($analyzerFilePath.FullName) | ||||||
|  |                 } | ||||||
|  |                 catch | ||||||
|  |                 { | ||||||
|  |  | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -91,7 +91,7 @@ public sealed class OperDescAttribute : MoAttribute | |||||||
|             OperDescAttribute.WriteToQueue(log); |             OperDescAttribute.WriteToQueue(log); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|     private static SqlSugarClient _db = DbContext.Db.GetConnectionScopeWithAttr<SysOperateLog>().CopyNew(); |     private static SqlSugarClient _db = DbContext.GetDB<SysOperateLog>(); | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// 将日志消息写入数据库中 |     /// 将日志消息写入数据库中 | ||||||
|     /// </summary> |     /// </summary> | ||||||
|   | |||||||
| @@ -8,5 +8,4 @@ | |||||||
| //  QQ群:605534569 | //  QQ群:605534569 | ||||||
| //------------------------------------------------------------------------------ | //------------------------------------------------------------------------------ | ||||||
|  |  | ||||||
| global using ThingsGateway; |  | ||||||
| global using ThingsGateway.NewLife.Extension; | global using ThingsGateway.NewLife.Extension; | ||||||
| @@ -61,7 +61,7 @@ public class HardwareJob : IJob, IHardwareJob | |||||||
|         var historyHardwareInfos = MemoryCache.Get<List<HistoryHardwareInfo>>(CacheKey); |         var historyHardwareInfos = MemoryCache.Get<List<HistoryHardwareInfo>>(CacheKey); | ||||||
|         if (historyHardwareInfos == null) |         if (historyHardwareInfos == null) | ||||||
|         { |         { | ||||||
|             using var db = _db.CopyNew(); |             using var db = _db; | ||||||
|             historyHardwareInfos = await db.Queryable<HistoryHardwareInfo>().Where(a => a.Date > DateTime.Now.AddDays(-3)).ToListAsync().ConfigureAwait(false); |             historyHardwareInfos = await db.Queryable<HistoryHardwareInfo>().Where(a => a.Date > DateTime.Now.AddDays(-3)).ToListAsync().ConfigureAwait(false); | ||||||
|  |  | ||||||
|             MemoryCache.Set(CacheKey, historyHardwareInfos); |             MemoryCache.Set(CacheKey, historyHardwareInfos); | ||||||
| @@ -71,7 +71,7 @@ public class HardwareJob : IJob, IHardwareJob | |||||||
|  |  | ||||||
|     private bool error = false; |     private bool error = false; | ||||||
|     private DateTime hisInsertTime = default; |     private DateTime hisInsertTime = default; | ||||||
|     private SqlSugarClient _db = DbContext.Db.GetConnectionScopeWithAttr<HistoryHardwareInfo>().CopyNew(); |     private SqlSugarClient _db = DbContext.GetDB<HistoryHardwareInfo>(); | ||||||
|  |  | ||||||
|     public async Task ExecuteAsync(JobExecutingContext context, CancellationToken stoppingToken) |     public async Task ExecuteAsync(JobExecutingContext context, CancellationToken stoppingToken) | ||||||
|     { |     { | ||||||
|   | |||||||
| @@ -27,7 +27,7 @@ public class LogJob : IJob | |||||||
|  |  | ||||||
|     private static async Task DeleteSysOperateLog(int daysAgo, CancellationToken stoppingToken) |     private static async Task DeleteSysOperateLog(int daysAgo, CancellationToken stoppingToken) | ||||||
|     { |     { | ||||||
|         using var db = DbContext.Db.GetConnectionScopeWithAttr<SysOperateLog>().CopyNew(); |         using var db = DbContext.GetDB<SysOperateLog>(); | ||||||
|         var time = DateTime.Now.AddDays(-daysAgo); |         var time = DateTime.Now.AddDays(-daysAgo); | ||||||
|         await db.DeleteableWithAttr<SysOperateLog>().Where(u => u.OpTime < time).ExecuteCommandAsync(stoppingToken).ConfigureAwait(false); // 删除操作日志 |         await db.DeleteableWithAttr<SysOperateLog>().Where(u => u.OpTime < time).ExecuteCommandAsync(stoppingToken).ConfigureAwait(false); // 删除操作日志 | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -143,7 +143,7 @@ public class DatabaseLoggingWriter : IDatabaseLoggingWriter | |||||||
|  |  | ||||||
|         if (flush) |         if (flush) | ||||||
|         { |         { | ||||||
|             SqlSugarClient ??= DbContext.Db.GetConnectionScopeWithAttr<SysOperateLog>().CopyNew(); |             SqlSugarClient ??= DbContext.GetDB<SysOperateLog>(); | ||||||
|             await SqlSugarClient.InsertableWithAttr(_operateLogMessageQueue.ToListWithDequeue()).ExecuteCommandAsync().ConfigureAwait(false);//入库 |             await SqlSugarClient.InsertableWithAttr(_operateLogMessageQueue.ToListWithDequeue()).ExecuteCommandAsync().ConfigureAwait(false);//入库 | ||||||
|             return true; |             return true; | ||||||
|         } |         } | ||||||
| @@ -202,7 +202,7 @@ public class DatabaseLoggingWriter : IDatabaseLoggingWriter | |||||||
|  |  | ||||||
|         if (flush) |         if (flush) | ||||||
|         { |         { | ||||||
|             SqlSugarClient ??= DbContext.Db.GetConnectionScopeWithAttr<SysOperateLog>().CopyNew(); |             SqlSugarClient ??= DbContext.GetDB<SysOperateLog>(); | ||||||
|             await SqlSugarClient.InsertableWithAttr(_operateLogMessageQueue.ToListWithDequeue()).ExecuteCommandAsync().ConfigureAwait(false);//入库 |             await SqlSugarClient.InsertableWithAttr(_operateLogMessageQueue.ToListWithDequeue()).ExecuteCommandAsync().ConfigureAwait(false);//入库 | ||||||
|             return true; |             return true; | ||||||
|         } |         } | ||||||
|   | |||||||
| @@ -46,7 +46,7 @@ public class AdminOAuthHandler<TOptions>( | |||||||
|     /// </summary> |     /// </summary> | ||||||
|     private static async Task Insertable() |     private static async Task Insertable() | ||||||
|     { |     { | ||||||
|         var db = DbContext.Db.GetConnectionScopeWithAttr<SysOperateLog>().CopyNew(); |         var db = DbContext.GetDB<SysOperateLog>(); | ||||||
|         var appLifetime = App.RootServices!.GetService<IHostApplicationLifetime>()!; |         var appLifetime = App.RootServices!.GetService<IHostApplicationLifetime>()!; | ||||||
|         while (!appLifetime.ApplicationStopping.IsCancellationRequested) |         while (!appLifetime.ApplicationStopping.IsCancellationRequested) | ||||||
|         { |         { | ||||||
| @@ -209,7 +209,7 @@ public class AdminOAuthHandler<TOptions>( | |||||||
|  |  | ||||||
|         #endregion 重新赋值属性,设置本次登录信息为最新的信息 |         #endregion 重新赋值属性,设置本次登录信息为最新的信息 | ||||||
|  |  | ||||||
|         using var db = DbContext.Db.GetConnectionScopeWithAttr<SysUser>().CopyNew(); |         using var db = DbContext.GetDB<SysUser>(); | ||||||
|         //更新用户登录信息 |         //更新用户登录信息 | ||||||
|         if (await db.Updateable(sysUser).UpdateColumns(it => new |         if (await db.Updateable(sysUser).UpdateColumns(it => new | ||||||
|         { |         { | ||||||
|   | |||||||
| @@ -25,7 +25,7 @@ public abstract class AdminOAuthOptions : OAuthOptions | |||||||
|  |  | ||||||
|         Backchannel = new HttpClient(new HttpClientHandler |         Backchannel = new HttpClient(new HttpClientHandler | ||||||
|         { |         { | ||||||
|             ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator // 若测试用 |             ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator | ||||||
|         }); |         }); | ||||||
|         Backchannel.DefaultRequestHeaders.UserAgent.Add( |         Backchannel.DefaultRequestHeaders.UserAgent.Add( | ||||||
|             new ProductInfoHeaderValue("ThingsGateway", "1.0")); |             new ProductInfoHeaderValue("ThingsGateway", "1.0")); | ||||||
|   | |||||||
| @@ -18,7 +18,7 @@ public class SysRelationSeedData : ISqlSugarEntitySeedData<SysRelation> | |||||||
|     /// <inheritdoc/> |     /// <inheritdoc/> | ||||||
|     public IEnumerable<SysRelation> SeedData() |     public IEnumerable<SysRelation> SeedData() | ||||||
|     { |     { | ||||||
|         using var db = DbContext.Db.GetConnectionScopeWithAttr<SysRelation>().CopyNew(); |         using var db = DbContext.GetDB<SysRelation>(); | ||||||
|         if (db.Queryable<SysRelation>().Any(a => a.ObjectId == RoleConst.SuperAdminId)) |         if (db.Queryable<SysRelation>().Any(a => a.ObjectId == RoleConst.SuperAdminId)) | ||||||
|             return Enumerable.Empty<SysRelation>(); |             return Enumerable.Empty<SysRelation>(); | ||||||
|         var data = SeedDataUtil.GetSeedData<SysRelation>(PathExtensions.CombinePathWithOs("SeedData", "Admin", "seed_sys_relation.json")); |         var data = SeedDataUtil.GetSeedData<SysRelation>(PathExtensions.CombinePathWithOs("SeedData", "Admin", "seed_sys_relation.json")); | ||||||
|   | |||||||
| @@ -324,7 +324,7 @@ public class AuthService : IAuthService | |||||||
|  |  | ||||||
|         #endregion 重新赋值属性,设置本次登录信息为最新的信息 |         #endregion 重新赋值属性,设置本次登录信息为最新的信息 | ||||||
|  |  | ||||||
|         using var db = DbContext.Db.GetConnectionScopeWithAttr<SysUser>().CopyNew(); |         using var db = DbContext.GetDB<SysUser>(); | ||||||
|         //更新用户登录信息 |         //更新用户登录信息 | ||||||
|         if (await db.Updateable(sysUser).UpdateColumns(it => new |         if (await db.Updateable(sysUser).UpdateColumns(it => new | ||||||
|         { |         { | ||||||
|   | |||||||
| @@ -78,7 +78,7 @@ public class Startup : AppStartup | |||||||
|         //遍历配置 |         //遍历配置 | ||||||
|         DbContext.DbConfigs?.ForEach(it => |         DbContext.DbConfigs?.ForEach(it => | ||||||
|         { |         { | ||||||
|             var connection = DbContext.Db.GetConnection(it.ConfigId);//获取数据库连接对象 |             var connection = DbContext.GetDB().GetConnection(it.ConfigId);//获取数据库连接对象 | ||||||
|             if (it.InitDatabase == true) |             if (it.InitDatabase == true) | ||||||
|                 connection.DbMaintenance.CreateDatabase();//创建数据库,如果存在则不创建 |                 connection.DbMaintenance.CreateDatabase();//创建数据库,如果存在则不创建 | ||||||
|         }); |         }); | ||||||
|   | |||||||
| @@ -46,7 +46,6 @@ | |||||||
| 	</ItemGroup> | 	</ItemGroup> | ||||||
|  |  | ||||||
| 	<ItemGroup> | 	<ItemGroup> | ||||||
| 		<ProjectReference Include="..\ThingsGateway.Razor\ThingsGateway.Razor.csproj" /> |  | ||||||
| 		<ProjectReference Include="..\ThingsGateway.DB\ThingsGateway.DB.csproj" /> | 		<ProjectReference Include="..\ThingsGateway.DB\ThingsGateway.DB.csproj" /> | ||||||
| 	</ItemGroup> | 	</ItemGroup> | ||||||
|  |  | ||||||
|   | |||||||
| @@ -40,7 +40,7 @@ public static class ClearTokenUtil | |||||||
|     public static async Task DeleteUserTokenByOrgIds(HashSet<long> orgIds) |     public static async Task DeleteUserTokenByOrgIds(HashSet<long> orgIds) | ||||||
|     { |     { | ||||||
|         // 获取用户ID列表 |         // 获取用户ID列表 | ||||||
|         var userIds = await DbContext.Db.CopyNew().QueryableWithAttr<SysUser>().Where(it => orgIds.Contains(it.OrgId)).Select(it => it.Id).ToListAsync().ConfigureAwait(false); |         var userIds = await DbContext.GetDB<SysUser>().Queryable<SysUser>().Where(it => orgIds.Contains(it.OrgId)).Select(it => it.Id).ToListAsync().ConfigureAwait(false); | ||||||
|         //从redis中删除所属机构的用户token |         //从redis中删除所属机构的用户token | ||||||
|         App.CacheService.HashDel<VerificatInfo>(CacheConst.Cache_Token, userIds.Select(it => it.ToString()).ToArray()); |         App.CacheService.HashDel<VerificatInfo>(CacheConst.Cache_Token, userIds.Select(it => it.ToString()).ToArray()); | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -19,3 +19,4 @@ global using System.Diagnostics.CodeAnalysis; | |||||||
| global using ThingsGateway.Razor; | global using ThingsGateway.Razor; | ||||||
| 
 | 
 | ||||||
| [assembly: SuppressMessage("Reliability", "CA2007", Justification = "<挂起>", Scope = "module")] | [assembly: SuppressMessage("Reliability", "CA2007", Justification = "<挂起>", Scope = "module")] | ||||||
|  | [assembly: BlazorSetParametersAsyncGenerator.GlobalGenerateSetParametersAsync(true)] | ||||||
| @@ -17,6 +17,7 @@ | |||||||
|  |  | ||||||
| 	<PropertyGroup> | 	<PropertyGroup> | ||||||
| 		<TargetFrameworks>net8.0;net9.0</TargetFrameworks> | 		<TargetFrameworks>net8.0;net9.0</TargetFrameworks> | ||||||
|  | 		<!--<UseRazorSourceGenerator>false</UseRazorSourceGenerator>--> | ||||||
| 	</PropertyGroup> | 	</PropertyGroup> | ||||||
| 	<ItemGroup> | 	<ItemGroup> | ||||||
| 		<Content Remove="Locales\*.json" /> | 		<Content Remove="Locales\*.json" /> | ||||||
|   | |||||||
| @@ -41,19 +41,19 @@ public abstract class PrimaryKeyEntity : PrimaryIdEntity | |||||||
|     [SugarColumn(ColumnDescription = "扩展信息", ColumnDataType = StaticConfig.CodeFirst_BigString, IsNullable = true)] |     [SugarColumn(ColumnDescription = "扩展信息", ColumnDataType = StaticConfig.CodeFirst_BigString, IsNullable = true)] | ||||||
|     [IgnoreExcel] |     [IgnoreExcel] | ||||||
|     [AutoGenerateColumn(Ignore = true)] |     [AutoGenerateColumn(Ignore = true)] | ||||||
|     public virtual string? ExtJson { get; set; } |     public virtual string ExtJson { get; set; } | ||||||
| } | } | ||||||
|  |  | ||||||
| public interface IBaseEntity | public interface IBaseEntity | ||||||
| { | { | ||||||
|     DateTime? CreateTime { get; set; } |     DateTime CreateTime { get; set; } | ||||||
|     string? CreateUser { get; set; } |     string CreateUser { get; set; } | ||||||
|     long CreateUserId { get; set; } |     long CreateUserId { get; set; } | ||||||
|     bool IsDelete { get; set; } |     bool IsDelete { get; set; } | ||||||
|     int? SortCode { get; set; } |     int SortCode { get; set; } | ||||||
|     DateTime? UpdateTime { get; set; } |     DateTime UpdateTime { get; set; } | ||||||
|     string? UpdateUser { get; set; } |     string UpdateUser { get; set; } | ||||||
|     long? UpdateUserId { get; set; } |     long UpdateUserId { get; set; } | ||||||
| } | } | ||||||
|  |  | ||||||
| /// <summary> | /// <summary> | ||||||
| @@ -61,13 +61,22 @@ public interface IBaseEntity | |||||||
| /// </summary> | /// </summary> | ||||||
| public abstract class BaseEntity : PrimaryKeyEntity, IBaseEntity | public abstract class BaseEntity : PrimaryKeyEntity, IBaseEntity | ||||||
| { | { | ||||||
|  |     private long createUserId; | ||||||
|  |     private long updateUserId; | ||||||
|  |     private DateTime createTime; | ||||||
|  |     private DateTime updateTime; | ||||||
|  |     private int sortCode; | ||||||
|  |     private bool isDelete = false; | ||||||
|  |     private string createUser; | ||||||
|  |     private string updateUser; | ||||||
|  |  | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// 创建时间 |     /// 创建时间 | ||||||
|     /// </summary> |     /// </summary> | ||||||
|     [SugarColumn(ColumnDescription = "创建时间", IsOnlyIgnoreUpdate = true, IsNullable = true)] |     [SugarColumn(ColumnDescription = "创建时间", IsOnlyIgnoreUpdate = true, IsNullable = true)] | ||||||
|     [IgnoreExcel] |     [IgnoreExcel] | ||||||
|     [AutoGenerateColumn(Visible = false, IsVisibleWhenAdd = false, IsVisibleWhenEdit = false)] |     [AutoGenerateColumn(Visible = false, IsVisibleWhenAdd = false, IsVisibleWhenEdit = false)] | ||||||
|     public virtual DateTime? CreateTime { get; set; } |     public virtual DateTime CreateTime { get => createTime; set => createTime = value; } | ||||||
|  |  | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// 创建人 |     /// 创建人 | ||||||
| @@ -76,7 +85,7 @@ public abstract class BaseEntity : PrimaryKeyEntity, IBaseEntity | |||||||
|     [IgnoreExcel] |     [IgnoreExcel] | ||||||
|     [NotNull] |     [NotNull] | ||||||
|     [AutoGenerateColumn(Ignore = true)] |     [AutoGenerateColumn(Ignore = true)] | ||||||
|     public virtual string? CreateUser { get; set; } |     public virtual string CreateUser { get => createUser; set => createUser = value; } | ||||||
|  |  | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// 创建者Id |     /// 创建者Id | ||||||
| @@ -84,7 +93,7 @@ public abstract class BaseEntity : PrimaryKeyEntity, IBaseEntity | |||||||
|     [SugarColumn(ColumnDescription = "创建者Id", IsOnlyIgnoreUpdate = true, IsNullable = true)] |     [SugarColumn(ColumnDescription = "创建者Id", IsOnlyIgnoreUpdate = true, IsNullable = true)] | ||||||
|     [IgnoreExcel] |     [IgnoreExcel] | ||||||
|     [AutoGenerateColumn(Ignore = true)] |     [AutoGenerateColumn(Ignore = true)] | ||||||
|     public virtual long CreateUserId { get; set; } |     public virtual long CreateUserId { get => createUserId; set => createUserId = value; } | ||||||
|  |  | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// 软删除 |     /// 软删除 | ||||||
| @@ -92,8 +101,7 @@ public abstract class BaseEntity : PrimaryKeyEntity, IBaseEntity | |||||||
|     [SugarColumn(ColumnDescription = "软删除", IsNullable = true)] |     [SugarColumn(ColumnDescription = "软删除", IsNullable = true)] | ||||||
|     [IgnoreExcel] |     [IgnoreExcel] | ||||||
|     [AutoGenerateColumn(Ignore = true)] |     [AutoGenerateColumn(Ignore = true)] | ||||||
|     public virtual bool IsDelete { get; set; } = false; |     public virtual bool IsDelete { get => isDelete; set => isDelete = value; } | ||||||
|  |  | ||||||
|  |  | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// 更新时间 |     /// 更新时间 | ||||||
| @@ -101,7 +109,7 @@ public abstract class BaseEntity : PrimaryKeyEntity, IBaseEntity | |||||||
|     [SugarColumn(ColumnDescription = "更新时间", IsOnlyIgnoreInsert = true, IsNullable = true)] |     [SugarColumn(ColumnDescription = "更新时间", IsOnlyIgnoreInsert = true, IsNullable = true)] | ||||||
|     [IgnoreExcel] |     [IgnoreExcel] | ||||||
|     [AutoGenerateColumn(Visible = false, IsVisibleWhenAdd = false, IsVisibleWhenEdit = false)] |     [AutoGenerateColumn(Visible = false, IsVisibleWhenAdd = false, IsVisibleWhenEdit = false)] | ||||||
|     public virtual DateTime? UpdateTime { get; set; } |     public virtual DateTime UpdateTime { get => updateTime; set => updateTime = value; } | ||||||
|  |  | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// 更新人 |     /// 更新人 | ||||||
| @@ -109,7 +117,7 @@ public abstract class BaseEntity : PrimaryKeyEntity, IBaseEntity | |||||||
|     [SugarColumn(ColumnDescription = "更新人", IsOnlyIgnoreInsert = true, IsNullable = true)] |     [SugarColumn(ColumnDescription = "更新人", IsOnlyIgnoreInsert = true, IsNullable = true)] | ||||||
|     [IgnoreExcel] |     [IgnoreExcel] | ||||||
|     [AutoGenerateColumn(Ignore = true)] |     [AutoGenerateColumn(Ignore = true)] | ||||||
|     public virtual string? UpdateUser { get; set; } |     public virtual string UpdateUser { get => updateUser; set => updateUser = value; } | ||||||
|  |  | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// 修改者Id |     /// 修改者Id | ||||||
| @@ -117,7 +125,7 @@ public abstract class BaseEntity : PrimaryKeyEntity, IBaseEntity | |||||||
|     [SugarColumn(ColumnDescription = "修改者Id", IsOnlyIgnoreInsert = true, IsNullable = true)] |     [SugarColumn(ColumnDescription = "修改者Id", IsOnlyIgnoreInsert = true, IsNullable = true)] | ||||||
|     [IgnoreExcel] |     [IgnoreExcel] | ||||||
|     [AutoGenerateColumn(Ignore = true)] |     [AutoGenerateColumn(Ignore = true)] | ||||||
|     public virtual long? UpdateUserId { get; set; } |     public virtual long UpdateUserId { get => updateUserId; set => updateUserId = value; } | ||||||
|  |  | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// 排序码 |     /// 排序码 | ||||||
| @@ -125,7 +133,7 @@ public abstract class BaseEntity : PrimaryKeyEntity, IBaseEntity | |||||||
|     [SugarColumn(ColumnDescription = "排序码", IsNullable = true)] |     [SugarColumn(ColumnDescription = "排序码", IsNullable = true)] | ||||||
|     [AutoGenerateColumn(Visible = false, DefaultSort = true, Sortable = true, DefaultSortOrder = SortOrder.Asc)] |     [AutoGenerateColumn(Visible = false, DefaultSort = true, Sortable = true, DefaultSortOrder = SortOrder.Asc)] | ||||||
|     [IgnoreExcel] |     [IgnoreExcel] | ||||||
|     public virtual int? SortCode { get; set; } |     public virtual int SortCode { get => sortCode; set => sortCode = value; } | ||||||
| } | } | ||||||
|  |  | ||||||
| public interface IBaseDataEntity | public interface IBaseDataEntity | ||||||
|   | |||||||
| @@ -161,7 +161,7 @@ public class BaseService<T> : IDataService<T>, IDisposable where T : class, new( | |||||||
|     /// <returns></returns> |     /// <returns></returns> | ||||||
|     protected SqlSugarClient GetDB() |     protected SqlSugarClient GetDB() | ||||||
|     { |     { | ||||||
|         return DbContext.Db.GetConnectionScopeWithAttr<T>().CopyNew(); |         return DbContext.GetDB<T>(); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |  | ||||||
|   | |||||||
| @@ -55,7 +55,7 @@ public static class CodeFirstUtils | |||||||
|             var entityType = seedType.GetInterfaces().First().GetGenericArguments().First();//获取实体类型 |             var entityType = seedType.GetInterfaces().First().GetGenericArguments().First();//获取实体类型 | ||||||
|             var tenantAtt = entityType.GetCustomAttribute<TenantAttribute>();//获取sqlSugar多库特性 |             var tenantAtt = entityType.GetCustomAttribute<TenantAttribute>();//获取sqlSugar多库特性 | ||||||
|             if (tenantAtt == null) continue;//如果没有多库特性就下一个 |             if (tenantAtt == null) continue;//如果没有多库特性就下一个 | ||||||
|             using var db = DbContext.Db.GetConnectionScope(tenantAtt.configId.ToString()).CopyNew();//获取数据库对象 |             using var db = DbContext.GetDB(tenantAtt.configId.ToString());//获取数据库对象 | ||||||
|             var config = DbContext.DbConfigs.FirstOrDefault(u => u.ConfigId.ToString() == tenantAtt.configId.ToString());//获取数据库配置 |             var config = DbContext.DbConfigs.FirstOrDefault(u => u.ConfigId.ToString() == tenantAtt.configId.ToString());//获取数据库配置 | ||||||
|             if (config?.InitSeedData != true) continue; |             if (config?.InitSeedData != true) continue; | ||||||
|             var entityInfo = db.EntityMaintenance.GetEntityInfo(entityType); |             var entityInfo = db.EntityMaintenance.GetEntityInfo(entityType); | ||||||
| @@ -99,7 +99,7 @@ public static class CodeFirstUtils | |||||||
|             var ignoreInit = entityType.GetCustomAttribute<IgnoreInitTableAttribute>();//获取忽略初始化特性 |             var ignoreInit = entityType.GetCustomAttribute<IgnoreInitTableAttribute>();//获取忽略初始化特性 | ||||||
|             if (ignoreInit != null) continue;//如果有忽略初始化特性 |             if (ignoreInit != null) continue;//如果有忽略初始化特性 | ||||||
|             if (tenantAtt == null) continue;//如果没有多库特性就下一个 |             if (tenantAtt == null) continue;//如果没有多库特性就下一个 | ||||||
|             using var db = DbContext.Db.GetConnectionScope(tenantAtt.configId.ToString()).CopyNew();//获取数据库对象 |             using var db = DbContext.GetDB(tenantAtt.configId.ToString());//获取数据库对象 | ||||||
|             var splitTable = entityType.GetCustomAttribute<SplitTableAttribute>();//获取自动分表特性 |             var splitTable = entityType.GetCustomAttribute<SplitTableAttribute>();//获取自动分表特性 | ||||||
|             if (splitTable == null)//如果特性是空 |             if (splitTable == null)//如果特性是空 | ||||||
|                 db.CodeFirst.InitTables(entityType);//普通创建 |                 db.CodeFirst.InitTables(entityType);//普通创建 | ||||||
|   | |||||||
| @@ -24,7 +24,7 @@ public static class DbContext | |||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// SqlSugar 数据库实例 |     /// SqlSugar 数据库实例 | ||||||
|     /// </summary> |     /// </summary> | ||||||
|     public static readonly SqlSugarScope Db; |     private static readonly SqlSugarClient Db; | ||||||
|  |  | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// 读取配置文件中的 ConnectionStrings:Sqlsugar 配置节点 |     /// 读取配置文件中的 ConnectionStrings:Sqlsugar 配置节点 | ||||||
| @@ -37,9 +37,28 @@ public static class DbContext | |||||||
|     /// <returns></returns> |     /// <returns></returns> | ||||||
|     public static SqlSugarClient GetDB<T>() |     public static SqlSugarClient GetDB<T>() | ||||||
|     { |     { | ||||||
|         return Db.GetConnectionScopeWithAttr<T>().CopyNew(); |         return Db.GetConnectionWithAttr<T>().CopyNew(); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     /// <summary> | ||||||
|  |     /// 获取数据库连接 | ||||||
|  |     /// </summary> | ||||||
|  |     /// <returns></returns> | ||||||
|  |     public static SqlSugarClient GetDB() | ||||||
|  |     { | ||||||
|  |         return Db; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /// <summary> | ||||||
|  |     /// 获取数据库连接 | ||||||
|  |     /// </summary> | ||||||
|  |     /// <returns></returns> | ||||||
|  |     public static SqlSugarClient GetDB(string tenant) | ||||||
|  |     { | ||||||
|  |         return Db.GetConnection(tenant).CopyNew();//获取数据库对象 | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |  | ||||||
|     private static ISugarAopService sugarAopService; |     private static ISugarAopService sugarAopService; | ||||||
|     private static ISugarAopService SugarAopService |     private static ISugarAopService SugarAopService | ||||||
|     { |     { | ||||||
| @@ -62,7 +81,7 @@ public static class DbContext | |||||||
|         { |         { | ||||||
|             DbConfigs.ForEach(it => |             DbConfigs.ForEach(it => | ||||||
|             { |             { | ||||||
|                 var sqlsugarScope = db.GetConnectionScope(it.ConfigId);//获取当前库 |                 var sqlsugarScope = db.GetConnection(it.ConfigId);//获取当前库 | ||||||
|                 MoreSetting(sqlsugarScope);//更多设置 |                 MoreSetting(sqlsugarScope);//更多设置 | ||||||
|                 SugarAopService.AopSetting(sqlsugarScope, it.IsShowSql);//aop配置 |                 SugarAopService.AopSetting(sqlsugarScope, it.IsShowSql);//aop配置 | ||||||
|             } |             } | ||||||
| @@ -75,7 +94,7 @@ public static class DbContext | |||||||
|     /// 实体更多配置 |     /// 实体更多配置 | ||||||
|     /// </summary> |     /// </summary> | ||||||
|     /// <param name="db"></param> |     /// <param name="db"></param> | ||||||
|     private static void MoreSetting(SqlSugarScopeProvider db) |     private static void MoreSetting(SqlSugarProvider db) | ||||||
|     { |     { | ||||||
|         db.CurrentConnectionConfig.MoreSettings = new ConnMoreSettings |         db.CurrentConnectionConfig.MoreSettings = new ConnMoreSettings | ||||||
|         { |         { | ||||||
|   | |||||||
| @@ -24,7 +24,7 @@ namespace ThingsGateway.Admin.Application; | |||||||
| /// 种子数据工具类 | /// 种子数据工具类 | ||||||
| /// </summary> | /// </summary> | ||||||
| [ThingsGateway.DependencyInjection.SuppressSniffer] | [ThingsGateway.DependencyInjection.SuppressSniffer] | ||||||
| public static class SeedDataUtil | public static partial class SeedDataUtil | ||||||
| { | { | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// 获取List列表 |     /// 获取List列表 | ||||||
| @@ -53,9 +53,7 @@ public static class SeedDataUtil | |||||||
|         if (!string.IsNullOrEmpty(json))//如果有内容 |         if (!string.IsNullOrEmpty(json))//如果有内容 | ||||||
|         { |         { | ||||||
|             //字段没有数据的替换成null |             //字段没有数据的替换成null | ||||||
|             json = Regex.Replace(json, "\\\"[^\"]+?\\\": \\\"\\\"", match => match.Value.Replace("\"\"", "null")); |             json = SeedDataRegex().Replace(json, match => match.Value.Replace("\"\"", "null")); | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|             var jtoken = JToken.Parse(json); |             var jtoken = JToken.Parse(json); | ||||||
|             jtoken = jtoken.SelectToken("Records") ?? jtoken.SelectToken("RECORDS"); |             jtoken = jtoken.SelectToken("Records") ?? jtoken.SelectToken("RECORDS"); | ||||||
| @@ -96,6 +94,9 @@ public static class SeedDataUtil | |||||||
|  |  | ||||||
|         return seedData; |         return seedData; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     [GeneratedRegex("\\\"[^\"]+?\\\": \\\"\\\"")] | ||||||
|  |     private static partial Regex SeedDataRegex(); | ||||||
| } | } | ||||||
|  |  | ||||||
| /// <summary> | /// <summary> | ||||||
|   | |||||||
| @@ -22,7 +22,8 @@ | |||||||
| 	</ItemGroup> | 	</ItemGroup> | ||||||
|  |  | ||||||
| 	<ItemGroup> | 	<ItemGroup> | ||||||
| 		<ProjectReference Include="..\ThingsGateway.Razor\ThingsGateway.Razor.csproj" /> | 		<PackageReference Include="ThingsGateway.Razor" Version="$(SourceGeneratorVersion)" /> | ||||||
|  | 		<!--<ProjectReference Include="..\ThingsGateway.Razor\ThingsGateway.Razor.csproj" />--> | ||||||
| 		<ProjectReference Include="..\ThingsGateway.SqlSugar\ThingsGateway.SqlSugar.csproj" /> | 		<ProjectReference Include="..\ThingsGateway.SqlSugar\ThingsGateway.SqlSugar.csproj" /> | ||||||
| 		<!--<PackageReference Include="SqlSugarCore" Version="5.1.4.195" />--> | 		<!--<PackageReference Include="SqlSugarCore" Version="5.1.4.195" />--> | ||||||
| 	</ItemGroup> | 	</ItemGroup> | ||||||
|   | |||||||
| @@ -87,8 +87,8 @@ internal static class Penetrates | |||||||
|         // 本地静态方法 |         // 本地静态方法 | ||||||
|         static bool Function(Type type) |         static bool Function(Type type) | ||||||
|         { |         { | ||||||
|             // 排除 OData 控制器 |             //// 排除 OData 控制器 | ||||||
|             if (type.Assembly.GetName().Name.StartsWith("Microsoft.AspNetCore.OData")) return false; |             //if (type.Assembly.GetName().Name.StartsWith("Microsoft.AspNetCore.OData")) return false; | ||||||
|  |  | ||||||
|             // 不能是非公开、基元类型、值类型、抽象类、接口、泛型类 |             // 不能是非公开、基元类型、值类型、抽象类、接口、泛型类 | ||||||
|             if (!type.IsPublic || type.IsPrimitive || type.IsValueType || type.IsAbstract || type.IsInterface || type.IsGenericType) return false; |             if (!type.IsPublic || type.IsPrimitive || type.IsValueType || type.IsAbstract || type.IsInterface || type.IsGenericType) return false; | ||||||
|   | |||||||
| @@ -13,6 +13,7 @@ namespace ThingsGateway.Razor; | |||||||
| /// <summary> | /// <summary> | ||||||
| /// 母版页基类 | /// 母版页基类 | ||||||
| /// </summary> | /// </summary> | ||||||
|  | [BlazorSetParametersAsyncGenerator.DoNotGenerateSetParametersAsync] | ||||||
| public partial class BaseLayout | public partial class BaseLayout | ||||||
| { | { | ||||||
| } | } | ||||||
|   | |||||||
| @@ -11,7 +11,7 @@ | |||||||
| namespace ThingsGateway.Razor; | namespace ThingsGateway.Razor; | ||||||
|  |  | ||||||
| /// <inheritdoc/> | /// <inheritdoc/> | ||||||
| public abstract class WebSiteModuleComponentBase : BootstrapModuleComponentBase | public abstract partial class WebSiteModuleComponentBase : BootstrapModuleComponentBase | ||||||
| { | { | ||||||
|     /// <inheritdoc/> |     /// <inheritdoc/> | ||||||
|     protected override void OnLoadJSModule() |     protected override void OnLoadJSModule() | ||||||
|   | |||||||
| @@ -41,14 +41,16 @@ | |||||||
|  |  | ||||||
|             } |             } | ||||||
|  |  | ||||||
|  |             <PopConfirmButton IsAsync IsDisabled=@_importPreviews.Any(it => it.Value.HasError) Color=Color.Warning class="mt-2" OnConfirm=@(SaveDeviceImport)>@Localizer["Import"]</PopConfirmButton> | ||||||
|  |  | ||||||
|             <Button IsAsync class="mt-2" IsDisabled=@_importPreviews.Any(it => it.Value.HasError) OnClick="() => step.Next()">@Localizer["Next"]</Button> | @*  | ||||||
|  |             <Button IsAsync class="mt-2" IsDisabled=@_importPreviews.Any(it => it.Value.HasError) OnClick="() => step.Next()">@Localizer["Next"]</Button> *@ | ||||||
|  |  | ||||||
|         </div> |         </div> | ||||||
|     </StepItem> |     </StepItem> | ||||||
|     <StepItem Text=@Localizer["Third"] Title=@Localizer["Import"]> | @*     <StepItem Text=@Localizer["Third"] Title=@Localizer["Import"]> | ||||||
|         <PopConfirmButton IsAsync Color=Color.Warning class="mt-2" OnConfirm=@(SaveDeviceImport)>@Localizer["Import"]</PopConfirmButton> |         <PopConfirmButton IsAsync Color=Color.Warning class="mt-2" OnConfirm=@(SaveDeviceImport)>@Localizer["Import"]</PopConfirmButton> | ||||||
|     </StepItem> |     </StepItem> *@ | ||||||
| </Step> | </Step> | ||||||
| @code { | @code { | ||||||
|     [NotNull] |     [NotNull] | ||||||
|   | |||||||
| @@ -8,6 +8,8 @@ | |||||||
| //  QQ群:605534569 | //  QQ群:605534569 | ||||||
| //------------------------------------------------------------------------------ | //------------------------------------------------------------------------------ | ||||||
|  |  | ||||||
|  | using System.Collections.Concurrent; | ||||||
|  |  | ||||||
| namespace ThingsGateway; | namespace ThingsGateway; | ||||||
|  |  | ||||||
| /// <summary> | /// <summary> | ||||||
| @@ -22,7 +24,7 @@ public static class ParallelExtensions | |||||||
|     /// <typeparam name="T">集合元素类型</typeparam> |     /// <typeparam name="T">集合元素类型</typeparam> | ||||||
|     /// <param name="source">要操作的集合</param> |     /// <param name="source">要操作的集合</param> | ||||||
|     /// <param name="body">要执行的操作</param> |     /// <param name="body">要执行的操作</param> | ||||||
|     public static void ParallelForEach<T>(this IEnumerable<T> source, Action<T> body) |     public static void ParallelForEach<T>(this IList<T> source, Action<T> body) | ||||||
|     { |     { | ||||||
|         ParallelOptions options = new(); |         ParallelOptions options = new(); | ||||||
|         options.MaxDegreeOfParallelism = Environment.ProcessorCount; |         options.MaxDegreeOfParallelism = Environment.ProcessorCount; | ||||||
| @@ -39,7 +41,7 @@ public static class ParallelExtensions | |||||||
|     /// <typeparam name="T">集合元素类型</typeparam> |     /// <typeparam name="T">集合元素类型</typeparam> | ||||||
|     /// <param name="source">要操作的集合</param> |     /// <param name="source">要操作的集合</param> | ||||||
|     /// <param name="body">要执行的操作</param> |     /// <param name="body">要执行的操作</param> | ||||||
|     public static void ParallelForEach<T>(this IEnumerable<T> source, Action<T, ParallelLoopState, long> body) |     public static void ParallelForEach<T>(this IList<T> source, Action<T, ParallelLoopState, long> body) | ||||||
|     { |     { | ||||||
|         ParallelOptions options = new(); |         ParallelOptions options = new(); | ||||||
|         options.MaxDegreeOfParallelism = Environment.ProcessorCount; |         options.MaxDegreeOfParallelism = Environment.ProcessorCount; | ||||||
| @@ -57,7 +59,7 @@ public static class ParallelExtensions | |||||||
|     /// <param name="source">要操作的集合</param> |     /// <param name="source">要操作的集合</param> | ||||||
|     /// <param name="body">要执行的操作</param> |     /// <param name="body">要执行的操作</param> | ||||||
|     /// <param name="parallelCount">最大并行度</param> |     /// <param name="parallelCount">最大并行度</param> | ||||||
|     public static void ParallelForEach<T>(this IEnumerable<T> source, Action<T> body, int parallelCount) |     public static void ParallelForEach<T>(this IList<T> source, Action<T> body, int parallelCount) | ||||||
|     { |     { | ||||||
|         // 创建并行操作的选项对象,设置最大并行度为指定的值 |         // 创建并行操作的选项对象,设置最大并行度为指定的值 | ||||||
|         var options = new ParallelOptions(); |         var options = new ParallelOptions(); | ||||||
| @@ -69,6 +71,47 @@ public static class ParallelExtensions | |||||||
|         }); |         }); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |     /// <summary> | ||||||
|  |     /// 使用默认的并行设置执行指定的操作(Partitioner 分区) | ||||||
|  |     /// </summary> | ||||||
|  |     public static void ParallelForEachStreamed<T>(this IEnumerable<T> source, Action<T> body) | ||||||
|  |     { | ||||||
|  |         var partitioner = Partitioner.Create<T>(source, EnumerablePartitionerOptions.NoBuffering); | ||||||
|  |         Parallel.ForEach(partitioner, new ParallelOptions | ||||||
|  |         { | ||||||
|  |             MaxDegreeOfParallelism = Environment.ProcessorCount | ||||||
|  |         }, body); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /// <summary> | ||||||
|  |     /// 使用默认的并行设置执行指定的操作(带索引和 LoopState,Partitioner 分区) | ||||||
|  |     /// </summary> | ||||||
|  |     public static void ParallelForEachStreamed<T>(this IEnumerable<T> source, Action<T, ParallelLoopState, long> body) | ||||||
|  |     { | ||||||
|  |         var partitioner = Partitioner.Create<T>(source, EnumerablePartitionerOptions.NoBuffering); | ||||||
|  |         Parallel.ForEach(partitioner, new ParallelOptions | ||||||
|  |         { | ||||||
|  |             MaxDegreeOfParallelism = Environment.ProcessorCount | ||||||
|  |         }, (item, state, index) => body(item, state, index)); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /// <summary> | ||||||
|  |     /// 执行指定的操作,并指定最大并行度(Partitioner 分区) | ||||||
|  |     /// </summary> | ||||||
|  |     public static void ParallelForEachStreamed<T>(this IEnumerable<T> source, Action<T> body, int parallelCount) | ||||||
|  |     { | ||||||
|  |         var options = new ParallelOptions | ||||||
|  |         { | ||||||
|  |             MaxDegreeOfParallelism = parallelCount <= 0 ? 1 : parallelCount | ||||||
|  |         }; | ||||||
|  |  | ||||||
|  |         var partitioner = Partitioner.Create<T>(source, EnumerablePartitionerOptions.NoBuffering); | ||||||
|  |         Parallel.ForEach(partitioner, options, body); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |  | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// 异步执行指定的操作,并指定最大并行度和取消标志 |     /// 异步执行指定的操作,并指定最大并行度和取消标志 | ||||||
|     /// </summary> |     /// </summary> | ||||||
| @@ -78,7 +121,7 @@ public static class ParallelExtensions | |||||||
|     /// <param name="parallelCount">最大并行度</param> |     /// <param name="parallelCount">最大并行度</param> | ||||||
|     /// <param name="cancellationToken">取消操作的标志</param> |     /// <param name="cancellationToken">取消操作的标志</param> | ||||||
|     /// <returns>表示异步操作的任务</returns> |     /// <returns>表示异步操作的任务</returns> | ||||||
|     public static Task ParallelForEachAsync<T>(this IEnumerable<T> source, Func<T, CancellationToken, ValueTask> body, int parallelCount, CancellationToken cancellationToken = default) |     public static Task ParallelForEachAsync<T>(this IList<T> source, Func<T, CancellationToken, ValueTask> body, int parallelCount, CancellationToken cancellationToken = default) | ||||||
|     { |     { | ||||||
|         // 创建并行操作的选项对象,设置最大并行度和取消标志 |         // 创建并行操作的选项对象,设置最大并行度和取消标志 | ||||||
|         var options = new ParallelOptions(); |         var options = new ParallelOptions(); | ||||||
| @@ -95,8 +138,10 @@ public static class ParallelExtensions | |||||||
|     /// <param name="body">异步执行的操作</param> |     /// <param name="body">异步执行的操作</param> | ||||||
|     /// <param name="cancellationToken">取消操作的标志</param> |     /// <param name="cancellationToken">取消操作的标志</param> | ||||||
|     /// <returns>表示异步操作的任务</returns> |     /// <returns>表示异步操作的任务</returns> | ||||||
|     public static Task ParallelForEachAsync<T>(this IEnumerable<T> source, Func<T, CancellationToken, ValueTask> body, CancellationToken cancellationToken = default) |     public static Task ParallelForEachAsync<T>(this IList<T> source, Func<T, CancellationToken, ValueTask> body, CancellationToken cancellationToken = default) | ||||||
|     { |     { | ||||||
|         return ParallelForEachAsync(source, body, Environment.ProcessorCount, cancellationToken); |         return ParallelForEachAsync(source, body, Environment.ProcessorCount, cancellationToken); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -21,3 +21,4 @@ global using System.Globalization; | |||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| [assembly: SuppressMessage("Reliability", "CA2007", Justification = "<挂起>", Scope = "module")] | [assembly: SuppressMessage("Reliability", "CA2007", Justification = "<挂起>", Scope = "module")] | ||||||
|  | [assembly: BlazorSetParametersAsyncGenerator.GlobalGenerateSetParametersAsync(true)] | ||||||
| @@ -5,10 +5,11 @@ | |||||||
|  |  | ||||||
| using Microsoft.Extensions.Logging; | using Microsoft.Extensions.Logging; | ||||||
|  |  | ||||||
| using System.Collections.Concurrent; |  | ||||||
| using System.Reflection; | using System.Reflection; | ||||||
| using System.Resources; | using System.Resources; | ||||||
|  |  | ||||||
|  | using ThingsGateway.NewLife.Collections; | ||||||
|  |  | ||||||
| namespace ThingsGateway; | namespace ThingsGateway; | ||||||
|  |  | ||||||
| /// <summary> | /// <summary> | ||||||
| @@ -107,14 +108,14 @@ internal class JsonStringLocalizer(Assembly assembly, string typeName, string ba | |||||||
|         return ret; |         return ret; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     private readonly ConcurrentDictionary<string, object?> _missingManifestCache = []; |     private readonly ConcurrentHashSet<string> _missingManifestCache = []; | ||||||
|     private string? GetStringFromJson(string name) |     private string? GetStringFromJson(string name) | ||||||
|     { |     { | ||||||
|         // get string from json localization file |         // get string from json localization file | ||||||
|         var localizerStrings = MegerResolveLocalizers(CacheManager.GetAllStringsByTypeName(Assembly, typeName)); |         var localizerStrings = MegerResolveLocalizers(CacheManager.GetAllStringsByTypeName(Assembly, typeName)); | ||||||
|         var cacheKey = $"name={name}&culture={CultureInfo.CurrentUICulture.Name}"; |         var cacheKey = $"name={name}&culture={CultureInfo.CurrentUICulture.Name}"; | ||||||
|         string? ret = null; |         string? ret = null; | ||||||
|         if (!_missingManifestCache.ContainsKey(cacheKey)) |         if (!_missingManifestCache.Contain(cacheKey)) | ||||||
|         { |         { | ||||||
|             var l = localizerStrings.Find(i => i.Name == name); |             var l = localizerStrings.Find(i => i.Name == name); | ||||||
|             if (l is { ResourceNotFound: false }) |             if (l is { ResourceNotFound: false }) | ||||||
| @@ -161,6 +162,7 @@ internal class JsonStringLocalizer(Assembly assembly, string typeName, string ba | |||||||
|     private List<LocalizedString> MegerResolveLocalizers(IEnumerable<LocalizedString>? localizerStrings) |     private List<LocalizedString> MegerResolveLocalizers(IEnumerable<LocalizedString>? localizerStrings) | ||||||
|     { |     { | ||||||
|         var localizers = new List<LocalizedString>(CacheManager.GetTypeStringsFromResolve(typeName)); |         var localizers = new List<LocalizedString>(CacheManager.GetTypeStringsFromResolve(typeName)); | ||||||
|  |  | ||||||
|         if (localizerStrings != null) |         if (localizerStrings != null) | ||||||
|         { |         { | ||||||
|             localizers.AddRange(localizerStrings); |             localizers.AddRange(localizerStrings); | ||||||
| @@ -175,7 +177,7 @@ internal class JsonStringLocalizer(Assembly assembly, string typeName, string ba | |||||||
|         { |         { | ||||||
|             Logger.LogInformation("{JsonStringLocalizerName} searched for '{Name}' in '{TypeName}' with culture '{CultureName}' not found.", nameof(JsonStringLocalizer), name, typeName, CultureInfo.CurrentUICulture.Name); |             Logger.LogInformation("{JsonStringLocalizerName} searched for '{Name}' in '{TypeName}' with culture '{CultureName}' not found.", nameof(JsonStringLocalizer), name, typeName, CultureInfo.CurrentUICulture.Name); | ||||||
|         } |         } | ||||||
|         _missingManifestCache.TryAdd($"name={name}&culture={CultureInfo.CurrentUICulture.Name}", null); |         _missingManifestCache.TryAdd($"name={name}&culture={CultureInfo.CurrentUICulture.Name}"); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     private List<LocalizedString>? _allLocalizerdStrings; |     private List<LocalizedString>? _allLocalizerdStrings; | ||||||
|   | |||||||
| @@ -1,9 +1,10 @@ | |||||||
| <Project Sdk="Microsoft.NET.Sdk.Razor"> | <Project Sdk="Microsoft.NET.Sdk.Razor"> | ||||||
|  |  | ||||||
| 	<Import Project="$(SolutionDir)Version.props" /> |  | ||||||
| 	<Import Project="$(SolutionDir)PackNuget.props" /> | 	<Import Project="$(SolutionDir)PackNuget.props" /> | ||||||
| 	<PropertyGroup> | 	<PropertyGroup> | ||||||
| 		<TargetFrameworks>net8.0;</TargetFrameworks> | 		<TargetFrameworks>net8.0</TargetFrameworks> | ||||||
|  | 		<Version>$(SourceGeneratorVersion)</Version> | ||||||
|  | 		<!--<UseRazorSourceGenerator>false</UseRazorSourceGenerator>--> | ||||||
| 	</PropertyGroup> | 	</PropertyGroup> | ||||||
| 	<ItemGroup> | 	<ItemGroup> | ||||||
| 		<PackageReference Include="BootstrapBlazor.FontAwesome" Version="9.0.2" /> | 		<PackageReference Include="BootstrapBlazor.FontAwesome" Version="9.0.2" /> | ||||||
| @@ -12,12 +13,11 @@ | |||||||
| 	</ItemGroup> | 	</ItemGroup> | ||||||
|  |  | ||||||
| 	<ItemGroup> | 	<ItemGroup> | ||||||
| 		<Content Remove="Locales\*.json" /> |  | ||||||
| 		<EmbeddedResource Include="Locales\*.json"> | 		<EmbeddedResource Include="Locales\*.json"> | ||||||
| 			<CopyToOutputDirectory>Never</CopyToOutputDirectory> | 			<CopyToOutputDirectory>Never</CopyToOutputDirectory> | ||||||
| 		</EmbeddedResource> | 		</EmbeddedResource> | ||||||
| 	</ItemGroup> | 	</ItemGroup> | ||||||
| 	 |  | ||||||
|  |  | ||||||
| 	<ItemGroup> | 	<ItemGroup> | ||||||
| 		<None Include="..\README.md" Pack="true" PackagePath="\" /> | 		<None Include="..\README.md" Pack="true" PackagePath="\" /> | ||||||
| @@ -30,6 +30,16 @@ | |||||||
| 		<ProjectReference Include="..\ThingsGateway.Furion\ThingsGateway.Furion.csproj" /> | 		<ProjectReference Include="..\ThingsGateway.Furion\ThingsGateway.Furion.csproj" /> | ||||||
| 	</ItemGroup> | 	</ItemGroup> | ||||||
|  |  | ||||||
|  |  | ||||||
|  | 	<ItemGroup Condition="'$(Configuration)' != 'Debug' "> | ||||||
|  | 		<None Include="..\BlazorSetParametersAsyncGenerator\tools\*.ps1" PackagePath="tools" Pack="true" Visible="false" /> | ||||||
|  | 		<None Include="..\BlazorSetParametersAsyncGenerator\bin\$(Configuration)\netstandard2.0\BlazorSetParametersAsyncGenerator.dll" PackagePath="analyzers\dotnet\cs" Pack="true" Visible="false" /> | ||||||
|  | 	</ItemGroup> | ||||||
|  |  | ||||||
|  | 	<ItemGroup> | ||||||
|  | 		<ProjectReference Include="..\BlazorSetParametersAsyncGenerator\BlazorSetParametersAsyncGenerator.csproj" PrivateAssets="all" OutputItemType="Analyzer" /> | ||||||
|  | 	</ItemGroup> | ||||||
|  |  | ||||||
| </Project> | </Project> | ||||||
|  |  | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1,5 +1,4 @@ | |||||||
|  | @using System.Net.Http | ||||||
| @using System.Net.Http |  | ||||||
| @using System.Net.Http.Json | @using System.Net.Http.Json | ||||||
| @using Microsoft.AspNetCore.Components.Forms | @using Microsoft.AspNetCore.Components.Forms | ||||||
| @using Microsoft.AspNetCore.Components.Routing | @using Microsoft.AspNetCore.Components.Routing | ||||||
| @@ -16,4 +15,5 @@ | |||||||
| @using BootstrapBlazor.Components | @using BootstrapBlazor.Components | ||||||
|  |  | ||||||
|  |  | ||||||
| @using ThingsGateway.Razor; | @using ThingsGateway.Razor | ||||||
|  |  | ||||||
|   | |||||||
| @@ -7,8 +7,8 @@ namespace ThingsGateway.SqlSugar | |||||||
|     /// </summary> |     /// </summary> | ||||||
|     public partial class SqlSugarScope : ISqlSugarClient, ITenant |     public partial class SqlSugarScope : ISqlSugarClient, ITenant | ||||||
|     { |     { | ||||||
|         private List<ConnectionConfig> _configs; |         protected List<ConnectionConfig> _configs; | ||||||
|         private Action<SqlSugarClient> _configAction; |         protected Action<SqlSugarClient> _configAction; | ||||||
|  |  | ||||||
|         protected virtual SqlSugarClient GetContext() |         protected virtual SqlSugarClient GetContext() | ||||||
|         { |         { | ||||||
|   | |||||||
| @@ -161,7 +161,7 @@ namespace ThingsGateway.SqlSugar | |||||||
|             } |             } | ||||||
|             else if (db is SqlSugarScope) |             else if (db is SqlSugarScope) | ||||||
|             { |             { | ||||||
|                 db = (db as SqlSugarScope).ScopedContext.Context; |                 db = (db as SqlSugarScope).Context; | ||||||
|             } |             } | ||||||
|             if (!(db is SqlSugarProvider)) |             if (!(db is SqlSugarProvider)) | ||||||
|             { |             { | ||||||
|   | |||||||
| @@ -1,4 +1,6 @@ | |||||||
| namespace ThingsGateway.SqlSugar | using ThingsGateway.NewLife.Caching; | ||||||
|  |  | ||||||
|  | namespace ThingsGateway.SqlSugar | ||||||
| { | { | ||||||
|     public class ReflectionInoCacheService : ICacheService |     public class ReflectionInoCacheService : ICacheService | ||||||
|     { |     { | ||||||
| @@ -6,6 +8,7 @@ | |||||||
|         { |         { | ||||||
|             ReflectionInoCore<V>.GetInstance().Add(key, value); |             ReflectionInoCore<V>.GetInstance().Add(key, value); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         public void Add<V>(string key, V value, int cacheDurationInSeconds) |         public void Add<V>(string key, V value, int cacheDurationInSeconds) | ||||||
|         { |         { | ||||||
|             ReflectionInoCore<V>.GetInstance().Add(key, value, cacheDurationInSeconds); |             ReflectionInoCore<V>.GetInstance().Add(key, value, cacheDurationInSeconds); | ||||||
| @@ -38,7 +41,7 @@ | |||||||
|     } |     } | ||||||
|     public class ReflectionInoCore<V> |     public class ReflectionInoCore<V> | ||||||
|     { |     { | ||||||
|         readonly System.Collections.Concurrent.ConcurrentDictionary<string, V> InstanceCache = new System.Collections.Concurrent.ConcurrentDictionary<string, V>(); |         readonly MemoryCache InstanceCache = new() { Expire = 1800 }; | ||||||
|         private static ReflectionInoCore<V> _instance = null; |         private static ReflectionInoCore<V> _instance = null; | ||||||
|         private static readonly object _instanceLock = new object(); |         private static readonly object _instanceLock = new object(); | ||||||
|         private ReflectionInoCore() { } |         private ReflectionInoCore() { } | ||||||
| @@ -58,10 +61,7 @@ | |||||||
|  |  | ||||||
|         public V Get(string key) |         public V Get(string key) | ||||||
|         { |         { | ||||||
|             if (this.ContainsKey(key)) |             return this.InstanceCache.Get<V>(key); | ||||||
|                 return this.InstanceCache[key]; |  | ||||||
|             else |  | ||||||
|                 return default(V); |  | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         public static ReflectionInoCore<V> GetInstance() |         public static ReflectionInoCore<V> GetInstance() | ||||||
| @@ -89,8 +89,7 @@ | |||||||
|  |  | ||||||
|         public void Remove(string key) |         public void Remove(string key) | ||||||
|         { |         { | ||||||
|             V val; |             this.InstanceCache.Remove(key); | ||||||
|             this.InstanceCache.TryRemove(key, out val); |  | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         public void RemoveAllCache() |         public void RemoveAllCache() | ||||||
| @@ -108,13 +107,7 @@ | |||||||
|  |  | ||||||
|         public V GetOrCreate(string cacheKey, Func<V> create) |         public V GetOrCreate(string cacheKey, Func<V> create) | ||||||
|         { |         { | ||||||
|             if (this.ContainsKey(cacheKey)) return Get(cacheKey); |             return InstanceCache.GetOrAdd<V>(cacheKey, (a) => create()); | ||||||
|             else |  | ||||||
|             { |  | ||||||
|                 var reval = create(); |  | ||||||
|                 this.Add(cacheKey, reval); |  | ||||||
|                 return reval; |  | ||||||
|             } |  | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|     public static class ReflectionInoHelper |     public static class ReflectionInoHelper | ||||||
|   | |||||||
| @@ -28,7 +28,8 @@ namespace ThingsGateway.SqlSugar | |||||||
|             _configs = configs; |             _configs = configs; | ||||||
|             this._configAction = configAction; |             this._configAction = configAction; | ||||||
|         } |         } | ||||||
|         public SqlSugarClient ScopedContext { get { return GetContext(); } } |         public ISqlSugarClient Context => ScopedContext.Context; | ||||||
|  |         protected SqlSugarClient ScopedContext { get { return GetContext(); } } | ||||||
|         public SugarActionType SugarActionType { get => ScopedContext.SugarActionType; set => ScopedContext.SugarActionType = value; } |         public SugarActionType SugarActionType { get => ScopedContext.SugarActionType; set => ScopedContext.SugarActionType = value; } | ||||||
|         public MappingTableList MappingTables { get => ScopedContext.MappingTables; set => ScopedContext.MappingTables = value; } |         public MappingTableList MappingTables { get => ScopedContext.MappingTables; set => ScopedContext.MappingTables = value; } | ||||||
|         public MappingColumnList MappingColumns { get => ScopedContext.MappingColumns; set => ScopedContext.MappingColumns = value; } |         public MappingColumnList MappingColumns { get => ScopedContext.MappingColumns; set => ScopedContext.MappingColumns = value; } | ||||||
|   | |||||||
							
								
								
									
										92
									
								
								src/Base1.sln
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										92
									
								
								src/Base1.sln
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,92 @@ | |||||||
|  | Microsoft Visual Studio Solution File, Format Version 12.00 | ||||||
|  | # Visual Studio Version 17 | ||||||
|  | VisualStudioVersion = 17.9.34622.214 | ||||||
|  | MinimumVisualStudioVersion = 10.0.40219.1 | ||||||
|  | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "other", "other", "{0B748352-5D27-4F14-8A20-364034C72867}" | ||||||
|  | 	ProjectSection(SolutionItems) = preProject | ||||||
|  | 		.editorconfig = .editorconfig | ||||||
|  | 		Directory.Build.props = Directory.Build.props | ||||||
|  | 		..\git_pull.bat = ..\git_pull.bat | ||||||
|  | 		..\README.md = ..\README.md | ||||||
|  | 		..\README.zh-CN.md = ..\README.zh-CN.md | ||||||
|  | 		Version.props = Version.props | ||||||
|  | 	EndProjectSection | ||||||
|  | EndProject | ||||||
|  | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Foundation", "Foundation", "{2AC600BB-4325-4E0A-93A7-B1F53C8E2CA7}" | ||||||
|  | EndProject | ||||||
|  | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ThingsGateway.CSScript", "Foundation\ThingsGateway.CSScript\ThingsGateway.CSScript.csproj", "{506232CE-0FB6-4ACB-96DE-C8C8D075A642}" | ||||||
|  | EndProject | ||||||
|  | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ThingsGateway.Foundation", "Foundation\ThingsGateway.Foundation\ThingsGateway.Foundation.csproj", "{9D49F8E2-A82C-4E36-8F54-4F45BF3E47C0}" | ||||||
|  | EndProject | ||||||
|  | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ThingsGateway.Foundation.SourceGenerator", "Foundation\ThingsGateway.Foundation.SourceGenerator\ThingsGateway.Foundation.SourceGenerator.csproj", "{E325A64C-2B72-4DD0-8A6C-229B29FB95EB}" | ||||||
|  | EndProject | ||||||
|  | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ThingsGateway.Foundation.Variable", "Foundation\ThingsGateway.Foundation.Variable\ThingsGateway.Foundation.Variable.csproj", "{8EE037EC-ED21-42A0-BE1F-219E9886E43A}" | ||||||
|  | EndProject | ||||||
|  | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Admin", "Admin", "{72C65578-92A5-4E99-9779-27835B12B32F}" | ||||||
|  | EndProject | ||||||
|  | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ThingsGateway.Furion", "Admin\ThingsGateway.Furion\ThingsGateway.Furion.csproj", "{D56A6669-28C5-4A99-89CF-356C7964B8E1}" | ||||||
|  | EndProject | ||||||
|  | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ThingsGateway.NewLife.X", "Admin\ThingsGateway.NewLife.X\ThingsGateway.NewLife.X.csproj", "{8198BEEA-AC24-4D70-B3D7-2601A803610B}" | ||||||
|  | EndProject | ||||||
|  | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ThingsGateway.Razor", "Admin\ThingsGateway.Razor\ThingsGateway.Razor.csproj", "{93C0CC9A-500E-419A-B896-F36225377D43}" | ||||||
|  | EndProject | ||||||
|  | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlazorSetParametersAsyncGenerator", "Admin\BlazorSetParametersAsyncGenerator\BlazorSetParametersAsyncGenerator.csproj", "{4C412EC1-8501-8211-5A57-3CEEE7EEA6B3}" | ||||||
|  | EndProject | ||||||
|  | Global | ||||||
|  | 	GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||||||
|  | 		Debug|Any CPU = Debug|Any CPU | ||||||
|  | 		Release|Any CPU = Release|Any CPU | ||||||
|  | 	EndGlobalSection | ||||||
|  | 	GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||||||
|  | 		{506232CE-0FB6-4ACB-96DE-C8C8D075A642}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||||||
|  | 		{506232CE-0FB6-4ACB-96DE-C8C8D075A642}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||||||
|  | 		{506232CE-0FB6-4ACB-96DE-C8C8D075A642}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||||||
|  | 		{506232CE-0FB6-4ACB-96DE-C8C8D075A642}.Release|Any CPU.Build.0 = Release|Any CPU | ||||||
|  | 		{9D49F8E2-A82C-4E36-8F54-4F45BF3E47C0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||||||
|  | 		{9D49F8E2-A82C-4E36-8F54-4F45BF3E47C0}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||||||
|  | 		{9D49F8E2-A82C-4E36-8F54-4F45BF3E47C0}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||||||
|  | 		{9D49F8E2-A82C-4E36-8F54-4F45BF3E47C0}.Release|Any CPU.Build.0 = Release|Any CPU | ||||||
|  | 		{E325A64C-2B72-4DD0-8A6C-229B29FB95EB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||||||
|  | 		{E325A64C-2B72-4DD0-8A6C-229B29FB95EB}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||||||
|  | 		{E325A64C-2B72-4DD0-8A6C-229B29FB95EB}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||||||
|  | 		{E325A64C-2B72-4DD0-8A6C-229B29FB95EB}.Release|Any CPU.Build.0 = Release|Any CPU | ||||||
|  | 		{8EE037EC-ED21-42A0-BE1F-219E9886E43A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||||||
|  | 		{8EE037EC-ED21-42A0-BE1F-219E9886E43A}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||||||
|  | 		{8EE037EC-ED21-42A0-BE1F-219E9886E43A}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||||||
|  | 		{8EE037EC-ED21-42A0-BE1F-219E9886E43A}.Release|Any CPU.Build.0 = Release|Any CPU | ||||||
|  | 		{D56A6669-28C5-4A99-89CF-356C7964B8E1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||||||
|  | 		{D56A6669-28C5-4A99-89CF-356C7964B8E1}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||||||
|  | 		{D56A6669-28C5-4A99-89CF-356C7964B8E1}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||||||
|  | 		{D56A6669-28C5-4A99-89CF-356C7964B8E1}.Release|Any CPU.Build.0 = Release|Any CPU | ||||||
|  | 		{8198BEEA-AC24-4D70-B3D7-2601A803610B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||||||
|  | 		{8198BEEA-AC24-4D70-B3D7-2601A803610B}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||||||
|  | 		{8198BEEA-AC24-4D70-B3D7-2601A803610B}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||||||
|  | 		{8198BEEA-AC24-4D70-B3D7-2601A803610B}.Release|Any CPU.Build.0 = Release|Any CPU | ||||||
|  | 		{93C0CC9A-500E-419A-B896-F36225377D43}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||||||
|  | 		{93C0CC9A-500E-419A-B896-F36225377D43}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||||||
|  | 		{93C0CC9A-500E-419A-B896-F36225377D43}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||||||
|  | 		{93C0CC9A-500E-419A-B896-F36225377D43}.Release|Any CPU.Build.0 = Release|Any CPU | ||||||
|  | 		{4C412EC1-8501-8211-5A57-3CEEE7EEA6B3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||||||
|  | 		{4C412EC1-8501-8211-5A57-3CEEE7EEA6B3}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||||||
|  | 		{4C412EC1-8501-8211-5A57-3CEEE7EEA6B3}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||||||
|  | 		{4C412EC1-8501-8211-5A57-3CEEE7EEA6B3}.Release|Any CPU.Build.0 = Release|Any CPU | ||||||
|  | 	EndGlobalSection | ||||||
|  | 	GlobalSection(SolutionProperties) = preSolution | ||||||
|  | 		HideSolutionNode = FALSE | ||||||
|  | 	EndGlobalSection | ||||||
|  | 	GlobalSection(NestedProjects) = preSolution | ||||||
|  | 		{506232CE-0FB6-4ACB-96DE-C8C8D075A642} = {2AC600BB-4325-4E0A-93A7-B1F53C8E2CA7} | ||||||
|  | 		{9D49F8E2-A82C-4E36-8F54-4F45BF3E47C0} = {2AC600BB-4325-4E0A-93A7-B1F53C8E2CA7} | ||||||
|  | 		{E325A64C-2B72-4DD0-8A6C-229B29FB95EB} = {2AC600BB-4325-4E0A-93A7-B1F53C8E2CA7} | ||||||
|  | 		{8EE037EC-ED21-42A0-BE1F-219E9886E43A} = {2AC600BB-4325-4E0A-93A7-B1F53C8E2CA7} | ||||||
|  | 		{D56A6669-28C5-4A99-89CF-356C7964B8E1} = {72C65578-92A5-4E99-9779-27835B12B32F} | ||||||
|  | 		{8198BEEA-AC24-4D70-B3D7-2601A803610B} = {72C65578-92A5-4E99-9779-27835B12B32F} | ||||||
|  | 		{93C0CC9A-500E-419A-B896-F36225377D43} = {72C65578-92A5-4E99-9779-27835B12B32F} | ||||||
|  | 		{4C412EC1-8501-8211-5A57-3CEEE7EEA6B3} = {72C65578-92A5-4E99-9779-27835B12B32F} | ||||||
|  | 	EndGlobalSection | ||||||
|  | 	GlobalSection(ExtensibilityGlobals) = postSolution | ||||||
|  | 		RESX_NeutralResourcesLanguage = zh-Hans | ||||||
|  | 		RESX_Rules = {"EnabledRules":[]} | ||||||
|  | 		SolutionGuid = {199B1B96-4F56-4828-9531-813BA02DB282} | ||||||
|  | 	EndGlobalSection | ||||||
|  | EndGlobal | ||||||
| @@ -1,9 +1,10 @@ | |||||||
| <Project> | <Project> | ||||||
|  |  | ||||||
| 	<PropertyGroup> | 	<PropertyGroup> | ||||||
| 		<PluginVersion>10.7.58</PluginVersion> | 		<PluginVersion>10.8.0</PluginVersion> | ||||||
| 		<ProPluginVersion>10.7.58</ProPluginVersion> | 		<ProPluginVersion>10.8.0</ProPluginVersion> | ||||||
| 		<AuthenticationVersion>2.6.0</AuthenticationVersion> | 		<AuthenticationVersion>2.8.0</AuthenticationVersion> | ||||||
|  | 		<SourceGeneratorVersion>10.8.0</SourceGeneratorVersion> | ||||||
| 		<NET8Version>8.0.17</NET8Version> | 		<NET8Version>8.0.17</NET8Version> | ||||||
| 		<NET9Version>9.0.6</NET9Version> | 		<NET9Version>9.0.6</NET9Version> | ||||||
| 	</PropertyGroup> | 	</PropertyGroup> | ||||||
| @@ -24,7 +25,7 @@ | |||||||
| 		<AnalysisModeStyle>None</AnalysisModeStyle> | 		<AnalysisModeStyle>None</AnalysisModeStyle> | ||||||
|  |  | ||||||
| 		<NoWarn> | 		<NoWarn> | ||||||
| 			CS8603;CS8618;CS1591;CS8625;CS8602;CS8604;CS8600;CS8601;CS8714;CS8619;CS8629;CS8765;CS8634;CS8621;CS8767;CS8633;CS8620;CS8610;CS8631;CS8605;CS8622;CS8613;NU5100;NU5104;NU1903;NU1902;CA1813;CA1852;CA1822;CA2100;CA2008;CA1812;CA1508;CA1512;CA1513;CA1810;CA1814;CA1815;CA1835;CA1819;CA1823;CA2002;CA5350;CA5351;CA5358;CA5384;CA5392;CA1805;CA1851;CA1510;CA5401;CA2022;CA1848;CA2000;CA5394;CA3003;CA1515;CA1849;CA1863 | 			CS8603;CS8618;CS1591;CS8625;CS8602;CS8604;CS8600;CS8601;CS8714;CS8619;CS8629;CS8765;CS8634;CS8621;CS8767;CS8633;CS8620;CS8610;CS8631;CS8605;CS8622;CS8613;NU5100;NU5104;NU1903;NU1902;CA1813;CA1852;CA1822;CA2100;CA2008;CA1812;CA1508;CA1512;CA1513;CA1810;CA1814;CA1815;CA1835;CA1819;CA1823;CA2002;CA5350;CA5351;CA5358;CA5384;CA5392;CA1805;CA1851;CA1510;CA5401;CA2022;CA1848;CA2000;CA5394;CA3003;CA1515;CA1849;CA1863;CA5400 | ||||||
| 		</NoWarn> | 		</NoWarn> | ||||||
| 		<TargetFrameworks>net8.0;</TargetFrameworks> | 		<TargetFrameworks>net8.0;</TargetFrameworks> | ||||||
| 		<LangVersion>13.0</LangVersion> | 		<LangVersion>13.0</LangVersion> | ||||||
|   | |||||||
| @@ -36,6 +36,7 @@ | |||||||
|                     <EditorItem @bind-Field="@context.StopBits" Ignore=@(context.ChannelType!=ChannelTypeEnum.SerialPort) /> |                     <EditorItem @bind-Field="@context.StopBits" Ignore=@(context.ChannelType!=ChannelTypeEnum.SerialPort) /> | ||||||
|                     <EditorItem @bind-Field="@context.DtrEnable" Ignore=@(context.ChannelType!=ChannelTypeEnum.SerialPort) /> |                     <EditorItem @bind-Field="@context.DtrEnable" Ignore=@(context.ChannelType!=ChannelTypeEnum.SerialPort) /> | ||||||
|                     <EditorItem @bind-Field="@context.RtsEnable" Ignore=@(context.ChannelType!=ChannelTypeEnum.SerialPort) /> |                     <EditorItem @bind-Field="@context.RtsEnable" Ignore=@(context.ChannelType!=ChannelTypeEnum.SerialPort) /> | ||||||
|  |                     <EditorItem @bind-Field="@context.StreamAsync" Ignore=@(context.ChannelType!=ChannelTypeEnum.SerialPort) /> | ||||||
|  |  | ||||||
|  |  | ||||||
|                     <EditorItem @bind-Field="@context.CacheTimeout" Ignore=@(context.ChannelType==ChannelTypeEnum.UdpSession||context.ChannelType==ChannelTypeEnum.Other) /> |                     <EditorItem @bind-Field="@context.CacheTimeout" Ignore=@(context.ChannelType==ChannelTypeEnum.UdpSession||context.ChannelType==ChannelTypeEnum.Other) /> | ||||||
|   | |||||||
| @@ -1,6 +1,7 @@ | |||||||
| @using Microsoft.AspNetCore.Components.Web; | @using Microsoft.AspNetCore.Components.Web; | ||||||
| @using Microsoft.AspNetCore.Components.Web.Virtualization | @using Microsoft.AspNetCore.Components.Web.Virtualization | ||||||
| @using Microsoft.JSInterop; | @using Microsoft.JSInterop; | ||||||
|  | @using ThingsGateway.Foundation | ||||||
| @using ThingsGateway.NewLife.Threading | @using ThingsGateway.NewLife.Threading | ||||||
| @using ThingsGateway.Extension; | @using ThingsGateway.Extension; | ||||||
| @using BootstrapBlazor.Components | @using BootstrapBlazor.Components | ||||||
|   | |||||||
| @@ -228,15 +228,3 @@ public partial class LogConsole : IDisposable | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| public class LogMessage |  | ||||||
| { |  | ||||||
|     public LogMessage(int level, string message) |  | ||||||
|     { |  | ||||||
|         Level = level; |  | ||||||
|         Message = message; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public int Level { get; set; } |  | ||||||
|     public string Message { get; set; } |  | ||||||
| } |  | ||||||
|   | |||||||
| @@ -0,0 +1,25 @@ | |||||||
|  | //------------------------------------------------------------------------------ | ||||||
|  | //  此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充 | ||||||
|  | //  此代码版权(除特别声明外的代码)归作者本人Diego所有 | ||||||
|  | //  源代码使用协议遵循本仓库的开源协议及附加协议 | ||||||
|  | //  Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway | ||||||
|  | //  Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway | ||||||
|  | //  使用文档:https://thingsgateway.cn/ | ||||||
|  | //  QQ群:605534569 | ||||||
|  | //------------------------------------------------------------------------------ | ||||||
|  |  | ||||||
|  | namespace ThingsGateway.Foundation; | ||||||
|  |  | ||||||
|  | /// <inheritdoc/> | ||||||
|  |  | ||||||
|  | public class LogMessage | ||||||
|  | { | ||||||
|  |     public LogMessage(int level, string message) | ||||||
|  |     { | ||||||
|  |         Level = level; | ||||||
|  |         Message = message; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public int Level { get; set; } | ||||||
|  |     public string Message { get; set; } | ||||||
|  | } | ||||||
| @@ -18,3 +18,5 @@ global using System.Diagnostics.CodeAnalysis; | |||||||
| global using ThingsGateway.Razor; | global using ThingsGateway.Razor; | ||||||
| 
 | 
 | ||||||
| [assembly: SuppressMessage("Reliability", "CA2007", Justification = "<挂起>", Scope = "module")] | [assembly: SuppressMessage("Reliability", "CA2007", Justification = "<挂起>", Scope = "module")] | ||||||
|  | 
 | ||||||
|  | [assembly: BlazorSetParametersAsyncGenerator.GlobalGenerateSetParametersAsync(true)] | ||||||
| @@ -23,6 +23,7 @@ | |||||||
|     "PortName": "COM Port", |     "PortName": "COM Port", | ||||||
|     "RemoteUrl": "Remote IP Address", |     "RemoteUrl": "Remote IP Address", | ||||||
|     "RtsEnable": "Rts", |     "RtsEnable": "Rts", | ||||||
|  |     "StreamAsync": "StreamAsync", | ||||||
|     "SaveChannel": "Add/Modify Channel", |     "SaveChannel": "Add/Modify Channel", | ||||||
|     "StopBits": "Stop Bits" |     "StopBits": "Stop Bits" | ||||||
|   }, |   }, | ||||||
| @@ -80,6 +81,7 @@ | |||||||
|     "PortName": "PortName", |     "PortName": "PortName", | ||||||
|     "RemoteUrl": "RemoteUrl", |     "RemoteUrl": "RemoteUrl", | ||||||
|     "RtsEnable": "RtsEnable", |     "RtsEnable": "RtsEnable", | ||||||
|  |     "StreamAsync": "StreamAsync", | ||||||
|     "StopBits": "StopBits" |     "StopBits": "StopBits" | ||||||
|   } |   } | ||||||
| } | } | ||||||
| @@ -23,6 +23,7 @@ | |||||||
|     "PortName": "COM口", |     "PortName": "COM口", | ||||||
|     "RemoteUrl": "远程url", |     "RemoteUrl": "远程url", | ||||||
|     "RtsEnable": "Rts", |     "RtsEnable": "Rts", | ||||||
|  |     "StreamAsync": "串口流读写", | ||||||
|     "SaveChannel": "添加/修改通道", |     "SaveChannel": "添加/修改通道", | ||||||
|     "StopBits": "停止位" |     "StopBits": "停止位" | ||||||
|   }, |   }, | ||||||
| @@ -80,6 +81,7 @@ | |||||||
|     "PortName": "COM口", |     "PortName": "COM口", | ||||||
|     "RemoteUrl": "远程url", |     "RemoteUrl": "远程url", | ||||||
|     "RtsEnable": "Rts", |     "RtsEnable": "Rts", | ||||||
|  |     "StreamAsync": "串口流读写", | ||||||
|     "StopBits": "停止位" |     "StopBits": "停止位" | ||||||
|   } |   } | ||||||
| } | } | ||||||
| @@ -4,9 +4,11 @@ | |||||||
| 	<Import Project="$(SolutionDir)PackNuget.props" /> | 	<Import Project="$(SolutionDir)PackNuget.props" /> | ||||||
| 	<PropertyGroup> | 	<PropertyGroup> | ||||||
| 		<TargetFrameworks>net8.0;</TargetFrameworks> | 		<TargetFrameworks>net8.0;</TargetFrameworks> | ||||||
|  | 		<!--<UseRazorSourceGenerator>false</UseRazorSourceGenerator>--> | ||||||
| 	</PropertyGroup> | 	</PropertyGroup> | ||||||
| 	<ItemGroup> | 	<ItemGroup> | ||||||
| 		<ProjectReference Include="..\..\Admin\ThingsGateway.Razor\ThingsGateway.Razor.csproj" /> | 		<PackageReference Include="ThingsGateway.Razor" Version="$(SourceGeneratorVersion)" /> | ||||||
|  | 		<!--<ProjectReference Include="..\..\Admin\ThingsGateway.Razor\ThingsGateway.Razor.csproj" />--> | ||||||
| 		<ProjectReference Include="..\ThingsGateway.Foundation\ThingsGateway.Foundation.csproj" /> | 		<ProjectReference Include="..\ThingsGateway.Foundation\ThingsGateway.Foundation.csproj" /> | ||||||
| 	</ItemGroup> | 	</ItemGroup> | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1,10 +1,10 @@ | |||||||
| <Project Sdk="Microsoft.NET.Sdk"> | <Project Sdk="Microsoft.NET.Sdk"> | ||||||
|  |  | ||||||
| 	<Import Project="$(SolutionDir)PackNuget.props" /> | 	<Import Project="$(SolutionDir)PackNuget.props" /> | ||||||
| 	<Import Project="$(SolutionDir)Version.props" /> |  | ||||||
|  |  | ||||||
| 	<PropertyGroup> | 	<PropertyGroup> | ||||||
| 		<TargetFrameworks>netstandard2.0;</TargetFrameworks> | 		<TargetFrameworks>netstandard2.0;</TargetFrameworks> | ||||||
|  | 		<Version>$(SourceGeneratorVersion)</Version> | ||||||
| 	</PropertyGroup> | 	</PropertyGroup> | ||||||
|  |  | ||||||
| 	<ItemGroup> | 	<ItemGroup> | ||||||
|   | |||||||
| @@ -68,6 +68,11 @@ namespace ThingsGateway.Foundation | |||||||
|         /// </summary> |         /// </summary> | ||||||
|         public virtual bool DtrEnable { get; set; } = true; |         public virtual bool DtrEnable { get; set; } = true; | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// StreamAsync | ||||||
|  |         /// </summary> | ||||||
|  |         public virtual bool StreamAsync { get; set; } = false; | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// RtsEnable |         /// RtsEnable | ||||||
|         /// </summary> |         /// </summary> | ||||||
|   | |||||||
| @@ -73,6 +73,10 @@ public interface IChannelOptions | |||||||
|     /// </summary> |     /// </summary> | ||||||
|     bool RtsEnable { get; set; } |     bool RtsEnable { get; set; } | ||||||
|  |  | ||||||
|  |     /// <summary> | ||||||
|  |     /// StreamAsync | ||||||
|  |     /// </summary> | ||||||
|  |     bool StreamAsync { get; set; } | ||||||
|  |  | ||||||
|     #endregion |     #endregion | ||||||
|     /// <summary> |     /// <summary> | ||||||
|   | |||||||
| @@ -20,6 +20,7 @@ | |||||||
|     "PortName": "PortName", |     "PortName": "PortName", | ||||||
|     "RemoteUrl": "RemoteUrl", |     "RemoteUrl": "RemoteUrl", | ||||||
|     "RtsEnable": "RtsEnable", |     "RtsEnable": "RtsEnable", | ||||||
|  |     "StreamAsync": "StreamAsync", | ||||||
|     "StopBits": "StopBits" |     "StopBits": "StopBits" | ||||||
|   }, |   }, | ||||||
|   "ThingsGateway.Foundation.ConverterConfig": { |   "ThingsGateway.Foundation.ConverterConfig": { | ||||||
|   | |||||||
| @@ -20,6 +20,7 @@ | |||||||
|     "PortName": "COM口", |     "PortName": "COM口", | ||||||
|     "RemoteUrl": "远程url", |     "RemoteUrl": "远程url", | ||||||
|     "RtsEnable": "Rts", |     "RtsEnable": "Rts", | ||||||
|  |     "StreamAsync": "串口流读写", | ||||||
|     "StopBits": "停止位" |     "StopBits": "停止位" | ||||||
|   }, |   }, | ||||||
|   "ThingsGateway.Foundation.ConverterConfig": { |   "ThingsGateway.Foundation.ConverterConfig": { | ||||||
|   | |||||||
| @@ -10,8 +10,8 @@ | |||||||
|  |  | ||||||
| 	<ItemGroup> | 	<ItemGroup> | ||||||
| 		<PackageReference Include="Microsoft.Extensions.Localization.Abstractions" Version="$(NET9Version)" /> | 		<PackageReference Include="Microsoft.Extensions.Localization.Abstractions" Version="$(NET9Version)" /> | ||||||
| 		<PackageReference Include="TouchSocket" Version="3.1.7" /> | 		<PackageReference Include="TouchSocket" Version="3.1.8" /> | ||||||
| 		<PackageReference Include="TouchSocket.SerialPorts" Version="3.1.7" /> | 		<PackageReference Include="TouchSocket.SerialPorts" Version="3.1.8" /> | ||||||
| 	</ItemGroup> | 	</ItemGroup> | ||||||
|  |  | ||||||
| 	<ItemGroup> | 	<ItemGroup> | ||||||
|   | |||||||
| @@ -24,7 +24,7 @@ public class KeyboardShortcutsBehavior : Behavior | |||||||
|  |  | ||||||
|     public KeyboardShortcutsBehavior(Diagram diagram) : base(diagram) |     public KeyboardShortcutsBehavior(Diagram diagram) : base(diagram) | ||||||
|     { |     { | ||||||
|         _shortcuts = new Dictionary<string, Func<Diagram, ValueTask>>(10000, new CaseInsensitiveComparer()); |         _shortcuts = new Dictionary<string, Func<Diagram, ValueTask>>(10, new CaseInsensitiveComparer()); | ||||||
|         SetShortcut("Delete", false, false, false, KeyboardShortcutsDefaults.DeleteSelection); |         SetShortcut("Delete", false, false, false, KeyboardShortcutsDefaults.DeleteSelection); | ||||||
|         SetShortcut("g", true, false, true, KeyboardShortcutsDefaults.Grouping); |         SetShortcut("g", true, false, true, KeyboardShortcutsDefaults.Grouping); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -11,3 +11,4 @@ | |||||||
|  |  | ||||||
| global using Microsoft.AspNetCore.Components; | global using Microsoft.AspNetCore.Components; | ||||||
|  |  | ||||||
|  | [assembly: BlazorSetParametersAsyncGenerator.GlobalGenerateSetParametersAsync(true)] | ||||||
| @@ -4,6 +4,7 @@ | |||||||
|  |  | ||||||
| 	<PropertyGroup> | 	<PropertyGroup> | ||||||
| 		<TargetFrameworks>net8.0;net9.0</TargetFrameworks> | 		<TargetFrameworks>net8.0;net9.0</TargetFrameworks> | ||||||
|  | 		<!--<UseRazorSourceGenerator>false</UseRazorSourceGenerator>--> | ||||||
| 	</PropertyGroup> | 	</PropertyGroup> | ||||||
|  |  | ||||||
| 	<ItemGroup> | 	<ItemGroup> | ||||||
| @@ -26,7 +27,9 @@ | |||||||
|  |  | ||||||
| 	</ItemGroup> | 	</ItemGroup> | ||||||
| 	<ItemGroup> | 	<ItemGroup> | ||||||
| 	  <ProjectReference Include="..\ThingsGateway.Blazor.Diagrams.Core\ThingsGateway.Blazor.Diagrams.Core.csproj" /> | 		<ProjectReference Include="..\ThingsGateway.Blazor.Diagrams.Core\ThingsGateway.Blazor.Diagrams.Core.csproj" /> | ||||||
|  |  | ||||||
|  | 		<ProjectReference Include="..\..\Admin\BlazorSetParametersAsyncGenerator\BlazorSetParametersAsyncGenerator.csproj" PrivateAssets="all" OutputItemType="Analyzer" /> | ||||||
| 	</ItemGroup> | 	</ItemGroup> | ||||||
| 	<ItemGroup> | 	<ItemGroup> | ||||||
|  |  | ||||||
|   | |||||||
| @@ -317,6 +317,11 @@ public class ChannelInput | |||||||
|     /// </summary> |     /// </summary> | ||||||
|     public virtual bool RtsEnable { get; set; } |     public virtual bool RtsEnable { get; set; } | ||||||
|  |  | ||||||
|  |     /// <summary> | ||||||
|  |     /// StreamAsync | ||||||
|  |     /// </summary> | ||||||
|  |     public virtual bool StreamAsync { get; set; } = false; | ||||||
|  |  | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// 缓存超时 |     /// 缓存超时 | ||||||
|     /// </summary> |     /// </summary> | ||||||
|   | |||||||
| @@ -53,7 +53,7 @@ public abstract class CollectBase : DriverBase, IRpcDriver | |||||||
|  |  | ||||||
|         //预热脚本,加速编译 |         //预热脚本,加速编译 | ||||||
|         IdVariableRuntimes.Where(a => !string.IsNullOrWhiteSpace(a.Value.ReadExpressions)) |         IdVariableRuntimes.Where(a => !string.IsNullOrWhiteSpace(a.Value.ReadExpressions)) | ||||||
|          .Select(b => b.Value.ReadExpressions).ToHashSet().ParallelForEach(script => |          .Select(b => b.Value.ReadExpressions).Distinct().ToArray().ParallelForEach(script => | ||||||
|          { |          { | ||||||
|              try |              try | ||||||
|              { |              { | ||||||
| @@ -590,11 +590,11 @@ public abstract class CollectBase : DriverBase, IRpcDriver | |||||||
|  |  | ||||||
|         try |         try | ||||||
|         { |         { | ||||||
|  |             var list = writeInfoLists | ||||||
|             // 使用并发方式遍历写入信息列表,并进行异步写入操作 |  | ||||||
|             await writeInfoLists |  | ||||||
|             .Where(a => !results.Any(b => b.Key == a.Key.Name)) |             .Where(a => !results.Any(b => b.Key == a.Key.Name)) | ||||||
|             .ToDictionary(item => item.Key, item => item.Value).ParallelForEachAsync(async (writeInfo, cancellationToken) => |             .ToDictionary(item => item.Key, item => item.Value).ToArray(); | ||||||
|  |             // 使用并发方式遍历写入信息列表,并进行异步写入操作 | ||||||
|  |             await list.ParallelForEachAsync(async (writeInfo, cancellationToken) => | ||||||
|         { |         { | ||||||
|             try |             try | ||||||
|             { |             { | ||||||
|   | |||||||
| @@ -177,9 +177,9 @@ public abstract class CollectFoundationBase : CollectBase | |||||||
|  |  | ||||||
|             // 创建用于存储操作结果的并发字典 |             // 创建用于存储操作结果的并发字典 | ||||||
|             ConcurrentDictionary<string, OperResult> operResults = new(); |             ConcurrentDictionary<string, OperResult> operResults = new(); | ||||||
|  |             var list = writeInfoLists.ToArray(); | ||||||
|             // 使用并发方式遍历写入信息列表,并进行异步写入操作 |             // 使用并发方式遍历写入信息列表,并进行异步写入操作 | ||||||
|             await writeInfoLists.ParallelForEachAsync(async (writeInfo, cancellationToken) => |             await list.ParallelForEachAsync(async (writeInfo, cancellationToken) => | ||||||
|             { |             { | ||||||
|                 try |                 try | ||||||
|                 { |                 { | ||||||
|   | |||||||
| @@ -137,6 +137,13 @@ public class Channel : ChannelOptionsBase, IPrimaryIdEntity, IBaseDataEntity, IB | |||||||
|     [AutoGenerateColumn(Visible = false, Filterable = true, Sortable = true)] |     [AutoGenerateColumn(Visible = false, Filterable = true, Sortable = true)] | ||||||
|     public override bool RtsEnable { get; set; } |     public override bool RtsEnable { get; set; } | ||||||
|  |  | ||||||
|  |     /// <summary> | ||||||
|  |     /// StreamAsync | ||||||
|  |     /// </summary> | ||||||
|  |     [SugarColumn(ColumnDescription = "StreamAsync", IsNullable = true)] | ||||||
|  |     [AutoGenerateColumn(Visible = false, Filterable = true, Sortable = true)] | ||||||
|  |     public override bool StreamAsync { get; set; } = false; | ||||||
|  |  | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// 缓存超时 |     /// 缓存超时 | ||||||
|     /// </summary> |     /// </summary> | ||||||
| @@ -203,7 +210,7 @@ public class Channel : ChannelOptionsBase, IPrimaryIdEntity, IBaseDataEntity, IB | |||||||
|     [SugarColumn(ColumnDescription = "创建时间", IsOnlyIgnoreUpdate = true, IsNullable = true)] |     [SugarColumn(ColumnDescription = "创建时间", IsOnlyIgnoreUpdate = true, IsNullable = true)] | ||||||
|     [IgnoreExcel] |     [IgnoreExcel] | ||||||
|     [AutoGenerateColumn(Visible = false, IsVisibleWhenAdd = false, IsVisibleWhenEdit = false)] |     [AutoGenerateColumn(Visible = false, IsVisibleWhenAdd = false, IsVisibleWhenEdit = false)] | ||||||
|     public virtual DateTime? CreateTime { get; set; } |     public virtual DateTime CreateTime { get; set; } | ||||||
|  |  | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// 创建人 |     /// 创建人 | ||||||
| @@ -237,7 +244,7 @@ public class Channel : ChannelOptionsBase, IPrimaryIdEntity, IBaseDataEntity, IB | |||||||
|     [SugarColumn(ColumnDescription = "更新时间", IsOnlyIgnoreInsert = true, IsNullable = true)] |     [SugarColumn(ColumnDescription = "更新时间", IsOnlyIgnoreInsert = true, IsNullable = true)] | ||||||
|     [IgnoreExcel] |     [IgnoreExcel] | ||||||
|     [AutoGenerateColumn(Visible = false, IsVisibleWhenAdd = false, IsVisibleWhenEdit = false)] |     [AutoGenerateColumn(Visible = false, IsVisibleWhenAdd = false, IsVisibleWhenEdit = false)] | ||||||
|     public virtual DateTime? UpdateTime { get; set; } |     public virtual DateTime UpdateTime { get; set; } | ||||||
|  |  | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// 更新人 |     /// 更新人 | ||||||
| @@ -245,7 +252,7 @@ public class Channel : ChannelOptionsBase, IPrimaryIdEntity, IBaseDataEntity, IB | |||||||
|     [SugarColumn(ColumnDescription = "更新人", IsOnlyIgnoreInsert = true, IsNullable = true)] |     [SugarColumn(ColumnDescription = "更新人", IsOnlyIgnoreInsert = true, IsNullable = true)] | ||||||
|     [IgnoreExcel] |     [IgnoreExcel] | ||||||
|     [AutoGenerateColumn(Ignore = true)] |     [AutoGenerateColumn(Ignore = true)] | ||||||
|     public virtual string? UpdateUser { get; set; } |     public virtual string UpdateUser { get; set; } | ||||||
|  |  | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// 修改者Id |     /// 修改者Id | ||||||
| @@ -253,7 +260,7 @@ public class Channel : ChannelOptionsBase, IPrimaryIdEntity, IBaseDataEntity, IB | |||||||
|     [SugarColumn(ColumnDescription = "修改者Id", IsOnlyIgnoreInsert = true, IsNullable = true)] |     [SugarColumn(ColumnDescription = "修改者Id", IsOnlyIgnoreInsert = true, IsNullable = true)] | ||||||
|     [IgnoreExcel] |     [IgnoreExcel] | ||||||
|     [AutoGenerateColumn(Ignore = true)] |     [AutoGenerateColumn(Ignore = true)] | ||||||
|     public virtual long? UpdateUserId { get; set; } |     public virtual long UpdateUserId { get; set; } | ||||||
|  |  | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// 排序码 |     /// 排序码 | ||||||
| @@ -261,7 +268,7 @@ public class Channel : ChannelOptionsBase, IPrimaryIdEntity, IBaseDataEntity, IB | |||||||
|     [SugarColumn(ColumnDescription = "排序码", IsNullable = true)] |     [SugarColumn(ColumnDescription = "排序码", IsNullable = true)] | ||||||
|     [AutoGenerateColumn(Visible = false, DefaultSort = true, Sortable = true, DefaultSortOrder = SortOrder.Asc)] |     [AutoGenerateColumn(Visible = false, DefaultSort = true, Sortable = true, DefaultSortOrder = SortOrder.Asc)] | ||||||
|     [IgnoreExcel] |     [IgnoreExcel] | ||||||
|     public int? SortCode { get; set; } |     public int SortCode { get; set; } | ||||||
|  |  | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// 导入验证专用 |     /// 导入验证专用 | ||||||
|   | |||||||
| @@ -32,6 +32,86 @@ public class Variable : BaseDataEntity, IValidatableObject | |||||||
| { | { | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |     /// <summary> | ||||||
|  |     /// 导入验证专用 | ||||||
|  |     /// </summary> | ||||||
|  |     [System.Text.Json.Serialization.JsonIgnore] | ||||||
|  |     [Newtonsoft.Json.JsonIgnore] | ||||||
|  |     internal long Row; | ||||||
|  |     private double hAlarmCode = 50; | ||||||
|  |     private double lAlarmCode = 10; | ||||||
|  |     private double hHAlarmCode = 90; | ||||||
|  |     private double lLAlarmCode = 0; | ||||||
|  |     private long deviceId; | ||||||
|  |     private int? arrayLength; | ||||||
|  |     private int alarmDelay; | ||||||
|  |     private ProtectTypeEnum protectType = ProtectTypeEnum.ReadWrite; | ||||||
|  |     private DataTypeEnum dataType = DataTypeEnum.Int16; | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |     /// <summary> | ||||||
|  |     /// 导入验证专用 | ||||||
|  |     /// </summary> | ||||||
|  |     [System.Text.Json.Serialization.JsonIgnore] | ||||||
|  |     [Newtonsoft.Json.JsonIgnore] | ||||||
|  |     internal bool IsUp; | ||||||
|  |     private bool enable = true; | ||||||
|  |     public bool DynamicVariable; | ||||||
|  |     private bool rpcWriteEnable = true; | ||||||
|  |     private bool saveValue = false; | ||||||
|  |     private bool boolOpenAlarmEnable; | ||||||
|  |     private bool boolCloseAlarmEnable; | ||||||
|  |     private bool hAlarmEnable; | ||||||
|  |     private bool hHAlarmEnable; | ||||||
|  |     private bool lLAlarmEnable; | ||||||
|  |     private bool lAlarmEnable; | ||||||
|  |     private bool customAlarmEnable; | ||||||
|  |  | ||||||
|  |     private object _value; | ||||||
|  |     private string name; | ||||||
|  |     private string collectGroup = string.Empty; | ||||||
|  |     private string businessGroup; | ||||||
|  |     private string description; | ||||||
|  |     private string unit; | ||||||
|  |     private string intervalTime; | ||||||
|  |     private string registerAddress; | ||||||
|  |     private string otherMethod; | ||||||
|  |     private string readExpressions; | ||||||
|  |     private string writeExpressions; | ||||||
|  |     private string boolOpenRestrainExpressions; | ||||||
|  |     private string boolOpenAlarmText; | ||||||
|  |     private string boolCloseRestrainExpressions; | ||||||
|  |     private string boolCloseAlarmText; | ||||||
|  |     private string hRestrainExpressions; | ||||||
|  |     private string hAlarmText; | ||||||
|  |     private Dictionary<long, Dictionary<string, string>>? variablePropertys; | ||||||
|  |     private string hHRestrainExpressions; | ||||||
|  |     private string hHAlarmText; | ||||||
|  |     private string lRestrainExpressions; | ||||||
|  |     private string lAlarmText; | ||||||
|  |  | ||||||
|  |     private string lLRestrainExpressions; | ||||||
|  |     private string lLAlarmText; | ||||||
|  |     private string customRestrainExpressions; | ||||||
|  |     private string customAlarmText; | ||||||
|  |     private string customAlarmCode; | ||||||
|  |     private string remark1; | ||||||
|  |     private string remark2; | ||||||
|  |     private string remark3; | ||||||
|  |     private string remark4; | ||||||
|  |     private string remark5; | ||||||
|  |  | ||||||
|  |     /// <summary> | ||||||
|  |     /// 变量额外属性Json | ||||||
|  |     /// </summary> | ||||||
|  |     [System.Text.Json.Serialization.JsonIgnore] | ||||||
|  |     [Newtonsoft.Json.JsonIgnore] | ||||||
|  |     [AdaptIgnore] | ||||||
|  |     public ConcurrentDictionary<long, ModelValueValidateForm>? VariablePropertyModels; | ||||||
|  |  | ||||||
|  |  | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// 设备 |     /// 设备 | ||||||
|     /// </summary> |     /// </summary> | ||||||
| @@ -40,7 +120,7 @@ public class Variable : BaseDataEntity, IValidatableObject | |||||||
|     [IgnoreExcel] |     [IgnoreExcel] | ||||||
|     [Required] |     [Required] | ||||||
|     [NotNull] |     [NotNull] | ||||||
|     public virtual long DeviceId { get; set; } |     public virtual long DeviceId { get => deviceId; set => deviceId = value; } | ||||||
|  |  | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// 变量名称 |     /// 变量名称 | ||||||
| @@ -48,112 +128,107 @@ public class Variable : BaseDataEntity, IValidatableObject | |||||||
|     [SugarColumn(ColumnDescription = "变量名称", IsNullable = false)] |     [SugarColumn(ColumnDescription = "变量名称", IsNullable = false)] | ||||||
|     [AutoGenerateColumn(Visible = true, Filterable = true, Sortable = true, Order = 1)] |     [AutoGenerateColumn(Visible = true, Filterable = true, Sortable = true, Order = 1)] | ||||||
|     [Required] |     [Required] | ||||||
|     public virtual string Name { get; set; } |     public virtual string Name { get => name; set => name = value; } | ||||||
|  |  | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// 采集组 |     /// 采集组 | ||||||
|     /// </summary> |     /// </summary> | ||||||
|     [SugarColumn(ColumnDescription = "采集组", IsNullable = true)] |     [SugarColumn(ColumnDescription = "采集组", IsNullable = true)] | ||||||
|     [AutoGenerateColumn(Visible = true, Filterable = true, Sortable = true, Order = 1)] |     [AutoGenerateColumn(Visible = true, Filterable = true, Sortable = true, Order = 1)] | ||||||
|     public virtual string CollectGroup { get; set; } = string.Empty; |     public virtual string CollectGroup { get => collectGroup; set => collectGroup = value; } | ||||||
|  |  | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// 分组名称 |     /// 分组名称 | ||||||
|     /// </summary> |     /// </summary> | ||||||
|     [SugarColumn(ColumnDescription = "分组名称", IsNullable = true)] |     [SugarColumn(ColumnDescription = "分组名称", IsNullable = true)] | ||||||
|     [AutoGenerateColumn(Visible = true, Filterable = true, Sortable = true, Order = 1)] |     [AutoGenerateColumn(Visible = true, Filterable = true, Sortable = true, Order = 1)] | ||||||
|     public virtual string BusinessGroup { get; set; } |     public virtual string BusinessGroup { get => businessGroup; set => businessGroup = value; } | ||||||
|  |  | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// 描述 |     /// 描述 | ||||||
|     /// </summary> |     /// </summary> | ||||||
|     [SugarColumn(ColumnDescription = "描述", Length = 200, IsNullable = true)] |     [SugarColumn(ColumnDescription = "描述", Length = 200, IsNullable = true)] | ||||||
|     [AutoGenerateColumn(Visible = true, Filterable = true, Sortable = true, Order = 2)] |     [AutoGenerateColumn(Visible = true, Filterable = true, Sortable = true, Order = 2)] | ||||||
|     public string? Description { get; set; } |     public string Description { get => description; set => description = value; } | ||||||
|  |  | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// 单位 |     /// 单位 | ||||||
|     /// </summary> |     /// </summary> | ||||||
|     [SugarColumn(ColumnDescription = "单位", Length = 200, IsNullable = true)] |     [SugarColumn(ColumnDescription = "单位", Length = 200, IsNullable = true)] | ||||||
|     [AutoGenerateColumn(Visible = true, Filterable = true, Sortable = true, Order = 3)] |     [AutoGenerateColumn(Visible = true, Filterable = true, Sortable = true, Order = 3)] | ||||||
|     public virtual string? Unit { get; set; } |     public virtual string Unit { get => unit; set => unit = value; } | ||||||
|  |  | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// 间隔时间 |     /// 间隔时间 | ||||||
|     /// </summary> |     /// </summary> | ||||||
|     [SugarColumn(ColumnDescription = "间隔时间", IsNullable = true)] |     [SugarColumn(ColumnDescription = "间隔时间", IsNullable = true)] | ||||||
|     [AutoGenerateColumn(Visible = true, Filterable = true, Sortable = true)] |     [AutoGenerateColumn(Visible = true, Filterable = true, Sortable = true)] | ||||||
|     public virtual string? IntervalTime { get; set; } |     public virtual string IntervalTime { get => intervalTime; set => intervalTime = value; } | ||||||
|  |  | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// 变量地址,可能带有额外的信息,比如<see cref="DataFormatEnum"/> ,以;分割 |     /// 变量地址,可能带有额外的信息,比如<see cref="DataFormatEnum"/> ,以;分割 | ||||||
|     /// </summary> |     /// </summary> | ||||||
|     [SugarColumn(ColumnDescription = "变量地址", Length = 200, IsNullable = true)] |     [SugarColumn(ColumnDescription = "变量地址", Length = 200, IsNullable = true)] | ||||||
|     [AutoGenerateColumn(Visible = true, Filterable = true, Sortable = true)] |     [AutoGenerateColumn(Visible = true, Filterable = true, Sortable = true)] | ||||||
|     public string? RegisterAddress { get; set; } |     public string RegisterAddress { get => registerAddress; set => registerAddress = value; } | ||||||
|  |  | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// 数组长度 |     /// 数组长度 | ||||||
|     /// </summary> |     /// </summary> | ||||||
|     [SugarColumn(ColumnDescription = "数组长度", IsNullable = true)] |     [SugarColumn(ColumnDescription = "数组长度", IsNullable = true)] | ||||||
|     [AutoGenerateColumn(Visible = true, Filterable = true, Sortable = true)] |     [AutoGenerateColumn(Visible = true, Filterable = true, Sortable = true)] | ||||||
|     public int? ArrayLength { get; set; } |     public int? ArrayLength { get => arrayLength; set => arrayLength = value; } | ||||||
|  |  | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// 其他方法,若不为空,此时RegisterAddress为方法参数 |     /// 其他方法,若不为空,此时RegisterAddress为方法参数 | ||||||
|     /// </summary> |     /// </summary> | ||||||
|     [SugarColumn(ColumnDescription = "特殊方法", Length = 200, IsNullable = true)] |     [SugarColumn(ColumnDescription = "特殊方法", Length = 200, IsNullable = true)] | ||||||
|     [AutoGenerateColumn(Visible = true, Filterable = true, Sortable = true)] |     [AutoGenerateColumn(Visible = true, Filterable = true, Sortable = true)] | ||||||
|     public string? OtherMethod { get; set; } |     public string OtherMethod { get => otherMethod; set => otherMethod = value; } | ||||||
|  |  | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// 使能 |     /// 使能 | ||||||
|     /// </summary> |     /// </summary> | ||||||
|     [SugarColumn(ColumnDescription = "使能")] |     [SugarColumn(ColumnDescription = "使能")] | ||||||
|     [AutoGenerateColumn(Visible = true, Filterable = true, Sortable = true)] |     [AutoGenerateColumn(Visible = true, Filterable = true, Sortable = true)] | ||||||
|     public virtual bool Enable { get; set; } = true; |     public virtual bool Enable { get => enable; set => enable = value; } | ||||||
|  |  | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// 读写权限 |     /// 读写权限 | ||||||
|     /// </summary> |     /// </summary> | ||||||
|     [SugarColumn(ColumnDescription = "读写权限", IsNullable = false)] |     [SugarColumn(ColumnDescription = "读写权限", IsNullable = false)] | ||||||
|     [AutoGenerateColumn(Visible = true, Filterable = true, Sortable = true)] |     [AutoGenerateColumn(Visible = true, Filterable = true, Sortable = true)] | ||||||
|     public virtual ProtectTypeEnum ProtectType { get; set; } = ProtectTypeEnum.ReadWrite; |     public virtual ProtectTypeEnum ProtectType { get => protectType; set => protectType = value; } | ||||||
|  |  | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// 数据类型 |     /// 数据类型 | ||||||
|     /// </summary> |     /// </summary> | ||||||
|     [SugarColumn(ColumnDescription = "数据类型")] |     [SugarColumn(ColumnDescription = "数据类型")] | ||||||
|     [AutoGenerateColumn(Visible = true, Filterable = true, Sortable = true)] |     [AutoGenerateColumn(Visible = true, Filterable = true, Sortable = true)] | ||||||
|     public virtual DataTypeEnum DataType { get; set; } = DataTypeEnum.Int16; |     public virtual DataTypeEnum DataType { get => dataType; set => dataType = value; } | ||||||
|  |  | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// 读取表达式 |     /// 读取表达式 | ||||||
|     /// </summary> |     /// </summary> | ||||||
|     [SugarColumn(ColumnDescription = "读取表达式", Length = 1000, IsNullable = true)] |     [SugarColumn(ColumnDescription = "读取表达式", Length = 1000, IsNullable = true)] | ||||||
|     [AutoGenerateColumn(Visible = true, Filterable = true, Sortable = true)] |     [AutoGenerateColumn(Visible = true, Filterable = true, Sortable = true)] | ||||||
|     public virtual string? ReadExpressions { get; set; } |     public virtual string ReadExpressions { get => readExpressions; set => readExpressions = value; } | ||||||
|  |  | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// 写入表达式 |     /// 写入表达式 | ||||||
|     /// </summary> |     /// </summary> | ||||||
|     [SugarColumn(ColumnDescription = "写入表达式", Length = 1000, IsNullable = true)] |     [SugarColumn(ColumnDescription = "写入表达式", Length = 1000, IsNullable = true)] | ||||||
|     [AutoGenerateColumn(Visible = true, Filterable = true, Sortable = true)] |     [AutoGenerateColumn(Visible = true, Filterable = true, Sortable = true)] | ||||||
|     public virtual string? WriteExpressions { get; set; } |     public virtual string WriteExpressions { get => writeExpressions; set => writeExpressions = value; } | ||||||
|  |  | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// 是否允许远程Rpc写入 |     /// 是否允许远程Rpc写入 | ||||||
|     /// </summary> |     /// </summary> | ||||||
|     [SugarColumn(ColumnDescription = "远程写入", IsNullable = true)] |     [SugarColumn(ColumnDescription = "远程写入", IsNullable = true)] | ||||||
|     [AutoGenerateColumn(Visible = true, Filterable = true, Sortable = true)] |     [AutoGenerateColumn(Visible = true, Filterable = true, Sortable = true)] | ||||||
|     public virtual bool RpcWriteEnable { get; set; } = true; |     public virtual bool RpcWriteEnable { get => rpcWriteEnable; set => rpcWriteEnable = value; } | ||||||
|  |  | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// 初始值 |     /// 初始值 | ||||||
|     /// </summary> |     /// </summary> | ||||||
|     [SugarColumn(IsJson = true, ColumnDataType = StaticConfig.CodeFirst_BigString, ColumnDescription = "初始值", IsNullable = true)] |     [SugarColumn(IsJson = true, ColumnDataType = StaticConfig.CodeFirst_BigString, ColumnDescription = "初始值", IsNullable = true)] | ||||||
|     [AutoGenerateColumn(Ignore = true)] |     [AutoGenerateColumn(Ignore = true)] | ||||||
|     public object? InitValue |     public object InitValue | ||||||
|     { |     { | ||||||
|         get |         get | ||||||
|         { |         { | ||||||
| @@ -167,22 +242,20 @@ public class Variable : BaseDataEntity, IValidatableObject | |||||||
|                 _value = null; |                 _value = null; | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|     private object? _value; |  | ||||||
|  |  | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// 保存初始值 |     /// 保存初始值 | ||||||
|     /// </summary> |     /// </summary> | ||||||
|     [SugarColumn(ColumnDescription = "保存初始值", IsNullable = true)] |     [SugarColumn(ColumnDescription = "保存初始值", IsNullable = true)] | ||||||
|     [AutoGenerateColumn(Visible = true, Filterable = true, Sortable = true)] |     [AutoGenerateColumn(Visible = true, Filterable = true, Sortable = true)] | ||||||
|     public virtual bool SaveValue { get; set; } = false; |     public virtual bool SaveValue { get => saveValue; set => saveValue = value; } | ||||||
|  |  | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// 变量额外属性Json |     /// 变量额外属性Json | ||||||
|     /// </summary> |     /// </summary> | ||||||
|     [SugarColumn(IsJson = true, ColumnDataType = StaticConfig.CodeFirst_BigString, ColumnDescription = "变量属性Json", IsNullable = true)] |     [SugarColumn(IsJson = true, ColumnDataType = StaticConfig.CodeFirst_BigString, ColumnDescription = "变量属性Json", IsNullable = true)] | ||||||
|     [IgnoreExcel] |     [IgnoreExcel] | ||||||
|     [AutoGenerateColumn(Ignore = true)] |     [AutoGenerateColumn(Ignore = true)] | ||||||
|     public Dictionary<long, Dictionary<string, string>>? VariablePropertys { get; set; } |     public Dictionary<long, Dictionary<string, string>>? VariablePropertys { get => variablePropertys; set => variablePropertys = value; } | ||||||
|  |  | ||||||
|     #region 报警 |     #region 报警 | ||||||
|     /// <summary> |     /// <summary> | ||||||
| @@ -190,189 +263,189 @@ public class Variable : BaseDataEntity, IValidatableObject | |||||||
|     /// </summary> |     /// </summary> | ||||||
|     [SugarColumn(ColumnDescription = "报警延时")] |     [SugarColumn(ColumnDescription = "报警延时")] | ||||||
|     [AutoGenerateColumn(Visible = false, Filterable = true, Sortable = true)] |     [AutoGenerateColumn(Visible = false, Filterable = true, Sortable = true)] | ||||||
|     public int AlarmDelay { get; set; } |     public int AlarmDelay { get => alarmDelay; set => alarmDelay = value; } | ||||||
|  |  | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// 布尔开报警使能 |     /// 布尔开报警使能 | ||||||
|     /// </summary> |     /// </summary> | ||||||
|     [SugarColumn(ColumnDescription = "布尔开报警使能")] |     [SugarColumn(ColumnDescription = "布尔开报警使能")] | ||||||
|     [AutoGenerateColumn(Visible = false, Filterable = true, Sortable = true)] |     [AutoGenerateColumn(Visible = false, Filterable = true, Sortable = true)] | ||||||
|     public bool BoolOpenAlarmEnable { get; set; } |     public bool BoolOpenAlarmEnable { get => boolOpenAlarmEnable; set => boolOpenAlarmEnable = value; } | ||||||
|  |  | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// 布尔开报警约束 |     /// 布尔开报警约束 | ||||||
|     /// </summary> |     /// </summary> | ||||||
|     [SugarColumn(ColumnDescription = "布尔开报警约束", IsNullable = true)] |     [SugarColumn(ColumnDescription = "布尔开报警约束", IsNullable = true)] | ||||||
|     [AutoGenerateColumn(Visible = false, Filterable = true, Sortable = true)] |     [AutoGenerateColumn(Visible = false, Filterable = true, Sortable = true)] | ||||||
|     public string? BoolOpenRestrainExpressions { get; set; } |     public string BoolOpenRestrainExpressions { get => boolOpenRestrainExpressions; set => boolOpenRestrainExpressions = value; } | ||||||
|  |  | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// 布尔开报警文本 |     /// 布尔开报警文本 | ||||||
|     /// </summary> |     /// </summary> | ||||||
|     [SugarColumn(ColumnDescription = "布尔开报警文本", IsNullable = true)] |     [SugarColumn(ColumnDescription = "布尔开报警文本", IsNullable = true)] | ||||||
|     [AutoGenerateColumn(Visible = false, Filterable = true, Sortable = true)] |     [AutoGenerateColumn(Visible = false, Filterable = true, Sortable = true)] | ||||||
|     public string? BoolOpenAlarmText { get; set; } |     public string BoolOpenAlarmText { get => boolOpenAlarmText; set => boolOpenAlarmText = value; } | ||||||
|  |  | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// 布尔关报警使能 |     /// 布尔关报警使能 | ||||||
|     /// </summary> |     /// </summary> | ||||||
|     [SugarColumn(ColumnDescription = "布尔关报警使能")] |     [SugarColumn(ColumnDescription = "布尔关报警使能")] | ||||||
|     [AutoGenerateColumn(Visible = false, Filterable = true, Sortable = true)] |     [AutoGenerateColumn(Visible = false, Filterable = true, Sortable = true)] | ||||||
|     public bool BoolCloseAlarmEnable { get; set; } |     public bool BoolCloseAlarmEnable { get => boolCloseAlarmEnable; set => boolCloseAlarmEnable = value; } | ||||||
|  |  | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// 布尔关报警约束 |     /// 布尔关报警约束 | ||||||
|     /// </summary> |     /// </summary> | ||||||
|     [SugarColumn(ColumnDescription = "布尔关报警约束", IsNullable = true)] |     [SugarColumn(ColumnDescription = "布尔关报警约束", IsNullable = true)] | ||||||
|     [AutoGenerateColumn(Visible = false, Filterable = true, Sortable = true)] |     [AutoGenerateColumn(Visible = false, Filterable = true, Sortable = true)] | ||||||
|     public string? BoolCloseRestrainExpressions { get; set; } |     public string BoolCloseRestrainExpressions { get => boolCloseRestrainExpressions; set => boolCloseRestrainExpressions = value; } | ||||||
|  |  | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// 布尔关报警文本 |     /// 布尔关报警文本 | ||||||
|     /// </summary> |     /// </summary> | ||||||
|     [SugarColumn(ColumnDescription = "布尔关报警文本", IsNullable = true)] |     [SugarColumn(ColumnDescription = "布尔关报警文本", IsNullable = true)] | ||||||
|     [AutoGenerateColumn(Visible = false, Filterable = true, Sortable = true)] |     [AutoGenerateColumn(Visible = false, Filterable = true, Sortable = true)] | ||||||
|     public string? BoolCloseAlarmText { get; set; } |     public string BoolCloseAlarmText { get => boolCloseAlarmText; set => boolCloseAlarmText = value; } | ||||||
|  |  | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// 高报使能 |     /// 高报使能 | ||||||
|     /// </summary> |     /// </summary> | ||||||
|     [SugarColumn(ColumnDescription = "高报使能")] |     [SugarColumn(ColumnDescription = "高报使能")] | ||||||
|     [AutoGenerateColumn(Visible = false, Filterable = true, Sortable = true)] |     [AutoGenerateColumn(Visible = false, Filterable = true, Sortable = true)] | ||||||
|     public bool HAlarmEnable { get; set; } |     public bool HAlarmEnable { get => hAlarmEnable; set => hAlarmEnable = value; } | ||||||
|  |  | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// 高报约束 |     /// 高报约束 | ||||||
|     /// </summary> |     /// </summary> | ||||||
|     [SugarColumn(ColumnDescription = "高报约束", IsNullable = true)] |     [SugarColumn(ColumnDescription = "高报约束", IsNullable = true)] | ||||||
|     [AutoGenerateColumn(Visible = false, Filterable = true, Sortable = true)] |     [AutoGenerateColumn(Visible = false, Filterable = true, Sortable = true)] | ||||||
|     public string? HRestrainExpressions { get; set; } |     public string HRestrainExpressions { get => hRestrainExpressions; set => hRestrainExpressions = value; } | ||||||
|  |  | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// 高报文本 |     /// 高报文本 | ||||||
|     /// </summary> |     /// </summary> | ||||||
|     [SugarColumn(ColumnDescription = "高报文本", IsNullable = true)] |     [SugarColumn(ColumnDescription = "高报文本", IsNullable = true)] | ||||||
|     [AutoGenerateColumn(Visible = false, Filterable = true, Sortable = true)] |     [AutoGenerateColumn(Visible = false, Filterable = true, Sortable = true)] | ||||||
|     public string? HAlarmText { get; set; } |     public string HAlarmText { get => hAlarmText; set => hAlarmText = value; } | ||||||
|  |  | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// 高限值 |     /// 高限值 | ||||||
|     /// </summary> |     /// </summary> | ||||||
|     [SugarColumn(ColumnDescription = "高限值", IsNullable = true)] |     [SugarColumn(ColumnDescription = "高限值", IsNullable = true)] | ||||||
|     [AutoGenerateColumn(Visible = false, Filterable = true, Sortable = true)] |     [AutoGenerateColumn(Visible = false, Filterable = true, Sortable = true)] | ||||||
|     public double? HAlarmCode { get; set; } |     public double HAlarmCode { get => hAlarmCode; set => hAlarmCode = value; } | ||||||
|  |  | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// 高高报使能 |     /// 高高报使能 | ||||||
|     /// </summary> |     /// </summary> | ||||||
|     [SugarColumn(ColumnDescription = "高高报使能")] |     [SugarColumn(ColumnDescription = "高高报使能")] | ||||||
|     [AutoGenerateColumn(Visible = false, Filterable = true, Sortable = true)] |     [AutoGenerateColumn(Visible = false, Filterable = true, Sortable = true)] | ||||||
|     public bool HHAlarmEnable { get; set; } |     public bool HHAlarmEnable { get => hHAlarmEnable; set => hHAlarmEnable = value; } | ||||||
|  |  | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// 高高报约束 |     /// 高高报约束 | ||||||
|     /// </summary> |     /// </summary> | ||||||
|     [SugarColumn(ColumnDescription = "高高报约束", IsNullable = true)] |     [SugarColumn(ColumnDescription = "高高报约束", IsNullable = true)] | ||||||
|     [AutoGenerateColumn(Visible = false, Filterable = true, Sortable = true)] |     [AutoGenerateColumn(Visible = false, Filterable = true, Sortable = true)] | ||||||
|     public string? HHRestrainExpressions { get; set; } |     public string HHRestrainExpressions { get => hHRestrainExpressions; set => hHRestrainExpressions = value; } | ||||||
|  |  | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// 高高报文本 |     /// 高高报文本 | ||||||
|     /// </summary> |     /// </summary> | ||||||
|     [SugarColumn(ColumnDescription = "高高报文本", IsNullable = true)] |     [SugarColumn(ColumnDescription = "高高报文本", IsNullable = true)] | ||||||
|     [AutoGenerateColumn(Visible = false, Filterable = true, Sortable = true)] |     [AutoGenerateColumn(Visible = false, Filterable = true, Sortable = true)] | ||||||
|     public string? HHAlarmText { get; set; } |     public string HHAlarmText { get => hHAlarmText; set => hHAlarmText = value; } | ||||||
|  |  | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// 高高限值 |     /// 高高限值 | ||||||
|     /// </summary> |     /// </summary> | ||||||
|     [SugarColumn(ColumnDescription = "高高限值", IsNullable = true)] |     [SugarColumn(ColumnDescription = "高高限值", IsNullable = true)] | ||||||
|     [AutoGenerateColumn(Visible = false, Filterable = true, Sortable = true)] |     [AutoGenerateColumn(Visible = false, Filterable = true, Sortable = true)] | ||||||
|     public double? HHAlarmCode { get; set; } |     public double HHAlarmCode { get => hHAlarmCode; set => hHAlarmCode = value; } | ||||||
|  |  | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// 低报使能 |     /// 低报使能 | ||||||
|     /// </summary> |     /// </summary> | ||||||
|     [SugarColumn(ColumnDescription = "低报使能")] |     [SugarColumn(ColumnDescription = "低报使能")] | ||||||
|     [AutoGenerateColumn(Visible = false, Filterable = true, Sortable = true)] |     [AutoGenerateColumn(Visible = false, Filterable = true, Sortable = true)] | ||||||
|     public bool LAlarmEnable { get; set; } |     public bool LAlarmEnable { get => lAlarmEnable; set => lAlarmEnable = value; } | ||||||
|  |  | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// 低报约束 |     /// 低报约束 | ||||||
|     /// </summary> |     /// </summary> | ||||||
|     [SugarColumn(ColumnDescription = "低报约束", IsNullable = true)] |     [SugarColumn(ColumnDescription = "低报约束", IsNullable = true)] | ||||||
|     [AutoGenerateColumn(Visible = false, Filterable = true, Sortable = true)] |     [AutoGenerateColumn(Visible = false, Filterable = true, Sortable = true)] | ||||||
|     public string? LRestrainExpressions { get; set; } |     public string LRestrainExpressions { get => lRestrainExpressions; set => lRestrainExpressions = value; } | ||||||
|  |  | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// 低报文本 |     /// 低报文本 | ||||||
|     /// </summary> |     /// </summary> | ||||||
|     [SugarColumn(ColumnDescription = "低报文本", IsNullable = true)] |     [SugarColumn(ColumnDescription = "低报文本", IsNullable = true)] | ||||||
|     [AutoGenerateColumn(Visible = false, Filterable = true, Sortable = true)] |     [AutoGenerateColumn(Visible = false, Filterable = true, Sortable = true)] | ||||||
|     public string? LAlarmText { get; set; } |     public string LAlarmText { get => lAlarmText; set => lAlarmText = value; } | ||||||
|  |  | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// 低限值 |     /// 低限值 | ||||||
|     /// </summary> |     /// </summary> | ||||||
|     [SugarColumn(ColumnDescription = "低限值", IsNullable = true)] |     [SugarColumn(ColumnDescription = "低限值", IsNullable = true)] | ||||||
|     [AutoGenerateColumn(Visible = false, Filterable = true, Sortable = true)] |     [AutoGenerateColumn(Visible = false, Filterable = true, Sortable = true)] | ||||||
|     public double? LAlarmCode { get; set; } |     public double LAlarmCode { get => lAlarmCode; set => lAlarmCode = value; } | ||||||
|  |  | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// 低低报使能 |     /// 低低报使能 | ||||||
|     /// </summary> |     /// </summary> | ||||||
|     [SugarColumn(ColumnDescription = "低低报使能")] |     [SugarColumn(ColumnDescription = "低低报使能")] | ||||||
|     [AutoGenerateColumn(Visible = false, Filterable = true, Sortable = true)] |     [AutoGenerateColumn(Visible = false, Filterable = true, Sortable = true)] | ||||||
|     public bool LLAlarmEnable { get; set; } |     public bool LLAlarmEnable { get => lLAlarmEnable; set => lLAlarmEnable = value; } | ||||||
|  |  | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// 低低报约束 |     /// 低低报约束 | ||||||
|     /// </summary> |     /// </summary> | ||||||
|     [SugarColumn(ColumnDescription = "低低报约束", IsNullable = true)] |     [SugarColumn(ColumnDescription = "低低报约束", IsNullable = true)] | ||||||
|     [AutoGenerateColumn(Visible = false, Filterable = true, Sortable = true)] |     [AutoGenerateColumn(Visible = false, Filterable = true, Sortable = true)] | ||||||
|     public string? LLRestrainExpressions { get; set; } |     public string LLRestrainExpressions { get => lLRestrainExpressions; set => lLRestrainExpressions = value; } | ||||||
|  |  | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// 低低报文本 |     /// 低低报文本 | ||||||
|     /// </summary> |     /// </summary> | ||||||
|     [SugarColumn(ColumnDescription = "低低报文本", IsNullable = true)] |     [SugarColumn(ColumnDescription = "低低报文本", IsNullable = true)] | ||||||
|     [AutoGenerateColumn(Visible = false, Filterable = true, Sortable = true)] |     [AutoGenerateColumn(Visible = false, Filterable = true, Sortable = true)] | ||||||
|     public string? LLAlarmText { get; set; } |     public string LLAlarmText { get => lLAlarmText; set => lLAlarmText = value; } | ||||||
|  |  | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// 低低限值 |     /// 低低限值 | ||||||
|     /// </summary> |     /// </summary> | ||||||
|     [SugarColumn(ColumnDescription = "低低限值", IsNullable = true)] |     [SugarColumn(ColumnDescription = "低低限值", IsNullable = true)] | ||||||
|     [AutoGenerateColumn(Visible = false, Filterable = true, Sortable = true)] |     [AutoGenerateColumn(Visible = false, Filterable = true, Sortable = true)] | ||||||
|     public double? LLAlarmCode { get; set; } |     public double LLAlarmCode { get => lLAlarmCode; set => lLAlarmCode = value; } | ||||||
|  |  | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// 自定义报警使能 |     /// 自定义报警使能 | ||||||
|     /// </summary> |     /// </summary> | ||||||
|     [SugarColumn(ColumnDescription = "自定义报警使能")] |     [SugarColumn(ColumnDescription = "自定义报警使能")] | ||||||
|     [AutoGenerateColumn(Visible = false, Filterable = true, Sortable = true)] |     [AutoGenerateColumn(Visible = false, Filterable = true, Sortable = true)] | ||||||
|     public bool CustomAlarmEnable { get; set; } |     public bool CustomAlarmEnable { get => customAlarmEnable; set => customAlarmEnable = value; } | ||||||
|  |  | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// 自定义报警条件约束 |     /// 自定义报警条件约束 | ||||||
|     /// </summary> |     /// </summary> | ||||||
|     [SugarColumn(ColumnDescription = "自定义报警条件约束", IsNullable = true)] |     [SugarColumn(ColumnDescription = "自定义报警条件约束", IsNullable = true)] | ||||||
|     [AutoGenerateColumn(Visible = false, Filterable = true, Sortable = true)] |     [AutoGenerateColumn(Visible = false, Filterable = true, Sortable = true)] | ||||||
|     public string? CustomRestrainExpressions { get; set; } |     public string CustomRestrainExpressions { get => customRestrainExpressions; set => customRestrainExpressions = value; } | ||||||
|  |  | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// 自定义文本 |     /// 自定义文本 | ||||||
|     /// </summary> |     /// </summary> | ||||||
|     [SugarColumn(ColumnDescription = "自定义文本", IsNullable = true)] |     [SugarColumn(ColumnDescription = "自定义文本", IsNullable = true)] | ||||||
|     [AutoGenerateColumn(Visible = false, Filterable = true, Sortable = true)] |     [AutoGenerateColumn(Visible = false, Filterable = true, Sortable = true)] | ||||||
|     public string? CustomAlarmText { get; set; } |     public string CustomAlarmText { get => customAlarmText; set => customAlarmText = value; } | ||||||
|  |  | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// 自定义报警条件 |     /// 自定义报警条件 | ||||||
|     /// </summary> |     /// </summary> | ||||||
|     [SugarColumn(ColumnDescription = "自定义报警条件", IsNullable = true)] |     [SugarColumn(ColumnDescription = "自定义报警条件", IsNullable = true)] | ||||||
|     [AutoGenerateColumn(Visible = false, Filterable = true, Sortable = true)] |     [AutoGenerateColumn(Visible = false, Filterable = true, Sortable = true)] | ||||||
|     public string? CustomAlarmCode { get; set; } |     public string CustomAlarmCode { get => customAlarmCode; set => customAlarmCode = value; } | ||||||
|  |  | ||||||
|     #endregion 报警 |     #endregion 报警 | ||||||
|  |  | ||||||
| @@ -383,64 +456,38 @@ public class Variable : BaseDataEntity, IValidatableObject | |||||||
|     /// </summary> |     /// </summary> | ||||||
|     [SugarColumn(ColumnDescription = "自定义1", Length = 200, IsNullable = true)] |     [SugarColumn(ColumnDescription = "自定义1", Length = 200, IsNullable = true)] | ||||||
|     [AutoGenerateColumn(Visible = false, Filterable = true, Sortable = true)] |     [AutoGenerateColumn(Visible = false, Filterable = true, Sortable = true)] | ||||||
|     public string? Remark1 { get; set; } |     public string Remark1 { get => remark1; set => remark1 = value; } | ||||||
|  |  | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// 自定义 |     /// 自定义 | ||||||
|     /// </summary> |     /// </summary> | ||||||
|     [SugarColumn(ColumnDescription = "自定义2", Length = 200, IsNullable = true)] |     [SugarColumn(ColumnDescription = "自定义2", Length = 200, IsNullable = true)] | ||||||
|     [AutoGenerateColumn(Visible = false, Filterable = true, Sortable = true)] |     [AutoGenerateColumn(Visible = false, Filterable = true, Sortable = true)] | ||||||
|     public string? Remark2 { get; set; } |     public string Remark2 { get => remark2; set => remark2 = value; } | ||||||
|  |  | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// 自定义 |     /// 自定义 | ||||||
|     /// </summary> |     /// </summary> | ||||||
|     [SugarColumn(ColumnDescription = "自定义3", Length = 200, IsNullable = true)] |     [SugarColumn(ColumnDescription = "自定义3", Length = 200, IsNullable = true)] | ||||||
|     [AutoGenerateColumn(Visible = false, Filterable = true, Sortable = true)] |     [AutoGenerateColumn(Visible = false, Filterable = true, Sortable = true)] | ||||||
|     public string? Remark3 { get; set; } |     public string Remark3 { get => remark3; set => remark3 = value; } | ||||||
|  |  | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// 自定义 |     /// 自定义 | ||||||
|     /// </summary> |     /// </summary> | ||||||
|     [SugarColumn(ColumnDescription = "自定义4", Length = 200, IsNullable = true)] |     [SugarColumn(ColumnDescription = "自定义4", Length = 200, IsNullable = true)] | ||||||
|     [AutoGenerateColumn(Visible = false, Filterable = true, Sortable = true)] |     [AutoGenerateColumn(Visible = false, Filterable = true, Sortable = true)] | ||||||
|     public string? Remark4 { get; set; } |     public string Remark4 { get => remark4; set => remark4 = value; } | ||||||
|  |  | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// 自定义 |     /// 自定义 | ||||||
|     /// </summary> |     /// </summary> | ||||||
|     [SugarColumn(ColumnDescription = "自定义5", Length = 200, IsNullable = true)] |     [SugarColumn(ColumnDescription = "自定义5", Length = 200, IsNullable = true)] | ||||||
|     [AutoGenerateColumn(Visible = false, Filterable = true, Sortable = true)] |     [AutoGenerateColumn(Visible = false, Filterable = true, Sortable = true)] | ||||||
|     public string? Remark5 { get; set; } |     public string Remark5 { get => remark5; set => remark5 = value; } | ||||||
|  |  | ||||||
|     #endregion 备用字段 |     #endregion 备用字段 | ||||||
|  |  | ||||||
|     /// <summary> |  | ||||||
|     /// 导入验证专用 |  | ||||||
|     /// </summary> |  | ||||||
|     [System.Text.Json.Serialization.JsonIgnore] |  | ||||||
|     [Newtonsoft.Json.JsonIgnore] |  | ||||||
|     internal bool IsUp; |  | ||||||
|  |  | ||||||
|     /// <summary> |  | ||||||
|     /// 导入验证专用 |  | ||||||
|     /// </summary> |  | ||||||
|     [System.Text.Json.Serialization.JsonIgnore] |  | ||||||
|     [Newtonsoft.Json.JsonIgnore] |  | ||||||
|     internal long Row; |  | ||||||
|  |  | ||||||
|     /// <summary> |  | ||||||
|     /// 变量额外属性Json |  | ||||||
|     /// </summary> |  | ||||||
|     [System.Text.Json.Serialization.JsonIgnore] |  | ||||||
|     [Newtonsoft.Json.JsonIgnore] |  | ||||||
|     [AdaptIgnore] |  | ||||||
|     public ConcurrentDictionary<long, ModelValueValidateForm>? VariablePropertyModels; |  | ||||||
|  |  | ||||||
|     /// <summary> |  | ||||||
|     /// 动态变量 |  | ||||||
|     /// </summary> |  | ||||||
|     public bool DynamicVariable; |  | ||||||
|  |  | ||||||
|     public IEnumerable<ValidationResult> Validate(ValidationContext validationContext) |     public IEnumerable<ValidationResult> Validate(ValidationContext validationContext) | ||||||
|     { |     { | ||||||
| @@ -448,22 +495,7 @@ public class Variable : BaseDataEntity, IValidatableObject | |||||||
|         { |         { | ||||||
|             yield return new ValidationResult("Both RegisterAddress and OtherMethod cannot be empty or null.", new[] { nameof(RegisterAddress), nameof(OtherMethod) }); |             yield return new ValidationResult("Both RegisterAddress and OtherMethod cannot be empty or null.", new[] { nameof(RegisterAddress), nameof(OtherMethod) }); | ||||||
|         } |         } | ||||||
|         if (HHAlarmEnable && HHAlarmCode == null) |  | ||||||
|         { |  | ||||||
|             yield return new ValidationResult("HHAlarmCode cannot be null when HHAlarmEnable is true", new[] { nameof(HHAlarmCode) }); |  | ||||||
|         } |  | ||||||
|         if (HAlarmEnable && HAlarmCode == null) |  | ||||||
|         { |  | ||||||
|             yield return new ValidationResult("HAlarmCode cannot be null when HAlarmEnable is true", new[] { nameof(HAlarmCode) }); |  | ||||||
|         } |  | ||||||
|         if (LAlarmEnable && LAlarmCode == null) |  | ||||||
|         { |  | ||||||
|             yield return new ValidationResult("LAlarmCode cannot be null when LAlarmEnable is true", new[] { nameof(LAlarmCode) }); |  | ||||||
|         } |  | ||||||
|         if (LLAlarmEnable && LLAlarmCode == null) |  | ||||||
|         { |  | ||||||
|             yield return new ValidationResult("LLAlarmCode cannot be null when LLAlarmEnable is true", new[] { nameof(LLAlarmCode) }); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         if (HHAlarmEnable && HAlarmEnable && HHAlarmCode <= HAlarmCode) |         if (HHAlarmEnable && HAlarmEnable && HHAlarmCode <= HAlarmCode) | ||||||
|         { |         { | ||||||
|   | |||||||
| @@ -0,0 +1,42 @@ | |||||||
|  | //------------------------------------------------------------------------------ | ||||||
|  | //  此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充 | ||||||
|  | //  此代码版权(除特别声明外的代码)归作者本人Diego所有 | ||||||
|  | //  源代码使用协议遵循本仓库的开源协议及附加协议 | ||||||
|  | //  Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway | ||||||
|  | //  Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway | ||||||
|  | //  使用文档:https://thingsgateway.cn/ | ||||||
|  | //  QQ群:605534569 | ||||||
|  | //------------------------------------------------------------------------------ | ||||||
|  |  | ||||||
|  | namespace ThingsGateway.Gateway.Application; | ||||||
|  |  | ||||||
|  | /// <summary> | ||||||
|  | /// 扩展 | ||||||
|  | /// </summary> | ||||||
|  | [ThingsGateway.DependencyInjection.SuppressSniffer] | ||||||
|  | public static class ParallelExtension | ||||||
|  | { | ||||||
|  |  | ||||||
|  |     /// <summary> | ||||||
|  |     /// 异步执行指定的操作,并指定最大并行度和取消标志 | ||||||
|  |     /// </summary> | ||||||
|  |     /// <typeparam name="T">集合元素类型</typeparam> | ||||||
|  |     /// <param name="source">要操作的集合</param> | ||||||
|  |     /// <param name="body">异步执行的操作</param> | ||||||
|  |     /// <param name="cancellationToken">取消操作的标志</param> | ||||||
|  |     /// <returns>表示异步操作的任务</returns> | ||||||
|  |     public static Task ParallelForEachStreamedAsync<T>(this IEnumerable<T> source, Func<T, CancellationToken, ValueTask> body, CancellationToken cancellationToken = default) | ||||||
|  |     { | ||||||
|  |         return ParallelForEachStreamedAsync(source, body, Environment.ProcessorCount, cancellationToken); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public static Task ParallelForEachStreamedAsync<T>(this IEnumerable<T> source, Func<T, CancellationToken, ValueTask> body, int parallelCount, CancellationToken cancellationToken = default) | ||||||
|  |     { | ||||||
|  |         // 创建并行操作的选项对象,设置最大并行度和取消标志 | ||||||
|  |         var options = new ParallelOptions(); | ||||||
|  |         options.CancellationToken = cancellationToken; | ||||||
|  |         options.MaxDegreeOfParallelism = parallelCount == 0 ? 1 : parallelCount; | ||||||
|  |         // 使用 Parallel.ForEachAsync 异步执行指定的操作,并返回表示异步操作的任务 | ||||||
|  |         return Parallel.ForEachAsync(source, options, body); | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -171,7 +171,7 @@ public static class GlobalData | |||||||
|  |  | ||||||
|     public static IEnumerable<VariableRuntime> GetEnableVariables() |     public static IEnumerable<VariableRuntime> GetEnableVariables() | ||||||
|     { |     { | ||||||
|         return IdDevices.SelectMany(a => a.Value.VariableRuntimes).Where(a => a.Value.Enable).Select(a => a.Value); |         return IdDevices.SelectMany(a => a.Value.VariableRuntimes).Where(a => a.Value?.Enable == true).Select(a => a.Value); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |  | ||||||
|   | |||||||
| @@ -33,14 +33,14 @@ public class LogJob : IJob | |||||||
|  |  | ||||||
|     private static async Task DeleteRpcLog(int daysAgo, CancellationToken stoppingToken) |     private static async Task DeleteRpcLog(int daysAgo, CancellationToken stoppingToken) | ||||||
|     { |     { | ||||||
|         using var db = DbContext.Db.GetConnectionScopeWithAttr<RpcLog>().CopyNew(); |         using var db = DbContext.GetDB<RpcLog>(); | ||||||
|         var time = DateTime.Now.AddDays(-daysAgo); |         var time = DateTime.Now.AddDays(-daysAgo); | ||||||
|         await db.DeleteableWithAttr<RpcLog>().Where(u => u.LogTime < time).ExecuteCommandAsync(stoppingToken).ConfigureAwait(false); // 删除操作日志 |         await db.DeleteableWithAttr<RpcLog>().Where(u => u.LogTime < time).ExecuteCommandAsync(stoppingToken).ConfigureAwait(false); // 删除操作日志 | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     private static async Task DeleteBackendLog(int daysAgo, CancellationToken stoppingToken) |     private static async Task DeleteBackendLog(int daysAgo, CancellationToken stoppingToken) | ||||||
|     { |     { | ||||||
|         using var db = DbContext.Db.GetConnectionScopeWithAttr<BackendLog>().CopyNew(); |         using var db = DbContext.GetDB<BackendLog>(); | ||||||
|         var time = DateTime.Now.AddDays(-daysAgo); |         var time = DateTime.Now.AddDays(-daysAgo); | ||||||
|         await db.DeleteableWithAttr<BackendLog>().Where(u => u.LogTime < time).ExecuteCommandAsync(stoppingToken).ConfigureAwait(false); // 删除操作日志 |         await db.DeleteableWithAttr<BackendLog>().Where(u => u.LogTime < time).ExecuteCommandAsync(stoppingToken).ConfigureAwait(false); // 删除操作日志 | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -266,6 +266,7 @@ | |||||||
|     "PortName": "PortName", |     "PortName": "PortName", | ||||||
|     "RemoteUrl": "RemoteUrl", |     "RemoteUrl": "RemoteUrl", | ||||||
|     "RtsEnable": "RtsEnable", |     "RtsEnable": "RtsEnable", | ||||||
|  |     "StreamAsync": "StreamAsync", | ||||||
|     "SaveChannel": "Add/Modify Channel", |     "SaveChannel": "Add/Modify Channel", | ||||||
|     "SortCode": "SortCode", |     "SortCode": "SortCode", | ||||||
|     "StopBits": "StopBits", |     "StopBits": "StopBits", | ||||||
|   | |||||||
| @@ -265,6 +265,7 @@ | |||||||
|     "PortName": "COM口", |     "PortName": "COM口", | ||||||
|     "RemoteUrl": "远程url", |     "RemoteUrl": "远程url", | ||||||
|     "RtsEnable": "Rts", |     "RtsEnable": "Rts", | ||||||
|  |     "StreamAsync": "串口流读写", | ||||||
|     "SaveChannel": "添加/修改通道", |     "SaveChannel": "添加/修改通道", | ||||||
|     "SortCode": "排序", |     "SortCode": "排序", | ||||||
|     "StopBits": "停止位", |     "StopBits": "停止位", | ||||||
|   | |||||||
| @@ -65,7 +65,7 @@ public class BackendLogDatabaseLoggingWriter : IDatabaseLoggingWriter | |||||||
|             if (flush) |             if (flush) | ||||||
|             { |             { | ||||||
|                 // 如果SqlSugar客户端未初始化,则进行初始化 |                 // 如果SqlSugar客户端未初始化,则进行初始化 | ||||||
|                 SqlSugarClient ??= DbContext.Db.GetConnectionScopeWithAttr<BackendLog>().CopyNew(); |                 SqlSugarClient ??= DbContext.GetDB<BackendLog>(); | ||||||
|  |  | ||||||
|                 // 异步执行入库操作 |                 // 异步执行入库操作 | ||||||
|                 await SqlSugarClient.InsertableWithAttr(_logQueues.ToListWithDequeue()).ExecuteCommandAsync().ConfigureAwait(false); |                 await SqlSugarClient.InsertableWithAttr(_logQueues.ToListWithDequeue()).ExecuteCommandAsync().ConfigureAwait(false); | ||||||
|   | |||||||
| @@ -8,8 +8,6 @@ | |||||||
| //  QQ群:605534569 | //  QQ群:605534569 | ||||||
| //------------------------------------------------------------------------------ | //------------------------------------------------------------------------------ | ||||||
|  |  | ||||||
| using BootstrapBlazor.Components; |  | ||||||
|  |  | ||||||
| using Mapster; | using Mapster; | ||||||
|  |  | ||||||
| using Newtonsoft.Json.Linq; | using Newtonsoft.Json.Linq; | ||||||
| @@ -17,131 +15,41 @@ using Newtonsoft.Json.Linq; | |||||||
| using ThingsGateway.Gateway.Application.Extensions; | using ThingsGateway.Gateway.Application.Extensions; | ||||||
| using ThingsGateway.NewLife.Extension; | using ThingsGateway.NewLife.Extension; | ||||||
| using ThingsGateway.NewLife.Json.Extension; | using ThingsGateway.NewLife.Json.Extension; | ||||||
| using ThingsGateway.SqlSugar; |  | ||||||
|  |  | ||||||
| namespace ThingsGateway.Gateway.Application; | namespace ThingsGateway.Gateway.Application; | ||||||
|  |  | ||||||
| /// <summary> | /// <summary> | ||||||
| /// 变量运行态 | /// 变量运行态 | ||||||
| /// </summary> | /// </summary> | ||||||
| public class VariableRuntime : Variable, IVariable, IDisposable | public partial class VariableRuntime : Variable, IVariable, IDisposable | ||||||
| { | { | ||||||
|     [SugarColumn(ColumnDescription = "排序码", IsNullable = true)] |     private DateTime? prepareEventTime; | ||||||
|     [AutoGenerateColumn(Visible = false, DefaultSort = false, Sortable = true)] |     private EventTypeEnum? eventType; | ||||||
|     [IgnoreExcel] |  | ||||||
|     public override int? SortCode { get; set; } |     private AlarmTypeEnum? alarmType { get; set; } | ||||||
|  |  | ||||||
|  |     private int index; | ||||||
|  |     private int sortCode; | ||||||
|  |     private DateTime changeTime = DateTime.UnixEpoch.ToLocalTime(); | ||||||
|  |     private DateTime alarmTime; | ||||||
|  |     private DateTime eventTime; | ||||||
|  |     private DateTime collectTime = DateTime.UnixEpoch.ToLocalTime(); | ||||||
|  |  | ||||||
|     private bool _isOnline; |     private bool _isOnline; | ||||||
|     private bool _isOnlineChanged; |     private bool _isOnlineChanged; | ||||||
|     protected object _value; |  | ||||||
|  |  | ||||||
|     /// <summary> |  | ||||||
|     /// 变化时间 |  | ||||||
|     /// </summary> |  | ||||||
|     [AutoGenerateColumn(Visible = true, Filterable = true, Sortable = true, Order = 5)] |  | ||||||
|     public DateTime ChangeTime { get; private set; } = DateTime.UnixEpoch.ToLocalTime(); |  | ||||||
|  |  | ||||||
|     /// <summary> |  | ||||||
|     /// 所在采集设备 |  | ||||||
|     /// </summary> |  | ||||||
|     [Newtonsoft.Json.JsonIgnore] |  | ||||||
|     [System.Text.Json.Serialization.JsonIgnore] |  | ||||||
|     [AutoGenerateColumn(Ignore = true)] |  | ||||||
|     public DeviceRuntime DeviceRuntime { get; set; } |  | ||||||
|  |  | ||||||
|     /// <summary> |  | ||||||
|     /// VariableSource |  | ||||||
|     /// </summary> |  | ||||||
|     [Newtonsoft.Json.JsonIgnore] |  | ||||||
|     [System.Text.Json.Serialization.JsonIgnore] |  | ||||||
|     [AdaptIgnore] |  | ||||||
|     [AutoGenerateColumn(Ignore = true)] |  | ||||||
|     public IVariableSource VariableSource { get; set; } |  | ||||||
|  |  | ||||||
|     /// <summary> |  | ||||||
|     /// VariableMethod |  | ||||||
|     /// </summary> |  | ||||||
|     [Newtonsoft.Json.JsonIgnore] |  | ||||||
|     [System.Text.Json.Serialization.JsonIgnore] |  | ||||||
|     [AdaptIgnore] |  | ||||||
|     [AutoGenerateColumn(Ignore = true)] |  | ||||||
|     public VariableMethod VariableMethod { get; set; } |  | ||||||
|  |  | ||||||
|     /// <summary> |  | ||||||
|     /// 采集时间 |  | ||||||
|     /// </summary> |  | ||||||
|     [AutoGenerateColumn(Visible = true, Filterable = true, Sortable = true, Order = 5)] |  | ||||||
|     public DateTime CollectTime { get; private set; } = DateTime.UnixEpoch.ToLocalTime(); |  | ||||||
|  |  | ||||||
|     /// <summary> |  | ||||||
|     /// 设备名称 |  | ||||||
|     /// </summary> |  | ||||||
|     [AutoGenerateColumn(Visible = true, Filterable = true, Sortable = true, Order = 4)] |  | ||||||
|     public string DeviceName => DeviceRuntime?.Name; |  | ||||||
|  |  | ||||||
|     /// <summary> |  | ||||||
|     /// 是否在线 |  | ||||||
|     /// </summary> |  | ||||||
|     [AutoGenerateColumn(Visible = true, Filterable = true, Sortable = true, Order = 5)] |  | ||||||
|     public bool IsOnline |  | ||||||
|     { |  | ||||||
|         get |  | ||||||
|         { |  | ||||||
|             return _isOnline; |  | ||||||
|         } |  | ||||||
|         private set |  | ||||||
|         { |  | ||||||
|             if (IsOnline != value) |  | ||||||
|             { |  | ||||||
|                 _isOnlineChanged = true; |  | ||||||
|             } |  | ||||||
|             else |  | ||||||
|             { |  | ||||||
|                 _isOnlineChanged = false; |  | ||||||
|             } |  | ||||||
|             _isOnline = value; |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|  |     private string alarmLimit; | ||||||
|  |     private string alarmText; | ||||||
|  |     private string alarmCode; | ||||||
|     private string _lastErrorMessage; |     private string _lastErrorMessage; | ||||||
|  |     private string recoveryCode; | ||||||
|     /// <summary> |     private object _value; | ||||||
|     /// <inheritdoc/> |     private object lastSetValue; | ||||||
|     /// </summary> |     private object rawValue; | ||||||
|     [AutoGenerateColumn(Visible = true, Filterable = true, Sortable = true, Order = 5)] |     private DeviceRuntime deviceRuntime; | ||||||
|     public string LastErrorMessage |     private IVariableSource variableSource; | ||||||
|     { |     private VariableMethod variableMethod; | ||||||
|         get |     private IThingsGatewayBitConverter thingsGatewayBitConverter; | ||||||
|         { |  | ||||||
|             if (_isOnline == false) |  | ||||||
|                 return _lastErrorMessage ?? VariableSource?.LastErrorMessage ?? VariableMethod?.LastErrorMessage; |  | ||||||
|             else |  | ||||||
|                 return null; |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /// <summary> |  | ||||||
|     /// 上次值 |  | ||||||
|     /// </summary> |  | ||||||
|     [AutoGenerateColumn(Visible = false, Order = 6)] |  | ||||||
|     public object LastSetValue { get; internal set; } |  | ||||||
|  |  | ||||||
|     /// <summary> |  | ||||||
|     /// 原始值 |  | ||||||
|     /// </summary> |  | ||||||
|     [AutoGenerateColumn(Visible = false, Order = 6)] |  | ||||||
|     public object RawValue { get; internal set; } |  | ||||||
|  |  | ||||||
|     /// <summary> |  | ||||||
|     /// 实时值 |  | ||||||
|     /// </summary> |  | ||||||
|     [AutoGenerateColumn(Visible = true, Order = 6)] |  | ||||||
|     public object Value { get => _value; set => _value = value; } |  | ||||||
|     /// <summary> |  | ||||||
|     /// 实时值 |  | ||||||
|     /// </summary> |  | ||||||
|     [AutoGenerateColumn(Visible = true, Order = 6)] |  | ||||||
|     public string RuntimeType => Value?.GetType()?.ToString(); |  | ||||||
|  |  | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// 设置变量值与时间/质量戳 |     /// 设置变量值与时间/质量戳 | ||||||
| @@ -252,92 +160,6 @@ public class VariableRuntime : Variable, IVariable, IDisposable | |||||||
|     } |     } | ||||||
|  |  | ||||||
|  |  | ||||||
|     #region LoadSourceRead |  | ||||||
|  |  | ||||||
|     /// <summary> |  | ||||||
|     /// 这个参数值由自动打包方法写入<see cref="IDevice.LoadSourceRead{T}(IEnumerable{IVariable}, int, string)"/> |  | ||||||
|     /// </summary> |  | ||||||
|     [AutoGenerateColumn(Visible = false)] |  | ||||||
|     public int Index { get; set; } |  | ||||||
|  |  | ||||||
|     /// <summary> |  | ||||||
|     /// 这个参数值由自动打包方法写入<see cref="IDevice.LoadSourceRead{T}(IEnumerable{IVariable}, int, string)"/> |  | ||||||
|     /// </summary> |  | ||||||
|     [Newtonsoft.Json.JsonIgnore] |  | ||||||
|     [System.Text.Json.Serialization.JsonIgnore] |  | ||||||
|     [AutoGenerateColumn(Ignore = true)] |  | ||||||
|     public IThingsGatewayBitConverter ThingsGatewayBitConverter { get; set; } |  | ||||||
|  |  | ||||||
|     #endregion LoadSourceRead |  | ||||||
|  |  | ||||||
|     #region 报警 |  | ||||||
|  |  | ||||||
|     /// <summary> |  | ||||||
|     /// 报警值 |  | ||||||
|     /// </summary> |  | ||||||
|     [AutoGenerateColumn(Visible = false)] |  | ||||||
|     public string AlarmCode { get; set; } |  | ||||||
|     /// <summary> |  | ||||||
|     /// 恢复值 |  | ||||||
|     /// </summary> |  | ||||||
|     [AutoGenerateColumn(Visible = false)] |  | ||||||
|     public string RecoveryCode { get; set; } |  | ||||||
|  |  | ||||||
|     /// <summary> |  | ||||||
|     /// 报警使能 |  | ||||||
|     /// </summary> |  | ||||||
|     [AutoGenerateColumn(Visible = false, Filterable = true, Sortable = true)] |  | ||||||
|     public bool AlarmEnable |  | ||||||
|     { |  | ||||||
|         get |  | ||||||
|         { |  | ||||||
|             return LAlarmEnable || LLAlarmEnable || HAlarmEnable || HHAlarmEnable || BoolOpenAlarmEnable || BoolCloseAlarmEnable || CustomAlarmEnable; |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /// <summary> |  | ||||||
|     /// 报警限值 |  | ||||||
|     /// </summary> |  | ||||||
|     [AutoGenerateColumn(Visible = false)] |  | ||||||
|     public string AlarmLimit { get; set; } |  | ||||||
|  |  | ||||||
|     /// <summary> |  | ||||||
|     /// 报警文本 |  | ||||||
|     /// </summary> |  | ||||||
|     [AutoGenerateColumn(Visible = false)] |  | ||||||
|     public string AlarmText { get; set; } |  | ||||||
|  |  | ||||||
|     /// <summary> |  | ||||||
|     /// 报警时间 |  | ||||||
|     /// </summary> |  | ||||||
|     [AutoGenerateColumn(Visible = false)] |  | ||||||
|     public DateTime AlarmTime { get; set; } |  | ||||||
|  |  | ||||||
|     /// <summary> |  | ||||||
|     /// 报警类型 |  | ||||||
|     /// </summary> |  | ||||||
|     [AutoGenerateColumn(Visible = false)] |  | ||||||
|     public AlarmTypeEnum? AlarmType { get; set; } |  | ||||||
|  |  | ||||||
|     /// <summary> |  | ||||||
|     /// 事件时间 |  | ||||||
|     /// </summary> |  | ||||||
|     [AutoGenerateColumn(Visible = false)] |  | ||||||
|     public DateTime EventTime { get; set; } |  | ||||||
|     /// <summary> |  | ||||||
|     /// 事件时间 |  | ||||||
|     /// </summary> |  | ||||||
|     [AutoGenerateColumn(Ignore = true)] |  | ||||||
|     internal DateTime? PrepareEventTime { get; set; } |  | ||||||
|  |  | ||||||
|     /// <summary> |  | ||||||
|     /// 事件类型 |  | ||||||
|     /// </summary> |  | ||||||
|     [AutoGenerateColumn(Visible = false)] |  | ||||||
|     public EventTypeEnum? EventType { get; set; } |  | ||||||
|  |  | ||||||
|     #endregion 报警 |  | ||||||
|  |  | ||||||
|     public void Init(DeviceRuntime deviceRuntime) |     public void Init(DeviceRuntime deviceRuntime) | ||||||
|     { |     { | ||||||
|  |  | ||||||
|   | |||||||
| @@ -0,0 +1,243 @@ | |||||||
|  | //------------------------------------------------------------------------------ | ||||||
|  | //  此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充 | ||||||
|  | //  此代码版权(除特别声明外的代码)归作者本人Diego所有 | ||||||
|  | //  源代码使用协议遵循本仓库的开源协议及附加协议 | ||||||
|  | //  Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway | ||||||
|  | //  Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway | ||||||
|  | //  使用文档:https://thingsgateway.cn/ | ||||||
|  | //  QQ群:605534569 | ||||||
|  | //------------------------------------------------------------------------------ | ||||||
|  |  | ||||||
|  | using BootstrapBlazor.Components; | ||||||
|  |  | ||||||
|  | using Mapster; | ||||||
|  |  | ||||||
|  | using ThingsGateway.SqlSugar; | ||||||
|  |  | ||||||
|  | namespace ThingsGateway.Gateway.Application; | ||||||
|  |  | ||||||
|  | /// <summary> | ||||||
|  | /// 变量运行态 | ||||||
|  | /// </summary> | ||||||
|  | public partial class VariableRuntime : Variable, IVariable, IDisposable | ||||||
|  | { | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |     #region 属性 | ||||||
|  |     /// <summary> | ||||||
|  |     /// 事件类型 | ||||||
|  |     /// </summary> | ||||||
|  |     [AutoGenerateColumn(Visible = false)] | ||||||
|  |     public EventTypeEnum? EventType { get => eventType; set => eventType = value; } | ||||||
|  |  | ||||||
|  |     /// <summary> | ||||||
|  |     /// 报警类型 | ||||||
|  |     /// </summary> | ||||||
|  |     [AutoGenerateColumn(Visible = false)] | ||||||
|  |     public AlarmTypeEnum? AlarmType { get => alarmType; set => alarmType = value; } | ||||||
|  |  | ||||||
|  |  | ||||||
|  |     /// <summary> | ||||||
|  |     /// 报警值 | ||||||
|  |     /// </summary> | ||||||
|  |     [AutoGenerateColumn(Visible = false)] | ||||||
|  |     public string AlarmCode { get => alarmCode; set => alarmCode = value; } | ||||||
|  |  | ||||||
|  |  | ||||||
|  |     /// <summary> | ||||||
|  |     /// 恢复值 | ||||||
|  |     /// </summary> | ||||||
|  |     [AutoGenerateColumn(Visible = false)] | ||||||
|  |     public string RecoveryCode { get => recoveryCode; set => recoveryCode = value; } | ||||||
|  |  | ||||||
|  |     /// <summary> | ||||||
|  |     /// 这个参数值由自动打包方法写入<see cref="IDevice.LoadSourceRead{T}(IEnumerable{IVariable}, int, string)"/> | ||||||
|  |     /// </summary> | ||||||
|  |     [AutoGenerateColumn(Visible = false)] | ||||||
|  |     public int Index { get => index; set => index = value; } | ||||||
|  |     /// <summary> | ||||||
|  |     /// 事件时间 | ||||||
|  |     /// </summary> | ||||||
|  |     [AutoGenerateColumn(Ignore = true)] | ||||||
|  |     internal DateTime? PrepareEventTime { get => prepareEventTime; set => prepareEventTime = value; } | ||||||
|  |  | ||||||
|  |     /// <summary> | ||||||
|  |     /// 变化时间 | ||||||
|  |     /// </summary> | ||||||
|  |     [AutoGenerateColumn(Visible = true, Filterable = true, Sortable = true, Order = 5)] | ||||||
|  |     public DateTime ChangeTime { get => changeTime; set => changeTime = value; } | ||||||
|  |  | ||||||
|  |     /// <summary> | ||||||
|  |     /// 报警时间 | ||||||
|  |     /// </summary> | ||||||
|  |     [AutoGenerateColumn(Visible = false)] | ||||||
|  |     public DateTime AlarmTime { get => alarmTime; set => alarmTime = value; } | ||||||
|  |  | ||||||
|  |  | ||||||
|  |     /// <summary> | ||||||
|  |     /// 事件时间 | ||||||
|  |     /// </summary> | ||||||
|  |     [AutoGenerateColumn(Visible = false)] | ||||||
|  |     public DateTime EventTime { get => eventTime; set => eventTime = value; } | ||||||
|  |  | ||||||
|  |  | ||||||
|  |     /// <summary> | ||||||
|  |     /// 采集时间 | ||||||
|  |     /// </summary> | ||||||
|  |     [AutoGenerateColumn(Visible = true, Filterable = true, Sortable = true, Order = 5)] | ||||||
|  |     public DateTime CollectTime { get => collectTime; set => collectTime = value; } | ||||||
|  |  | ||||||
|  |  | ||||||
|  |     [SugarColumn(ColumnDescription = "排序码", IsNullable = true)] | ||||||
|  |     [AutoGenerateColumn(Visible = false, DefaultSort = false, Sortable = true)] | ||||||
|  |     [IgnoreExcel] | ||||||
|  |     public override int SortCode { get => sortCode; set => sortCode = value; } | ||||||
|  |  | ||||||
|  |  | ||||||
|  |     /// <summary> | ||||||
|  |     /// 上次值 | ||||||
|  |     /// </summary> | ||||||
|  |     [AutoGenerateColumn(Visible = false, Order = 6)] | ||||||
|  |     public object LastSetValue { get => lastSetValue; set => lastSetValue = value; } | ||||||
|  |  | ||||||
|  |     /// <summary> | ||||||
|  |     /// 原始值 | ||||||
|  |     /// </summary> | ||||||
|  |     [AutoGenerateColumn(Visible = false, Order = 6)] | ||||||
|  |     public object RawValue { get => rawValue; set => rawValue = value; } | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |     /// <summary> | ||||||
|  |     /// 所在采集设备 | ||||||
|  |     /// </summary> | ||||||
|  |     [Newtonsoft.Json.JsonIgnore] | ||||||
|  |     [System.Text.Json.Serialization.JsonIgnore] | ||||||
|  |     [AutoGenerateColumn(Ignore = true)] | ||||||
|  |     public DeviceRuntime DeviceRuntime { get => deviceRuntime; set => deviceRuntime = value; } | ||||||
|  |  | ||||||
|  |     /// <summary> | ||||||
|  |     /// VariableSource | ||||||
|  |     /// </summary> | ||||||
|  |     [Newtonsoft.Json.JsonIgnore] | ||||||
|  |     [System.Text.Json.Serialization.JsonIgnore] | ||||||
|  |     [AdaptIgnore] | ||||||
|  |     [AutoGenerateColumn(Ignore = true)] | ||||||
|  |     public IVariableSource VariableSource { get => variableSource; set => variableSource = value; } | ||||||
|  |  | ||||||
|  |     /// <summary> | ||||||
|  |     /// VariableMethod | ||||||
|  |     /// </summary> | ||||||
|  |     [Newtonsoft.Json.JsonIgnore] | ||||||
|  |     [System.Text.Json.Serialization.JsonIgnore] | ||||||
|  |     [AdaptIgnore] | ||||||
|  |     [AutoGenerateColumn(Ignore = true)] | ||||||
|  |     public VariableMethod VariableMethod { get => variableMethod; set => variableMethod = value; } | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |     /// <summary> | ||||||
|  |     /// 这个参数值由自动打包方法写入<see cref="IDevice.LoadSourceRead{T}(IEnumerable{IVariable}, int, string)"/> | ||||||
|  |     /// </summary> | ||||||
|  |     [Newtonsoft.Json.JsonIgnore] | ||||||
|  |     [System.Text.Json.Serialization.JsonIgnore] | ||||||
|  |     [AutoGenerateColumn(Ignore = true)] | ||||||
|  |     public IThingsGatewayBitConverter ThingsGatewayBitConverter { get => thingsGatewayBitConverter; set => thingsGatewayBitConverter = value; } | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |     /// <summary> | ||||||
|  |     /// 设备名称 | ||||||
|  |     /// </summary> | ||||||
|  |     [AutoGenerateColumn(Visible = true, Filterable = true, Sortable = true, Order = 4)] | ||||||
|  |     public string DeviceName => DeviceRuntime?.Name; | ||||||
|  |  | ||||||
|  |     /// <summary> | ||||||
|  |     /// 是否在线 | ||||||
|  |     /// </summary> | ||||||
|  |     [AutoGenerateColumn(Visible = true, Filterable = true, Sortable = true, Order = 5)] | ||||||
|  |     public bool IsOnline | ||||||
|  |     { | ||||||
|  |         get | ||||||
|  |         { | ||||||
|  |             return _isOnline; | ||||||
|  |         } | ||||||
|  |         private set | ||||||
|  |         { | ||||||
|  |             if (IsOnline != value) | ||||||
|  |             { | ||||||
|  |                 _isOnlineChanged = true; | ||||||
|  |             } | ||||||
|  |             else | ||||||
|  |             { | ||||||
|  |                 _isOnlineChanged = false; | ||||||
|  |             } | ||||||
|  |             _isOnline = value; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |  | ||||||
|  |     /// <summary> | ||||||
|  |     /// <inheritdoc/> | ||||||
|  |     /// </summary> | ||||||
|  |     [AutoGenerateColumn(Visible = true, Filterable = true, Sortable = true, Order = 5)] | ||||||
|  |     public string LastErrorMessage | ||||||
|  |     { | ||||||
|  |         get | ||||||
|  |         { | ||||||
|  |             if (_isOnline == false) | ||||||
|  |                 return _lastErrorMessage ?? VariableSource?.LastErrorMessage ?? VariableMethod?.LastErrorMessage; | ||||||
|  |             else | ||||||
|  |                 return null; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |  | ||||||
|  |     /// <summary> | ||||||
|  |     /// 实时值 | ||||||
|  |     /// </summary> | ||||||
|  |     [AutoGenerateColumn(Visible = true, Order = 6)] | ||||||
|  |     public string RuntimeType => Value?.GetType()?.ToString(); | ||||||
|  |  | ||||||
|  |     /// <summary> | ||||||
|  |     /// 实时值 | ||||||
|  |     /// </summary> | ||||||
|  |     [AutoGenerateColumn(Visible = true, Order = 6)] | ||||||
|  |     public object Value { get => _value; set => _value = value; } | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |     /// <summary> | ||||||
|  |     /// 报警使能 | ||||||
|  |     /// </summary> | ||||||
|  |     [AutoGenerateColumn(Visible = false, Filterable = true, Sortable = true)] | ||||||
|  |     public bool AlarmEnable | ||||||
|  |     { | ||||||
|  |         get | ||||||
|  |         { | ||||||
|  |             return LAlarmEnable || LLAlarmEnable || HAlarmEnable || HHAlarmEnable || BoolOpenAlarmEnable || BoolCloseAlarmEnable || CustomAlarmEnable; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /// <summary> | ||||||
|  |     /// 报警限值 | ||||||
|  |     /// </summary> | ||||||
|  |     [AutoGenerateColumn(Visible = false)] | ||||||
|  |     public string AlarmLimit { get => alarmLimit; set => alarmLimit = value; } | ||||||
|  |  | ||||||
|  |     /// <summary> | ||||||
|  |     /// 报警文本 | ||||||
|  |     /// </summary> | ||||||
|  |     [AutoGenerateColumn(Visible = false)] | ||||||
|  |     public string AlarmText { get => alarmText; set => alarmText = value; } | ||||||
|  |  | ||||||
|  |     #endregion | ||||||
|  |  | ||||||
|  | } | ||||||
|  |  | ||||||
| @@ -93,15 +93,15 @@ public class ChannelRuntimeService : IChannelRuntimeService | |||||||
|         { |         { | ||||||
|             await WaitLock.WaitAsync(cancellationToken).ConfigureAwait(false); |             await WaitLock.WaitAsync(cancellationToken).ConfigureAwait(false); | ||||||
|  |  | ||||||
|             ids = ids.ToHashSet(); |             var array = ids.ToArray(); | ||||||
|             var result = await GlobalData.ChannelService.DeleteChannelAsync(ids).ConfigureAwait(false); |             var result = await GlobalData.ChannelService.DeleteChannelAsync(array).ConfigureAwait(false); | ||||||
|  |  | ||||||
|             var changedDriver = RuntimeServiceHelper.DeleteChannelRuntime(ids); |             var changedDriver = RuntimeServiceHelper.DeleteChannelRuntime(array); | ||||||
|  |  | ||||||
|             //根据条件重启通道线程 |             //根据条件重启通道线程 | ||||||
|             if (restart) |             if (restart) | ||||||
|             { |             { | ||||||
|                 await GlobalData.ChannelThreadManage.RemoveChannelAsync(ids).ConfigureAwait(false); |                 await GlobalData.ChannelThreadManage.RemoveChannelAsync(array).ConfigureAwait(false); | ||||||
|  |  | ||||||
|                 await RuntimeServiceHelper.ChangedDriverAsync(changedDriver, _logger, cancellationToken).ConfigureAwait(false); |                 await RuntimeServiceHelper.ChangedDriverAsync(changedDriver, _logger, cancellationToken).ConfigureAwait(false); | ||||||
|             } |             } | ||||||
|   | |||||||
| @@ -101,12 +101,12 @@ public class DeviceRuntimeService : IDeviceRuntimeService | |||||||
|             await WaitLock.WaitAsync(cancellationToken).ConfigureAwait(false); |             await WaitLock.WaitAsync(cancellationToken).ConfigureAwait(false); | ||||||
|  |  | ||||||
|  |  | ||||||
|             ids = ids.ToHashSet(); |             var devids = ids.ToHashSet(); | ||||||
|  |  | ||||||
|             var result = await GlobalData.DeviceService.DeleteDeviceAsync(ids).ConfigureAwait(false); |             var result = await GlobalData.DeviceService.DeleteDeviceAsync(devids).ConfigureAwait(false); | ||||||
|  |  | ||||||
|             //根据条件重启通道线程 |             //根据条件重启通道线程 | ||||||
|             var deviceRuntimes = GlobalData.IdDevices.Where(a => ids.Contains(a.Key)).Select(a => a.Value).ToList(); |             var deviceRuntimes = GlobalData.IdDevices.Where(a => devids.Contains(a.Key)).Select(a => a.Value).ToList(); | ||||||
|  |  | ||||||
|             ConcurrentHashSet<IDriver> changedDriver = RuntimeServiceHelper.DeleteDeviceRuntime(deviceRuntimes); |             ConcurrentHashSet<IDriver> changedDriver = RuntimeServiceHelper.DeleteDeviceRuntime(deviceRuntimes); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -396,50 +396,60 @@ internal sealed class AlarmHostedService : BackgroundService, IAlarmHostedServic | |||||||
|     /// <param name="cancellation">取消任务的 CancellationToken</param> |     /// <param name="cancellation">取消任务的 CancellationToken</param> | ||||||
|     private async Task DoWork(CancellationToken cancellation) |     private async Task DoWork(CancellationToken cancellation) | ||||||
|     { |     { | ||||||
|         try |         while (!cancellation.IsCancellationRequested) | ||||||
|         { |         { | ||||||
|             if (!GlobalData.StartBusinessChannelEnable) |  | ||||||
|                 return; |  | ||||||
|  |  | ||||||
|             //Stopwatch stopwatch = Stopwatch.StartNew(); |             try | ||||||
|             // 遍历设备变量列表 |  | ||||||
|  |  | ||||||
|             GlobalData.AlarmEnableIdVariables.ParallelForEach((kv, state, index) => |  | ||||||
|             { |             { | ||||||
|  |                 if (!GlobalData.StartBusinessChannelEnable) | ||||||
|  |                     return; | ||||||
|  |  | ||||||
|  |                 //Stopwatch stopwatch = Stopwatch.StartNew(); | ||||||
|  |                 // 遍历设备变量列表 | ||||||
|  |  | ||||||
|  |                 if (!GlobalData.AlarmEnableIdVariables.IsEmpty) | ||||||
|                 { |                 { | ||||||
|                     // 如果取消请求已经被触发,则结束任务 |                     var list = GlobalData.AlarmEnableIdVariables.Select(a => a.Value).ToArray(); | ||||||
|                     if (cancellation.IsCancellationRequested) |                     list.ParallelForEach((item, state, index) => | ||||||
|                         return; |                 { | ||||||
|  |                     { | ||||||
|  |                         // 如果取消请求已经被触发,则结束任务 | ||||||
|  |                         if (cancellation.IsCancellationRequested) | ||||||
|  |                             return; | ||||||
|  |  | ||||||
|                     var item = kv.Value; |                         // 如果该变量的报警功能未启用,则跳过该变量 | ||||||
|  |                         if (!item.AlarmEnable) | ||||||
|  |                             return; | ||||||
|  |  | ||||||
|                     // 如果该变量的报警功能未启用,则跳过该变量 |                         // 如果该变量离线,则跳过该变量 | ||||||
|                     if (!item.AlarmEnable) |                         if (!item.IsOnline) | ||||||
|                         return; |                             return; | ||||||
|  |  | ||||||
|                     // 如果该变量离线,则跳过该变量 |                         // 对该变量进行报警分析 | ||||||
|                     if (!item.IsOnline) |                         AlarmAnalysis(item); | ||||||
|                         return; |  | ||||||
|  |  | ||||||
|                     // 对该变量进行报警分析 |  | ||||||
|                     AlarmAnalysis(item); |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |                     } | ||||||
|  |                 }); | ||||||
|  |                 } | ||||||
|  |                 else | ||||||
|  |                 { | ||||||
|  |                     await Task.Delay(5000, cancellation).ConfigureAwait(false); | ||||||
|                 } |                 } | ||||||
|             }); |  | ||||||
|  |  | ||||||
|  |  | ||||||
|             //stopwatch.Stop(); |                 //stopwatch.Stop(); | ||||||
|             //_logger.LogInformation("报警分析耗时:" + stopwatch.ElapsedMilliseconds + "ms"); |                 //_logger.LogInformation("报警分析耗时:" + stopwatch.ElapsedMilliseconds + "ms"); | ||||||
|         } |             } | ||||||
|         catch (Exception ex) |             catch (Exception ex) | ||||||
|         { |             { | ||||||
|             _logger.LogWarning(ex, "Alarm analysis fail"); |                 _logger.LogWarning(ex, "Alarm analysis fail"); | ||||||
|         } |             } | ||||||
|         finally |             finally | ||||||
|         { |             { | ||||||
|             // 延迟一段时间,避免过于频繁地执行任务 |                 // 延迟一段时间,避免过于频繁地执行任务 | ||||||
|             await Task.Delay(50, cancellation).ConfigureAwait(false); |                 await Task.Delay(50, cancellation).ConfigureAwait(false); | ||||||
|  |             } | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -447,10 +457,9 @@ internal sealed class AlarmHostedService : BackgroundService, IAlarmHostedServic | |||||||
|     protected override async Task ExecuteAsync(CancellationToken stoppingToken) |     protected override async Task ExecuteAsync(CancellationToken stoppingToken) | ||||||
|     { |     { | ||||||
|         _logger.LogInformation(AppResource.RealAlarmTaskStart); |         _logger.LogInformation(AppResource.RealAlarmTaskStart); | ||||||
|         while (!stoppingToken.IsCancellationRequested) |  | ||||||
|         { |         await DoWork(stoppingToken).ConfigureAwait(false); | ||||||
|             await DoWork(stoppingToken).ConfigureAwait(false); |  | ||||||
|         } |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -34,7 +34,7 @@ internal sealed class ChannelThreadManage : IChannelThreadManage | |||||||
|     /// 移除指定通道 |     /// 移除指定通道 | ||||||
|     /// </summary> |     /// </summary> | ||||||
|     /// <param name="channelIds">要移除的通道ID</param> |     /// <param name="channelIds">要移除的通道ID</param> | ||||||
|     private async Task PrivateRemoveChannelsAsync(IEnumerable<long> channelIds) |     private async Task PrivateRemoveChannelsAsync(IList<long> channelIds) | ||||||
|     { |     { | ||||||
|  |  | ||||||
|         await channelIds.ParallelForEachAsync(async (channelId, token) => |         await channelIds.ParallelForEachAsync(async (channelId, token) => | ||||||
| @@ -64,7 +64,7 @@ internal sealed class ChannelThreadManage : IChannelThreadManage | |||||||
|         { |         { | ||||||
|             await NewChannelLock.WaitAsync().ConfigureAwait(false); |             await NewChannelLock.WaitAsync().ConfigureAwait(false); | ||||||
|  |  | ||||||
|             await PrivateRemoveChannelsAsync(Enumerable.Repeat(channelId, 1)).ConfigureAwait(false); |             await PrivateRemoveChannelsAsync([channelId]).ConfigureAwait(false); | ||||||
|         } |         } | ||||||
|         finally |         finally | ||||||
|         { |         { | ||||||
| @@ -77,7 +77,7 @@ internal sealed class ChannelThreadManage : IChannelThreadManage | |||||||
|     /// 移除指定通道 |     /// 移除指定通道 | ||||||
|     /// </summary> |     /// </summary> | ||||||
|     /// <param name="channelIds">要移除的通道ID</param> |     /// <param name="channelIds">要移除的通道ID</param> | ||||||
|     public async Task RemoveChannelAsync(IEnumerable<long> channelIds) |     public async Task RemoveChannelAsync(IList<long> channelIds) | ||||||
|     { |     { | ||||||
|         try |         try | ||||||
|         { |         { | ||||||
| @@ -94,9 +94,9 @@ internal sealed class ChannelThreadManage : IChannelThreadManage | |||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|     private async Task PrivateRestartChannelAsync(IEnumerable<ChannelRuntime> channelRuntimes) |     private async Task PrivateRestartChannelAsync(IList<ChannelRuntime> channelRuntimes) | ||||||
|     { |     { | ||||||
|         await PrivateRemoveChannelsAsync(channelRuntimes.Select(a => a.Id)).ConfigureAwait(false); |         await PrivateRemoveChannelsAsync(channelRuntimes.Select(a => a.Id).ToArray()).ConfigureAwait(false); | ||||||
|  |  | ||||||
|         await channelRuntimes.ParallelForEachAsync(async (channelRuntime, token) => |         await channelRuntimes.ParallelForEachAsync(async (channelRuntime, token) => | ||||||
|         { |         { | ||||||
| @@ -128,7 +128,7 @@ internal sealed class ChannelThreadManage : IChannelThreadManage | |||||||
|  |  | ||||||
|                 deviceThreadManage.ChannelThreadManage = this; |                 deviceThreadManage.ChannelThreadManage = this; | ||||||
|  |  | ||||||
|                 await deviceThreadManage.RestartDeviceAsync(channelRuntime.DeviceRuntimes.Select(a => a.Value), false).ConfigureAwait(false); |                 await deviceThreadManage.RestartDeviceAsync(channelRuntime.DeviceRuntimes.Select(a => a.Value).ToList(), false).ConfigureAwait(false); | ||||||
|  |  | ||||||
|             } |             } | ||||||
|             catch (Exception ex) |             catch (Exception ex) | ||||||
| @@ -149,7 +149,7 @@ internal sealed class ChannelThreadManage : IChannelThreadManage | |||||||
|         try |         try | ||||||
|         { |         { | ||||||
|             await NewChannelLock.WaitAsync().ConfigureAwait(false); |             await NewChannelLock.WaitAsync().ConfigureAwait(false); | ||||||
|             await PrivateRestartChannelAsync(Enumerable.Repeat(channelRuntime, 1)).ConfigureAwait(false); |             await PrivateRestartChannelAsync([channelRuntime]).ConfigureAwait(false); | ||||||
|         } |         } | ||||||
|         finally |         finally | ||||||
|         { |         { | ||||||
| @@ -160,7 +160,7 @@ internal sealed class ChannelThreadManage : IChannelThreadManage | |||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// 向当前通道添加设备 |     /// 向当前通道添加设备 | ||||||
|     /// </summary> |     /// </summary> | ||||||
|     public async Task RestartChannelAsync(IEnumerable<ChannelRuntime> channelRuntimes) |     public async Task RestartChannelAsync(IList<ChannelRuntime> channelRuntimes) | ||||||
|     { |     { | ||||||
|  |  | ||||||
|         try |         try | ||||||
|   | |||||||
| @@ -17,8 +17,8 @@ public interface IChannelThreadManage | |||||||
|     ConcurrentDictionary<long, IDeviceThreadManage> DeviceThreadManages { get; } |     ConcurrentDictionary<long, IDeviceThreadManage> DeviceThreadManages { get; } | ||||||
|  |  | ||||||
|     Task RestartChannelAsync(ChannelRuntime channelRuntime); |     Task RestartChannelAsync(ChannelRuntime channelRuntime); | ||||||
|     Task RestartChannelAsync(IEnumerable<ChannelRuntime> channelRuntimes); |     Task RestartChannelAsync(IList<ChannelRuntime> channelRuntimes); | ||||||
|  |  | ||||||
|     Task RemoveChannelAsync(IEnumerable<long> channelIds); |     Task RemoveChannelAsync(IList<long> channelIds); | ||||||
|     Task RemoveChannelAsync(long channelId); |     Task RemoveChannelAsync(long channelId); | ||||||
| } | } | ||||||
| @@ -235,7 +235,7 @@ internal sealed class DeviceThreadManage : IAsyncDisposable, IDeviceThreadManage | |||||||
|         try |         try | ||||||
|         { |         { | ||||||
|             await NewDeviceLock.WaitAsync().ConfigureAwait(false); |             await NewDeviceLock.WaitAsync().ConfigureAwait(false); | ||||||
|             await PrivateRestartDeviceAsync(Enumerable.Repeat(deviceRuntime, 1), deleteCache).ConfigureAwait(false); |             await PrivateRestartDeviceAsync([deviceRuntime], deleteCache).ConfigureAwait(false); | ||||||
|         } |         } | ||||||
|         finally |         finally | ||||||
|         { |         { | ||||||
| @@ -246,7 +246,7 @@ internal sealed class DeviceThreadManage : IAsyncDisposable, IDeviceThreadManage | |||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// 向当前通道添加设备 |     /// 向当前通道添加设备 | ||||||
|     /// </summary> |     /// </summary> | ||||||
|     public async Task RestartDeviceAsync(IEnumerable<DeviceRuntime> deviceRuntimes, bool deleteCache) |     public async Task RestartDeviceAsync(IList<DeviceRuntime> deviceRuntimes, bool deleteCache) | ||||||
|     { |     { | ||||||
|  |  | ||||||
|         try |         try | ||||||
| @@ -260,12 +260,12 @@ internal sealed class DeviceThreadManage : IAsyncDisposable, IDeviceThreadManage | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     private async Task PrivateRestartDeviceAsync(IEnumerable<DeviceRuntime> deviceRuntimes, bool deleteCache) |     private async Task PrivateRestartDeviceAsync(IList<DeviceRuntime> deviceRuntimes, bool deleteCache) | ||||||
|     { |     { | ||||||
|         try |         try | ||||||
|         { |         { | ||||||
|  |  | ||||||
|             await PrivateRemoveDevicesAsync(deviceRuntimes.Select(a => a.Id)).ConfigureAwait(false); |             await PrivateRemoveDevicesAsync(deviceRuntimes.Select(a => a.Id).ToArray()).ConfigureAwait(false); | ||||||
|  |  | ||||||
|             if (Disposed) |             if (Disposed) | ||||||
|             { |             { | ||||||
| @@ -307,7 +307,7 @@ internal sealed class DeviceThreadManage : IAsyncDisposable, IDeviceThreadManage | |||||||
|                         } |                         } | ||||||
|                         else |                         else | ||||||
|                         { |                         { | ||||||
|                             await PrivateRemoveDevicesAsync(Enumerable.Repeat(redundantDeviceRuntime.Id, 1)).ConfigureAwait(false); |                             await PrivateRemoveDevicesAsync([redundantDeviceRuntime.Id]).ConfigureAwait(false); | ||||||
|                         } |                         } | ||||||
|                         redundantDeviceThreadManage.LogMessage?.LogInformation($"The device {redundantDeviceRuntime.Name} is standby and no communication tasks are created"); |                         redundantDeviceThreadManage.LogMessage?.LogInformation($"The device {redundantDeviceRuntime.Name} is standby and no communication tasks are created"); | ||||||
|  |  | ||||||
| @@ -386,7 +386,7 @@ internal sealed class DeviceThreadManage : IAsyncDisposable, IDeviceThreadManage | |||||||
|                 } |                 } | ||||||
|  |  | ||||||
|                 // 初始化业务线程 |                 // 初始化业务线程 | ||||||
|                 var driverTask = new DoTask(t => DoWork(driver, t), driver.LogMessage, null); |                 var driverTask = new DoTask(t => DoWork(driver, IsCollectChannel, t), driver.LogMessage, null); | ||||||
|                 DriverTasks.TryAdd(driver.DeviceId, driverTask); |                 DriverTasks.TryAdd(driver.DeviceId, driverTask); | ||||||
|  |  | ||||||
|                 token.Register(driver.Stop); |                 token.Register(driver.Stop); | ||||||
| @@ -423,7 +423,7 @@ internal sealed class DeviceThreadManage : IAsyncDisposable, IDeviceThreadManage | |||||||
|         { |         { | ||||||
|             await NewDeviceLock.WaitAsync().ConfigureAwait(false); |             await NewDeviceLock.WaitAsync().ConfigureAwait(false); | ||||||
|  |  | ||||||
|             await PrivateRemoveDevicesAsync(Enumerable.Repeat(deviceId, 1)).ConfigureAwait(false); |             await PrivateRemoveDevicesAsync([deviceId]).ConfigureAwait(false); | ||||||
|         } |         } | ||||||
|         finally |         finally | ||||||
|         { |         { | ||||||
| @@ -436,7 +436,7 @@ internal sealed class DeviceThreadManage : IAsyncDisposable, IDeviceThreadManage | |||||||
|     /// 移除指定设备 |     /// 移除指定设备 | ||||||
|     /// </summary> |     /// </summary> | ||||||
|     /// <param name="deviceIds">要移除的设备ID</param> |     /// <param name="deviceIds">要移除的设备ID</param> | ||||||
|     public async Task RemoveDeviceAsync(IEnumerable<long> deviceIds) |     public async Task RemoveDeviceAsync(IList<long> deviceIds) | ||||||
|     { |     { | ||||||
|         try |         try | ||||||
|         { |         { | ||||||
| @@ -455,7 +455,7 @@ internal sealed class DeviceThreadManage : IAsyncDisposable, IDeviceThreadManage | |||||||
|     /// 移除指定设备 |     /// 移除指定设备 | ||||||
|     /// </summary> |     /// </summary> | ||||||
|     /// <param name="deviceIds">要移除的设备ID</param> |     /// <param name="deviceIds">要移除的设备ID</param> | ||||||
|     private async Task PrivateRemoveDevicesAsync(IEnumerable<long> deviceIds) |     private async Task PrivateRemoveDevicesAsync(IList<long> deviceIds) | ||||||
|     { |     { | ||||||
|         try |         try | ||||||
|         { |         { | ||||||
| @@ -533,7 +533,7 @@ internal sealed class DeviceThreadManage : IAsyncDisposable, IDeviceThreadManage | |||||||
|     } |     } | ||||||
|  |  | ||||||
|  |  | ||||||
|     private async ValueTask DoWork(DriverBase driver, CancellationToken token) |     private static async ValueTask DoWork(DriverBase driver, bool? isCollectChannel, CancellationToken token) | ||||||
|     { |     { | ||||||
|         try |         try | ||||||
|         { |         { | ||||||
| @@ -549,7 +549,7 @@ internal sealed class DeviceThreadManage : IAsyncDisposable, IDeviceThreadManage | |||||||
|                 if (result == ThreadRunReturnTypeEnum.None) |                 if (result == ThreadRunReturnTypeEnum.None) | ||||||
|                 { |                 { | ||||||
|                     // 如果驱动处于离线状态且为采集驱动,则根据配置的间隔时间进行延迟 |                     // 如果驱动处于离线状态且为采集驱动,则根据配置的间隔时间进行延迟 | ||||||
|                     if (driver.CurrentDevice.DeviceStatus == DeviceStatusEnum.OffLine && IsCollectChannel == true) |                     if (driver.CurrentDevice.DeviceStatus == DeviceStatusEnum.OffLine && isCollectChannel == true) | ||||||
|                     { |                     { | ||||||
|                         var collectBase = (CollectBase)driver; |                         var collectBase = (CollectBase)driver; | ||||||
|                         if (collectBase.CollectProperties.ReIntervalTime > 0) |                         if (collectBase.CollectProperties.ReIntervalTime > 0) | ||||||
| @@ -643,7 +643,8 @@ internal sealed class DeviceThreadManage : IAsyncDisposable, IDeviceThreadManage | |||||||
|     { |     { | ||||||
|         //传入变量 |         //传入变量 | ||||||
|         //newDeviceRuntime.VariableRuntimes.ParallelForEach(a => a.Value.SafeDispose()); |         //newDeviceRuntime.VariableRuntimes.ParallelForEach(a => a.Value.SafeDispose()); | ||||||
|         deviceRuntime.VariableRuntimes.ParallelForEach(a => a.Value.Init(newDeviceRuntime)); |         var list = deviceRuntime.VariableRuntimes.Select(a => a.Value).ToArray(); | ||||||
|  |         list.ParallelForEach(a => a.Init(newDeviceRuntime)); | ||||||
|         GlobalData.VariableRuntimeDispatchService.Dispatch(null); |         GlobalData.VariableRuntimeDispatchService.Dispatch(null); | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -729,7 +730,7 @@ internal sealed class DeviceThreadManage : IAsyncDisposable, IDeviceThreadManage | |||||||
|             channelRuntime.DeviceThreadManage.LogMessage?.LogInformation($"Device {newDeviceRuntime.Name} switched to primary channel"); |             channelRuntime.DeviceThreadManage.LogMessage?.LogInformation($"Device {newDeviceRuntime.Name} switched to primary channel"); | ||||||
|  |  | ||||||
|             //需要重启业务线程 |             //需要重启业务线程 | ||||||
|             var businessDeviceRuntimes = GlobalData.IdDevices.Where(a => a.Value.Driver is BusinessBase).Where(a => ((BusinessBase)a.Value.Driver).CollectDevices.ContainsKey(a.Key) == true).Select(a => a.Value); |             var businessDeviceRuntimes = GlobalData.IdDevices.Where(a => a.Value.Driver is BusinessBase).Where(a => ((BusinessBase)a.Value.Driver).CollectDevices.ContainsKey(a.Key) == true).Select(a => a.Value).ToArray(); | ||||||
|             await businessDeviceRuntimes.ParallelForEachAsync(async (businessDeviceRuntime, token) => |             await businessDeviceRuntimes.ParallelForEachAsync(async (businessDeviceRuntime, token) => | ||||||
|               { |               { | ||||||
|                   if (businessDeviceRuntime.Driver != null) |                   if (businessDeviceRuntime.Driver != null) | ||||||
| @@ -886,7 +887,7 @@ internal sealed class DeviceThreadManage : IAsyncDisposable, IDeviceThreadManage | |||||||
|             GlobalData.DeviceStatusChangeEvent -= GlobalData_DeviceStatusChangeEvent; |             GlobalData.DeviceStatusChangeEvent -= GlobalData_DeviceStatusChangeEvent; | ||||||
|             await NewDeviceLock.WaitAsync().ConfigureAwait(false); |             await NewDeviceLock.WaitAsync().ConfigureAwait(false); | ||||||
|             _logger?.TryDispose(); |             _logger?.TryDispose(); | ||||||
|             await PrivateRemoveDevicesAsync(Drivers.Keys).ConfigureAwait(false); |             await PrivateRemoveDevicesAsync(Drivers.Select(a => a.Key).ToArray()).ConfigureAwait(false); | ||||||
|             if (Channel?.Collects.Count == 0) |             if (Channel?.Collects.Count == 0) | ||||||
|                 Channel?.SafeDispose(); |                 Channel?.SafeDispose(); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -24,9 +24,9 @@ public interface IDeviceThreadManage : IAsyncDisposable | |||||||
|  |  | ||||||
|     Task SetLogAsync(LogLevel? logLevel = null, bool upDataBase = true); |     Task SetLogAsync(LogLevel? logLevel = null, bool upDataBase = true); | ||||||
|     Task RestartDeviceAsync(DeviceRuntime deviceRuntime, bool deleteCache); |     Task RestartDeviceAsync(DeviceRuntime deviceRuntime, bool deleteCache); | ||||||
|     Task RestartDeviceAsync(IEnumerable<DeviceRuntime> deviceRuntimes, bool deleteCache); |     Task RestartDeviceAsync(IList<DeviceRuntime> deviceRuntimes, bool deleteCache); | ||||||
|  |  | ||||||
|     Task RemoveDeviceAsync(IEnumerable<long> deviceIds); |     Task RemoveDeviceAsync(IList<long> deviceIds); | ||||||
|     Task RemoveDeviceAsync(long deviceId); |     Task RemoveDeviceAsync(long deviceId); | ||||||
|     Task DeviceRedundantThreadAsync(long deviceId, CancellationToken cancellationToken); |     Task DeviceRedundantThreadAsync(long deviceId, CancellationToken cancellationToken); | ||||||
| } | } | ||||||
| @@ -55,7 +55,7 @@ internal sealed class GatewayMonitorHostedService : BackgroundService, IGatewayM | |||||||
|                     { |                     { | ||||||
|                         item.Init(channelRuntime); |                         item.Init(channelRuntime); | ||||||
|  |  | ||||||
|                         var varRuntimes = variableRuntimes.Where(x => x.DeviceId == item.Id); |                         var varRuntimes = variableRuntimes.Where(x => x.DeviceId == item.Id).ToArray(); | ||||||
|  |  | ||||||
|                         varRuntimes.ParallelForEach(varItem => |                         varRuntimes.ParallelForEach(varItem => | ||||||
|                         { |                         { | ||||||
|   | |||||||
| @@ -136,8 +136,9 @@ internal sealed class RedundancyHostedService : BackgroundService, IRedundancyHo | |||||||
|     /// </summary> |     /// </summary> | ||||||
|     /// <param name="tcpDmtpService">服务</param> |     /// <param name="tcpDmtpService">服务</param> | ||||||
|     /// <param name="syncInterval">同步间隔</param> |     /// <param name="syncInterval">同步间隔</param> | ||||||
|  |     /// <param name="log">log</param> | ||||||
|     /// <param name="stoppingToken">取消任务的 CancellationToken</param> |     /// <param name="stoppingToken">取消任务的 CancellationToken</param> | ||||||
|     private async ValueTask DoMasterWork(TcpDmtpService tcpDmtpService, int syncInterval, CancellationToken stoppingToken) |     private static async ValueTask DoMasterWork(TcpDmtpService tcpDmtpService, int syncInterval, ILog log, CancellationToken stoppingToken) | ||||||
|     { |     { | ||||||
|         // 延迟一段时间,避免过于频繁地执行任务 |         // 延迟一段时间,避免过于频繁地执行任务 | ||||||
|         await Task.Delay(500, stoppingToken).ConfigureAwait(false); |         await Task.Delay(500, stoppingToken).ConfigureAwait(false); | ||||||
| @@ -168,7 +169,7 @@ internal sealed class RedundancyHostedService : BackgroundService, IRedundancyHo | |||||||
|                         // 将 GlobalData.CollectDevices 和 GlobalData.Variables 同步到从站 |                         // 将 GlobalData.CollectDevices 和 GlobalData.Variables 同步到从站 | ||||||
|                         await item.GetDmtpRpcActor().InvokeAsync( |                         await item.GetDmtpRpcActor().InvokeAsync( | ||||||
|                                          nameof(ReverseCallbackServer.UpData), null, waitInvoke, deviceRunTimes).ConfigureAwait(false); |                                          nameof(ReverseCallbackServer.UpData), null, waitInvoke, deviceRunTimes).ConfigureAwait(false); | ||||||
|                         LogMessage?.LogTrace($"{item.GetIPPort()} Update StandbyStation data success"); |                         log?.LogTrace($"{item.GetIPPort()} Update StandbyStation data success"); | ||||||
|                     } |                     } | ||||||
|  |  | ||||||
|                 } |                 } | ||||||
| @@ -176,7 +177,7 @@ internal sealed class RedundancyHostedService : BackgroundService, IRedundancyHo | |||||||
|             catch (Exception ex) |             catch (Exception ex) | ||||||
|             { |             { | ||||||
|                 // 输出警告日志,指示同步数据到从站时发生错误 |                 // 输出警告日志,指示同步数据到从站时发生错误 | ||||||
|                 LogMessage?.LogWarning(ex, "Synchronize data to standby site error"); |                 log?.LogWarning(ex, "Synchronize data to standby site error"); | ||||||
|             } |             } | ||||||
|             await Task.Delay(syncInterval, stoppingToken).ConfigureAwait(false); |             await Task.Delay(syncInterval, stoppingToken).ConfigureAwait(false); | ||||||
|         } |         } | ||||||
| @@ -188,7 +189,7 @@ internal sealed class RedundancyHostedService : BackgroundService, IRedundancyHo | |||||||
|         } |         } | ||||||
|         catch (Exception ex) |         catch (Exception ex) | ||||||
|         { |         { | ||||||
|             LogMessage?.LogWarning(ex, "Execute"); |             log?.LogWarning(ex, "Execute"); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -328,9 +329,10 @@ internal sealed class RedundancyHostedService : BackgroundService, IRedundancyHo | |||||||
|     private WaitLock _switchLock = new(); |     private WaitLock _switchLock = new(); | ||||||
|  |  | ||||||
|     /// <inheritdoc/> |     /// <inheritdoc/> | ||||||
|     protected override Task ExecuteAsync(CancellationToken stoppingToken) |     protected override async Task ExecuteAsync(CancellationToken stoppingToken) | ||||||
|     { |     { | ||||||
|         return StartRedundancyTaskAsync(); |         await Task.Yield(); | ||||||
|  |         await StartRedundancyTaskAsync().ConfigureAwait(false); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public async Task<OperResult> StartRedundancyTaskAsync() |     public async Task<OperResult> StartRedundancyTaskAsync() | ||||||
| @@ -348,7 +350,7 @@ internal sealed class RedundancyHostedService : BackgroundService, IRedundancyHo | |||||||
|             { |             { | ||||||
|                 if (RedundancyOptions.IsMaster) |                 if (RedundancyOptions.IsMaster) | ||||||
|                 { |                 { | ||||||
|                     RedundancyTask = new DoTask(a => DoMasterWork(TcpDmtpService, RedundancyOptions.SyncInterval, a), LogMessage); // 创建新的任务 |                     RedundancyTask = new DoTask(a => DoMasterWork(TcpDmtpService, RedundancyOptions.SyncInterval, LogMessage, a), LogMessage); // 创建新的任务 | ||||||
|                 } |                 } | ||||||
|                 else |                 else | ||||||
|                 { |                 { | ||||||
|   | |||||||
| @@ -47,6 +47,7 @@ internal sealed class UpdateZipFileHostedService : BackgroundService, IUpdateZip | |||||||
|  |  | ||||||
|     protected override async Task ExecuteAsync(CancellationToken stoppingToken) |     protected override async Task ExecuteAsync(CancellationToken stoppingToken) | ||||||
|     { |     { | ||||||
|  |         await Task.Yield(); | ||||||
|  |  | ||||||
|         TcpDmtpClient = await GetTcpDmtpClient().ConfigureAwait(false); |         TcpDmtpClient = await GetTcpDmtpClient().ConfigureAwait(false); | ||||||
|         var upgradeServerOptions = App.GetOptions<UpgradeServerOptions>(); |         var upgradeServerOptions = App.GetOptions<UpgradeServerOptions>(); | ||||||
|   | |||||||
| @@ -125,9 +125,9 @@ internal sealed class RpcService : IRpcService | |||||||
|             } |             } | ||||||
|  |  | ||||||
|         } |         } | ||||||
|  |         var writeVariableArrays = writeVariables.ToArray(); | ||||||
|         // 使用并行方式写入变量 |         // 使用并行方式写入变量 | ||||||
|         await writeVariables.ParallelForEachAsync(async (driverData, cancellationToken) => |         await writeVariableArrays.ParallelForEachAsync(async (driverData, cancellationToken) => | ||||||
|         { |         { | ||||||
|             try |             try | ||||||
|             { |             { | ||||||
| @@ -184,9 +184,10 @@ internal sealed class RpcService : IRpcService | |||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|         }, cancellationToken).ConfigureAwait(false); |         }, cancellationToken).ConfigureAwait(false); | ||||||
|  |         var writeMethodArrays = writeMethods.ToArray(); | ||||||
|  |  | ||||||
|         // 使用并行方式执行方法 |         // 使用并行方式执行方法 | ||||||
|         await writeMethods.ParallelForEachAsync(async (driverData, cancellationToken) => |         await writeMethodArrays.ParallelForEachAsync(async (driverData, cancellationToken) => | ||||||
|         { |         { | ||||||
|             try |             try | ||||||
|             { |             { | ||||||
| @@ -250,7 +251,7 @@ internal sealed class RpcService : IRpcService | |||||||
|         return new(results); |         return new(results); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     private SqlSugarClient _db = DbContext.Db.GetConnectionScopeWithAttr<RpcLog>().CopyNew(); // 创建一个新的数据库上下文实例 |     private SqlSugarClient _db = DbContext.GetDB<RpcLog>(); // 创建一个新的数据库上下文实例 | ||||||
|  |  | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// 异步执行RPC日志插入操作的方法。 |     /// 异步执行RPC日志插入操作的方法。 | ||||||
|   | |||||||
| @@ -76,7 +76,7 @@ public class AlarmChangedTriggerNode : VariableNode, ITriggerNode, IDisposable | |||||||
|     } |     } | ||||||
|     static Task RunAsync() |     static Task RunAsync() | ||||||
|     { |     { | ||||||
|         return AlarmVariables.GetConsumingEnumerable().ParallelForEachAsync((async (alarmVariable, token) => |         return AlarmVariables.GetConsumingEnumerable().ParallelForEachStreamedAsync((async (alarmVariable, token) => | ||||||
|             { |             { | ||||||
|                 if (AlarmChangedTriggerNodeDict.TryGetValue(alarmVariable.DeviceName, out var alarmNodeDict) && |                 if (AlarmChangedTriggerNodeDict.TryGetValue(alarmVariable.DeviceName, out var alarmNodeDict) && | ||||||
|             alarmNodeDict.TryGetValue(alarmVariable.Name, out var alarmChangedTriggerNodes)) |             alarmNodeDict.TryGetValue(alarmVariable.Name, out var alarmChangedTriggerNodes)) | ||||||
|   | |||||||
| @@ -59,7 +59,7 @@ public class DeviceChangedTriggerNode : TextNode, ITriggerNode, IDisposable | |||||||
|     } |     } | ||||||
|     static Task RunAsync() |     static Task RunAsync() | ||||||
|     { |     { | ||||||
|         return DeviceDatas.GetConsumingEnumerable().ParallelForEachAsync((async (deviceDatas, token) => |         return DeviceDatas.GetConsumingEnumerable().ParallelForEachStreamedAsync((async (deviceDatas, token) => | ||||||
|             { |             { | ||||||
|  |  | ||||||
|                 if (DeviceChangedTriggerNodeDict.TryGetValue(deviceDatas.Name ?? string.Empty, out var valueChangedTriggerNodes)) |                 if (DeviceChangedTriggerNodeDict.TryGetValue(deviceDatas.Name ?? string.Empty, out var valueChangedTriggerNodes)) | ||||||
|   | |||||||
| @@ -68,7 +68,7 @@ public class ValueChangedTriggerNode : VariableNode, ITriggerNode, IDisposable | |||||||
|     } |     } | ||||||
|     static Task RunAsync() |     static Task RunAsync() | ||||||
|     { |     { | ||||||
|         return VariableBasicDatas.GetConsumingEnumerable().ParallelForEachAsync((async (variableBasicData, token) => |         return VariableBasicDatas.GetConsumingEnumerable().ParallelForEachStreamedAsync((async (variableBasicData, token) => | ||||||
|         { |         { | ||||||
|  |  | ||||||
|             if (ValueChangedTriggerNodeDict.TryGetValue(variableBasicData.DeviceName, out var valueNodeDict) && |             if (ValueChangedTriggerNodeDict.TryGetValue(variableBasicData.DeviceName, out var valueNodeDict) && | ||||||
|   | |||||||
| @@ -129,7 +129,8 @@ internal static class RuntimeServiceHelper | |||||||
|             } |             } | ||||||
|             if (deviceRuntime != null) |             if (deviceRuntime != null) | ||||||
|             { |             { | ||||||
|                 deviceRuntime.VariableRuntimes.ParallelForEach(a => a.Value.Init(newDeviceRuntime)); |                 var list = deviceRuntime.VariableRuntimes.Select(a => a.Value).ToArray(); | ||||||
|  |                 list.ParallelForEach(a => a.Init(newDeviceRuntime)); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |  | ||||||
| @@ -156,9 +157,10 @@ internal static class RuntimeServiceHelper | |||||||
|  |  | ||||||
|     public static void RemoveOldChannelRuntimes(IEnumerable<ChannelRuntime> oldChannelRuntimes) |     public static void RemoveOldChannelRuntimes(IEnumerable<ChannelRuntime> oldChannelRuntimes) | ||||||
|     { |     { | ||||||
|         oldChannelRuntimes.SelectMany(a => a.DeviceRuntimes.SelectMany(a => a.Value.VariableRuntimes)).ParallelForEach(a => a.Value.Dispose()); |         var devs = oldChannelRuntimes.SelectMany(a => a.DeviceRuntimes).Select(a => a.Value).ToArray(); | ||||||
|         oldChannelRuntimes.SelectMany(a => a.DeviceRuntimes).ParallelForEach(a => a.Value.Dispose()); |         devs.SelectMany(a => a.VariableRuntimes).Select(a => a.Value).ToArray().ParallelForEach(a => a.Dispose()); | ||||||
|         oldChannelRuntimes.ParallelForEach(a => a.Dispose()); |         devs.ParallelForEach(a => a.Dispose()); | ||||||
|  |         oldChannelRuntimes.ToArray().ParallelForEach(a => a.Dispose()); | ||||||
|  |  | ||||||
|         GlobalData.ChannelDeviceRuntimeDispatchService.Dispatch(null); |         GlobalData.ChannelDeviceRuntimeDispatchService.Dispatch(null); | ||||||
|         GlobalData.VariableRuntimeDispatchService.Dispatch(null); |         GlobalData.VariableRuntimeDispatchService.Dispatch(null); | ||||||
| @@ -184,11 +186,12 @@ internal static class RuntimeServiceHelper | |||||||
|         foreach (var deviceRuntime in deviceRuntimes) |         foreach (var deviceRuntime in deviceRuntimes) | ||||||
|         { |         { | ||||||
|             //也需要删除变量 |             //也需要删除变量 | ||||||
|             deviceRuntime.VariableRuntimes.ParallelForEach(v => |             var vars = deviceRuntime.VariableRuntimes.Select(a => a.Value).ToArray(); | ||||||
|  |             vars.ParallelForEach(v => | ||||||
|             { |             { | ||||||
|  |  | ||||||
|                 //需要重启业务线程 |                 //需要重启业务线程 | ||||||
|                 var deviceRuntimes = GlobalData.IdDevices.Where(a => GlobalData.ContainsVariable(a.Key, v.Value)).Select(a => a.Value); |                 var deviceRuntimes = GlobalData.IdDevices.Where(a => GlobalData.ContainsVariable(a.Key, v)).Select(a => a.Value); | ||||||
|                 foreach (var deviceRuntime in deviceRuntimes) |                 foreach (var deviceRuntime in deviceRuntimes) | ||||||
|                 { |                 { | ||||||
|                     if (deviceRuntime.Driver != null) |                     if (deviceRuntime.Driver != null) | ||||||
| @@ -197,7 +200,7 @@ internal static class RuntimeServiceHelper | |||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
|  |  | ||||||
|                 v.Value.Dispose(); |                 v.Dispose(); | ||||||
|             }); |             }); | ||||||
|             deviceRuntime.Dispose(); |             deviceRuntime.Dispose(); | ||||||
|         } |         } | ||||||
| @@ -216,15 +219,16 @@ internal static class RuntimeServiceHelper | |||||||
|             if (GlobalData.Channels.TryGetValue(id, out var channelRuntime)) |             if (GlobalData.Channels.TryGetValue(id, out var channelRuntime)) | ||||||
|             { |             { | ||||||
|                 channelRuntime.Dispose(); |                 channelRuntime.Dispose(); | ||||||
|  |                 var devs = channelRuntime.DeviceRuntimes.Select(a => a.Value).ToArray(); | ||||||
|  |  | ||||||
|                 //也需要删除设备和变量 |                 //也需要删除设备和变量 | ||||||
|                 channelRuntime.DeviceRuntimes.ParallelForEach((a => |                 devs.ParallelForEach((a => | ||||||
|                 { |                 { | ||||||
|  |                     var vars = a.VariableRuntimes.Select(b => b.Value).ToArray(); | ||||||
|                     ParallelExtensions.ParallelForEach(a.Value.VariableRuntimes, (v => |                     ParallelExtensions.ParallelForEach(vars, (v => | ||||||
|                     { |                     { | ||||||
|                         //需要重启业务线程 |                         //需要重启业务线程 | ||||||
|                         var deviceRuntimes = GlobalData.IdDevices.Where(a => GlobalData.ContainsVariable(a.Key, v.Value)).Select(a => a.Value); |                         var deviceRuntimes = GlobalData.IdDevices.Where(a => GlobalData.ContainsVariable(a.Key, v)).Select(a => a.Value); | ||||||
|                         foreach (var deviceRuntime in deviceRuntimes) |                         foreach (var deviceRuntime in deviceRuntimes) | ||||||
|                         { |                         { | ||||||
|                             if (deviceRuntime.Driver != null) |                             if (deviceRuntime.Driver != null) | ||||||
| @@ -234,12 +238,12 @@ internal static class RuntimeServiceHelper | |||||||
|                         } |                         } | ||||||
|  |  | ||||||
|  |  | ||||||
|                         v.Value.Dispose(); |                         v.Dispose(); | ||||||
|  |  | ||||||
|  |  | ||||||
|                     } |                     } | ||||||
|                     )); |                     )); | ||||||
|                     a.Value.Dispose(); |                     a.Dispose(); | ||||||
|  |  | ||||||
|                 })); |                 })); | ||||||
|             } |             } | ||||||
| @@ -274,20 +278,20 @@ internal static class RuntimeServiceHelper | |||||||
|         foreach (var group in groups) |         foreach (var group in groups) | ||||||
|         { |         { | ||||||
|             if (group.Key != null) |             if (group.Key != null) | ||||||
|                 await group.Key.RemoveDeviceAsync(group.Value.Select(a => a.Id)).ConfigureAwait(false); |                 await group.Key.RemoveDeviceAsync(group.Value.Select(a => a.Id).ToArray()).ConfigureAwait(false); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |  | ||||||
|     public static async Task ChangedDriverAsync(ILogger logger, CancellationToken cancellationToken) |     public static async Task ChangedDriverAsync(ILogger logger, CancellationToken cancellationToken) | ||||||
|     { |     { | ||||||
|         var channelDevice = GlobalData.IdDevices.Where(a => a.Value.Driver?.DriverProperties is IBusinessPropertyAllVariableBase property && property.IsAllVariable); |         var channelDevice = GlobalData.IdDevices.Where(a => a.Value.Driver?.DriverProperties is IBusinessPropertyAllVariableBase property && property.IsAllVariable).Select(a => a.Value).ToArray(); | ||||||
|  |  | ||||||
|         await channelDevice.ParallelForEachAsync(async (item, token) => |         await channelDevice.ParallelForEachAsync(async (item, token) => | ||||||
|          { |          { | ||||||
|              try |              try | ||||||
|              { |              { | ||||||
|                  await item.Value.Driver.AfterVariablesChangedAsync(token).ConfigureAwait(false); |                  await item.Driver.AfterVariablesChangedAsync(token).ConfigureAwait(false); | ||||||
|              } |              } | ||||||
|              catch (Exception ex) |              catch (Exception ex) | ||||||
|              { |              { | ||||||
| @@ -299,7 +303,7 @@ internal static class RuntimeServiceHelper | |||||||
|     { |     { | ||||||
|         var drivers = GlobalData.IdDevices.Where(a => a.Value.Driver?.DriverProperties is IBusinessPropertyAllVariableBase property && property.IsAllVariable).Select(a => a.Value.Driver); |         var drivers = GlobalData.IdDevices.Where(a => a.Value.Driver?.DriverProperties is IBusinessPropertyAllVariableBase property && property.IsAllVariable).Select(a => a.Value.Driver); | ||||||
|  |  | ||||||
|         var changedDrivers = drivers.Concat(changedDriver).Where(a => a.DisposedValue == false).ToHashSet(); |         var changedDrivers = drivers.Concat(changedDriver).Where(a => a.DisposedValue == false).Distinct().ToArray(); | ||||||
|         await changedDrivers.ParallelForEachAsync(async (driver, token) => |         await changedDrivers.ParallelForEachAsync(async (driver, token) => | ||||||
|          { |          { | ||||||
|              try |              try | ||||||
|   | |||||||
| @@ -586,7 +586,7 @@ internal sealed class VariableService : BaseService<Variable>, IVariableService | |||||||
|             var dbVariableDicts = await GetVariableImportData().ConfigureAwait(false); |             var dbVariableDicts = await GetVariableImportData().ConfigureAwait(false); | ||||||
|  |  | ||||||
|             // 并行处理每一行数据 |             // 并行处理每一行数据 | ||||||
|             rows.ParallelForEach((item, state, index) => |             rows.ParallelForEachStreamed((item, state, index) => | ||||||
|             { |             { | ||||||
|                 try |                 try | ||||||
|                 { |                 { | ||||||
| @@ -720,7 +720,7 @@ internal sealed class VariableService : BaseService<Variable>, IVariableService | |||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
|  |  | ||||||
|                 rows.ParallelForEach(item => |                 rows.ParallelForEachStreamed(item => | ||||||
|                 { |                 { | ||||||
|                     try |                     try | ||||||
|                     { |                     { | ||||||
|   | |||||||
| @@ -68,7 +68,7 @@ public static class VariableServiceHelpers | |||||||
|  |  | ||||||
|         #endregion 列名称 |         #endregion 列名称 | ||||||
|         var varName = nameof(Variable.Name); |         var varName = nameof(Variable.Name); | ||||||
|         data.ParallelForEach((variable, state, index) => |         data.ParallelForEachStreamed((variable, state, index) => | ||||||
|         { |         { | ||||||
|             Dictionary<string, object> varExport = new(); |             Dictionary<string, object> varExport = new(); | ||||||
|             deviceDicts.TryGetValue(variable.DeviceId, out var device); |             deviceDicts.TryGetValue(variable.DeviceId, out var device); | ||||||
|   | |||||||
| @@ -103,7 +103,7 @@ public class Startup : AppStartup | |||||||
|         //遍历配置 |         //遍历配置 | ||||||
|         DbContext.DbConfigs?.ForEach(it => |         DbContext.DbConfigs?.ForEach(it => | ||||||
|         { |         { | ||||||
|             var connection = DbContext.Db.GetConnection(it.ConfigId);//获取数据库连接对象 |             var connection = DbContext.GetDB().GetConnection(it.ConfigId);//获取数据库连接对象 | ||||||
|  |  | ||||||
|             if (it.InitDatabase == true) |             if (it.InitDatabase == true) | ||||||
|                 connection.DbMaintenance.CreateDatabase();//创建数据库,如果存在则不创建 |                 connection.DbMaintenance.CreateDatabase();//创建数据库,如果存在则不创建 | ||||||
|   | |||||||
| @@ -8,8 +8,8 @@ | |||||||
| 	<ItemGroup> | 	<ItemGroup> | ||||||
| 		<PackageReference Include="Portable.BouncyCastle" Version="1.9.0" /> | 		<PackageReference Include="Portable.BouncyCastle" Version="1.9.0" /> | ||||||
| 		<PackageReference Include="Rougamo.Fody" Version="5.0.0" /> | 		<PackageReference Include="Rougamo.Fody" Version="5.0.0" /> | ||||||
| 		<PackageReference Include="TouchSocket.Dmtp" Version="3.1.7" /> | 		<PackageReference Include="TouchSocket.Dmtp" Version="3.1.8" /> | ||||||
| 		<PackageReference Include="TouchSocket.WebApi.Swagger" Version="3.1.7" /> | 		<PackageReference Include="TouchSocket.WebApi.Swagger" Version="3.1.8" /> | ||||||
| 		<PackageReference Include="ThingsGateway.Authentication" Version="$(AuthenticationVersion)" /> | 		<PackageReference Include="ThingsGateway.Authentication" Version="$(AuthenticationVersion)" /> | ||||||
| 		<!--<ProjectReference Include="..\..\PluginPro\ThingsGateway.Authentication\ThingsGateway.Authentication.csproj" />--> | 		<!--<ProjectReference Include="..\..\PluginPro\ThingsGateway.Authentication\ThingsGateway.Authentication.csproj" />--> | ||||||
|  |  | ||||||
|   | |||||||
| @@ -89,23 +89,3 @@ public partial class TcpServiceComponent : IDriverUIBase | |||||||
|     public ITcpServiceChannel? TcpServiceChannel => (((DriverBase)Driver)?.Channel as ITcpServiceChannel); |     public ITcpServiceChannel? TcpServiceChannel => (((DriverBase)Driver)?.Channel as ITcpServiceChannel); | ||||||
| } | } | ||||||
|  |  | ||||||
| public class TcpSessionClientDto |  | ||||||
| { |  | ||||||
|     [AutoGenerateColumn(Searchable = true, Filterable = true, Sortable = true)] |  | ||||||
|     public string Id { get; set; } |  | ||||||
|  |  | ||||||
|     [AutoGenerateColumn(Searchable = true, Filterable = true, Sortable = true)] |  | ||||||
|     public string IP { get; set; } |  | ||||||
|  |  | ||||||
|     [AutoGenerateColumn(Searchable = true, Filterable = true, Sortable = true)] |  | ||||||
|     public int Port { get; set; } |  | ||||||
|  |  | ||||||
|     [AutoGenerateColumn(Searchable = true, Filterable = true, Sortable = true, ShowTips = true)] |  | ||||||
|     public string PluginInfos { get; set; } |  | ||||||
|  |  | ||||||
|     [AutoGenerateColumn(Searchable = true, Filterable = true, Sortable = true)] |  | ||||||
|     public DateTimeOffset LastReceivedTime { get; set; } |  | ||||||
|  |  | ||||||
|     [AutoGenerateColumn(Searchable = true, Filterable = true, Sortable = true)] |  | ||||||
|     public DateTimeOffset LastSentTime { get; set; } |  | ||||||
| } |  | ||||||
|   | |||||||
| @@ -0,0 +1,32 @@ | |||||||
|  | //------------------------------------------------------------------------------ | ||||||
|  | //  此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充 | ||||||
|  | //  此代码版权(除特别声明外的代码)归作者本人Diego所有 | ||||||
|  | //  源代码使用协议遵循本仓库的开源协议及附加协议 | ||||||
|  | //  Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway | ||||||
|  | //  Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway | ||||||
|  | //  使用文档:https://thingsgateway.cn/ | ||||||
|  | //  QQ群:605534569 | ||||||
|  | //------------------------------------------------------------------------------ | ||||||
|  |  | ||||||
|  | namespace ThingsGateway.Gateway.Razor; | ||||||
|  |  | ||||||
|  | public class TcpSessionClientDto | ||||||
|  | { | ||||||
|  |     [AutoGenerateColumn(Searchable = true, Filterable = true, Sortable = true)] | ||||||
|  |     public string Id { get; set; } | ||||||
|  |  | ||||||
|  |     [AutoGenerateColumn(Searchable = true, Filterable = true, Sortable = true)] | ||||||
|  |     public string IP { get; set; } | ||||||
|  |  | ||||||
|  |     [AutoGenerateColumn(Searchable = true, Filterable = true, Sortable = true)] | ||||||
|  |     public int Port { get; set; } | ||||||
|  |  | ||||||
|  |     [AutoGenerateColumn(Searchable = true, Filterable = true, Sortable = true, ShowTips = true)] | ||||||
|  |     public string PluginInfos { get; set; } | ||||||
|  |  | ||||||
|  |     [AutoGenerateColumn(Searchable = true, Filterable = true, Sortable = true)] | ||||||
|  |     public DateTimeOffset LastReceivedTime { get; set; } | ||||||
|  |  | ||||||
|  |     [AutoGenerateColumn(Searchable = true, Filterable = true, Sortable = true)] | ||||||
|  |     public DateTimeOffset LastSentTime { get; set; } | ||||||
|  | } | ||||||
| @@ -19,3 +19,5 @@ global using ThingsGateway.Gateway.Application; | |||||||
| global using ThingsGateway.Razor; | global using ThingsGateway.Razor; | ||||||
| 
 | 
 | ||||||
| [assembly: SuppressMessage("Reliability", "CA2007", Justification = "<挂起>", Scope = "module")] | [assembly: SuppressMessage("Reliability", "CA2007", Justification = "<挂起>", Scope = "module")] | ||||||
|  | 
 | ||||||
|  | [assembly: BlazorSetParametersAsyncGenerator.GlobalGenerateSetParametersAsync(true)] | ||||||
| @@ -112,6 +112,7 @@ | |||||||
|             <EditorItem @bind-Field="@context.StopBits" Ignore=@(context.ChannelType!=ChannelTypeEnum.SerialPort) /> |             <EditorItem @bind-Field="@context.StopBits" Ignore=@(context.ChannelType!=ChannelTypeEnum.SerialPort) /> | ||||||
|             <EditorItem @bind-Field="@context.DtrEnable" Ignore=@(context.ChannelType!=ChannelTypeEnum.SerialPort) /> |             <EditorItem @bind-Field="@context.DtrEnable" Ignore=@(context.ChannelType!=ChannelTypeEnum.SerialPort) /> | ||||||
|             <EditorItem @bind-Field="@context.RtsEnable" Ignore=@(context.ChannelType!=ChannelTypeEnum.SerialPort) /> |             <EditorItem @bind-Field="@context.RtsEnable" Ignore=@(context.ChannelType!=ChannelTypeEnum.SerialPort) /> | ||||||
|  |             <EditorItem @bind-Field="@context.StreamAsync" Ignore=@(context.ChannelType!=ChannelTypeEnum.SerialPort) /> | ||||||
|  |  | ||||||
|  |  | ||||||
|             <EditorItem @bind-Field="@context.CacheTimeout" Ignore=@(context.ChannelType==ChannelTypeEnum.UdpSession||context.ChannelType==ChannelTypeEnum.Other) /> |             <EditorItem @bind-Field="@context.CacheTimeout" Ignore=@(context.ChannelType==ChannelTypeEnum.UdpSession||context.ChannelType==ChannelTypeEnum.Other) /> | ||||||
|   | |||||||
| @@ -82,6 +82,7 @@ | |||||||
|                         <EditorItem @bind-Field="@context.StopBits" Ignore=@(context.ChannelType!=ChannelTypeEnum.SerialPort) /> |                         <EditorItem @bind-Field="@context.StopBits" Ignore=@(context.ChannelType!=ChannelTypeEnum.SerialPort) /> | ||||||
|                         <EditorItem @bind-Field="@context.DtrEnable" Ignore=@(context.ChannelType!=ChannelTypeEnum.SerialPort) /> |                         <EditorItem @bind-Field="@context.DtrEnable" Ignore=@(context.ChannelType!=ChannelTypeEnum.SerialPort) /> | ||||||
|                         <EditorItem @bind-Field="@context.RtsEnable" Ignore=@(context.ChannelType!=ChannelTypeEnum.SerialPort) /> |                         <EditorItem @bind-Field="@context.RtsEnable" Ignore=@(context.ChannelType!=ChannelTypeEnum.SerialPort) /> | ||||||
|  |                         <EditorItem @bind-Field="@context.StreamAsync" Ignore=@(context.ChannelType!=ChannelTypeEnum.SerialPort) /> | ||||||
|  |  | ||||||
|  |  | ||||||
|                         <EditorItem @bind-Field="@context.CacheTimeout" Ignore=@(context.ChannelType==ChannelTypeEnum.UdpSession||context.ChannelType==ChannelTypeEnum.Other) /> |                         <EditorItem @bind-Field="@context.CacheTimeout" Ignore=@(context.ChannelType==ChannelTypeEnum.UdpSession||context.ChannelType==ChannelTypeEnum.Other) /> | ||||||
|   | |||||||
| @@ -345,8 +345,8 @@ public partial class VariableRuntimeInfo : IDisposable | |||||||
|             ShowCloseButton = false, |             ShowCloseButton = false, | ||||||
|         }; |         }; | ||||||
|         var models = Items |         var models = Items | ||||||
|                 .WhereIf(!_option.SearchText.IsNullOrWhiteSpace(), a => a.Name.Contains(_option.SearchText)).GetData(_option, out var total).ToList(); |                 .WhereIf(!_option.SearchText.IsNullOrWhiteSpace(), a => a.Name.Contains(_option.SearchText)).GetData(_option, out var total); | ||||||
|         if (models.Count > 50000) |         if (models.Count() > 50000) | ||||||
|         { |         { | ||||||
|             await ToastService.Warning("online Excel max data count 50000"); |             await ToastService.Warning("online Excel max data count 50000"); | ||||||
|             return; |             return; | ||||||
|   | |||||||
| @@ -4,6 +4,7 @@ | |||||||
|  |  | ||||||
| 	<PropertyGroup> | 	<PropertyGroup> | ||||||
| 		<TargetFrameworks>net8.0;</TargetFrameworks> | 		<TargetFrameworks>net8.0;</TargetFrameworks> | ||||||
|  | 		<!--<UseRazorSourceGenerator>false</UseRazorSourceGenerator>--> | ||||||
| 	</PropertyGroup> | 	</PropertyGroup> | ||||||
| 	<ItemGroup> | 	<ItemGroup> | ||||||
| 		<ProjectReference Include="..\ThingsGateway.Blazor.Diagrams\ThingsGateway.Blazor.Diagrams.csproj" /> | 		<ProjectReference Include="..\ThingsGateway.Blazor.Diagrams\ThingsGateway.Blazor.Diagrams.csproj" /> | ||||||
|   | |||||||
Some files were not shown because too many files have changed in this diff Show More
		Reference in New Issue
	
	Block a user
	 Diego
					Diego