mirror of
https://gitee.com/ThingsGateway/ThingsGateway.git
synced 2025-10-21 03:01:28 +08:00
Compare commits
32 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
b2589fc634 | ||
![]() |
c80e57a4e8 | ||
![]() |
6510c3e289 | ||
![]() |
920e407d05 | ||
![]() |
7314c8901d | ||
![]() |
4e9f02b48c | ||
![]() |
9ae7602cb4 | ||
![]() |
aa8aa36aef | ||
![]() |
0174f7c6f2 | ||
![]() |
df9e7d6ff1 | ||
![]() |
b40ca920d3 | ||
![]() |
5a4b0a0e93 | ||
![]() |
a879edd68b | ||
![]() |
62e0a6ee9d | ||
![]() |
765e5564d4 | ||
![]() |
10eecac19b | ||
![]() |
59241b8faa | ||
![]() |
52b3097f04 | ||
![]() |
d922296b70 | ||
![]() |
aec91da28b | ||
![]() |
013ff394be | ||
![]() |
081e07473d | ||
![]() |
d33d900592 | ||
![]() |
29365c4ef9 | ||
![]() |
17a6189089 | ||
![]() |
003b8a3763 | ||
![]() |
1c7f8b5cab | ||
![]() |
b7ff9ffca2 | ||
![]() |
9bba9bda76 | ||
![]() |
ec2fcc75d3 | ||
![]() |
57a4038577 | ||
![]() |
b78a76e60f |
2
LICENSE
2
LICENSE
@@ -85,7 +85,7 @@
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
as of the date such litigation is field.
|
||||
|
||||
4. Cachetribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
|
@@ -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="..\..\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>
|
@@ -7,12 +7,3 @@
|
||||
// 使用文档:https://thingsgateway.cn/
|
||||
// QQ群:605534569
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
global using BootstrapBlazor.Components;
|
||||
|
||||
global using Microsoft.AspNetCore.Components;
|
||||
global using Microsoft.Extensions.Localization;
|
||||
|
||||
global using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
global using ThingsGateway.Razor;
|
@@ -0,0 +1,534 @@
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
|
||||
namespace Microsoft.AspNetCore.Components;
|
||||
|
||||
[Generator]
|
||||
public partial class SetParametersAsyncGenerator : ISourceGenerator
|
||||
{
|
||||
|
||||
private string m_DoNotGenerateSetParametersAsyncAttribute = """
|
||||
|
||||
using System;
|
||||
namespace Microsoft.AspNetCore.Components
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = true)]
|
||||
internal sealed class DoNotGenerateSetParametersAsyncAttribute : Attribute
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
"""
|
||||
;
|
||||
private string m_GenerateSetParametersAsyncAttribute = """
|
||||
|
||||
using System;
|
||||
namespace Microsoft.AspNetCore.Components
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = true)]
|
||||
internal sealed class GenerateSetParametersAsyncAttribute : Attribute
|
||||
{
|
||||
public bool RequireExactMatch { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
"""
|
||||
;
|
||||
private string m_GlobalGenerateSetParametersAsyncAttribute = """
|
||||
|
||||
using System;
|
||||
namespace Microsoft.AspNetCore.Components
|
||||
{
|
||||
[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("Microsoft.AspNetCore.Components.GenerateSetParametersAsyncAttribute");
|
||||
var negativeAttributeSymbol = compilation.GetTypeByMetadataName("Microsoft.AspNetCore.Components.DoNotGenerateSetParametersAsyncAttribute");
|
||||
|
||||
// loop over the candidate methods, and keep the ones that are actually annotated
|
||||
|
||||
// 找特性
|
||||
var assemblyAttributes = compilation.Assembly.GetAttributes();
|
||||
|
||||
var enableAttr = assemblyAttributes.FirstOrDefault(attr =>
|
||||
attr.AttributeClass?.ToDisplayString() == "Microsoft.AspNetCore.Components.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 Microsoft.AspNetCore.Components
|
||||
{
|
||||
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 Microsoft.AspNetCore.Components
|
||||
{
|
||||
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 Microsoft.AspNetCore.Components
|
||||
{
|
||||
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
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -20,6 +20,7 @@ using System.Collections.Concurrent;
|
||||
using ThingsGateway.Extension;
|
||||
using ThingsGateway.FriendlyException;
|
||||
using ThingsGateway.NewLife.Json.Extension;
|
||||
using ThingsGateway.SqlSugar;
|
||||
|
||||
namespace ThingsGateway.Admin.Application;
|
||||
|
||||
@@ -90,13 +91,12 @@ public sealed class OperDescAttribute : MoAttribute
|
||||
OperDescAttribute.WriteToQueue(log);
|
||||
}
|
||||
}
|
||||
|
||||
private static SqlSugarClient _db = DbContext.GetDB<SysOperateLog>();
|
||||
/// <summary>
|
||||
/// 将日志消息写入数据库中
|
||||
/// </summary>
|
||||
private static async Task ProcessQueue()
|
||||
{
|
||||
var db = DbContext.Db.GetConnectionScopeWithAttr<SysOperateLog>().CopyNew();
|
||||
var appLifetime = App.RootServices!.GetService<IHostApplicationLifetime>()!;
|
||||
while (!appLifetime.ApplicationStopping.IsCancellationRequested)
|
||||
{
|
||||
@@ -105,7 +105,7 @@ public sealed class OperDescAttribute : MoAttribute
|
||||
var data = _logMessageQueue.ToListWithDequeue(); // 从日志队列中获取数据
|
||||
if (data.Count > 0)
|
||||
{
|
||||
await db.InsertableWithAttr(data).ExecuteCommandAsync(appLifetime.ApplicationStopping).ConfigureAwait(false);//入库
|
||||
await _db.InsertableWithAttr(data).ExecuteCommandAsync(appLifetime.ApplicationStopping).ConfigureAwait(false);//入库
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
@@ -267,7 +267,7 @@ public class RequestAuditFilter : IAsyncActionFilter, IOrderedFilter
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.Log(LogLevel.Warning, $"{logData.Method}:{logData.Path}-{logData.Operation}{Environment.NewLine}{logData.Exception.ToSystemTextJsonString()}");
|
||||
logger.Log(LogLevel.Warning, $"{logData.Method}:{logData.Path}-{logData.Operation}{Environment.NewLine}{logData.Exception?.ToSystemTextJsonString()}{Environment.NewLine}{logData.Validation?.ToSystemTextJsonString()}");
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,40 +0,0 @@
|
||||
using Microsoft.AspNetCore.Authentication.OAuth;
|
||||
|
||||
using System.Text.Json;
|
||||
|
||||
namespace ThingsGateway.Admin.Application;
|
||||
|
||||
/// <summary>OAuthOptions 配置类</summary>
|
||||
public abstract class AdminOAuthOptions : OAuthOptions
|
||||
{
|
||||
/// <summary>默认构造函数</summary>
|
||||
protected AdminOAuthOptions()
|
||||
{
|
||||
ConfigureClaims();
|
||||
this.Events.OnRemoteFailure = context =>
|
||||
{
|
||||
var redirectUri = string.IsNullOrEmpty(HomePath) ? "/" : HomePath;
|
||||
context.Response.Redirect(redirectUri);
|
||||
context.HandleResponse();
|
||||
return Task.CompletedTask;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// <summary>配置 Claims 映射</summary>
|
||||
protected virtual void ConfigureClaims()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual string GetName(JsonElement element)
|
||||
{
|
||||
JsonElement.ObjectEnumerator target = element.EnumerateObject();
|
||||
return target.TryGetValue("name");
|
||||
}
|
||||
|
||||
/// <summary>获得/设置 登陆后首页</summary>
|
||||
public string HomePath { get; set; } = "/";
|
||||
|
||||
}
|
@@ -1,12 +0,0 @@
|
||||
namespace ThingsGateway.Admin.Application;
|
||||
|
||||
public class GiteeOAuthUser
|
||||
{
|
||||
public string Id { get; set; }
|
||||
|
||||
public string Login { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
public string Avatar_Url { get; set; }
|
||||
}
|
@@ -1,22 +0,0 @@
|
||||
using System.Text.Json;
|
||||
|
||||
namespace ThingsGateway.Admin.Application;
|
||||
|
||||
public static class OAuthUserExtensions
|
||||
{
|
||||
public static GiteeOAuthUser ToAuthUser(this JsonElement element)
|
||||
{
|
||||
GiteeOAuthUser authUser = new GiteeOAuthUser();
|
||||
JsonElement.ObjectEnumerator target = element.EnumerateObject();
|
||||
authUser.Id = target.TryGetValue("id");
|
||||
authUser.Login = target.TryGetValue("login");
|
||||
authUser.Name = target.TryGetValue("name");
|
||||
authUser.Avatar_Url = target.TryGetValue("avatar_url");
|
||||
return authUser;
|
||||
}
|
||||
|
||||
public static string TryGetValue(this JsonElement.ObjectEnumerator target, string propertyName)
|
||||
{
|
||||
return target.FirstOrDefault<JsonProperty>((Func<JsonProperty, bool>)(t => t.Name.Equals(propertyName, StringComparison.OrdinalIgnoreCase))).Value.ToString() ?? string.Empty;
|
||||
}
|
||||
}
|
@@ -8,5 +8,4 @@
|
||||
// QQ群:605534569
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
global using ThingsGateway;
|
||||
global using ThingsGateway.NewLife.Extension;
|
@@ -20,6 +20,7 @@ using ThingsGateway.NewLife;
|
||||
using ThingsGateway.NewLife.Caching;
|
||||
using ThingsGateway.NewLife.Threading;
|
||||
using ThingsGateway.Schedule;
|
||||
using ThingsGateway.SqlSugar;
|
||||
|
||||
namespace ThingsGateway.Admin.Application;
|
||||
|
||||
@@ -60,7 +61,7 @@ public class HardwareJob : IJob, IHardwareJob
|
||||
var historyHardwareInfos = MemoryCache.Get<List<HistoryHardwareInfo>>(CacheKey);
|
||||
if (historyHardwareInfos == null)
|
||||
{
|
||||
using var db = DbContext.Db.GetConnectionScopeWithAttr<HistoryHardwareInfo>().CopyNew();
|
||||
using var db = DbContext.GetDB<HistoryHardwareInfo>(); ;
|
||||
historyHardwareInfos = await db.Queryable<HistoryHardwareInfo>().Where(a => a.Date > DateTime.Now.AddDays(-3)).ToListAsync().ConfigureAwait(false);
|
||||
|
||||
MemoryCache.Set(CacheKey, historyHardwareInfos);
|
||||
@@ -70,6 +71,7 @@ public class HardwareJob : IJob, IHardwareJob
|
||||
|
||||
private bool error = false;
|
||||
private DateTime hisInsertTime = default;
|
||||
private SqlSugarClient _db = DbContext.GetDB<HistoryHardwareInfo>();
|
||||
|
||||
public async Task ExecuteAsync(JobExecutingContext context, CancellationToken stoppingToken)
|
||||
{
|
||||
@@ -79,7 +81,7 @@ public class HardwareJob : IJob, IHardwareJob
|
||||
{
|
||||
if (HardwareInfo.MachineInfo == null)
|
||||
{
|
||||
await MachineInfo.RegisterAsync().ConfigureAwait(false);
|
||||
MachineInfo.Register();
|
||||
HardwareInfo.MachineInfo = MachineInfo.Current;
|
||||
|
||||
string currentPath = Directory.GetCurrentDirectory();
|
||||
@@ -121,7 +123,6 @@ public class HardwareJob : IJob, IHardwareJob
|
||||
if (DateTime.Now > hisInsertTime.Add(TimeSpan.FromMilliseconds(HardwareInfoOptions.HistoryInterval)))
|
||||
{
|
||||
hisInsertTime = DateTime.Now;
|
||||
using var db = DbContext.Db.GetConnectionScopeWithAttr<HistoryHardwareInfo>().CopyNew();
|
||||
{
|
||||
var his = new HistoryHardwareInfo()
|
||||
{
|
||||
@@ -132,12 +133,12 @@ public class HardwareJob : IJob, IHardwareJob
|
||||
CpuUsage = (HardwareInfo.MachineInfo.CpuRate * 100).ToInt(),
|
||||
Temperature = (HardwareInfo.MachineInfo.Temperature).ToInt(),
|
||||
};
|
||||
await db.Insertable(his).ExecuteCommandAsync(stoppingToken).ConfigureAwait(false);
|
||||
await _db.Insertable(his).ExecuteCommandAsync(stoppingToken).ConfigureAwait(false);
|
||||
MemoryCache.Remove(CacheKey);
|
||||
}
|
||||
var sevenDaysAgo = TimerX.Now.AddDays(-HardwareInfoOptions.DaysAgo);
|
||||
//删除特定信息
|
||||
var result = await db.Deleteable<HistoryHardwareInfo>(a => a.Date <= sevenDaysAgo).ExecuteCommandAsync(stoppingToken).ConfigureAwait(false);
|
||||
var result = await _db.Deleteable<HistoryHardwareInfo>(a => a.Date <= sevenDaysAgo).ExecuteCommandAsync(stoppingToken).ConfigureAwait(false);
|
||||
if (result > 0)
|
||||
{
|
||||
MemoryCache.Remove(CacheKey);
|
||||
|
@@ -27,7 +27,7 @@ public class LogJob : IJob
|
||||
|
||||
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);
|
||||
await db.DeleteableWithAttr<SysOperateLog>().Where(u => u.OpTime < time).ExecuteCommandAsync(stoppingToken).ConfigureAwait(false); // 删除操作日志
|
||||
}
|
||||
|
@@ -143,7 +143,7 @@ public class DatabaseLoggingWriter : IDatabaseLoggingWriter
|
||||
|
||||
if (flush)
|
||||
{
|
||||
SqlSugarClient ??= DbContext.Db.GetConnectionScopeWithAttr<SysOperateLog>().CopyNew();
|
||||
SqlSugarClient ??= DbContext.GetDB<SysOperateLog>();
|
||||
await SqlSugarClient.InsertableWithAttr(_operateLogMessageQueue.ToListWithDequeue()).ExecuteCommandAsync().ConfigureAwait(false);//入库
|
||||
return true;
|
||||
}
|
||||
@@ -202,7 +202,7 @@ public class DatabaseLoggingWriter : IDatabaseLoggingWriter
|
||||
|
||||
if (flush)
|
||||
{
|
||||
SqlSugarClient ??= DbContext.Db.GetConnectionScopeWithAttr<SysOperateLog>().CopyNew();
|
||||
SqlSugarClient ??= DbContext.GetDB<SysOperateLog>();
|
||||
await SqlSugarClient.InsertableWithAttr(_operateLogMessageQueue.ToListWithDequeue()).ExecuteCommandAsync().ConfigureAwait(false);//入库
|
||||
return true;
|
||||
}
|
||||
|
@@ -1,18 +1,14 @@
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.AspNetCore.Authentication.OAuth;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.WebUtilities;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
using System.Collections.Concurrent;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Security.Claims;
|
||||
using System.Text;
|
||||
using System.Text.Encodings.Web;
|
||||
using System.Text.Json;
|
||||
|
||||
using ThingsGateway.Extension;
|
||||
|
||||
@@ -50,7 +46,7 @@ public class AdminOAuthHandler<TOptions>(
|
||||
/// </summary>
|
||||
private static async Task Insertable()
|
||||
{
|
||||
var db = DbContext.Db.GetConnectionScopeWithAttr<SysOperateLog>().CopyNew();
|
||||
var db = DbContext.GetDB<SysOperateLog>();
|
||||
var appLifetime = App.RootServices!.GetService<IHostApplicationLifetime>()!;
|
||||
while (!appLifetime.ApplicationStopping.IsCancellationRequested)
|
||||
{
|
||||
@@ -80,6 +76,7 @@ public class AdminOAuthHandler<TOptions>(
|
||||
AuthenticationProperties properties,
|
||||
OAuthTokenResponse tokens)
|
||||
{
|
||||
Backchannel.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", tokens.AccessToken);
|
||||
properties.RedirectUri = Options.HomePath;
|
||||
properties.IsPersistent = true;
|
||||
var appConfig = await configService.GetAppConfigAsync().ConfigureAwait(false);
|
||||
@@ -90,7 +87,7 @@ public class AdminOAuthHandler<TOptions>(
|
||||
properties.ExpiresUtc = TimeProvider.System.GetUtcNow().AddSeconds(result);
|
||||
expire = (int)(result / 60.0);
|
||||
}
|
||||
var user = await HandleUserInfoAsync(tokens).ConfigureAwait(false);
|
||||
var user = await Options.HandleUserInfoAsync(Context, tokens).ConfigureAwait(false);
|
||||
|
||||
var loginEvent = await GetLogin(expire).ConfigureAwait(false);
|
||||
await UpdateUser(loginEvent).ConfigureAwait(false);
|
||||
@@ -148,43 +145,8 @@ public class AdminOAuthHandler<TOptions>(
|
||||
}
|
||||
|
||||
|
||||
/// <summary>处理用户信息方法</summary>
|
||||
protected virtual async Task<JsonElement> HandleUserInfoAsync(OAuthTokenResponse tokens)
|
||||
{
|
||||
var request = new HttpRequestMessage(HttpMethod.Get, BuildUserInfoUrl(tokens));
|
||||
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||
|
||||
var response = await Backchannel.SendAsync(request, Context.RequestAborted).ConfigureAwait(false);
|
||||
|
||||
var content = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
|
||||
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
return JsonDocument.Parse(content).RootElement;
|
||||
}
|
||||
|
||||
throw new OAuthTokenException($"OAuth user info endpoint failure: {await Display(response).ConfigureAwait(false)}");
|
||||
}
|
||||
|
||||
/// <summary>生成用户信息请求地址方法</summary>
|
||||
protected virtual string BuildUserInfoUrl(OAuthTokenResponse tokens)
|
||||
{
|
||||
return QueryHelpers.AddQueryString(Options.UserInformationEndpoint, new Dictionary<string, string>
|
||||
{
|
||||
{ "access_token", tokens.AccessToken }
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>生成错误信息方法</summary>
|
||||
protected static async Task<string> Display(HttpResponseMessage response)
|
||||
{
|
||||
var output = new StringBuilder();
|
||||
output.Append($"Status: {response.StatusCode}; ");
|
||||
output.Append($"Headers: {response.Headers}; ");
|
||||
output.Append($"Body: {await response.Content.ReadAsStringAsync().ConfigureAwait(false)};");
|
||||
|
||||
return output.ToString();
|
||||
}
|
||||
|
||||
private async Task<LoginEvent> GetLogin(int expire)
|
||||
{
|
||||
@@ -247,7 +209,7 @@ public class AdminOAuthHandler<TOptions>(
|
||||
|
||||
#endregion 重新赋值属性,设置本次登录信息为最新的信息
|
||||
|
||||
using var db = DbContext.Db.GetConnectionScopeWithAttr<SysUser>().CopyNew();
|
||||
using var db = DbContext.GetDB<SysUser>();
|
||||
//更新用户登录信息
|
||||
if (await db.Updateable(sysUser).UpdateColumns(it => new
|
||||
{
|
@@ -0,0 +1,87 @@
|
||||
using Microsoft.AspNetCore.Authentication.OAuth;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.WebUtilities;
|
||||
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace ThingsGateway.Admin.Application;
|
||||
|
||||
/// <summary>OAuthOptions 配置类</summary>
|
||||
public abstract class AdminOAuthOptions : OAuthOptions
|
||||
{
|
||||
/// <summary>默认构造函数</summary>
|
||||
protected AdminOAuthOptions()
|
||||
{
|
||||
ConfigureClaims();
|
||||
this.Events.OnRemoteFailure = context =>
|
||||
{
|
||||
var redirectUri = string.IsNullOrEmpty(HomePath) ? "/" : HomePath;
|
||||
context.Response.Redirect(redirectUri);
|
||||
context.HandleResponse();
|
||||
return Task.CompletedTask;
|
||||
};
|
||||
|
||||
Backchannel = new HttpClient(new HttpClientHandler
|
||||
{
|
||||
ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator
|
||||
});
|
||||
Backchannel.DefaultRequestHeaders.UserAgent.Add(
|
||||
new ProductInfoHeaderValue("ThingsGateway", "1.0"));
|
||||
}
|
||||
|
||||
/// <summary>配置 Claims 映射</summary>
|
||||
protected virtual void ConfigureClaims()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual string GetName(JsonElement element)
|
||||
{
|
||||
JsonElement.ObjectEnumerator target = element.EnumerateObject();
|
||||
return target.TryGetValue("name");
|
||||
}
|
||||
|
||||
/// <summary>获得/设置 登陆后首页</summary>
|
||||
public string HomePath { get; set; } = "/";
|
||||
|
||||
|
||||
|
||||
/// <summary>处理用户信息方法</summary>
|
||||
public virtual async Task<JsonElement> HandleUserInfoAsync(HttpContext context, OAuthTokenResponse tokens)
|
||||
{
|
||||
var request = new HttpRequestMessage(HttpMethod.Get, BuildUserInfoUrl(tokens));
|
||||
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||
|
||||
var response = await Backchannel.SendAsync(request, context.RequestAborted).ConfigureAwait(false);
|
||||
|
||||
var content = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
|
||||
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
return JsonDocument.Parse(content).RootElement;
|
||||
}
|
||||
|
||||
throw new OAuthTokenException($"OAuth user info endpoint failure: {await Display(response).ConfigureAwait(false)}");
|
||||
}
|
||||
|
||||
/// <summary>生成用户信息请求地址方法</summary>
|
||||
protected virtual string BuildUserInfoUrl(OAuthTokenResponse tokens)
|
||||
{
|
||||
return QueryHelpers.AddQueryString(UserInformationEndpoint, new Dictionary<string, string>
|
||||
{
|
||||
{ "access_token", tokens.AccessToken }
|
||||
});
|
||||
}
|
||||
/// <summary>生成错误信息方法</summary>
|
||||
protected async Task<string> Display(HttpResponseMessage response)
|
||||
{
|
||||
var output = new StringBuilder();
|
||||
output.Append($"Status: {response.StatusCode}; ");
|
||||
output.Append($"Headers: {response.Headers}; ");
|
||||
output.Append($"Body: {await response.Content.ReadAsStringAsync().ConfigureAwait(false)};");
|
||||
|
||||
return output.ToString();
|
||||
}
|
||||
}
|
@@ -3,16 +3,20 @@ using Microsoft.AspNetCore.Authentication.OAuth;
|
||||
using Microsoft.AspNetCore.WebUtilities;
|
||||
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
|
||||
using ThingsGateway.NewLife.Log;
|
||||
|
||||
namespace ThingsGateway.Admin.Application;
|
||||
|
||||
public class GiteeOAuthOptions : AdminOAuthOptions
|
||||
{
|
||||
|
||||
INoticeService _noticeService;
|
||||
IVerificatInfoService _verificatInfoService;
|
||||
public GiteeOAuthOptions() : base()
|
||||
{
|
||||
_noticeService = App.GetService<INoticeService>();
|
||||
_verificatInfoService = App.GetService<IVerificatInfoService>();
|
||||
this.SignInScheme = ClaimConst.Scheme;
|
||||
this.AuthorizationEndpoint = "https://gitee.com/oauth/authorize";
|
||||
this.TokenEndpoint = "https://gitee.com/oauth/token";
|
||||
@@ -29,11 +33,14 @@ public class GiteeOAuthOptions : AdminOAuthOptions
|
||||
|
||||
Events.OnRedirectToAuthorizationEndpoint = context =>
|
||||
{
|
||||
//context.RedirectUri = context.RedirectUri.Replace("http%3A%2F%2F", "https%3A%2F%2F"); // 强制替换
|
||||
context.Response.Redirect(context.RedirectUri);
|
||||
return Task.CompletedTask;
|
||||
};
|
||||
|
||||
Events.OnRemoteFailure = context =>
|
||||
{
|
||||
XTrace.WriteException(context.Failure);
|
||||
return Task.CompletedTask;
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>刷新 Token 方法</summary>
|
||||
@@ -60,16 +67,7 @@ public class GiteeOAuthOptions : AdminOAuthOptions
|
||||
return OAuthTokenResponse.Failed(new OAuthTokenException($"OAuth token endpoint failure: {await Display(response).ConfigureAwait(false)}"));
|
||||
}
|
||||
|
||||
/// <summary>生成错误信息方法</summary>
|
||||
protected static async Task<string> Display(HttpResponseMessage response)
|
||||
{
|
||||
var output = new StringBuilder();
|
||||
output.Append($"Status: {response.StatusCode}; ");
|
||||
output.Append($"Headers: {response.Headers}; ");
|
||||
output.Append($"Body: {await response.Content.ReadAsStringAsync().ConfigureAwait(false)};");
|
||||
|
||||
return output.ToString();
|
||||
}
|
||||
|
||||
public override string GetName(JsonElement element)
|
||||
{
|
||||
@@ -77,7 +75,7 @@ public class GiteeOAuthOptions : AdminOAuthOptions
|
||||
return target.TryGetValue("name");
|
||||
}
|
||||
|
||||
private static async Task HandlerGiteeStarredUrl(OAuthCreatingTicketContext context, string repoFullName = "ThingsGateway/ThingsGateway")
|
||||
private async Task HandlerGiteeStarredUrl(OAuthCreatingTicketContext context, string repoFullName = "ThingsGateway/ThingsGateway")
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(context.AccessToken))
|
||||
throw new InvalidOperationException("Access token is missing.");
|
||||
@@ -89,7 +87,7 @@ public class GiteeOAuthOptions : AdminOAuthOptions
|
||||
{ "access_token", context.AccessToken }
|
||||
};
|
||||
|
||||
var request = new HttpRequestMessage(HttpMethod.Put, QueryHelpers.AddQueryString(uri, queryString))
|
||||
var request = new HttpRequestMessage(HttpMethod.Get, QueryHelpers.AddQueryString(uri, queryString))
|
||||
{
|
||||
Headers = { Accept = { new MediaTypeWithQualityHeaderValue("application/json") } }
|
||||
};
|
||||
@@ -99,7 +97,17 @@ public class GiteeOAuthOptions : AdminOAuthOptions
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
var content = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
|
||||
throw new Exception($"Failed to star repository: {response.StatusCode}, {content}");
|
||||
|
||||
var id = context.Identity.Claims.FirstOrDefault(a => a.Type == ClaimConst.VerificatId).Value;
|
||||
|
||||
var verificatInfoIds = _verificatInfoService.GetOne(id.ToLong());
|
||||
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
await Task.Delay(5000).ConfigureAwait(false);
|
||||
await _noticeService.NavigationMesage(verificatInfoIds.ClientIds, "https://gitee.com/ThingsGateway/ThingsGateway", "创作不易,如有帮助请star仓库").ConfigureAwait(false);
|
||||
});
|
||||
//throw new Exception($"Failed to star repository: {response.StatusCode}, {content}");
|
||||
}
|
||||
|
||||
|
@@ -0,0 +1,122 @@
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.AspNetCore.Authentication.OAuth;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text.Json;
|
||||
|
||||
using ThingsGateway.NewLife.Log;
|
||||
|
||||
namespace ThingsGateway.Admin.Application;
|
||||
|
||||
public class GitHubOAuthOptions : AdminOAuthOptions
|
||||
{
|
||||
INoticeService _noticeService;
|
||||
IVerificatInfoService _verificatInfoService;
|
||||
public GitHubOAuthOptions() : base()
|
||||
{
|
||||
_noticeService = App.GetService<INoticeService>();
|
||||
_verificatInfoService = App.GetService<IVerificatInfoService>();
|
||||
SignInScheme = ClaimConst.Scheme;
|
||||
AuthorizationEndpoint = "https://github.com/login/oauth/authorize";
|
||||
TokenEndpoint = "https://github.com/login/oauth/access_token";
|
||||
UserInformationEndpoint = "https://api.github.com/user";
|
||||
HomePath = "/";
|
||||
CallbackPath = "/signin-github";
|
||||
|
||||
Scope.Add("read:user");
|
||||
Scope.Add("public_repo"); // 需要用于 Star 仓库
|
||||
|
||||
Events.OnCreatingTicket = async context =>
|
||||
{
|
||||
await HandleGitHubStarAsync(context).ConfigureAwait(false);
|
||||
};
|
||||
|
||||
Events.OnRedirectToAuthorizationEndpoint = context =>
|
||||
{
|
||||
context.Response.Redirect(context.RedirectUri);
|
||||
return Task.CompletedTask;
|
||||
};
|
||||
Events.OnRemoteFailure = context =>
|
||||
{
|
||||
XTrace.WriteException(context.Failure);
|
||||
return Task.CompletedTask;
|
||||
};
|
||||
}
|
||||
|
||||
protected override void ConfigureClaims()
|
||||
{
|
||||
ClaimActions.MapJsonKey(ClaimConst.AvatarUrl, "avatar_url");
|
||||
ClaimActions.MapJsonKey(ClaimConst.Account, "login");
|
||||
|
||||
base.ConfigureClaims();
|
||||
}
|
||||
|
||||
public override string GetName(JsonElement element)
|
||||
{
|
||||
if (element.TryGetProperty("login", out var loginProp))
|
||||
{
|
||||
return loginProp.GetString() ?? string.Empty;
|
||||
}
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
private async Task HandleGitHubStarAsync(OAuthCreatingTicketContext context, string repoFullName = "ThingsGateway/ThingsGateway")
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(context.AccessToken))
|
||||
throw new InvalidOperationException("Access token is missing.");
|
||||
|
||||
|
||||
|
||||
var request = new HttpRequestMessage(HttpMethod.Put, $"https://api.github.com/user/starred/{repoFullName}")
|
||||
{
|
||||
Headers =
|
||||
{
|
||||
Accept = { new MediaTypeWithQualityHeaderValue("application/vnd.github+json") },
|
||||
Authorization = new AuthenticationHeaderValue("Bearer", context.AccessToken),
|
||||
},
|
||||
Content = new StringContent(string.Empty) // GitHub Star 接口需要空内容
|
||||
};
|
||||
request.Headers.UserAgent.Add(new ProductInfoHeaderValue("ThingsGateway", "1.0")); // GitHub API 要求 User-Agent
|
||||
|
||||
var response = await context.Backchannel.SendAsync(request, context.HttpContext.RequestAborted).ConfigureAwait(false);
|
||||
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
var content = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
|
||||
|
||||
var id = context.Identity.Claims.FirstOrDefault(a => a.Type == ClaimConst.VerificatId).Value;
|
||||
|
||||
var verificatInfoIds = _verificatInfoService.GetOne(id.ToLong());
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
await Task.Delay(5000).ConfigureAwait(false);
|
||||
await _noticeService.NavigationMesage(verificatInfoIds.ClientIds, "https://github.com/ThingsGateway/ThingsGateway", "创作不易,如有帮助请star仓库").ConfigureAwait(false);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>处理用户信息方法</summary>
|
||||
public override async Task<JsonElement> HandleUserInfoAsync(HttpContext context, OAuthTokenResponse tokens)
|
||||
{
|
||||
|
||||
var request = new HttpRequestMessage(HttpMethod.Get, UserInformationEndpoint);
|
||||
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", tokens.AccessToken);
|
||||
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/vnd.github+json"));
|
||||
request.Headers.UserAgent.Add(new ProductInfoHeaderValue("ThingsGateway", "1.0")); // GitHub API 要求 User-Agent
|
||||
var response = await Backchannel.SendAsync(request, context.RequestAborted).ConfigureAwait(false);
|
||||
|
||||
var content = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
|
||||
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
return JsonDocument.Parse(content).RootElement;
|
||||
}
|
||||
|
||||
throw new OAuthTokenException($"OAuth user info endpoint failure: {await Display(response).ConfigureAwait(false)}");
|
||||
}
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
namespace ThingsGateway.Admin.Application;
|
||||
|
||||
public class GithubOAuthSettings : GiteeOAuthSettings
|
||||
{
|
||||
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
using System.Text.Json;
|
||||
|
||||
namespace ThingsGateway.Admin.Application;
|
||||
|
||||
public static class OAuthUserExtensions
|
||||
{
|
||||
public static string TryGetValue(this JsonElement.ObjectEnumerator target, string propertyName)
|
||||
{
|
||||
return target.FirstOrDefault<JsonProperty>((Func<JsonProperty, bool>)(t => t.Name.Equals(propertyName, StringComparison.OrdinalIgnoreCase))).Value.ToString() ?? string.Empty;
|
||||
}
|
||||
}
|
@@ -18,7 +18,7 @@ public class SysRelationSeedData : ISqlSugarEntitySeedData<SysRelation>
|
||||
/// <inheritdoc/>
|
||||
public IEnumerable<SysRelation> SeedData()
|
||||
{
|
||||
var db = DbContext.Db.GetConnectionScopeWithAttr<SysRelation>().CopyNew();
|
||||
using var db = DbContext.GetDB<SysRelation>();
|
||||
if (db.Queryable<SysRelation>().Any(a => a.ObjectId == RoleConst.SuperAdminId))
|
||||
return Enumerable.Empty<SysRelation>();
|
||||
var data = SeedDataUtil.GetSeedData<SysRelation>(PathExtensions.CombinePathWithOs("SeedData", "Admin", "seed_sys_relation.json"));
|
||||
|
@@ -324,7 +324,7 @@ public class AuthService : IAuthService
|
||||
|
||||
#endregion 重新赋值属性,设置本次登录信息为最新的信息
|
||||
|
||||
using var db = DbContext.Db.GetConnectionScopeWithAttr<SysUser>().CopyNew();
|
||||
using var db = DbContext.GetDB<SysUser>();
|
||||
//更新用户登录信息
|
||||
if (await db.Updateable(sysUser).UpdateColumns(it => new
|
||||
{
|
||||
|
@@ -10,7 +10,6 @@
|
||||
|
||||
using BootstrapBlazor.Components;
|
||||
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
using System.Reflection;
|
||||
@@ -67,7 +66,7 @@ public class Startup : AppStartup
|
||||
|
||||
}
|
||||
|
||||
public void Use(IApplicationBuilder applicationBuilder)
|
||||
public void Use(IServiceProvider serviceProvider)
|
||||
{
|
||||
//检查ConfigId
|
||||
var configIdGroup = DbContext.DbConfigs.GroupBy(it => it.ConfigId);
|
||||
@@ -79,7 +78,7 @@ public class Startup : AppStartup
|
||||
//遍历配置
|
||||
DbContext.DbConfigs?.ForEach(it =>
|
||||
{
|
||||
var connection = DbContext.Db.GetConnection(it.ConfigId);//获取数据库连接对象
|
||||
var connection = DbContext.GetDB().GetConnection(it.ConfigId);//获取数据库连接对象
|
||||
if (it.InitDatabase == true)
|
||||
connection.DbMaintenance.CreateDatabase();//创建数据库,如果存在则不创建
|
||||
});
|
||||
|
@@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<Import Project="$(SolutionDir)Version.props" />
|
||||
<Import Project="$(SolutionDir)PackNuget.props" />
|
||||
<Import Project="..\..\Version.props" />
|
||||
<Import Project="..\..\PackNuget.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<GenerateDocumentationFile>True</GenerateDocumentationFile>
|
||||
@@ -18,7 +18,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Rougamo.Fody" Version="5.0.0" />
|
||||
<PackageReference Include="Rougamo.Fody" Version="5.0.1" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition=" '$(TargetFramework)' == 'net8.0' ">
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.1" />
|
||||
@@ -41,13 +41,20 @@
|
||||
<ItemGroup>
|
||||
<None Include="..\README.md" Pack="true" PackagePath="\" />
|
||||
<None Include="..\README.zh-CN.md" Pack="true" PackagePath="\" />
|
||||
<None Remove="$(SolutionDir)..\README.md" Pack="false" PackagePath="\" />
|
||||
<None Remove="$(SolutionDir)..\README.zh-CN.md" Pack="false" PackagePath="\" />
|
||||
<None Remove="..\..\..\README.md" Pack="false" PackagePath="\" />
|
||||
<None Remove="..\..\..\README.zh-CN.md" Pack="false" PackagePath="\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ThingsGateway.Razor\ThingsGateway.Razor.csproj" />
|
||||
<ProjectReference Include="..\ThingsGateway.DB\ThingsGateway.DB.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
<!--<Target Name="Mapster" AfterTargets="AfterBuild">
|
||||
<Exec WorkingDirectory="$(ProjectDir)" Command="dotnet tool restore" />
|
||||
<Exec WorkingDirectory="$(ProjectDir)" Command="dotnet mapster extension -o MapsterGenerator -a "$(TargetDir)$(ProjectName).dll"" />
|
||||
<Exec WorkingDirectory="$(ProjectDir)" Command="dotnet mapster mapper -o MapsterGenerator -a "$(TargetDir)$(ProjectName).dll"" />
|
||||
</Target>-->
|
||||
|
||||
|
||||
</Project>
|
||||
|
@@ -40,7 +40,7 @@ public static class ClearTokenUtil
|
||||
public static async Task DeleteUserTokenByOrgIds(HashSet<long> orgIds)
|
||||
{
|
||||
// 获取用户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
|
||||
App.CacheService.HashDel<VerificatInfo>(CacheConst.Cache_Token, userIds.Select(it => it.ToString()).ToArray());
|
||||
}
|
||||
|
@@ -5,6 +5,9 @@
|
||||
@<div>
|
||||
<span class="mx-3">@item.ConfirmMessage</span>
|
||||
|
||||
<Button Text=@Localizers["Jump"] Color="Color.Link" OnClick="()=>NavigationManager.NavigateTo(item.Uri)"></Button>
|
||||
<a href=@item.Uri target="_blank">
|
||||
@item.Uri
|
||||
</a>
|
||||
|
||||
</div>;
|
||||
}
|
||||
|
@@ -156,7 +156,7 @@ public class BlazorAppContext
|
||||
CurrentUser = (await SysUserService.GetUserByIdAsync(UserManager.UserId))!;
|
||||
}
|
||||
}
|
||||
TimeTick timeTick = new("50000");
|
||||
TimeTick timeTick = new("60000");
|
||||
/// <summary>
|
||||
/// 是否拥有按钮授权
|
||||
/// </summary>
|
||||
|
@@ -19,3 +19,4 @@ global using System.Diagnostics.CodeAnalysis;
|
||||
global using ThingsGateway.Razor;
|
||||
|
||||
[assembly: SuppressMessage("Reliability", "CA2007", Justification = "<挂起>", Scope = "module")]
|
||||
[assembly: GlobalGenerateSetParametersAsync(true)]
|
@@ -33,7 +33,7 @@
|
||||
</PopConfirmButton>
|
||||
<PopConfirmButton Color=Color.Warning IsDisabled="SelectedRows.Count!=1||!AuthorizeButton(AdminOperConst.Edit)" Text=@OperDescLocalizer["ChangeParentResource"] Icon="fa fa-copy" OnConfirm="OnChangeParent">
|
||||
<BodyTemplate>
|
||||
<div class="min-height-500 overflow-y-auto">
|
||||
<div class="overflow-y-auto" style="height:500px">
|
||||
<TreeView Items="MenuTreeItems" IsVirtualize="true" OnTreeItemClick="a=>{ChangeParentId=a.Value.Id;return Task.CompletedTask;}" />
|
||||
</div>
|
||||
</BodyTemplate>
|
||||
|
@@ -22,12 +22,11 @@ public partial class SessionPage
|
||||
|
||||
#region 查询
|
||||
|
||||
private async Task<QueryData<SessionOutput>> OnQueryAsync(QueryPageOptions options)
|
||||
private Task<QueryData<SessionOutput>> OnQueryAsync(QueryPageOptions options)
|
||||
{
|
||||
return await Task.Run(async () =>
|
||||
return Task.Run(() =>
|
||||
{
|
||||
var data = await SessionService.PageAsync(options);
|
||||
return data;
|
||||
return SessionService.PageAsync(options);
|
||||
});
|
||||
}
|
||||
|
||||
|
@@ -39,6 +39,7 @@ public partial class SysUserEdit
|
||||
var items = await SysPositionService.SelectorAsync(new PositionSelectorInput() { });
|
||||
Items = PositionUtil.BuildCascaderItemList(items);
|
||||
ModuleSelectedItems = ResourceUtil.BuildModuleSelectList((await SysResourceService.GetAllAsync())).ToList();
|
||||
await InvokeAsync(StateHasChanged);
|
||||
await base.OnInitializedAsync();
|
||||
}
|
||||
|
||||
|
@@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Razor">
|
||||
|
||||
<Import Project="$(SolutionDir)Version.props" />
|
||||
<Import Project="$(SolutionDir)PackNuget.props" />
|
||||
<Import Project="..\..\Version.props" />
|
||||
<Import Project="..\..\PackNuget.props" />
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ThingsGateway.Admin.Application\ThingsGateway.Admin.Application.csproj" />
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
|
||||
<!--<UseRazorSourceGenerator>false</UseRazorSourceGenerator>-->
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Content Remove="Locales\*.json" />
|
||||
@@ -29,9 +30,15 @@
|
||||
<ItemGroup>
|
||||
<None Include="..\README.md" Pack="true" PackagePath="\" />
|
||||
<None Include="..\README.zh-CN.md" Pack="true" PackagePath="\" />
|
||||
<None Remove="$(SolutionDir)..\README.md" Pack="false" PackagePath="\" />
|
||||
<None Remove="$(SolutionDir)..\README.zh-CN.md" Pack="false" PackagePath="\" />
|
||||
<None Remove="..\..\..\README.md" Pack="false" PackagePath="\" />
|
||||
<None Remove="..\..\..\README.zh-CN.md" Pack="false" PackagePath="\" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\BlazorSetParametersAsyncGenerator\BlazorSetParametersAsyncGenerator.csproj" PrivateAssets="all" OutputItemType="Analyzer" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
|
||||
|
@@ -14,6 +14,7 @@
|
||||
"ThingsGateway.SqlSugar",
|
||||
"ThingsGateway.Admin.Application",
|
||||
"ThingsGateway.Admin.Razor",
|
||||
"ThingsGateway.DB",
|
||||
"ThingsGateway.Razor"
|
||||
]
|
||||
},
|
||||
|
@@ -14,6 +14,7 @@
|
||||
"ThingsGateway.SqlSugar",
|
||||
"ThingsGateway.Admin.Application",
|
||||
"ThingsGateway.Admin.Razor",
|
||||
"ThingsGateway.DB",
|
||||
"ThingsGateway.Razor"
|
||||
]
|
||||
},
|
||||
|
@@ -40,6 +40,7 @@ public class SingleFilePublish : ISingleFilePublish
|
||||
"ThingsGateway.NewLife.X",
|
||||
"ThingsGateway.Razor",
|
||||
"ThingsGateway.Admin.Razor" ,
|
||||
"ThingsGateway.DB",
|
||||
"ThingsGateway.Admin.Application",
|
||||
"ThingsGateway.SqlSugar",
|
||||
];
|
||||
|
@@ -48,11 +48,11 @@ public class Startup : AppStartup
|
||||
});
|
||||
|
||||
|
||||
// 事件总线
|
||||
services.AddEventBus(options =>
|
||||
{
|
||||
//// 事件总线
|
||||
//services.AddEventBus(options =>
|
||||
//{
|
||||
|
||||
});
|
||||
//});
|
||||
|
||||
// 任务调度
|
||||
services.AddSchedule(options =>
|
||||
@@ -151,8 +151,6 @@ public class Startup : AppStartup
|
||||
});
|
||||
|
||||
|
||||
services.AddHealthChecks();
|
||||
|
||||
|
||||
#region 控制台美化
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<Import Project="$(SolutionDir)Version.props" />
|
||||
<Import Project="..\..\Version.props" />
|
||||
|
||||
|
||||
<PropertyGroup>
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
<!--动态适用GC-->
|
||||
<GarbageCollectionAdaptationMode>1</GarbageCollectionAdaptationMode>
|
||||
<CETCompat>false</CETCompat>
|
||||
<!--使用自托管线程池-->
|
||||
<!--<UseWindowsThreadPool>false</UseWindowsThreadPool> -->
|
||||
|
||||
|
@@ -41,19 +41,19 @@ public abstract class PrimaryKeyEntity : PrimaryIdEntity
|
||||
[SugarColumn(ColumnDescription = "扩展信息", ColumnDataType = StaticConfig.CodeFirst_BigString, IsNullable = true)]
|
||||
[IgnoreExcel]
|
||||
[AutoGenerateColumn(Ignore = true)]
|
||||
public virtual string? ExtJson { get; set; }
|
||||
public virtual string ExtJson { get; set; }
|
||||
}
|
||||
|
||||
public interface IBaseEntity
|
||||
{
|
||||
DateTime? CreateTime { get; set; }
|
||||
string? CreateUser { get; set; }
|
||||
DateTime CreateTime { get; set; }
|
||||
string CreateUser { get; set; }
|
||||
long CreateUserId { get; set; }
|
||||
bool IsDelete { get; set; }
|
||||
int? SortCode { get; set; }
|
||||
DateTime? UpdateTime { get; set; }
|
||||
string? UpdateUser { get; set; }
|
||||
long? UpdateUserId { get; set; }
|
||||
int SortCode { get; set; }
|
||||
DateTime UpdateTime { get; set; }
|
||||
string UpdateUser { get; set; }
|
||||
long UpdateUserId { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -61,13 +61,22 @@ public interface IBaseEntity
|
||||
/// </summary>
|
||||
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>
|
||||
[SugarColumn(ColumnDescription = "创建时间", IsOnlyIgnoreUpdate = true, IsNullable = true)]
|
||||
[IgnoreExcel]
|
||||
[AutoGenerateColumn(Visible = false, IsVisibleWhenAdd = false, IsVisibleWhenEdit = false)]
|
||||
public virtual DateTime? CreateTime { get; set; }
|
||||
public virtual DateTime CreateTime { get => createTime; set => createTime = value; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建人
|
||||
@@ -76,7 +85,7 @@ public abstract class BaseEntity : PrimaryKeyEntity, IBaseEntity
|
||||
[IgnoreExcel]
|
||||
[NotNull]
|
||||
[AutoGenerateColumn(Ignore = true)]
|
||||
public virtual string? CreateUser { get; set; }
|
||||
public virtual string CreateUser { get => createUser; set => createUser = value; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建者Id
|
||||
@@ -84,7 +93,7 @@ public abstract class BaseEntity : PrimaryKeyEntity, IBaseEntity
|
||||
[SugarColumn(ColumnDescription = "创建者Id", IsOnlyIgnoreUpdate = true, IsNullable = true)]
|
||||
[IgnoreExcel]
|
||||
[AutoGenerateColumn(Ignore = true)]
|
||||
public virtual long CreateUserId { get; set; }
|
||||
public virtual long CreateUserId { get => createUserId; set => createUserId = value; }
|
||||
|
||||
/// <summary>
|
||||
/// 软删除
|
||||
@@ -92,8 +101,7 @@ public abstract class BaseEntity : PrimaryKeyEntity, IBaseEntity
|
||||
[SugarColumn(ColumnDescription = "软删除", IsNullable = true)]
|
||||
[IgnoreExcel]
|
||||
[AutoGenerateColumn(Ignore = true)]
|
||||
public virtual bool IsDelete { get; set; } = false;
|
||||
|
||||
public virtual bool IsDelete { get => isDelete; set => isDelete = value; }
|
||||
|
||||
/// <summary>
|
||||
/// 更新时间
|
||||
@@ -101,7 +109,7 @@ public abstract class BaseEntity : PrimaryKeyEntity, IBaseEntity
|
||||
[SugarColumn(ColumnDescription = "更新时间", IsOnlyIgnoreInsert = true, IsNullable = true)]
|
||||
[IgnoreExcel]
|
||||
[AutoGenerateColumn(Visible = false, IsVisibleWhenAdd = false, IsVisibleWhenEdit = false)]
|
||||
public virtual DateTime? UpdateTime { get; set; }
|
||||
public virtual DateTime UpdateTime { get => updateTime; set => updateTime = value; }
|
||||
|
||||
/// <summary>
|
||||
/// 更新人
|
||||
@@ -109,7 +117,7 @@ public abstract class BaseEntity : PrimaryKeyEntity, IBaseEntity
|
||||
[SugarColumn(ColumnDescription = "更新人", IsOnlyIgnoreInsert = true, IsNullable = true)]
|
||||
[IgnoreExcel]
|
||||
[AutoGenerateColumn(Ignore = true)]
|
||||
public virtual string? UpdateUser { get; set; }
|
||||
public virtual string UpdateUser { get => updateUser; set => updateUser = value; }
|
||||
|
||||
/// <summary>
|
||||
/// 修改者Id
|
||||
@@ -117,7 +125,7 @@ public abstract class BaseEntity : PrimaryKeyEntity, IBaseEntity
|
||||
[SugarColumn(ColumnDescription = "修改者Id", IsOnlyIgnoreInsert = true, IsNullable = true)]
|
||||
[IgnoreExcel]
|
||||
[AutoGenerateColumn(Ignore = true)]
|
||||
public virtual long? UpdateUserId { get; set; }
|
||||
public virtual long UpdateUserId { get => updateUserId; set => updateUserId = value; }
|
||||
|
||||
/// <summary>
|
||||
/// 排序码
|
||||
@@ -125,7 +133,7 @@ public abstract class BaseEntity : PrimaryKeyEntity, IBaseEntity
|
||||
[SugarColumn(ColumnDescription = "排序码", IsNullable = true)]
|
||||
[AutoGenerateColumn(Visible = false, DefaultSort = true, Sortable = true, DefaultSortOrder = SortOrder.Asc)]
|
||||
[IgnoreExcel]
|
||||
public virtual int? SortCode { get; set; }
|
||||
public virtual int SortCode { get => sortCode; set => sortCode = value; }
|
||||
}
|
||||
|
||||
public interface IBaseDataEntity
|
||||
|
@@ -124,16 +124,8 @@ public class SugarAopService : ISugarAopService
|
||||
//执行时间超过1秒
|
||||
if (db.Ado.SqlExecutionTime.TotalSeconds > 1)
|
||||
{
|
||||
//代码CS文件名
|
||||
var fileName = db.Ado.SqlStackTrace.FirstFileName;
|
||||
//代码行数
|
||||
var fileLine = db.Ado.SqlStackTrace.FirstLine;
|
||||
//方法名
|
||||
var FirstMethodName = db.Ado.SqlStackTrace.FirstMethodName;
|
||||
|
||||
DbContext.WriteLog($"{fileName}-{FirstMethodName}-{fileLine} 执行时间超过1秒");
|
||||
DbContext.WriteLog($"SQL执行时间超过1秒");
|
||||
DbContext.WriteLogWithSql(UtilMethods.GetNativeSql(sql, pars));
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@@ -161,7 +161,7 @@ public class BaseService<T> : IDataService<T>, IDisposable where T : class, new(
|
||||
/// <returns></returns>
|
||||
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 tenantAtt = entityType.GetCustomAttribute<TenantAttribute>();//获取sqlSugar多库特性
|
||||
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());//获取数据库配置
|
||||
if (config?.InitSeedData != true) continue;
|
||||
var entityInfo = db.EntityMaintenance.GetEntityInfo(entityType);
|
||||
@@ -66,7 +66,8 @@ public static class CodeFirstUtils
|
||||
{
|
||||
// 按主键进行批量增加和更新
|
||||
var storage = db.StorageableByObject(seedData.ToList()).ToStorage();
|
||||
if (ignoreAdd == null) storage.AsInsertable.ExecuteCommand();//执行插入
|
||||
if (ignoreAdd == null)
|
||||
storage.AsInsertable.ExecuteCommand();//执行插入
|
||||
if (ignoreUpdate == null && config.IsUpdateSeedData) storage.AsUpdateable.ExecuteCommand();//只有没有忽略更新的特性才执行更新
|
||||
}
|
||||
else// 没有主键或者不是预定义的主键(有重复的可能)
|
||||
@@ -98,7 +99,7 @@ public static class CodeFirstUtils
|
||||
var ignoreInit = entityType.GetCustomAttribute<IgnoreInitTableAttribute>();//获取忽略初始化特性
|
||||
if (ignoreInit != 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>();//获取自动分表特性
|
||||
if (splitTable == null)//如果特性是空
|
||||
db.CodeFirst.InitTables(entityType);//普通创建
|
||||
|
@@ -24,7 +24,7 @@ public static class DbContext
|
||||
/// <summary>
|
||||
/// SqlSugar 数据库实例
|
||||
/// </summary>
|
||||
public static readonly SqlSugarScope Db;
|
||||
private static readonly SqlSugarClient Db;
|
||||
|
||||
/// <summary>
|
||||
/// 读取配置文件中的 ConnectionStrings:Sqlsugar 配置节点
|
||||
@@ -37,9 +37,28 @@ public static class DbContext
|
||||
/// <returns></returns>
|
||||
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
|
||||
{
|
||||
@@ -62,7 +81,7 @@ public static class DbContext
|
||||
{
|
||||
DbConfigs.ForEach(it =>
|
||||
{
|
||||
var sqlsugarScope = db.GetConnectionScope(it.ConfigId);//获取当前库
|
||||
var sqlsugarScope = db.GetConnection(it.ConfigId);//获取当前库
|
||||
MoreSetting(sqlsugarScope);//更多设置
|
||||
SugarAopService.AopSetting(sqlsugarScope, it.IsShowSql);//aop配置
|
||||
}
|
||||
@@ -75,7 +94,7 @@ public static class DbContext
|
||||
/// 实体更多配置
|
||||
/// </summary>
|
||||
/// <param name="db"></param>
|
||||
private static void MoreSetting(SqlSugarScopeProvider db)
|
||||
private static void MoreSetting(SqlSugarProvider db)
|
||||
{
|
||||
db.CurrentConnectionConfig.MoreSettings = new ConnMoreSettings
|
||||
{
|
||||
|
@@ -24,7 +24,7 @@ namespace ThingsGateway.Admin.Application;
|
||||
/// 种子数据工具类
|
||||
/// </summary>
|
||||
[ThingsGateway.DependencyInjection.SuppressSniffer]
|
||||
public static class SeedDataUtil
|
||||
public static partial class SeedDataUtil
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取List列表
|
||||
@@ -53,9 +53,7 @@ public static class SeedDataUtil
|
||||
if (!string.IsNullOrEmpty(json))//如果有内容
|
||||
{
|
||||
//字段没有数据的替换成null
|
||||
json = Regex.Replace(json, "\\\"[^\"]+?\\\": \\\"\\\"", match => match.Value.Replace("\"\"", "null"));
|
||||
|
||||
|
||||
json = SeedDataRegex().Replace(json, match => match.Value.Replace("\"\"", "null"));
|
||||
|
||||
var jtoken = JToken.Parse(json);
|
||||
jtoken = jtoken.SelectToken("Records") ?? jtoken.SelectToken("RECORDS");
|
||||
@@ -96,6 +94,9 @@ public static class SeedDataUtil
|
||||
|
||||
return seedData;
|
||||
}
|
||||
|
||||
[GeneratedRegex("\\\"[^\"]+?\\\": \\\"\\\"")]
|
||||
private static partial Regex SeedDataRegex();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@@ -10,7 +10,6 @@
|
||||
|
||||
using BootstrapBlazor.Components;
|
||||
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
using ThingsGateway.SqlSugar;
|
||||
@@ -32,11 +31,10 @@ public class Startup : AppStartup
|
||||
|
||||
StaticConfig.EnableAllWhereIF = true;
|
||||
|
||||
services.AddSingleton<ISugarAopService, SugarAopService>();
|
||||
|
||||
}
|
||||
|
||||
public void Use(IApplicationBuilder applicationBuilder)
|
||||
public void Use(IServiceProvider serviceProvider)
|
||||
{
|
||||
|
||||
|
||||
|
@@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<Import Project="$(SolutionDir)Version.props" />
|
||||
<Import Project="$(SolutionDir)PackNuget.props" />
|
||||
<Import Project="..\..\Version.props" />
|
||||
<Import Project="..\..\PackNuget.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<GenerateDocumentationFile>True</GenerateDocumentationFile>
|
||||
@@ -11,17 +11,18 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="BootstrapBlazor.TableExport" Version="9.2.5" />
|
||||
<PackageReference Include="BootstrapBlazor.TableExport" Version="9.2.6" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="..\README.md" Pack="true" PackagePath="\" />
|
||||
<None Include="..\README.zh-CN.md" Pack="true" PackagePath="\" />
|
||||
<None Remove="$(SolutionDir)..\README.md" Pack="false" PackagePath="\" />
|
||||
<None Remove="$(SolutionDir)..\README.zh-CN.md" Pack="false" PackagePath="\" />
|
||||
<None Remove="..\..\..\README.md" Pack="false" PackagePath="\" />
|
||||
<None Remove="..\..\..\README.zh-CN.md" Pack="false" PackagePath="\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<!--<PackageReference Include="ThingsGateway.Razor" Version="$(SourceGeneratorVersion)" />-->
|
||||
<ProjectReference Include="..\ThingsGateway.Razor\ThingsGateway.Razor.csproj" />
|
||||
<ProjectReference Include="..\ThingsGateway.SqlSugar\ThingsGateway.SqlSugar.csproj" />
|
||||
<!--<PackageReference Include="SqlSugarCore" Version="5.1.4.195" />-->
|
||||
|
@@ -67,13 +67,13 @@ internal static class Penetrates
|
||||
["patch"] = "PATCH"
|
||||
};
|
||||
|
||||
IsApiControllerCached = new ConcurrentDictionary<Type, bool>();
|
||||
//IsApiControllerCached = new ConcurrentDictionary<Type, bool>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="IsApiController(Type)"/> 缓存集合
|
||||
/// </summary>
|
||||
private static readonly ConcurrentDictionary<Type, bool> IsApiControllerCached;
|
||||
///// <summary>
|
||||
///// <see cref="IsApiController(Type)"/> 缓存集合
|
||||
///// </summary>
|
||||
//private static readonly ConcurrentDictionary<Type, bool> IsApiControllerCached;
|
||||
|
||||
/// <summary>
|
||||
/// 是否是Api控制器
|
||||
@@ -82,13 +82,13 @@ internal static class Penetrates
|
||||
/// <returns></returns>
|
||||
internal static bool IsApiController(Type type)
|
||||
{
|
||||
return IsApiControllerCached.GetOrAdd(type, Function);
|
||||
|
||||
//return IsApiControllerCached.GetOrAdd(type, Function);
|
||||
return Function(type);
|
||||
// 本地静态方法
|
||||
static bool Function(Type type)
|
||||
{
|
||||
// 排除 OData 控制器
|
||||
if (type.Assembly.GetName().Name.StartsWith("Microsoft.AspNetCore.OData")) return false;
|
||||
//// 排除 OData 控制器
|
||||
//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;
|
||||
|
@@ -37,15 +37,15 @@ public sealed class Retry
|
||||
{
|
||||
if (action == null) throw new ArgumentNullException(nameof(action));
|
||||
|
||||
InvokeAsync(async () =>
|
||||
InvokeAsync(() =>
|
||||
{
|
||||
action();
|
||||
await Task.CompletedTask.ConfigureAwait(false);
|
||||
return Task.CompletedTask;
|
||||
}, numRetries, retryTimeout, finalThrow, exceptionTypes, fallbackPolicy == null ? null
|
||||
: async (ex) =>
|
||||
: (ex) =>
|
||||
{
|
||||
fallbackPolicy?.Invoke(ex);
|
||||
await Task.CompletedTask.ConfigureAwait(false);
|
||||
return Task.CompletedTask;
|
||||
}, retryAction).GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
|
@@ -15,6 +15,7 @@ using Microsoft.Extensions.Logging;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
using ThingsGateway.NewLife.Caching;
|
||||
using ThingsGateway.NewLife.Log;
|
||||
|
||||
namespace ThingsGateway.Logging;
|
||||
|
||||
@@ -33,7 +34,7 @@ public sealed class DatabaseLoggerProvider : ILoggerProvider, ISupportExternalSc
|
||||
/// <summary>
|
||||
/// 日志消息队列(线程安全)
|
||||
/// </summary>
|
||||
private readonly BlockingCollection<LogMessage> _logMessageQueue = new(12000);
|
||||
private readonly BlockingCollection<LogMessage> _logMessageQueue = new(20000);
|
||||
|
||||
/// <summary>
|
||||
/// 日志作用域提供器
|
||||
@@ -135,7 +136,10 @@ public sealed class DatabaseLoggerProvider : ILoggerProvider, ISupportExternalSc
|
||||
{
|
||||
try
|
||||
{
|
||||
_logMessageQueue.Add(logMsg);
|
||||
if (!_logMessageQueue.TryAdd(logMsg, 5000))
|
||||
{
|
||||
XTrace.Log.Warn($"{nameof(DatabaseLoggerProvider)} queue add fail");
|
||||
}
|
||||
return;
|
||||
}
|
||||
catch (InvalidOperationException) { }
|
||||
@@ -160,8 +164,8 @@ public sealed class DatabaseLoggerProvider : ILoggerProvider, ISupportExternalSc
|
||||
_databaseLoggingWriter = _serviceScope.ServiceProvider.GetRequiredService(databaseLoggingWriterType) as IDatabaseLoggingWriter;
|
||||
|
||||
// 创建长时间运行的后台任务,并将日志消息队列中数据写入存储中
|
||||
_processQueueTask = Task.Factory.StartNew(async state => await ((DatabaseLoggerProvider)state).ProcessQueueAsync().ConfigureAwait(false)
|
||||
, this, TaskCreationOptions.LongRunning);
|
||||
_processQueueTask = Task.Factory.StartNew(ProcessQueueAsync
|
||||
, TaskCreationOptions.LongRunning);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@@ -14,6 +14,7 @@ using Microsoft.Extensions.Logging;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
using ThingsGateway.NewLife.Caching;
|
||||
using ThingsGateway.NewLife.Log;
|
||||
|
||||
namespace ThingsGateway.Logging;
|
||||
|
||||
@@ -32,7 +33,7 @@ public sealed class FileLoggerProvider : ILoggerProvider, ISupportExternalScope
|
||||
/// <summary>
|
||||
/// 日志消息队列(线程安全)
|
||||
/// </summary>
|
||||
private readonly BlockingCollection<LogMessage> _logMessageQueue = new(12000);
|
||||
private readonly BlockingCollection<LogMessage> _logMessageQueue = new(20000);
|
||||
|
||||
/// <summary>
|
||||
/// 日志作用域提供器
|
||||
@@ -90,8 +91,7 @@ public sealed class FileLoggerProvider : ILoggerProvider, ISupportExternalScope
|
||||
_fileLoggingWriter = new FileLoggingWriter(this);
|
||||
|
||||
// 创建长时间运行的后台任务,并将日志消息队列中数据写入文件中
|
||||
_processQueueTask = Task.Factory.StartNew(async state => await ((FileLoggerProvider)state).ProcessQueueAsync().ConfigureAwait(false)
|
||||
, this, TaskCreationOptions.LongRunning);
|
||||
_processQueueTask = Task.Factory.StartNew(ProcessQueueAsync, TaskCreationOptions.LongRunning);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -171,8 +171,10 @@ public sealed class FileLoggerProvider : ILoggerProvider, ISupportExternalScope
|
||||
{
|
||||
try
|
||||
{
|
||||
_logMessageQueue.Add(logMsg);
|
||||
return;
|
||||
if (!_logMessageQueue.TryAdd(logMsg, 5000))
|
||||
{
|
||||
XTrace.Log.Warn($"{nameof(DatabaseLoggerProvider)} queue add fail");
|
||||
}
|
||||
}
|
||||
catch (InvalidOperationException) { }
|
||||
catch { }
|
||||
|
@@ -46,6 +46,8 @@ public static class ObjectMapperServiceCollectionExtensions
|
||||
// 获取全局映射配置
|
||||
var config = TypeAdapterConfig.GlobalSettings;
|
||||
|
||||
//config.Compiler = exp => exp.CompileFast();
|
||||
|
||||
// 扫描所有继承 IRegister 接口的对象映射配置
|
||||
if (assemblies?.Length > 0) config.Scan(assemblies);
|
||||
|
||||
|
@@ -76,7 +76,7 @@ internal sealed partial class SchedulerFactory : ISchedulerFactory
|
||||
/// <summary>
|
||||
/// 作业持久化记录消息队列(线程安全)
|
||||
/// </summary>
|
||||
private readonly BlockingCollection<PersistenceContext> _persistenceMessageQueue = new(12000);
|
||||
private readonly BlockingCollection<PersistenceContext> _persistenceMessageQueue = new(20000);
|
||||
|
||||
/// <summary>
|
||||
/// 不受控的作业 Id 集合
|
||||
@@ -110,8 +110,7 @@ internal sealed partial class SchedulerFactory : ISchedulerFactory
|
||||
if (Persistence is not null)
|
||||
{
|
||||
// 创建长时间运行的后台任务,并将作业运行消息写入持久化中
|
||||
_processQueueTask = Task.Factory.StartNew(async state => await ((SchedulerFactory)state).ProcessQueueAsync().ConfigureAwait(false)
|
||||
, this, TaskCreationOptions.LongRunning);
|
||||
_processQueueTask = Task.Factory.StartNew(ProcessQueueAsync, TaskCreationOptions.LongRunning);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<Import Project="$(SolutionDir)Version.props" />
|
||||
<Import Project="$(SolutionDir)PackNuget.props" />
|
||||
<Import Project="..\..\Version.props" />
|
||||
<Import Project="..\..\PackNuget.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net8.0;net9.0;</TargetFrameworks>
|
||||
@@ -36,10 +36,11 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Ben.Demystifier" Version="0.4.1" />
|
||||
<!--<PackageReference Include="FastExpressionCompiler" Version="5.3.0" />-->
|
||||
<PackageReference Include="System.Text.RegularExpressions" Version="4.3.1" />
|
||||
<PackageReference Include="Mapster" Version="7.4.0" />
|
||||
<PackageReference Include="MiniProfiler.AspNetCore.Mvc" Version="4.5.4" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="8.1.4" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="9.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition=" '$(TargetFramework)' == 'net8.0' ">
|
||||
@@ -61,8 +62,8 @@
|
||||
<ItemGroup>
|
||||
<None Include="README.md" Pack="true" PackagePath="\" />
|
||||
<None Include="README.zh-CN.md" Pack="true" PackagePath="\" />
|
||||
<None Remove="$(SolutionDir)..\README.md" Pack="false" PackagePath="\" />
|
||||
<None Remove="$(SolutionDir)..\README.zh-CN.md" Pack="false" PackagePath="\" />
|
||||
<None Remove="..\..\..\README.md" Pack="false" PackagePath="\" />
|
||||
<None Remove="..\..\..\README.zh-CN.md" Pack="false" PackagePath="\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@@ -79,11 +79,6 @@ public abstract class DisposeBase : IDisposable2
|
||||
OnDisposed?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
///// <summary>释放资源,参数表示是否由Dispose调用。该方法保证OnDispose只被调用一次!</summary>
|
||||
///// <param name="disposing"></param>
|
||||
//[Obsolete("=>Dispose")]
|
||||
//protected virtual void OnDispose(Boolean disposing) { }
|
||||
|
||||
/// <summary>析构函数</summary>
|
||||
/// <remarks>
|
||||
/// 如果忘记调用Dispose,这里会释放非托管资源。
|
||||
|
@@ -127,63 +127,57 @@ public class MachineInfo
|
||||
|
||||
//static MachineInfo() => RegisterAsync().Wait(100);
|
||||
|
||||
private static Task<MachineInfo>? _task;
|
||||
/// <summary>异步注册一个初始化后的机器信息实例</summary>
|
||||
/// <returns></returns>
|
||||
public static Task<MachineInfo> RegisterAsync()
|
||||
public static MachineInfo Register()
|
||||
{
|
||||
|
||||
if (_task != null) return _task;
|
||||
|
||||
return _task = Task.Factory.StartNew(() =>
|
||||
if (Current != null) return Current;
|
||||
// 文件缓存,加快机器信息获取。在Linux下,可能StarAgent以root权限写入缓存文件,其它应用以普通用户访问
|
||||
var file = Path.GetTempPath().CombinePath("machine_info.json");
|
||||
var json = "";
|
||||
if (Current == null)
|
||||
{
|
||||
// 文件缓存,加快机器信息获取。在Linux下,可能StarAgent以root权限写入缓存文件,其它应用以普通用户访问
|
||||
var file = Path.GetTempPath().CombinePath("machine_info.json");
|
||||
var json = "";
|
||||
if (Current == null)
|
||||
var f = file;
|
||||
if (File.Exists(f))
|
||||
{
|
||||
var f = file;
|
||||
if (File.Exists(f))
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
//XTrace.WriteLine("Load MachineInfo {0}", f);
|
||||
json = File.ReadAllText(f);
|
||||
Current = json.FromJsonNetString<MachineInfo>();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (XTrace.Log.Level <= LogLevel.Debug) NewLife.Log.XTrace.WriteException(ex);
|
||||
}
|
||||
//XTrace.WriteLine("Load MachineInfo {0}", f);
|
||||
json = File.ReadAllText(f);
|
||||
Current = json.FromJsonNetString<MachineInfo>();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (XTrace.Log.Level <= LogLevel.Debug) NewLife.Log.XTrace.WriteException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var mi = Current ?? new MachineInfo();
|
||||
var mi = Current ?? new MachineInfo();
|
||||
|
||||
mi.Init();
|
||||
Current = mi;
|
||||
mi.Init();
|
||||
Current = mi;
|
||||
|
||||
try
|
||||
try
|
||||
{
|
||||
var json2 = mi.ToJsonNetString();
|
||||
if (json != json2)
|
||||
{
|
||||
var json2 = mi.ToJsonNetString();
|
||||
if (json != json2)
|
||||
{
|
||||
File.WriteAllText(file.EnsureDirectory(true), json2);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (XTrace.Log.Level <= LogLevel.Debug) NewLife.Log.XTrace.WriteException(ex);
|
||||
File.WriteAllText(file.EnsureDirectory(true), json2);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (XTrace.Log.Level <= LogLevel.Debug) NewLife.Log.XTrace.WriteException(ex);
|
||||
}
|
||||
|
||||
return mi;
|
||||
});
|
||||
return mi;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>获取当前信息,如果未设置则等待异步注册结果</summary>
|
||||
/// <returns></returns>
|
||||
public static MachineInfo GetCurrent() => Current ?? RegisterAsync().ConfigureAwait(false).GetAwaiter().GetResult();
|
||||
public static MachineInfo GetCurrent() => Current ?? Register();
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -1160,7 +1154,7 @@ public class MachineInfo
|
||||
public static String GetInfo(String path, String property, String? nameSpace = null)
|
||||
{
|
||||
// Linux Mono不支持WMI
|
||||
if (Runtime.Mono) return "";
|
||||
if (Runtime.Mono) return string.Empty;
|
||||
|
||||
var bbs = new List<String>();
|
||||
try
|
||||
@@ -1181,7 +1175,7 @@ public class MachineInfo
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (XTrace.Log.Level <= LogLevel.Debug) XTrace.WriteLine("WMI.GetInfo({0})失败!{1}", path, ex.Message);
|
||||
return "";
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
bbs.Sort();
|
||||
|
@@ -95,7 +95,6 @@ public class Config<TConfig> where TConfig : Config<TConfig>, new()
|
||||
#region 属性
|
||||
/// <summary>是否新的配置文件</summary>
|
||||
[XmlIgnore, IgnoreDataMember]
|
||||
//[Obsolete("=>_Provider.IsNew")]
|
||||
public Boolean IsNew => Provider?.IsNew ?? false;
|
||||
#endregion
|
||||
|
||||
@@ -104,7 +103,6 @@ public class Config<TConfig> where TConfig : Config<TConfig>, new()
|
||||
protected virtual void OnLoaded() { }
|
||||
|
||||
/// <summary>保存到配置文件中去</summary>
|
||||
//[Obsolete("=>Provider.Save")]
|
||||
public virtual void Save() => Provider?.Save(this);
|
||||
#endregion
|
||||
}
|
@@ -41,12 +41,6 @@ public static class ProcessHelper
|
||||
return pname;
|
||||
}
|
||||
|
||||
/// <summary>获取二级进程名</summary>
|
||||
/// <param name="process"></param>
|
||||
/// <returns></returns>
|
||||
[Obsolete("=>GetProcessName", true)]
|
||||
public static String GetProcessName2(this Process process) => GetProcessName(process);
|
||||
|
||||
///// <summary>根据名称获取进程。支持dotnet/java</summary>
|
||||
///// <param name="name"></param>
|
||||
///// <returns></returns>
|
||||
|
@@ -236,25 +236,6 @@ public static class StringHelper
|
||||
return sb.Return(true);
|
||||
}
|
||||
|
||||
///// <summary>把一个列表组合成为一个字符串,默认逗号分隔</summary>
|
||||
///// <param name="value"></param>
|
||||
///// <param name="separator">组合分隔符,默认逗号</param>
|
||||
///// <param name="func">把对象转为字符串的委托</param>
|
||||
///// <returns></returns>
|
||||
//[Obsolete]
|
||||
//public static String Join<T>(this IEnumerable<T> value, String separator, Func<T, String>? func)
|
||||
//{
|
||||
// var sb = Pool.StringBuilder.Get();
|
||||
// if (value != null)
|
||||
// {
|
||||
// if (func == null) func = obj => obj + "";
|
||||
// foreach (var item in value)
|
||||
// {
|
||||
// sb.Separate(separator).Append(func(item));
|
||||
// }
|
||||
// }
|
||||
// return sb.Put(true);
|
||||
//}
|
||||
|
||||
/// <summary>把一个列表组合成为一个字符串,默认逗号分隔</summary>
|
||||
/// <param name="value"></param>
|
||||
@@ -301,28 +282,6 @@ public static class StringHelper
|
||||
return encoding.GetBytes(value);
|
||||
}
|
||||
|
||||
/// <summary>格式化字符串。特别支持无格式化字符串的时间参数</summary>
|
||||
/// <param name="value">格式字符串</param>
|
||||
/// <param name="args">参数</param>
|
||||
/// <returns></returns>
|
||||
[Obsolete("建议使用插值字符串")]
|
||||
public static String F(this String value, params Object?[] args)
|
||||
{
|
||||
if (String.IsNullOrEmpty(value)) return value;
|
||||
|
||||
// 特殊处理时间格式化。这些年,无数项目实施因为时间格式问题让人发狂
|
||||
for (var i = 0; i < args.Length; i++)
|
||||
{
|
||||
if (args[i] is DateTime dt)
|
||||
{
|
||||
// 没有写格式化字符串的时间参数,一律转为标准时间字符串
|
||||
if (value.Contains("{" + i + "}")) args[i] = dt.ToFullString();
|
||||
}
|
||||
}
|
||||
|
||||
return String.Format(value, args);
|
||||
}
|
||||
|
||||
/// <summary>指定输入是否匹配目标表达式,支持*匹配</summary>
|
||||
/// <param name="pattern">匹配表达式</param>
|
||||
/// <param name="input">输入字符串</param>
|
||||
|
@@ -854,13 +854,13 @@ public static class IOHelper
|
||||
/// <returns></returns>
|
||||
public static String ToHex(this Byte[]? data, Int32 offset = 0, Int32 count = -1)
|
||||
{
|
||||
if (data == null || data.Length <= 0) return "";
|
||||
if (data == null || data.Length <= 0) return string.Empty;
|
||||
|
||||
if (count < 0)
|
||||
count = data.Length - offset;
|
||||
else if (offset + count > data.Length)
|
||||
count = data.Length - offset;
|
||||
if (count == 0) return "";
|
||||
if (count == 0) return string.Empty;
|
||||
|
||||
//return BitConverter.ToString(data).Replace("-", null);
|
||||
// 上面的方法要替换-,效率太低
|
||||
@@ -883,7 +883,7 @@ public static class IOHelper
|
||||
/// <returns></returns>
|
||||
public static String ToHex(this Byte[]? data, String? separate, Int32 groupSize = 0, Int32 maxLength = -1)
|
||||
{
|
||||
if (data == null || data.Length <= 0) return "";
|
||||
if (data == null || data.Length <= 0) return string.Empty;
|
||||
|
||||
if (groupSize < 0) groupSize = 0;
|
||||
|
||||
|
@@ -1,15 +0,0 @@
|
||||
namespace ThingsGateway.NewLife.Reflection
|
||||
{
|
||||
/// <summary>
|
||||
/// 索引器接访问口。
|
||||
/// 该接口用于通过名称快速访问对象属性或字段(属性优先)。
|
||||
/// </summary>
|
||||
//[Obsolete("=>IIndex")]
|
||||
public interface IIndexAccessor
|
||||
{
|
||||
/// <summary>获取/设置 指定名称的属性或字段的值</summary>
|
||||
/// <param name="name">名称</param>
|
||||
/// <returns></returns>
|
||||
Object this[String name] { get; set; }
|
||||
}
|
||||
}
|
@@ -521,12 +521,7 @@ public static class Reflect
|
||||
/// <returns></returns>
|
||||
public static IEnumerable<Type> GetAllSubclasses(this Type baseType) => Provider.GetAllSubclasses(baseType);
|
||||
|
||||
///// <summary>在所有程序集中查找指定基类或接口的子类实现</summary>
|
||||
///// <param name="baseType">基类或接口</param>
|
||||
///// <param name="isLoadAssembly">是否加载为加载程序集</param>
|
||||
///// <returns></returns>
|
||||
//[Obsolete]
|
||||
//public static IEnumerable<Type> GetAllSubclasses(this Type baseType, Boolean isLoadAssembly) => Provider.GetAllSubclasses(baseType, isLoadAssembly);
|
||||
|
||||
#endregion
|
||||
|
||||
#region 辅助方法
|
||||
|
@@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<Import Project="$(SolutionDir)Version.props" />
|
||||
<Import Project="$(SolutionDir)PackNuget.props" />
|
||||
<Import Project="..\..\Version.props" />
|
||||
<Import Project="..\..\PackNuget.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net462;netstandard2.0;net6.0;net6.0-windows;net8.0;net8.0-windows;</TargetFrameworks>
|
||||
@@ -16,8 +16,8 @@
|
||||
<ItemGroup>
|
||||
<None Include="README.md" Pack="true" PackagePath="\" />
|
||||
<None Include="README.zh-CN.md" Pack="true" PackagePath="\" />
|
||||
<None Remove="$(SolutionDir)..\README.md" Pack="false" PackagePath="\" />
|
||||
<None Remove="$(SolutionDir)..\README.zh-CN.md" Pack="false" PackagePath="\" />
|
||||
<None Remove="..\..\..\README.md" Pack="false" PackagePath="\" />
|
||||
<None Remove="..\..\..\README.zh-CN.md" Pack="false" PackagePath="\" />
|
||||
</ItemGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(TargetFramework)'=='net462' or '$(TargetFramework)'=='net5.0-windows' or '$(TargetFramework)'=='net6.0-windows' or '$(TargetFramework)'=='net7.0-windows' or '$(TargetFramework)'=='net8.0-windows'">
|
||||
|
@@ -172,7 +172,6 @@ public class TimerScheduler : ILogFeature
|
||||
else if (!timer.Async)
|
||||
Execute(timer);
|
||||
else
|
||||
//Task.Factory.StartNew(() => ProcessItem(timer));
|
||||
// 不需要上下文流动,捕获所有异常
|
||||
ThreadPool.UnsafeQueueUserWorkItem(s =>
|
||||
{
|
||||
@@ -231,8 +230,6 @@ public class TimerScheduler : ILogFeature
|
||||
{
|
||||
if (state is not TimerX timer) return;
|
||||
|
||||
TimerX.Current = timer;
|
||||
|
||||
// 控制日志显示
|
||||
WriteLogEventArgs.CurrentThreadName = Name == "Default" ? "T" : Name;
|
||||
|
||||
@@ -274,7 +271,6 @@ public class TimerScheduler : ILogFeature
|
||||
{
|
||||
if (state is not TimerX timer) return;
|
||||
|
||||
TimerX.Current = timer;
|
||||
|
||||
// 控制日志显示
|
||||
WriteLogEventArgs.CurrentThreadName = Name == "Default" ? "T" : Name;
|
||||
@@ -322,8 +318,6 @@ public class TimerScheduler : ILogFeature
|
||||
|
||||
timer.Calling = false;
|
||||
|
||||
TimerX.Current = null;
|
||||
|
||||
// 控制日志显示
|
||||
WriteLogEventArgs.CurrentThreadName = null;
|
||||
|
||||
|
@@ -84,15 +84,7 @@ public class TimerX : ITimer, IDisposable
|
||||
private readonly Cron[]? _crons;
|
||||
#endregion
|
||||
|
||||
#region 静态
|
||||
#if NET452
|
||||
private static readonly ThreadLocal<TimerX?> _Current = new();
|
||||
#else
|
||||
private static readonly AsyncLocal<TimerX?> _Current = new();
|
||||
#endif
|
||||
/// <summary>当前定时器</summary>
|
||||
public static TimerX? Current { get => _Current.Value; set => _Current.Value = value; }
|
||||
#endregion
|
||||
|
||||
|
||||
#region 构造
|
||||
private TimerX(Object? target, MethodInfo method, Object? state, String? scheduler = null)
|
||||
@@ -382,19 +374,27 @@ public class TimerX : ITimer, IDisposable
|
||||
/// <param name="period">构造 Timer 时指定的回调方法调用之间的时间间隔。 指定 InfiniteTimeSpan 可以禁用定期终止。</param>
|
||||
/// <returns></returns>
|
||||
public Boolean Change(TimeSpan dueTime, TimeSpan period)
|
||||
{
|
||||
return Change((int)dueTime.TotalMilliseconds, (int)period.TotalMilliseconds);
|
||||
}
|
||||
/// <summary>更改计时器的启动时间和方法调用之间的时间间隔,使用 TimeSpan 值度量时间间隔。</summary>
|
||||
/// <param name="dueTime">一个 TimeSpan,表示在调用构造 ITimer 时指定的回调方法之前的延迟时间量。 指定 InfiniteTimeSpan 可防止重新启动计时器。 指定 Zero 可立即重新启动计时器。</param>
|
||||
/// <param name="period">构造 Timer 时指定的回调方法调用之间的时间间隔。 指定 InfiniteTimeSpan 可以禁用定期终止。</param>
|
||||
/// <returns></returns>
|
||||
public Boolean Change(int dueTime, int period)
|
||||
{
|
||||
if (Absolutely) return false;
|
||||
if (Crons?.Length > 0) return false;
|
||||
|
||||
if (period.TotalMilliseconds <= 0)
|
||||
if (period <= 0)
|
||||
{
|
||||
Dispose();
|
||||
return true;
|
||||
}
|
||||
|
||||
Period = (Int32)period.TotalMilliseconds;
|
||||
Period = period;
|
||||
|
||||
if (dueTime.TotalMilliseconds >= 0) SetNext((Int32)dueTime.TotalMilliseconds);
|
||||
if (dueTime >= 0) SetNext(dueTime);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@@ -280,43 +280,6 @@ public static class ControlHelper
|
||||
}
|
||||
}
|
||||
|
||||
private static void ProcessBell(ref String m)
|
||||
{
|
||||
var ch = (Char)7;
|
||||
var p = 0;
|
||||
while (true)
|
||||
{
|
||||
p = m.IndexOf(ch, p);
|
||||
if (p < 0) break;
|
||||
|
||||
if (p > 0)
|
||||
{
|
||||
var str = m[..p];
|
||||
if (p + 1 < m.Length) str += m[(p + 1)..];
|
||||
m = str;
|
||||
}
|
||||
|
||||
//Console.Beep();
|
||||
// 用定时器来控制Beep,避免被堵塞
|
||||
_timer ??= new TimerX(Bell, null, 100, 100);
|
||||
_Beep = true;
|
||||
//SystemSounds.Beep.Play();
|
||||
p++;
|
||||
}
|
||||
}
|
||||
|
||||
private static TimerX? _timer;
|
||||
private static Boolean _Beep;
|
||||
|
||||
private static void Bell(Object? state)
|
||||
{
|
||||
if (_Beep)
|
||||
{
|
||||
_Beep = false;
|
||||
Console.Beep();
|
||||
}
|
||||
}
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
private static extern Int32 SendMessage(IntPtr hwnd, Int32 wMsg, Int32 wParam, Int32 lParam);
|
||||
private const Int32 SB_TOP = 6;
|
||||
|
@@ -20,7 +20,6 @@ namespace ThingsGateway.NewLife.Xml;
|
||||
/// 用户也可以通过配置实体类的静态构造函数修改基类的<see cref="_.ConfigFile"/>和<see cref="_.ReloadTime"/>来动态配置加载信息。
|
||||
/// </remarks>
|
||||
/// <typeparam name="TConfig"></typeparam>
|
||||
//[Obsolete("=>Config<TConfig>")]
|
||||
public class XmlConfig<TConfig> : DisposeBase where TConfig : XmlConfig<TConfig>, new()
|
||||
{
|
||||
#region 静态
|
||||
|
@@ -1,6 +1,6 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Razor">
|
||||
<Import Project="$(SolutionDir)Version.props" />
|
||||
<Import Project="$(SolutionDir)PackNuget.props" />
|
||||
<Import Project="..\..\Version.props" />
|
||||
<Import Project="..\..\PackNuget.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net8.0;net9.0;</TargetFrameworks>
|
||||
|
@@ -13,6 +13,7 @@ namespace ThingsGateway.Razor;
|
||||
/// <summary>
|
||||
/// 母版页基类
|
||||
/// </summary>
|
||||
[DoNotGenerateSetParametersAsync]
|
||||
public partial class BaseLayout
|
||||
{
|
||||
}
|
||||
|
@@ -11,7 +11,7 @@
|
||||
namespace ThingsGateway.Razor;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public abstract class WebSiteModuleComponentBase : BootstrapModuleComponentBase
|
||||
public abstract partial class WebSiteModuleComponentBase : BootstrapModuleComponentBase
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
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>
|
||||
</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>
|
||||
</StepItem>
|
||||
</StepItem> *@
|
||||
</Step>
|
||||
@code {
|
||||
[NotNull]
|
||||
|
@@ -10,16 +10,12 @@
|
||||
|
||||
using System.Reflection;
|
||||
|
||||
using ThingsGateway.NewLife.Caching;
|
||||
|
||||
namespace ThingsGateway.Extension.Generic;
|
||||
|
||||
/// <inheritdoc/>
|
||||
[ThingsGateway.DependencyInjection.SuppressSniffer]
|
||||
public static class GenericExtensions
|
||||
{
|
||||
private static MemoryCache Instance { get; set; } = new MemoryCache();
|
||||
|
||||
/// <summary>
|
||||
/// 把已修改的属性赋值到列表中,并返回字典
|
||||
/// </summary>
|
||||
|
@@ -8,6 +8,8 @@
|
||||
// QQ群:605534569
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace ThingsGateway;
|
||||
|
||||
/// <summary>
|
||||
@@ -22,7 +24,7 @@ public static class ParallelExtensions
|
||||
/// <typeparam name="T">集合元素类型</typeparam>
|
||||
/// <param name="source">要操作的集合</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();
|
||||
options.MaxDegreeOfParallelism = Environment.ProcessorCount;
|
||||
@@ -39,7 +41,7 @@ public static class ParallelExtensions
|
||||
/// <typeparam name="T">集合元素类型</typeparam>
|
||||
/// <param name="source">要操作的集合</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();
|
||||
options.MaxDegreeOfParallelism = Environment.ProcessorCount;
|
||||
@@ -57,7 +59,7 @@ public static class ParallelExtensions
|
||||
/// <param name="source">要操作的集合</param>
|
||||
/// <param name="body">要执行的操作</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();
|
||||
@@ -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>
|
||||
@@ -78,7 +121,7 @@ public static class ParallelExtensions
|
||||
/// <param name="parallelCount">最大并行度</param>
|
||||
/// <param name="cancellationToken">取消操作的标志</param>
|
||||
/// <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();
|
||||
@@ -95,8 +138,10 @@ public static class ParallelExtensions
|
||||
/// <param name="body">异步执行的操作</param>
|
||||
/// <param name="cancellationToken">取消操作的标志</param>
|
||||
/// <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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -21,3 +21,4 @@ global using System.Globalization;
|
||||
|
||||
|
||||
[assembly: SuppressMessage("Reliability", "CA2007", Justification = "<挂起>", Scope = "module")]
|
||||
[assembly: GlobalGenerateSetParametersAsync(true)]
|
@@ -5,10 +5,11 @@
|
||||
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
using System.Collections.Concurrent;
|
||||
using System.Reflection;
|
||||
using System.Resources;
|
||||
|
||||
using ThingsGateway.NewLife.Collections;
|
||||
|
||||
namespace ThingsGateway;
|
||||
|
||||
/// <summary>
|
||||
@@ -107,14 +108,14 @@ internal class JsonStringLocalizer(Assembly assembly, string typeName, string ba
|
||||
return ret;
|
||||
}
|
||||
|
||||
private readonly ConcurrentDictionary<string, object?> _missingManifestCache = [];
|
||||
private readonly ConcurrentHashSet<string> _missingManifestCache = [];
|
||||
private string? GetStringFromJson(string name)
|
||||
{
|
||||
// get string from json localization file
|
||||
var localizerStrings = MegerResolveLocalizers(CacheManager.GetAllStringsByTypeName(Assembly, typeName));
|
||||
var cacheKey = $"name={name}&culture={CultureInfo.CurrentUICulture.Name}";
|
||||
string? ret = null;
|
||||
if (!_missingManifestCache.ContainsKey(cacheKey))
|
||||
if (!_missingManifestCache.Contain(cacheKey))
|
||||
{
|
||||
var l = localizerStrings.Find(i => i.Name == name);
|
||||
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)
|
||||
{
|
||||
var localizers = new List<LocalizedString>(CacheManager.GetTypeStringsFromResolve(typeName));
|
||||
|
||||
if (localizerStrings != null)
|
||||
{
|
||||
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);
|
||||
}
|
||||
_missingManifestCache.TryAdd($"name={name}&culture={CultureInfo.CurrentUICulture.Name}", null);
|
||||
_missingManifestCache.TryAdd($"name={name}&culture={CultureInfo.CurrentUICulture.Name}");
|
||||
}
|
||||
|
||||
private List<LocalizedString>? _allLocalizerdStrings;
|
||||
|
@@ -8,7 +8,6 @@
|
||||
// QQ群:605534569
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
using ThingsGateway.NewLife;
|
||||
@@ -48,7 +47,7 @@ public class Startup : AppStartup
|
||||
// 缓存
|
||||
services.AddSingleton<ICache, MemoryCache>();
|
||||
|
||||
MachineInfo.RegisterAsync();
|
||||
MachineInfo.Register();
|
||||
|
||||
// 配置雪花Id算法机器码
|
||||
YitIdHelper.SetIdGenerator(new IdGeneratorOptions
|
||||
@@ -59,7 +58,7 @@ public class Startup : AppStartup
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Use(IApplicationBuilder applicationBuilder)
|
||||
public void Use(IServiceProvider serviceProvider)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
@@ -1,35 +1,43 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Razor">
|
||||
|
||||
<Import Project="$(SolutionDir)Version.props" />
|
||||
<Import Project="$(SolutionDir)PackNuget.props" />
|
||||
<Import Project="..\..\Version.props" />
|
||||
<Import Project="..\..\PackNuget.props" />
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net8.0;</TargetFrameworks>
|
||||
<TargetFrameworks>net8.0</TargetFrameworks>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="BootstrapBlazor.FontAwesome" Version="9.0.2" />
|
||||
<PackageReference Include="BootstrapBlazor" Version="9.7.2" />
|
||||
<PackageReference Include="BootstrapBlazor" Version="9.7.4" />
|
||||
<PackageReference Include="Yitter.IdGenerator" Version="1.0.14" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Remove="Locales\*.json" />
|
||||
<EmbeddedResource Include="Locales\*.json">
|
||||
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="..\README.md" Pack="true" PackagePath="\" />
|
||||
<None Include="..\README.zh-CN.md" Pack="true" PackagePath="\" />
|
||||
<None Remove="$(SolutionDir)..\README.md" Pack="false" PackagePath="\" />
|
||||
<None Remove="$(SolutionDir)..\README.zh-CN.md" Pack="false" PackagePath="\" />
|
||||
<None Remove="..\..\..\README.md" Pack="false" PackagePath="\" />
|
||||
<None Remove="..\..\..\README.zh-CN.md" Pack="false" PackagePath="\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ThingsGateway.Furion\ThingsGateway.Furion.csproj" />
|
||||
</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>
|
||||
|
||||
|
||||
|
@@ -1,5 +1,4 @@
|
||||
|
||||
@using System.Net.Http
|
||||
@using System.Net.Http
|
||||
@using System.Net.Http.Json
|
||||
@using Microsoft.AspNetCore.Components.Forms
|
||||
@using Microsoft.AspNetCore.Components.Routing
|
||||
@@ -16,4 +15,5 @@
|
||||
@using BootstrapBlazor.Components
|
||||
|
||||
|
||||
@using ThingsGateway.Razor;
|
||||
@using ThingsGateway.Razor
|
||||
|
||||
|
@@ -355,7 +355,7 @@ namespace ThingsGateway.SqlSugar
|
||||
{
|
||||
var querybulder = InstanceFactory.GetSqlbuilder(this.Context.CurrentConnectionConfig);
|
||||
querybulder.Context = this.Context;
|
||||
var fileds = item.IndexFields
|
||||
var fields = item.IndexFields
|
||||
.Select(it =>
|
||||
{
|
||||
var dbColumn = entityInfo.Columns.FirstOrDefault(z => z.PropertyName == it.Key);
|
||||
@@ -366,7 +366,7 @@ namespace ThingsGateway.SqlSugar
|
||||
return new KeyValuePair<string, OrderByType>(dbColumn.DbColumnName, it.Value);
|
||||
})
|
||||
.Select(it => querybulder.GetTranslationColumnName(it.Key) + " " + it.Value).ToArray();
|
||||
this.Context.DbMaintenance.CreateIndex(entityInfo.DbTableName, fileds, item.IndexName + include, item.IsUnique);
|
||||
this.Context.DbMaintenance.CreateIndex(entityInfo.DbTableName, fields, item.IndexName + include, item.IsUnique);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -384,7 +384,7 @@ namespace ThingsGateway.SqlSugar
|
||||
DbColumnInfo dbColumnInfo = EntityColumnToDbColumn(entityInfo, tableName, item);
|
||||
columns.Add(dbColumnInfo);
|
||||
}
|
||||
if (entityInfo.IsCreateTableFiledSort)
|
||||
if (entityInfo.IsCreateTableFieldSort)
|
||||
{
|
||||
columns = columns.OrderBy(c => c.CreateTableFieldSort).ToList();
|
||||
columns = columns.OrderBy(it => it.IsPrimarykey ? 0 : 1).ToList();
|
||||
|
@@ -154,7 +154,7 @@ namespace ThingsGateway.SqlSugar
|
||||
if (DeleteBuilder.BigDataInValues == null)
|
||||
DeleteBuilder.BigDataInValues = new List<object>();
|
||||
DeleteBuilder.BigDataInValues.AddRange(primaryKeyValues);
|
||||
DeleteBuilder.BigDataFiled = primaryField;
|
||||
DeleteBuilder.BigDataField = primaryField;
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -520,7 +520,7 @@ namespace ThingsGateway.SqlSugar
|
||||
if (DeleteBuilder.BigDataInValues == null)
|
||||
DeleteBuilder.BigDataInValues = new List<object>();
|
||||
DeleteBuilder.BigDataInValues.AddRange(primaryKeyValues.Select(it => (object)it));
|
||||
DeleteBuilder.BigDataFiled = primaryField;
|
||||
DeleteBuilder.BigDataField = primaryField;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
@@ -35,7 +35,7 @@ namespace ThingsGateway.SqlSugar
|
||||
attributeType.GetProperty(nameof(SugarTable.TableDescription)) ,
|
||||
attributeType.GetProperty(nameof(SugarTable.IsDisabledUpdateAll)) ,
|
||||
attributeType.GetProperty(nameof(SugarTable.IsDisabledDelete)),
|
||||
attributeType.GetProperty(nameof(SugarTable.IsCreateTableFiledSort)),
|
||||
attributeType.GetProperty(nameof(SugarTable.IsCreateTableFieldSort)),
|
||||
attributeType.GetProperty(nameof(SugarTable.Discrimator))
|
||||
}
|
||||
, new object[] {
|
||||
@@ -43,7 +43,7 @@ namespace ThingsGateway.SqlSugar
|
||||
sugarTable.TableDescription ,
|
||||
sugarTable.IsDisabledUpdateAll,
|
||||
sugarTable.IsDisabledDelete,
|
||||
sugarTable.IsCreateTableFiledSort,
|
||||
sugarTable.IsCreateTableFieldSort,
|
||||
sugarTable.Discrimator
|
||||
});
|
||||
return attributeBuilder;
|
||||
|
@@ -63,7 +63,7 @@ namespace ThingsGateway.SqlSugar
|
||||
result.TableDescription = sugarTable.TableDescription.ToSqlFilter();
|
||||
result.IsDisabledUpdateAll = sugarTable.IsDisabledUpdateAll;
|
||||
result.IsDisabledDelete = sugarTable.IsDisabledDelete;
|
||||
result.IsCreateTableFiledSort = sugarTable.IsCreateTableFiledSort;
|
||||
result.IsCreateTableFieldSort = sugarTable.IsCreateTableFieldSort;
|
||||
result.Discrimator = sugarTable.Discrimator;
|
||||
}
|
||||
var indexs = type.GetCustomAttributes(typeof(SugarIndexAttribute));
|
||||
@@ -201,9 +201,9 @@ namespace ThingsGateway.SqlSugar
|
||||
try
|
||||
{
|
||||
|
||||
if (this.Context.CurrentConnectionConfig?.MoreSettings?.IsNoReadXmlDescription == true)
|
||||
if (this.Context.CurrentConnectionConfig?.MoreSettings?.IsNoReadXmlDescription ?? true == true)
|
||||
{
|
||||
return "";
|
||||
return string.Empty;
|
||||
}
|
||||
if (entityType.Assembly.IsDynamic && entityType.Assembly.FullName.StartsWith("Dynamic"))
|
||||
{
|
||||
|
@@ -566,11 +566,11 @@ namespace ThingsGateway.SqlSugar
|
||||
foreach (var item in this.EntityInfo.Columns.Where(it => it.IsIgnore == false && GetPrimaryKeys().Any(pk => pk.Equals(it.DbColumnName, StringComparison.CurrentCultureIgnoreCase))))
|
||||
{
|
||||
var fielddName = item.DbColumnName;
|
||||
var filedObject = this.EntityInfo.Columns.FirstOrDefault(it => it.PropertyName == item.PropertyName).PropertyInfo.GetValue(this.InsertObjs.Last(), null);
|
||||
var fieldValue = filedObject.ObjToString();
|
||||
if (filedObject != null && filedObject.GetType() != typeof(string) && this.Context.CurrentConnectionConfig.DbType == DbType.PostgreSQL)
|
||||
var fieldObject = this.EntityInfo.Columns.FirstOrDefault(it => it.PropertyName == item.PropertyName).PropertyInfo.GetValue(this.InsertObjs.Last(), null);
|
||||
var fieldValue = fieldObject.ObjToString();
|
||||
if (fieldObject != null && fieldObject.GetType() != typeof(string) && this.Context.CurrentConnectionConfig.DbType == DbType.PostgreSQL)
|
||||
{
|
||||
cons.Add(new ConditionalModel() { ConditionalType = ConditionalType.Equal, FieldName = fielddName, FieldValue = fieldValue, FieldValueConvertFunc = it => UtilMethods.ChangeType2(it, filedObject.GetType()) });
|
||||
cons.Add(new ConditionalModel() { ConditionalType = ConditionalType.Equal, FieldName = fielddName, FieldValue = fieldValue, FieldValueConvertFunc = it => UtilMethods.ChangeType2(it, fieldObject.GetType()) });
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@@ -73,11 +73,6 @@ namespace ThingsGateway.SqlSugar
|
||||
return resul;
|
||||
}
|
||||
|
||||
[Obsolete("use ExecuteCommand")]
|
||||
public object ExecuteReturnPrimaryKey()
|
||||
{
|
||||
return ExecuteCommand();
|
||||
}
|
||||
|
||||
public async Task<object> ExecuteCommandAsync()
|
||||
{
|
||||
@@ -137,11 +132,7 @@ namespace ThingsGateway.SqlSugar
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
[Obsolete("use ExecuteCommandAsync")]
|
||||
public Task<object> ExecuteReturnPrimaryKeyAsync()
|
||||
{
|
||||
return Task.FromResult(ExecuteReturnPrimaryKey());
|
||||
}
|
||||
|
||||
|
||||
private bool IsIdEntity(EntityInfo entity)
|
||||
{
|
||||
|
@@ -9,17 +9,17 @@ namespace ThingsGateway.SqlSugar
|
||||
public EntityInfo NavEntity { get; set; }
|
||||
public EntityInfo RootEntity { get; set; }
|
||||
|
||||
public MappingFieldsInfo GetMappings(Expression thisFiled, Expression mappingFiled)
|
||||
public MappingFieldsInfo GetMappings(Expression thisField, Expression mappingField)
|
||||
{
|
||||
MappingFieldsInfo mappingFields = new MappingFieldsInfo();
|
||||
var pkName = "";
|
||||
if ((mappingFiled as LambdaExpression).Body is UnaryExpression)
|
||||
if ((mappingField as LambdaExpression).Body is UnaryExpression)
|
||||
{
|
||||
pkName = (((mappingFiled as LambdaExpression).Body as UnaryExpression).Operand as MemberExpression).Member.Name;
|
||||
pkName = (((mappingField as LambdaExpression).Body as UnaryExpression).Operand as MemberExpression).Member.Name;
|
||||
}
|
||||
else
|
||||
{
|
||||
pkName = ((mappingFiled as LambdaExpression).Body as MemberExpression).Member.Name;
|
||||
pkName = ((mappingField as LambdaExpression).Body as MemberExpression).Member.Name;
|
||||
}
|
||||
return mappingFields;
|
||||
}
|
||||
|
@@ -577,7 +577,7 @@ namespace ThingsGateway.SqlSugar
|
||||
var result = new List<T>();
|
||||
throw new Exception("开发中");
|
||||
}
|
||||
public List<T> SetContext<ParameterT>(Expression<Func<T, object>> thisFiled, Expression<Func<object>> mappingFiled, ParameterT parameter)
|
||||
public List<T> SetContext<ParameterT>(Expression<Func<T, object>> thisField, Expression<Func<object>> mappingField, ParameterT parameter)
|
||||
{
|
||||
if (parameter == null)
|
||||
{
|
||||
@@ -588,15 +588,15 @@ namespace ThingsGateway.SqlSugar
|
||||
var queryableContext = this.Context.TempItems["Queryable_To_Context"] as MapperContext<ParameterT>;
|
||||
var list = queryableContext.list;
|
||||
var pkName = "";
|
||||
if ((mappingFiled as LambdaExpression).Body is UnaryExpression)
|
||||
if ((mappingField as LambdaExpression).Body is UnaryExpression)
|
||||
{
|
||||
pkName = (((mappingFiled as LambdaExpression).Body as UnaryExpression).Operand as MemberExpression).Member.Name;
|
||||
pkName = (((mappingField as LambdaExpression).Body as UnaryExpression).Operand as MemberExpression).Member.Name;
|
||||
}
|
||||
else
|
||||
{
|
||||
pkName = ((mappingFiled as LambdaExpression).Body as MemberExpression).Member.Name;
|
||||
pkName = ((mappingField as LambdaExpression).Body as MemberExpression).Member.Name;
|
||||
}
|
||||
var key = thisFiled.ToString() + mappingFiled.ToString() + typeof(ParameterT).FullName + typeof(T).FullName;
|
||||
var key = thisField.ToString() + mappingField.ToString() + typeof(ParameterT).FullName + typeof(T).FullName;
|
||||
var ids = list.Where(it => it != null).Select(it => it.GetType().GetProperty(pkName).GetValue(it)).Distinct().ToArray();
|
||||
if (queryableContext.TempChildLists == null)
|
||||
queryableContext.TempChildLists = new Dictionary<string, object>();
|
||||
@@ -610,25 +610,25 @@ namespace ThingsGateway.SqlSugar
|
||||
queryableContext.TempChildLists = new Dictionary<string, object>();
|
||||
this.Context.Utilities.PageEach(ids, 200, pageIds =>
|
||||
{
|
||||
result.AddRange(this.Clone().In(thisFiled, pageIds).ToList());
|
||||
result.AddRange(this.Clone().In(thisField, pageIds).ToList());
|
||||
});
|
||||
queryableContext.TempChildLists[key] = result;
|
||||
}
|
||||
var name = "";
|
||||
if ((thisFiled as LambdaExpression).Body is UnaryExpression)
|
||||
if ((thisField as LambdaExpression).Body is UnaryExpression)
|
||||
{
|
||||
name = (((thisFiled as LambdaExpression).Body as UnaryExpression).Operand as MemberExpression).Member.Name;
|
||||
name = (((thisField as LambdaExpression).Body as UnaryExpression).Operand as MemberExpression).Member.Name;
|
||||
}
|
||||
else
|
||||
{
|
||||
name = ((thisFiled as LambdaExpression).Body as MemberExpression).Member.Name;
|
||||
name = ((thisField as LambdaExpression).Body as MemberExpression).Member.Name;
|
||||
}
|
||||
var pkValue = parameter.GetType().GetProperty(pkName).GetValue(parameter);
|
||||
result = result.Where(it => it.GetType().GetProperty(name).GetValue(it).ObjToString() == pkValue.ObjToString()).ToList();
|
||||
return result;
|
||||
}
|
||||
public List<T> SetContext<ParameterT>(Expression<Func<T, object>> thisFiled1, Expression<Func<object>> mappingFiled1,
|
||||
Expression<Func<T, object>> thisFiled2, Expression<Func<object>> mappingFiled2,
|
||||
public List<T> SetContext<ParameterT>(Expression<Func<T, object>> thisField1, Expression<Func<object>> mappingField1,
|
||||
Expression<Func<T, object>> thisField2, Expression<Func<object>> mappingField2,
|
||||
ParameterT parameter)
|
||||
{
|
||||
if (parameter == null)
|
||||
@@ -640,22 +640,22 @@ namespace ThingsGateway.SqlSugar
|
||||
List<T> result = new List<T>();
|
||||
var queryableContext = this.Context.TempItems["Queryable_To_Context"] as MapperContext<ParameterT>;
|
||||
var list = queryableContext.list;
|
||||
var key = thisFiled1.ToString() + mappingFiled1.ToString() +
|
||||
thisFiled2.ToString() + mappingFiled2.ToString() +
|
||||
var key = thisField1.ToString() + mappingField1.ToString() +
|
||||
thisField2.ToString() + mappingField2.ToString() +
|
||||
typeof(ParameterT).FullName + typeof(T).FullName;
|
||||
MappingFieldsHelper<ParameterT> fieldsHelper = new MappingFieldsHelper<ParameterT>();
|
||||
var mappings = new List<MappingFieldsExpression>() {
|
||||
new MappingFieldsExpression(){
|
||||
LeftColumnExpression=thisFiled1,
|
||||
LeftEntityColumn=leftEntity.Columns.First(it=>it.PropertyName==ExpressionTool.GetMemberName(thisFiled1)),
|
||||
RightColumnExpression=mappingFiled1,
|
||||
RightEntityColumn=rightEntity.Columns.First(it=>it.PropertyName==ExpressionTool.GetMemberName(mappingFiled1))
|
||||
LeftColumnExpression=thisField1,
|
||||
LeftEntityColumn=leftEntity.Columns.First(it=>it.PropertyName==ExpressionTool.GetMemberName(thisField1)),
|
||||
RightColumnExpression=mappingField1,
|
||||
RightEntityColumn=rightEntity.Columns.First(it=>it.PropertyName==ExpressionTool.GetMemberName(mappingField1))
|
||||
},
|
||||
new MappingFieldsExpression(){
|
||||
LeftColumnExpression=thisFiled2,
|
||||
LeftEntityColumn=leftEntity.Columns.First(it=>it.PropertyName==ExpressionTool.GetMemberName(thisFiled2)),
|
||||
RightColumnExpression=mappingFiled2,
|
||||
RightEntityColumn=rightEntity.Columns.First(it=>it.PropertyName==ExpressionTool.GetMemberName(mappingFiled2))
|
||||
LeftColumnExpression=thisField2,
|
||||
LeftEntityColumn=leftEntity.Columns.First(it=>it.PropertyName==ExpressionTool.GetMemberName(thisField2)),
|
||||
RightColumnExpression=mappingField2,
|
||||
RightEntityColumn=rightEntity.Columns.First(it=>it.PropertyName==ExpressionTool.GetMemberName(mappingField2))
|
||||
}
|
||||
};
|
||||
var conditionals = fieldsHelper.GetMppingSql(list.Cast<object>().ToList(), mappings);
|
||||
|
@@ -502,8 +502,8 @@ namespace ThingsGateway.SqlSugar
|
||||
totalNumber.Value = count;
|
||||
}
|
||||
|
||||
public async Task<List<T>> SetContextAsync<ParameterT>(Expression<Func<T, object>> thisFiled1, Expression<Func<object>> mappingFiled1,
|
||||
Expression<Func<T, object>> thisFiled2, Expression<Func<object>> mappingFiled2,
|
||||
public async Task<List<T>> SetContextAsync<ParameterT>(Expression<Func<T, object>> thisField1, Expression<Func<object>> mappingField1,
|
||||
Expression<Func<T, object>> thisField2, Expression<Func<object>> mappingField2,
|
||||
ParameterT parameter)
|
||||
{
|
||||
if (parameter == null)
|
||||
@@ -515,22 +515,22 @@ ParameterT parameter)
|
||||
List<T> result = new List<T>();
|
||||
var queryableContext = this.Context.TempItems["Queryable_To_Context"] as MapperContext<ParameterT>;
|
||||
var list = queryableContext.list;
|
||||
var key = thisFiled1.ToString() + mappingFiled1.ToString() +
|
||||
thisFiled2.ToString() + mappingFiled2.ToString() +
|
||||
var key = thisField1.ToString() + mappingField1.ToString() +
|
||||
thisField2.ToString() + mappingField2.ToString() +
|
||||
typeof(ParameterT).FullName + typeof(T).FullName;
|
||||
MappingFieldsHelper<ParameterT> fieldsHelper = new MappingFieldsHelper<ParameterT>();
|
||||
var mappings = new List<MappingFieldsExpression>() {
|
||||
new MappingFieldsExpression(){
|
||||
LeftColumnExpression=thisFiled1,
|
||||
LeftEntityColumn=leftEntity.Columns.First(it=>it.PropertyName==ExpressionTool.GetMemberName(thisFiled1)),
|
||||
RightColumnExpression=mappingFiled1,
|
||||
RightEntityColumn=rightEntity.Columns.First(it=>it.PropertyName==ExpressionTool.GetMemberName(mappingFiled1))
|
||||
LeftColumnExpression=thisField1,
|
||||
LeftEntityColumn=leftEntity.Columns.First(it=>it.PropertyName==ExpressionTool.GetMemberName(thisField1)),
|
||||
RightColumnExpression=mappingField1,
|
||||
RightEntityColumn=rightEntity.Columns.First(it=>it.PropertyName==ExpressionTool.GetMemberName(mappingField1))
|
||||
},
|
||||
new MappingFieldsExpression(){
|
||||
LeftColumnExpression=thisFiled2,
|
||||
LeftEntityColumn=leftEntity.Columns.First(it=>it.PropertyName==ExpressionTool.GetMemberName(thisFiled2)),
|
||||
RightColumnExpression=mappingFiled2,
|
||||
RightEntityColumn=rightEntity.Columns.First(it=>it.PropertyName==ExpressionTool.GetMemberName(mappingFiled2))
|
||||
LeftColumnExpression=thisField2,
|
||||
LeftEntityColumn=leftEntity.Columns.First(it=>it.PropertyName==ExpressionTool.GetMemberName(thisField2)),
|
||||
RightColumnExpression=mappingField2,
|
||||
RightEntityColumn=rightEntity.Columns.First(it=>it.PropertyName==ExpressionTool.GetMemberName(mappingField2))
|
||||
}
|
||||
};
|
||||
var conditionals = fieldsHelper.GetMppingSql(list.Cast<object>().ToList(), mappings);
|
||||
@@ -550,22 +550,22 @@ ParameterT parameter)
|
||||
var newResult = fieldsHelper.GetSetList(obj, listObj, mappings).Select(it => (T)it).ToList();
|
||||
return newResult;
|
||||
}
|
||||
public async Task<List<T>> SetContextAsync<ParameterT>(Expression<Func<T, object>> thisFiled, Expression<Func<object>> mappingFiled, ParameterT parameter)
|
||||
public async Task<List<T>> SetContextAsync<ParameterT>(Expression<Func<T, object>> thisField, Expression<Func<object>> mappingField, ParameterT parameter)
|
||||
{
|
||||
List<T> result = new List<T>();
|
||||
var entity = this.Context.EntityMaintenance.GetEntityInfo<ParameterT>();
|
||||
var queryableContext = this.Context.TempItems["Queryable_To_Context"] as MapperContext<ParameterT>;
|
||||
var list = queryableContext.list;
|
||||
var pkName = "";
|
||||
if ((mappingFiled as LambdaExpression).Body is UnaryExpression)
|
||||
if ((mappingField as LambdaExpression).Body is UnaryExpression)
|
||||
{
|
||||
pkName = (((mappingFiled as LambdaExpression).Body as UnaryExpression).Operand as MemberExpression).Member.Name;
|
||||
pkName = (((mappingField as LambdaExpression).Body as UnaryExpression).Operand as MemberExpression).Member.Name;
|
||||
}
|
||||
else
|
||||
{
|
||||
pkName = ((mappingFiled as LambdaExpression).Body as MemberExpression).Member.Name;
|
||||
pkName = ((mappingField as LambdaExpression).Body as MemberExpression).Member.Name;
|
||||
}
|
||||
var key = thisFiled.ToString() + mappingFiled.ToString() + typeof(ParameterT).FullName + typeof(T).FullName;
|
||||
var key = thisField.ToString() + mappingField.ToString() + typeof(ParameterT).FullName + typeof(T).FullName;
|
||||
var ids = list.Select(it => it.GetType().GetProperty(pkName).GetValue(it)).ToArray();
|
||||
if (queryableContext.TempChildLists == null)
|
||||
queryableContext.TempChildLists = new Dictionary<string, object>();
|
||||
@@ -579,18 +579,18 @@ ParameterT parameter)
|
||||
queryableContext.TempChildLists = new Dictionary<string, object>();
|
||||
await Context.Utilities.PageEachAsync(ids, 200, async pageIds =>
|
||||
{
|
||||
result.AddRange(await Clone().In(thisFiled, pageIds).ToListAsync().ConfigureAwait(false));
|
||||
result.AddRange(await Clone().In(thisField, pageIds).ToListAsync().ConfigureAwait(false));
|
||||
}).ConfigureAwait(false);
|
||||
queryableContext.TempChildLists[key] = result;
|
||||
}
|
||||
var name = "";
|
||||
if ((thisFiled as LambdaExpression).Body is UnaryExpression)
|
||||
if ((thisField as LambdaExpression).Body is UnaryExpression)
|
||||
{
|
||||
name = (((thisFiled as LambdaExpression).Body as UnaryExpression).Operand as MemberExpression).Member.Name;
|
||||
name = (((thisField as LambdaExpression).Body as UnaryExpression).Operand as MemberExpression).Member.Name;
|
||||
}
|
||||
else
|
||||
{
|
||||
name = ((thisFiled as LambdaExpression).Body as MemberExpression).Member.Name;
|
||||
name = ((thisField as LambdaExpression).Body as MemberExpression).Member.Name;
|
||||
}
|
||||
var pkValue = parameter.GetType().GetProperty(pkName).GetValue(parameter);
|
||||
result = result.Where(it => it.GetType().GetProperty(name).GetValue(it).ObjToString() == pkValue.ObjToString()).ToList();
|
||||
|
@@ -952,17 +952,17 @@ namespace ThingsGateway.SqlSugar
|
||||
var mapperFieldExp = mapperField as MemberExpression;
|
||||
Check.Exception(mapperFieldExp.Type.IsClass(), ".Mapper() parameter error");
|
||||
var objType = mapperObjectExp.Type;
|
||||
var filedType = mapperFieldExp.Expression.Type;
|
||||
var fieldType = mapperFieldExp.Expression.Type;
|
||||
Check.Exception(objType != typeof(TObject) && objType != typeof(List<TObject>), ".Mapper() parameter error");
|
||||
if (objType == typeof(List<TObject>))
|
||||
{
|
||||
objType = typeof(TObject);
|
||||
}
|
||||
var filedName = mapperFieldExp.Member.Name;
|
||||
var fieldName = mapperFieldExp.Member.Name;
|
||||
var objName = mapperObjectExp.Member.Name;
|
||||
var filedEntity = this.Context.EntityMaintenance.GetEntityInfo(objType);
|
||||
var objEntity = this.Context.EntityMaintenance.GetEntityInfo(filedType);
|
||||
var isSelf = filedType == typeof(T);
|
||||
var fieldEntity = this.Context.EntityMaintenance.GetEntityInfo(objType);
|
||||
var objEntity = this.Context.EntityMaintenance.GetEntityInfo(fieldType);
|
||||
var isSelf = fieldType == typeof(T);
|
||||
if (Mappers == null)
|
||||
Mappers = new List<Action<List<T>>>();
|
||||
if (isSelf)
|
||||
@@ -971,29 +971,29 @@ namespace ThingsGateway.SqlSugar
|
||||
{
|
||||
if (entitys.IsNullOrEmpty() || entitys.Count == 0) return;
|
||||
var entity = entitys.First();
|
||||
var whereCol = filedEntity.Columns.FirstOrDefault(it => it.PropertyName.Equals(filedName, StringComparison.CurrentCultureIgnoreCase));
|
||||
var whereCol = fieldEntity.Columns.FirstOrDefault(it => it.PropertyName.Equals(fieldName, StringComparison.CurrentCultureIgnoreCase));
|
||||
if (whereCol == null)
|
||||
{
|
||||
whereCol = filedEntity.Columns.FirstOrDefault(it => it.IsPrimarykey == true);
|
||||
whereCol = fieldEntity.Columns.FirstOrDefault(it => it.IsPrimarykey == true);
|
||||
}
|
||||
if (whereCol == null)
|
||||
{
|
||||
whereCol = filedEntity.Columns.FirstOrDefault(it => GetPrimaryKeys().Any(pk => pk.Equals(it.DbColumnName, StringComparison.CurrentCultureIgnoreCase)));
|
||||
whereCol = fieldEntity.Columns.FirstOrDefault(it => GetPrimaryKeys().Any(pk => pk.Equals(it.DbColumnName, StringComparison.CurrentCultureIgnoreCase)));
|
||||
}
|
||||
if (whereCol == null)
|
||||
{
|
||||
whereCol = filedEntity.Columns.FirstOrDefault(it => it.PropertyName.Equals("id", StringComparison.CurrentCultureIgnoreCase));
|
||||
whereCol = fieldEntity.Columns.FirstOrDefault(it => it.PropertyName.Equals("id", StringComparison.CurrentCultureIgnoreCase));
|
||||
}
|
||||
if (whereCol == null)
|
||||
{
|
||||
whereCol = filedEntity.Columns.FirstOrDefault(it => (it.PropertyName).Equals(it.EntityName + "id", StringComparison.CurrentCultureIgnoreCase));
|
||||
whereCol = fieldEntity.Columns.FirstOrDefault(it => (it.PropertyName).Equals(it.EntityName + "id", StringComparison.CurrentCultureIgnoreCase));
|
||||
}
|
||||
if (whereCol == null)
|
||||
{
|
||||
Check.Exception(true, ".Mapper() parameter error");
|
||||
}
|
||||
List<string> inValues = entitys.Select(it => it.GetType().GetProperty(filedName).GetValue(it, null).ObjToString()).ToList();
|
||||
if (inValues != null && inValues.Count != 0 && UtilMethods.GetUnderType(entitys.First().GetType().GetProperty(filedName).PropertyType) == UtilConstants.GuidType)
|
||||
List<string> inValues = entitys.Select(it => it.GetType().GetProperty(fieldName).GetValue(it, null).ObjToString()).ToList();
|
||||
if (inValues != null && inValues.Count != 0 && UtilMethods.GetUnderType(entitys.First().GetType().GetProperty(fieldName).PropertyType) == UtilConstants.GuidType)
|
||||
{
|
||||
inValues = inValues.Select(x => string.IsNullOrEmpty(x) ? "null" : x).Distinct().ToList();
|
||||
}
|
||||
@@ -1010,7 +1010,7 @@ namespace ThingsGateway.SqlSugar
|
||||
var list = this.Context.Queryable<TObject>().Where(wheres).ToList();
|
||||
foreach (var item in entitys)
|
||||
{
|
||||
var whereValue = item.GetType().GetProperty(filedName).GetValue(item, null);
|
||||
var whereValue = item.GetType().GetProperty(fieldName).GetValue(item, null);
|
||||
var setValue = list.Where(x => x.GetType().GetProperty(whereCol.PropertyName).GetValue(x, null).ObjToString() == whereValue.ObjToString()).ToList();
|
||||
var setObject = item.GetType().GetProperty(objName);
|
||||
if (setObject.PropertyType.FullName.IsCollectionsList())
|
||||
@@ -1032,7 +1032,7 @@ namespace ThingsGateway.SqlSugar
|
||||
if (entitys.IsNullOrEmpty() || entitys.Count == 0) return;
|
||||
var entity = entitys.First();
|
||||
var tEntity = this.Context.EntityMaintenance.GetEntityInfo<T>();
|
||||
var whereCol = tEntity.Columns.FirstOrDefault(it => it.PropertyName.Equals(filedName, StringComparison.CurrentCultureIgnoreCase));
|
||||
var whereCol = tEntity.Columns.FirstOrDefault(it => it.PropertyName.Equals(fieldName, StringComparison.CurrentCultureIgnoreCase));
|
||||
if (whereCol == null)
|
||||
{
|
||||
whereCol = tEntity.Columns.FirstOrDefault(it => it.IsPrimarykey == true);
|
||||
@@ -1054,7 +1054,7 @@ namespace ThingsGateway.SqlSugar
|
||||
Check.Exception(true, ".Mapper() parameter error");
|
||||
}
|
||||
List<string> inValues = entitys.Select(it => it.GetType().GetProperty(whereCol.PropertyName).GetValue(it, null).ObjToString()).ToList();
|
||||
var dbColumnName = filedEntity.Columns.FirstOrDefault(it => it.PropertyName == filedName).DbColumnName;
|
||||
var dbColumnName = fieldEntity.Columns.FirstOrDefault(it => it.PropertyName == fieldName).DbColumnName;
|
||||
List<IConditionalModel> wheres = new List<IConditionalModel>()
|
||||
{
|
||||
new ConditionalModel()
|
||||
@@ -1068,7 +1068,7 @@ namespace ThingsGateway.SqlSugar
|
||||
foreach (var item in entitys)
|
||||
{
|
||||
var whereValue = item.GetType().GetProperty(whereCol.PropertyName).GetValue(item, null);
|
||||
var setValue = list.Where(x => x.GetType().GetProperty(filedName).GetValue(x, null).ObjToString() == whereValue.ObjToString()).ToList();
|
||||
var setValue = list.Where(x => x.GetType().GetProperty(fieldName).GetValue(x, null).ObjToString() == whereValue.ObjToString()).ToList();
|
||||
var setObject = item.GetType().GetProperty(objName);
|
||||
if (setObject.PropertyType.FullName.IsCollectionsList())
|
||||
{
|
||||
@@ -1118,18 +1118,18 @@ namespace ThingsGateway.SqlSugar
|
||||
Check.Exception(mainFieldExp.Type.IsClass(), ".Mapper() parameter error");
|
||||
Check.Exception(childFieldExp.Type.IsClass(), ".Mapper() parameter error");
|
||||
var objType = mapperObjectExp.Type;
|
||||
var filedType = mainFieldExp.Expression.Type;
|
||||
var fieldType = mainFieldExp.Expression.Type;
|
||||
Check.Exception(objType != typeof(TObject) && objType != typeof(List<TObject>), ".Mapper() parameter error");
|
||||
if (objType == typeof(List<TObject>))
|
||||
{
|
||||
objType = typeof(TObject);
|
||||
}
|
||||
var mainFiledName = mainFieldExp.Member.Name;
|
||||
var childFiledName = childFieldExp.Member.Name;
|
||||
var mainFieldName = mainFieldExp.Member.Name;
|
||||
var childFieldName = childFieldExp.Member.Name;
|
||||
var objName = mapperObjectExp.Member.Name;
|
||||
var filedEntity = this.Context.EntityMaintenance.GetEntityInfo(objType);
|
||||
var objEntity = this.Context.EntityMaintenance.GetEntityInfo(filedType);
|
||||
var isSelf = filedType == typeof(T);
|
||||
var fieldEntity = this.Context.EntityMaintenance.GetEntityInfo(objType);
|
||||
var objEntity = this.Context.EntityMaintenance.GetEntityInfo(fieldType);
|
||||
var isSelf = fieldType == typeof(T);
|
||||
if (Mappers == null)
|
||||
Mappers = new List<Action<List<T>>>();
|
||||
if (isSelf)
|
||||
@@ -1138,28 +1138,28 @@ namespace ThingsGateway.SqlSugar
|
||||
{
|
||||
if (entitys.IsNullOrEmpty() || entitys.Count == 0) return;
|
||||
var entity = entitys.First();
|
||||
var whereCol = filedEntity.Columns.FirstOrDefault(it => it.PropertyName.Equals(childFiledName, StringComparison.CurrentCultureIgnoreCase));
|
||||
var whereCol = fieldEntity.Columns.FirstOrDefault(it => it.PropertyName.Equals(childFieldName, StringComparison.CurrentCultureIgnoreCase));
|
||||
if (whereCol == null)
|
||||
{
|
||||
whereCol = filedEntity.Columns.FirstOrDefault(it => it.IsPrimarykey == true);
|
||||
whereCol = fieldEntity.Columns.FirstOrDefault(it => it.IsPrimarykey == true);
|
||||
}
|
||||
if (whereCol == null)
|
||||
{
|
||||
whereCol = filedEntity.Columns.FirstOrDefault(it => GetPrimaryKeys().Any(pk => pk.Equals(it.DbColumnName, StringComparison.CurrentCultureIgnoreCase)));
|
||||
whereCol = fieldEntity.Columns.FirstOrDefault(it => GetPrimaryKeys().Any(pk => pk.Equals(it.DbColumnName, StringComparison.CurrentCultureIgnoreCase)));
|
||||
}
|
||||
if (whereCol == null)
|
||||
{
|
||||
whereCol = filedEntity.Columns.FirstOrDefault(it => it.PropertyName.Equals("id", StringComparison.CurrentCultureIgnoreCase));
|
||||
whereCol = fieldEntity.Columns.FirstOrDefault(it => it.PropertyName.Equals("id", StringComparison.CurrentCultureIgnoreCase));
|
||||
}
|
||||
if (whereCol == null)
|
||||
{
|
||||
whereCol = filedEntity.Columns.FirstOrDefault(it => (it.PropertyName).Equals(it.EntityName + "id", StringComparison.CurrentCultureIgnoreCase));
|
||||
whereCol = fieldEntity.Columns.FirstOrDefault(it => (it.PropertyName).Equals(it.EntityName + "id", StringComparison.CurrentCultureIgnoreCase));
|
||||
}
|
||||
if (whereCol == null)
|
||||
{
|
||||
Check.Exception(true, ".Mapper() parameter error");
|
||||
}
|
||||
List<string> inValues = entitys.Select(it => it.GetType().GetProperty(mainFiledName).GetValue(it, null).ObjToString()).ToList();
|
||||
List<string> inValues = entitys.Select(it => it.GetType().GetProperty(mainFieldName).GetValue(it, null).ObjToString()).ToList();
|
||||
List<IConditionalModel> wheres = new List<IConditionalModel>()
|
||||
{
|
||||
new ConditionalModel()
|
||||
@@ -1172,7 +1172,7 @@ namespace ThingsGateway.SqlSugar
|
||||
var list = this.Context.Queryable<TObject>().Where(wheres).ToList();
|
||||
foreach (var item in entitys)
|
||||
{
|
||||
var whereValue = item.GetType().GetProperty(mainFiledName).GetValue(item, null);
|
||||
var whereValue = item.GetType().GetProperty(mainFieldName).GetValue(item, null);
|
||||
var setValue = list.Where(x => x.GetType().GetProperty(whereCol.PropertyName).GetValue(x, null).ObjToString() == whereValue.ObjToString()).ToList();
|
||||
var setObject = item.GetType().GetProperty(objName);
|
||||
if (setObject.PropertyType.FullName.IsCollectionsList())
|
||||
@@ -1194,7 +1194,7 @@ namespace ThingsGateway.SqlSugar
|
||||
if (entitys.IsNullOrEmpty() || entitys.Count == 0) return;
|
||||
var entity = entitys.First();
|
||||
var tEntity = this.Context.EntityMaintenance.GetEntityInfo<T>();
|
||||
var whereCol = tEntity.Columns.FirstOrDefault(it => it.PropertyName.Equals(childFiledName, StringComparison.CurrentCultureIgnoreCase));
|
||||
var whereCol = tEntity.Columns.FirstOrDefault(it => it.PropertyName.Equals(childFieldName, StringComparison.CurrentCultureIgnoreCase));
|
||||
if (whereCol == null)
|
||||
{
|
||||
whereCol = tEntity.Columns.FirstOrDefault(it => it.IsPrimarykey == true);
|
||||
@@ -1216,7 +1216,7 @@ namespace ThingsGateway.SqlSugar
|
||||
Check.Exception(true, ".Mapper() parameter error");
|
||||
}
|
||||
List<string> inValues = entitys.Select(it => it.GetType().GetProperty(whereCol.PropertyName).GetValue(it, null).ObjToString()).ToList();
|
||||
var dbColumnName = filedEntity.Columns.FirstOrDefault(it => it.PropertyName == mainFiledName).DbColumnName;
|
||||
var dbColumnName = fieldEntity.Columns.FirstOrDefault(it => it.PropertyName == mainFieldName).DbColumnName;
|
||||
List<IConditionalModel> wheres = new List<IConditionalModel>()
|
||||
{
|
||||
new ConditionalModel()
|
||||
@@ -1230,7 +1230,7 @@ namespace ThingsGateway.SqlSugar
|
||||
foreach (var item in entitys)
|
||||
{
|
||||
var whereValue = item.GetType().GetProperty(whereCol.PropertyName).GetValue(item, null);
|
||||
var setValue = list.Where(x => x.GetType().GetProperty(mainFiledName).GetValue(x, null).ObjToString() == whereValue.ObjToString()).ToList();
|
||||
var setValue = list.Where(x => x.GetType().GetProperty(mainFieldName).GetValue(x, null).ObjToString() == whereValue.ObjToString()).ToList();
|
||||
var setObject = item.GetType().GetProperty(objName);
|
||||
if (setObject.PropertyType.FullName.IsCollectionsList())
|
||||
{
|
||||
@@ -1612,8 +1612,8 @@ namespace ThingsGateway.SqlSugar
|
||||
result.SqlBuilder = this.SqlBuilder;
|
||||
result.SqlBuilder.QueryBuilder.Parameters = QueryBuilder.Parameters;
|
||||
result.SqlBuilder.QueryBuilder.SelectValue = expression;
|
||||
result.SqlBuilder.QueryBuilder.IsSelectSingleFiledJson = UtilMethods.IsJsonMember(expression, this.Context);
|
||||
result.SqlBuilder.QueryBuilder.IsSelectSingleFiledArray = UtilMethods.IsArrayMember(expression, this.Context);
|
||||
result.SqlBuilder.QueryBuilder.IsSelectSingleFieldJson = UtilMethods.IsJsonMember(expression, this.Context);
|
||||
result.SqlBuilder.QueryBuilder.IsSelectSingleFieldArray = UtilMethods.IsArrayMember(expression, this.Context);
|
||||
if (this.IsCache)
|
||||
{
|
||||
result.WithCache(this.CacheTime);
|
||||
@@ -1949,11 +1949,11 @@ namespace ThingsGateway.SqlSugar
|
||||
{
|
||||
result = this.Context.Utilities.DataReaderToExpandoObjectList(dataReader).Select(it => ((TResult)(object)it)).ToList();
|
||||
}
|
||||
else if (QueryBuilder.IsSelectSingleFiledJson)
|
||||
else if (QueryBuilder.IsSelectSingleFieldJson)
|
||||
{
|
||||
result = this.Context.Utilities.DataReaderToSelectJsonList<TResult>(dataReader);
|
||||
}
|
||||
else if (QueryBuilder.IsSelectSingleFiledArray)
|
||||
else if (QueryBuilder.IsSelectSingleFieldArray)
|
||||
{
|
||||
result = this.Context.Utilities.DataReaderToSelectArrayList<TResult>(dataReader);
|
||||
}
|
||||
@@ -1995,11 +1995,11 @@ namespace ThingsGateway.SqlSugar
|
||||
var expObj = await Context.Utilities.DataReaderToExpandoObjectListAsync(dataReader).ConfigureAwait(false);
|
||||
result = expObj.Select(it => ((TResult)(object)it)).ToList();
|
||||
}
|
||||
else if (QueryBuilder.IsSelectSingleFiledJson)
|
||||
else if (QueryBuilder.IsSelectSingleFieldJson)
|
||||
{
|
||||
result = await Context.Utilities.DataReaderToSelectJsonListAsync<TResult>(dataReader).ConfigureAwait(false);
|
||||
}
|
||||
else if (QueryBuilder.IsSelectSingleFiledArray)
|
||||
else if (QueryBuilder.IsSelectSingleFieldArray)
|
||||
{
|
||||
result = await Context.Utilities.DataReaderToSelectArrayListAsync<TResult>(dataReader).ConfigureAwait(false);
|
||||
}
|
||||
|
@@ -474,7 +474,7 @@ namespace ThingsGateway.SqlSugar
|
||||
var bEntity = this.Context.EntityMaintenance.GetEntityInfo(bType);
|
||||
var bProperty = bEntity.Columns.FirstOrDefault(it => it.IsPrimarykey == true)?.PropertyName;
|
||||
Check.Exception(bProperty == null, bEntity.EntityName + " no primary key");
|
||||
var bDbFiled = bEntity.Columns.FirstOrDefault(it => it.IsPrimarykey == true).DbColumnName;
|
||||
var bDbField = bEntity.Columns.FirstOrDefault(it => it.IsPrimarykey == true).DbColumnName;
|
||||
this.Mapper((it, cache) =>
|
||||
{
|
||||
var list = cache.Get<Dictionary<object, List<BType>>>(oldList =>
|
||||
@@ -496,7 +496,7 @@ namespace ThingsGateway.SqlSugar
|
||||
cons = new List<IConditionalModel>() {
|
||||
new ConditionalModel(){
|
||||
ConditionalType=ConditionalType.In,
|
||||
FieldName= bDbFiled,
|
||||
FieldName= bDbField,
|
||||
FieldValue=string.Join(",",mappingList.Select(z=>UtilMethods.GetPropertyValue(z,m_bPropertyName)).Distinct())
|
||||
}
|
||||
};
|
||||
@@ -1139,12 +1139,12 @@ namespace ThingsGateway.SqlSugar
|
||||
}
|
||||
var pks = GetPrimaryKeys().Select(it => SqlBuilder.GetTranslationTableName(it)).ToList();
|
||||
Check.Exception(pks == null || pks.Count != 1, "Queryable.In(params object[] pkValues): Only one primary key");
|
||||
string filed = pks.FirstOrDefault();
|
||||
string field = pks.FirstOrDefault();
|
||||
string shortName = QueryBuilder.TableShortName == null ? null : (QueryBuilder.TableShortName + ".");
|
||||
filed = shortName + filed;
|
||||
return In(filed, pkValues);
|
||||
field = shortName + field;
|
||||
return In(field, pkValues);
|
||||
}
|
||||
public virtual ISugarQueryable<T> In<FieldType>(string filed, params FieldType[] inValues)
|
||||
public virtual ISugarQueryable<T> In<FieldType>(string field, params FieldType[] inValues)
|
||||
{
|
||||
if (inValues.Length == 1)
|
||||
{
|
||||
@@ -1153,7 +1153,7 @@ namespace ThingsGateway.SqlSugar
|
||||
var whereIndex = QueryBuilder.WhereIndex;
|
||||
string parameterName = this.SqlBuilder.SqlParameterKeyWord + "InPara" + whereIndex;
|
||||
this.AddParameters(new SugarParameter(parameterName, inValues[0]));
|
||||
this.Where(string.Format(QueryBuilder.EqualTemplate, SqlBuilder.GetTranslationColumnName(filed), parameterName));
|
||||
this.Where(string.Format(QueryBuilder.EqualTemplate, SqlBuilder.GetTranslationColumnName(field), parameterName));
|
||||
QueryBuilder.WhereIndex++;
|
||||
}
|
||||
else
|
||||
@@ -1166,7 +1166,7 @@ namespace ThingsGateway.SqlSugar
|
||||
values.Add(item.ToString().ToSqlValue());
|
||||
}
|
||||
}
|
||||
this.Where(string.Format(QueryBuilder.InTemplate, SqlBuilder.GetTranslationColumnName(filed), string.Join(",", values)));
|
||||
this.Where(string.Format(QueryBuilder.InTemplate, SqlBuilder.GetTranslationColumnName(field), string.Join(",", values)));
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -1186,7 +1186,7 @@ namespace ThingsGateway.SqlSugar
|
||||
}
|
||||
}
|
||||
}
|
||||
this.Where(string.Format(QueryBuilder.InTemplate, SqlBuilder.GetTranslationColumnName(filed), string.Join(",", values)));
|
||||
this.Where(string.Format(QueryBuilder.InTemplate, SqlBuilder.GetTranslationColumnName(field), string.Join(",", values)));
|
||||
|
||||
}
|
||||
return this;
|
||||
@@ -1395,15 +1395,15 @@ namespace ThingsGateway.SqlSugar
|
||||
return this;
|
||||
}
|
||||
|
||||
public virtual ISugarQueryable<T> GroupBy(string groupFileds)
|
||||
public virtual ISugarQueryable<T> GroupBy(string groupFields)
|
||||
{
|
||||
groupFileds = groupFileds.ToCheckField();
|
||||
groupFields = groupFields.ToCheckField();
|
||||
var croupByValue = QueryBuilder.GroupByValue;
|
||||
if (QueryBuilder.GroupByValue.IsNullOrEmpty())
|
||||
{
|
||||
QueryBuilder.GroupByValue = QueryBuilder.GroupByTemplate;
|
||||
}
|
||||
QueryBuilder.GroupByValue += string.IsNullOrEmpty(croupByValue) ? groupFileds : ("," + groupFileds);
|
||||
QueryBuilder.GroupByValue += string.IsNullOrEmpty(croupByValue) ? groupFields : ("," + groupFields);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -1415,14 +1415,14 @@ namespace ThingsGateway.SqlSugar
|
||||
QueryBuilder.DisableTop = true;
|
||||
return this;
|
||||
}
|
||||
public virtual ISugarQueryable<T> PartitionBy(string groupFileds)
|
||||
public virtual ISugarQueryable<T> PartitionBy(string groupFields)
|
||||
{
|
||||
var partitionByValue = QueryBuilder.PartitionByValue;
|
||||
if (QueryBuilder.PartitionByValue.IsNullOrEmpty())
|
||||
{
|
||||
QueryBuilder.PartitionByValue = QueryBuilder.PartitionByTemplate;
|
||||
}
|
||||
QueryBuilder.PartitionByValue += string.IsNullOrEmpty(partitionByValue) ? groupFileds : ("," + groupFileds);
|
||||
QueryBuilder.PartitionByValue += string.IsNullOrEmpty(partitionByValue) ? groupFields : ("," + groupFields);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@@ -435,9 +435,9 @@ namespace ThingsGateway.SqlSugar
|
||||
QueryBuilder.DisableTop = true;
|
||||
return this;
|
||||
}
|
||||
public new ISugarQueryable<T, T2> PartitionBy(string groupFileds)
|
||||
public new ISugarQueryable<T, T2> PartitionBy(string groupFields)
|
||||
{
|
||||
base.PartitionBy(groupFileds);
|
||||
base.PartitionBy(groupFields);
|
||||
return this;
|
||||
}
|
||||
public new virtual ISugarQueryable<T, T2> GroupByIF(bool isGroupBy, Expression<Func<T, object>> expression)
|
||||
@@ -1010,9 +1010,9 @@ namespace ThingsGateway.SqlSugar
|
||||
QueryBuilder.DisableTop = true;
|
||||
return this;
|
||||
}
|
||||
public new ISugarQueryable<T, T2, T3> PartitionBy(string groupFileds)
|
||||
public new ISugarQueryable<T, T2, T3> PartitionBy(string groupFields)
|
||||
{
|
||||
base.PartitionBy(groupFileds);
|
||||
base.PartitionBy(groupFields);
|
||||
return this;
|
||||
}
|
||||
public new virtual ISugarQueryable<T, T2, T3> GroupByIF(bool isGroupBy, Expression<Func<T, object>> expression)
|
||||
|
@@ -27,7 +27,7 @@ namespace ThingsGateway.SqlSugar
|
||||
set { _WhereInfos = value; }
|
||||
}
|
||||
public virtual List<object> BigDataInValues { get; set; }
|
||||
public virtual string BigDataFiled { get; set; }
|
||||
public virtual string BigDataField { get; set; }
|
||||
#endregion
|
||||
|
||||
#region Sql Template
|
||||
@@ -136,7 +136,7 @@ namespace ThingsGateway.SqlSugar
|
||||
while (pageCount >= pageIndex)
|
||||
{
|
||||
var inValues = this.BigDataInValues.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
|
||||
batchDeleteSql.Append(sql + string.Format(WhereInTemplate, BigDataFiled, inValues.ToArray().ToJoinSqlInVals()));
|
||||
batchDeleteSql.Append(sql + string.Format(WhereInTemplate, BigDataField, inValues.ToArray().ToJoinSqlInVals()));
|
||||
batchDeleteSql.Append(';');
|
||||
pageIndex++;
|
||||
}
|
||||
|
@@ -13,7 +13,7 @@ namespace ThingsGateway.SqlSugar
|
||||
this.Parameters = new List<SugarParameter>();
|
||||
}
|
||||
|
||||
#region Private Fileds
|
||||
#region Private Fields
|
||||
protected List<JoinQueryInfo> _JoinQueryInfos;
|
||||
protected Dictionary<string, string> _EasyJoinInfos;
|
||||
private List<string> _WhereInfos;
|
||||
@@ -42,8 +42,8 @@ namespace ThingsGateway.SqlSugar
|
||||
internal List<List<QueryableAppendColumn>> AppendValues { get; set; }
|
||||
public bool IsCrossQueryWithAttr { get; set; }
|
||||
public Dictionary<string, string> CrossQueryItems { get; set; }
|
||||
public bool IsSelectSingleFiledJson { get; set; }
|
||||
public bool IsSelectSingleFiledArray { get; set; }
|
||||
public bool IsSelectSingleFieldJson { get; set; }
|
||||
public bool IsSelectSingleFieldArray { get; set; }
|
||||
public string TranLock { get; set; }
|
||||
public bool IsDisableMasterSlaveSeparation { get; set; }
|
||||
public bool IsEnableMasterSlaveSeparation { get; set; }
|
||||
|
@@ -7,8 +7,8 @@ namespace ThingsGateway.SqlSugar
|
||||
/// </summary>
|
||||
public partial class SqlSugarScope : ISqlSugarClient, ITenant
|
||||
{
|
||||
private List<ConnectionConfig> _configs;
|
||||
private Action<SqlSugarClient> _configAction;
|
||||
protected List<ConnectionConfig> _configs;
|
||||
protected Action<SqlSugarClient> _configAction;
|
||||
|
||||
protected virtual SqlSugarClient GetContext()
|
||||
{
|
||||
|
@@ -54,12 +54,7 @@ namespace ThingsGateway.SqlSugar
|
||||
#endregion
|
||||
|
||||
#region Util Methods
|
||||
[Obsolete("Use SqlSugarClient.Utilities")]
|
||||
public virtual IContextMethods RewritableMethods
|
||||
{
|
||||
get { return this.Context.Utilities; }
|
||||
set { this.Context.Utilities = value; }
|
||||
}
|
||||
|
||||
public virtual IContextMethods Utilities
|
||||
{
|
||||
get
|
||||
@@ -1376,16 +1371,7 @@ namespace ThingsGateway.SqlSugar
|
||||
Check.ExceptionEasy(" var childDb=Db.GetConnection(configId); use Db.CreateContext ", " 例如 var childDb=Db.GetConnection(configId);其中Db才能使用CreateContext,childDb不能使用");
|
||||
return null;
|
||||
}
|
||||
//[Obsolete("Use SqlSugarClient.GetSimpleClient() Or SqlSugarClient.GetSimpleClient<T>() ")]
|
||||
//public virtual SimpleClient SimpleClient
|
||||
//{
|
||||
// get
|
||||
// {
|
||||
// if (this._SimpleClient == null)
|
||||
// this._SimpleClient = new SimpleClient(this);
|
||||
// return this._SimpleClient;
|
||||
// }
|
||||
//}
|
||||
|
||||
public virtual SimpleClient<T> GetSimpleClient<T>() where T : class, new()
|
||||
{
|
||||
return new SimpleClient<T>(this);
|
||||
|
@@ -445,7 +445,7 @@ namespace ThingsGateway.SqlSugar
|
||||
}
|
||||
return this;
|
||||
}
|
||||
public IUpdateable<T> PublicSetColumns(Expression<Func<T, object>> filedNameExpression, string computationalSymbol)
|
||||
public IUpdateable<T> PublicSetColumns(Expression<Func<T, object>> fieldNameExpression, string computationalSymbol)
|
||||
{
|
||||
if (UpdateParameterIsNull == true)
|
||||
{
|
||||
@@ -453,10 +453,10 @@ namespace ThingsGateway.SqlSugar
|
||||
}
|
||||
else
|
||||
{
|
||||
var name = ExpressionTool.GetMemberName(filedNameExpression);
|
||||
var name = ExpressionTool.GetMemberName(fieldNameExpression);
|
||||
if (name == null)
|
||||
{
|
||||
Check.ExceptionEasy(filedNameExpression + " format error ", filedNameExpression + "参数格式错误");
|
||||
Check.ExceptionEasy(fieldNameExpression + " format error ", fieldNameExpression + "参数格式错误");
|
||||
}
|
||||
//var value = this.UpdateBuilder.GetExpressionValue(ValueExpExpression, ResolveExpressType.WhereSingle).GetResultString();
|
||||
if (this.UpdateBuilder.ReSetValueBySqlExpList == null)
|
||||
@@ -476,18 +476,18 @@ namespace ThingsGateway.SqlSugar
|
||||
return this;
|
||||
}
|
||||
|
||||
public IUpdateable<T> PublicSetColumns(Expression<Func<T, object>> filedNameExpression, Expression<Func<T, object>> ValueExpExpression)
|
||||
public IUpdateable<T> PublicSetColumns(Expression<Func<T, object>> fieldNameExpression, Expression<Func<T, object>> ValueExpExpression)
|
||||
{
|
||||
if (UpdateParameterIsNull == true)
|
||||
{
|
||||
return SetColumns(filedNameExpression, ValueExpExpression);
|
||||
return SetColumns(fieldNameExpression, ValueExpExpression);
|
||||
}
|
||||
else
|
||||
{
|
||||
var name = ExpressionTool.GetMemberName(filedNameExpression);
|
||||
var name = ExpressionTool.GetMemberName(fieldNameExpression);
|
||||
if (name == null)
|
||||
{
|
||||
Check.ExceptionEasy(filedNameExpression + " format error ", filedNameExpression + "参数格式错误");
|
||||
Check.ExceptionEasy(fieldNameExpression + " format error ", fieldNameExpression + "参数格式错误");
|
||||
}
|
||||
var value = this.UpdateBuilder.GetExpressionValue(ValueExpExpression, ResolveExpressType.WhereSingle).GetResultString();
|
||||
if (this.UpdateBuilder.ReSetValueBySqlExpList == null)
|
||||
@@ -712,24 +712,24 @@ namespace ThingsGateway.SqlSugar
|
||||
AppendSets();
|
||||
return this;
|
||||
}
|
||||
public IUpdateable<T> SetColumnsIF(bool isUpdateColumns, Expression<Func<T, object>> filedNameExpression, object fieldValue)
|
||||
public IUpdateable<T> SetColumnsIF(bool isUpdateColumns, Expression<Func<T, object>> fieldNameExpression, object fieldValue)
|
||||
{
|
||||
if (isUpdateColumns)
|
||||
{
|
||||
return SetColumns(filedNameExpression, fieldValue);
|
||||
return SetColumns(fieldNameExpression, fieldValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
return this;
|
||||
}
|
||||
}
|
||||
public virtual IUpdateable<T> SetColumns(Expression<Func<T, object>> filedNameExpression, Expression<Func<T, object>> valueExpression)
|
||||
public virtual IUpdateable<T> SetColumns(Expression<Func<T, object>> fieldNameExpression, Expression<Func<T, object>> valueExpression)
|
||||
{
|
||||
if (valueExpression == null)
|
||||
{
|
||||
return SetColumns(filedNameExpression, (object)null);
|
||||
return SetColumns(fieldNameExpression, (object)null);
|
||||
}
|
||||
var name = UpdateBuilder.GetExpressionValue(filedNameExpression, ResolveExpressType.FieldSingle).GetString();
|
||||
var name = UpdateBuilder.GetExpressionValue(fieldNameExpression, ResolveExpressType.FieldSingle).GetString();
|
||||
name = UpdateBuilder.Builder.GetTranslationColumnName(name);
|
||||
var exp = ExpressionTool.RemoveConvert((valueExpression as LambdaExpression).Body);
|
||||
var value = UpdateBuilder.GetExpressionValue(exp, ResolveExpressType.WhereSingle).GetString();
|
||||
@@ -749,9 +749,9 @@ namespace ThingsGateway.SqlSugar
|
||||
}
|
||||
return this;
|
||||
}
|
||||
public virtual IUpdateable<T> SetColumns(Expression<Func<T, object>> filedNameExpression, object fieldValue)
|
||||
public virtual IUpdateable<T> SetColumns(Expression<Func<T, object>> fieldNameExpression, object fieldValue)
|
||||
{
|
||||
var name = UpdateBuilder.GetExpressionValue(filedNameExpression, ResolveExpressType.FieldSingle).GetString();
|
||||
var name = UpdateBuilder.GetExpressionValue(fieldNameExpression, ResolveExpressType.FieldSingle).GetString();
|
||||
name = UpdateBuilder.Builder.GetNoTranslationColumnName(name);
|
||||
return SetColumns(name, fieldValue);
|
||||
}
|
||||
|
@@ -17,7 +17,7 @@
|
||||
public int DefaultCacheDurationInSeconds { get; set; }
|
||||
public bool? TableEnumIsString { get; set; }
|
||||
public DateTime? DbMinDate { get; set; } = DateTime.MinValue.Date.AddYears(1900 - 1);
|
||||
public bool IsNoReadXmlDescription { get; set; }
|
||||
public bool IsNoReadXmlDescription { get; set; } = true;
|
||||
public bool SqlServerCodeFirstNvarchar { get; set; }
|
||||
public bool OracleCodeFirstNvarchar2 { get; set; }
|
||||
public bool SqliteCodeFirstEnableDefaultValue { get; set; }
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user