Compare commits
35 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 | ||
![]() |
28bd751d44 | ||
![]() |
dcba7b9810 | ||
![]() |
7f1a741ce6 |
2
LICENSE
2
LICENSE
@@ -85,7 +85,7 @@
|
|||||||
or a Contribution incorporated within the Work constitutes direct
|
or a Contribution incorporated within the Work constitutes direct
|
||||||
or contributory patent infringement, then any patent licenses
|
or contributory patent infringement, then any patent licenses
|
||||||
granted to You under this License for that Work shall terminate
|
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
|
4. Cachetribution. You may reproduce and distribute copies of the
|
||||||
Work or Derivative Works thereof in any medium, with or without
|
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/
|
// 使用文档:https://thingsgateway.cn/
|
||||||
// QQ群:605534569
|
// 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.Extension;
|
||||||
using ThingsGateway.FriendlyException;
|
using ThingsGateway.FriendlyException;
|
||||||
using ThingsGateway.NewLife.Json.Extension;
|
using ThingsGateway.NewLife.Json.Extension;
|
||||||
|
using ThingsGateway.SqlSugar;
|
||||||
|
|
||||||
namespace ThingsGateway.Admin.Application;
|
namespace ThingsGateway.Admin.Application;
|
||||||
|
|
||||||
@@ -90,13 +91,12 @@ public sealed class OperDescAttribute : MoAttribute
|
|||||||
OperDescAttribute.WriteToQueue(log);
|
OperDescAttribute.WriteToQueue(log);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private static SqlSugarClient _db = DbContext.GetDB<SysOperateLog>();
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 将日志消息写入数据库中
|
/// 将日志消息写入数据库中
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private static async Task ProcessQueue()
|
private static async Task ProcessQueue()
|
||||||
{
|
{
|
||||||
var db = DbContext.Db.GetConnectionScopeWithAttr<SysOperateLog>().CopyNew();
|
|
||||||
var appLifetime = App.RootServices!.GetService<IHostApplicationLifetime>()!;
|
var appLifetime = App.RootServices!.GetService<IHostApplicationLifetime>()!;
|
||||||
while (!appLifetime.ApplicationStopping.IsCancellationRequested)
|
while (!appLifetime.ApplicationStopping.IsCancellationRequested)
|
||||||
{
|
{
|
||||||
@@ -105,7 +105,7 @@ public sealed class OperDescAttribute : MoAttribute
|
|||||||
var data = _logMessageQueue.ToListWithDequeue(); // 从日志队列中获取数据
|
var data = _logMessageQueue.ToListWithDequeue(); // 从日志队列中获取数据
|
||||||
if (data.Count > 0)
|
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)
|
catch (Exception ex)
|
||||||
|
@@ -267,7 +267,7 @@ public class RequestAuditFilter : IAsyncActionFilter, IOrderedFilter
|
|||||||
}
|
}
|
||||||
else
|
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
|
// QQ群:605534569
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
global using ThingsGateway;
|
|
||||||
global using ThingsGateway.NewLife.Extension;
|
global using ThingsGateway.NewLife.Extension;
|
@@ -20,6 +20,7 @@ using ThingsGateway.NewLife;
|
|||||||
using ThingsGateway.NewLife.Caching;
|
using ThingsGateway.NewLife.Caching;
|
||||||
using ThingsGateway.NewLife.Threading;
|
using ThingsGateway.NewLife.Threading;
|
||||||
using ThingsGateway.Schedule;
|
using ThingsGateway.Schedule;
|
||||||
|
using ThingsGateway.SqlSugar;
|
||||||
|
|
||||||
namespace ThingsGateway.Admin.Application;
|
namespace ThingsGateway.Admin.Application;
|
||||||
|
|
||||||
@@ -60,7 +61,7 @@ public class HardwareJob : IJob, IHardwareJob
|
|||||||
var historyHardwareInfos = MemoryCache.Get<List<HistoryHardwareInfo>>(CacheKey);
|
var historyHardwareInfos = MemoryCache.Get<List<HistoryHardwareInfo>>(CacheKey);
|
||||||
if (historyHardwareInfos == null)
|
if (historyHardwareInfos == null)
|
||||||
{
|
{
|
||||||
using var db = 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);
|
historyHardwareInfos = await db.Queryable<HistoryHardwareInfo>().Where(a => a.Date > DateTime.Now.AddDays(-3)).ToListAsync().ConfigureAwait(false);
|
||||||
|
|
||||||
MemoryCache.Set(CacheKey, historyHardwareInfos);
|
MemoryCache.Set(CacheKey, historyHardwareInfos);
|
||||||
@@ -70,6 +71,7 @@ public class HardwareJob : IJob, IHardwareJob
|
|||||||
|
|
||||||
private bool error = false;
|
private bool error = false;
|
||||||
private DateTime hisInsertTime = default;
|
private DateTime hisInsertTime = default;
|
||||||
|
private SqlSugarClient _db = DbContext.GetDB<HistoryHardwareInfo>();
|
||||||
|
|
||||||
public async Task ExecuteAsync(JobExecutingContext context, CancellationToken stoppingToken)
|
public async Task ExecuteAsync(JobExecutingContext context, CancellationToken stoppingToken)
|
||||||
{
|
{
|
||||||
@@ -79,7 +81,7 @@ public class HardwareJob : IJob, IHardwareJob
|
|||||||
{
|
{
|
||||||
if (HardwareInfo.MachineInfo == null)
|
if (HardwareInfo.MachineInfo == null)
|
||||||
{
|
{
|
||||||
await MachineInfo.RegisterAsync().ConfigureAwait(false);
|
MachineInfo.Register();
|
||||||
HardwareInfo.MachineInfo = MachineInfo.Current;
|
HardwareInfo.MachineInfo = MachineInfo.Current;
|
||||||
|
|
||||||
string currentPath = Directory.GetCurrentDirectory();
|
string currentPath = Directory.GetCurrentDirectory();
|
||||||
@@ -121,7 +123,6 @@ public class HardwareJob : IJob, IHardwareJob
|
|||||||
if (DateTime.Now > hisInsertTime.Add(TimeSpan.FromMilliseconds(HardwareInfoOptions.HistoryInterval)))
|
if (DateTime.Now > hisInsertTime.Add(TimeSpan.FromMilliseconds(HardwareInfoOptions.HistoryInterval)))
|
||||||
{
|
{
|
||||||
hisInsertTime = DateTime.Now;
|
hisInsertTime = DateTime.Now;
|
||||||
using var db = DbContext.Db.GetConnectionScopeWithAttr<HistoryHardwareInfo>().CopyNew();
|
|
||||||
{
|
{
|
||||||
var his = new HistoryHardwareInfo()
|
var his = new HistoryHardwareInfo()
|
||||||
{
|
{
|
||||||
@@ -132,12 +133,12 @@ public class HardwareJob : IJob, IHardwareJob
|
|||||||
CpuUsage = (HardwareInfo.MachineInfo.CpuRate * 100).ToInt(),
|
CpuUsage = (HardwareInfo.MachineInfo.CpuRate * 100).ToInt(),
|
||||||
Temperature = (HardwareInfo.MachineInfo.Temperature).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);
|
MemoryCache.Remove(CacheKey);
|
||||||
}
|
}
|
||||||
var sevenDaysAgo = TimerX.Now.AddDays(-HardwareInfoOptions.DaysAgo);
|
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)
|
if (result > 0)
|
||||||
{
|
{
|
||||||
MemoryCache.Remove(CacheKey);
|
MemoryCache.Remove(CacheKey);
|
||||||
|
@@ -27,7 +27,7 @@ public class LogJob : IJob
|
|||||||
|
|
||||||
private static async Task DeleteSysOperateLog(int daysAgo, CancellationToken stoppingToken)
|
private static async Task DeleteSysOperateLog(int daysAgo, CancellationToken stoppingToken)
|
||||||
{
|
{
|
||||||
using var db = DbContext.Db.GetConnectionScopeWithAttr<SysOperateLog>().CopyNew();
|
using var db = DbContext.GetDB<SysOperateLog>();
|
||||||
var time = DateTime.Now.AddDays(-daysAgo);
|
var time = DateTime.Now.AddDays(-daysAgo);
|
||||||
await db.DeleteableWithAttr<SysOperateLog>().Where(u => u.OpTime < time).ExecuteCommandAsync(stoppingToken).ConfigureAwait(false); // 删除操作日志
|
await db.DeleteableWithAttr<SysOperateLog>().Where(u => u.OpTime < time).ExecuteCommandAsync(stoppingToken).ConfigureAwait(false); // 删除操作日志
|
||||||
}
|
}
|
||||||
|
@@ -143,7 +143,7 @@ public class DatabaseLoggingWriter : IDatabaseLoggingWriter
|
|||||||
|
|
||||||
if (flush)
|
if (flush)
|
||||||
{
|
{
|
||||||
SqlSugarClient ??= DbContext.Db.GetConnectionScopeWithAttr<SysOperateLog>().CopyNew();
|
SqlSugarClient ??= DbContext.GetDB<SysOperateLog>();
|
||||||
await SqlSugarClient.InsertableWithAttr(_operateLogMessageQueue.ToListWithDequeue()).ExecuteCommandAsync().ConfigureAwait(false);//入库
|
await SqlSugarClient.InsertableWithAttr(_operateLogMessageQueue.ToListWithDequeue()).ExecuteCommandAsync().ConfigureAwait(false);//入库
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -202,7 +202,7 @@ public class DatabaseLoggingWriter : IDatabaseLoggingWriter
|
|||||||
|
|
||||||
if (flush)
|
if (flush)
|
||||||
{
|
{
|
||||||
SqlSugarClient ??= DbContext.Db.GetConnectionScopeWithAttr<SysOperateLog>().CopyNew();
|
SqlSugarClient ??= DbContext.GetDB<SysOperateLog>();
|
||||||
await SqlSugarClient.InsertableWithAttr(_operateLogMessageQueue.ToListWithDequeue()).ExecuteCommandAsync().ConfigureAwait(false);//入库
|
await SqlSugarClient.InsertableWithAttr(_operateLogMessageQueue.ToListWithDequeue()).ExecuteCommandAsync().ConfigureAwait(false);//入库
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@@ -1,18 +1,14 @@
|
|||||||
using Microsoft.AspNetCore.Authentication;
|
using Microsoft.AspNetCore.Authentication;
|
||||||
using Microsoft.AspNetCore.Authentication.OAuth;
|
using Microsoft.AspNetCore.Authentication.OAuth;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.WebUtilities;
|
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
|
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Net.Http.Headers;
|
|
||||||
using System.Security.Claims;
|
using System.Security.Claims;
|
||||||
using System.Text;
|
|
||||||
using System.Text.Encodings.Web;
|
using System.Text.Encodings.Web;
|
||||||
using System.Text.Json;
|
|
||||||
|
|
||||||
using ThingsGateway.Extension;
|
using ThingsGateway.Extension;
|
||||||
|
|
||||||
@@ -50,7 +46,7 @@ public class AdminOAuthHandler<TOptions>(
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private static async Task Insertable()
|
private static async Task Insertable()
|
||||||
{
|
{
|
||||||
var db = DbContext.Db.GetConnectionScopeWithAttr<SysOperateLog>().CopyNew();
|
var db = DbContext.GetDB<SysOperateLog>();
|
||||||
var appLifetime = App.RootServices!.GetService<IHostApplicationLifetime>()!;
|
var appLifetime = App.RootServices!.GetService<IHostApplicationLifetime>()!;
|
||||||
while (!appLifetime.ApplicationStopping.IsCancellationRequested)
|
while (!appLifetime.ApplicationStopping.IsCancellationRequested)
|
||||||
{
|
{
|
||||||
@@ -80,6 +76,7 @@ public class AdminOAuthHandler<TOptions>(
|
|||||||
AuthenticationProperties properties,
|
AuthenticationProperties properties,
|
||||||
OAuthTokenResponse tokens)
|
OAuthTokenResponse tokens)
|
||||||
{
|
{
|
||||||
|
Backchannel.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", tokens.AccessToken);
|
||||||
properties.RedirectUri = Options.HomePath;
|
properties.RedirectUri = Options.HomePath;
|
||||||
properties.IsPersistent = true;
|
properties.IsPersistent = true;
|
||||||
var appConfig = await configService.GetAppConfigAsync().ConfigureAwait(false);
|
var appConfig = await configService.GetAppConfigAsync().ConfigureAwait(false);
|
||||||
@@ -90,7 +87,7 @@ public class AdminOAuthHandler<TOptions>(
|
|||||||
properties.ExpiresUtc = TimeProvider.System.GetUtcNow().AddSeconds(result);
|
properties.ExpiresUtc = TimeProvider.System.GetUtcNow().AddSeconds(result);
|
||||||
expire = (int)(result / 60.0);
|
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);
|
var loginEvent = await GetLogin(expire).ConfigureAwait(false);
|
||||||
await UpdateUser(loginEvent).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)
|
private async Task<LoginEvent> GetLogin(int expire)
|
||||||
{
|
{
|
||||||
@@ -247,7 +209,7 @@ public class AdminOAuthHandler<TOptions>(
|
|||||||
|
|
||||||
#endregion 重新赋值属性,设置本次登录信息为最新的信息
|
#endregion 重新赋值属性,设置本次登录信息为最新的信息
|
||||||
|
|
||||||
using var db = DbContext.Db.GetConnectionScopeWithAttr<SysUser>().CopyNew();
|
using var db = DbContext.GetDB<SysUser>();
|
||||||
//更新用户登录信息
|
//更新用户登录信息
|
||||||
if (await db.Updateable(sysUser).UpdateColumns(it => new
|
if (await db.Updateable(sysUser).UpdateColumns(it => new
|
||||||
{
|
{
|
@@ -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 Microsoft.AspNetCore.WebUtilities;
|
||||||
|
|
||||||
using System.Net.Http.Headers;
|
using System.Net.Http.Headers;
|
||||||
using System.Text;
|
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
|
|
||||||
|
using ThingsGateway.NewLife.Log;
|
||||||
|
|
||||||
namespace ThingsGateway.Admin.Application;
|
namespace ThingsGateway.Admin.Application;
|
||||||
|
|
||||||
public class GiteeOAuthOptions : AdminOAuthOptions
|
public class GiteeOAuthOptions : AdminOAuthOptions
|
||||||
{
|
{
|
||||||
|
INoticeService _noticeService;
|
||||||
|
IVerificatInfoService _verificatInfoService;
|
||||||
public GiteeOAuthOptions() : base()
|
public GiteeOAuthOptions() : base()
|
||||||
{
|
{
|
||||||
|
_noticeService = App.GetService<INoticeService>();
|
||||||
|
_verificatInfoService = App.GetService<IVerificatInfoService>();
|
||||||
this.SignInScheme = ClaimConst.Scheme;
|
this.SignInScheme = ClaimConst.Scheme;
|
||||||
this.AuthorizationEndpoint = "https://gitee.com/oauth/authorize";
|
this.AuthorizationEndpoint = "https://gitee.com/oauth/authorize";
|
||||||
this.TokenEndpoint = "https://gitee.com/oauth/token";
|
this.TokenEndpoint = "https://gitee.com/oauth/token";
|
||||||
@@ -29,11 +33,14 @@ public class GiteeOAuthOptions : AdminOAuthOptions
|
|||||||
|
|
||||||
Events.OnRedirectToAuthorizationEndpoint = context =>
|
Events.OnRedirectToAuthorizationEndpoint = context =>
|
||||||
{
|
{
|
||||||
//context.RedirectUri = context.RedirectUri.Replace("http%3A%2F%2F", "https%3A%2F%2F"); // 强制替换
|
|
||||||
context.Response.Redirect(context.RedirectUri);
|
context.Response.Redirect(context.RedirectUri);
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
};
|
};
|
||||||
|
Events.OnRemoteFailure = context =>
|
||||||
|
{
|
||||||
|
XTrace.WriteException(context.Failure);
|
||||||
|
return Task.CompletedTask;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>刷新 Token 方法</summary>
|
/// <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)}"));
|
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)
|
public override string GetName(JsonElement element)
|
||||||
{
|
{
|
||||||
@@ -77,7 +75,7 @@ public class GiteeOAuthOptions : AdminOAuthOptions
|
|||||||
return target.TryGetValue("name");
|
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))
|
if (string.IsNullOrWhiteSpace(context.AccessToken))
|
||||||
throw new InvalidOperationException("Access token is missing.");
|
throw new InvalidOperationException("Access token is missing.");
|
||||||
@@ -89,7 +87,7 @@ public class GiteeOAuthOptions : AdminOAuthOptions
|
|||||||
{ "access_token", context.AccessToken }
|
{ "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") } }
|
Headers = { Accept = { new MediaTypeWithQualityHeaderValue("application/json") } }
|
||||||
};
|
};
|
||||||
@@ -99,7 +97,17 @@ public class GiteeOAuthOptions : AdminOAuthOptions
|
|||||||
if (!response.IsSuccessStatusCode)
|
if (!response.IsSuccessStatusCode)
|
||||||
{
|
{
|
||||||
var content = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
|
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/>
|
/// <inheritdoc/>
|
||||||
public IEnumerable<SysRelation> SeedData()
|
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))
|
if (db.Queryable<SysRelation>().Any(a => a.ObjectId == RoleConst.SuperAdminId))
|
||||||
return Enumerable.Empty<SysRelation>();
|
return Enumerable.Empty<SysRelation>();
|
||||||
var data = SeedDataUtil.GetSeedData<SysRelation>(PathExtensions.CombinePathWithOs("SeedData", "Admin", "seed_sys_relation.json"));
|
var data = SeedDataUtil.GetSeedData<SysRelation>(PathExtensions.CombinePathWithOs("SeedData", "Admin", "seed_sys_relation.json"));
|
||||||
|
@@ -324,7 +324,7 @@ public class AuthService : IAuthService
|
|||||||
|
|
||||||
#endregion 重新赋值属性,设置本次登录信息为最新的信息
|
#endregion 重新赋值属性,设置本次登录信息为最新的信息
|
||||||
|
|
||||||
using var db = DbContext.Db.GetConnectionScopeWithAttr<SysUser>().CopyNew();
|
using var db = DbContext.GetDB<SysUser>();
|
||||||
//更新用户登录信息
|
//更新用户登录信息
|
||||||
if (await db.Updateable(sysUser).UpdateColumns(it => new
|
if (await db.Updateable(sysUser).UpdateColumns(it => new
|
||||||
{
|
{
|
||||||
|
@@ -10,7 +10,6 @@
|
|||||||
|
|
||||||
using BootstrapBlazor.Components;
|
using BootstrapBlazor.Components;
|
||||||
|
|
||||||
using Microsoft.AspNetCore.Builder;
|
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
@@ -67,7 +66,7 @@ public class Startup : AppStartup
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Use(IApplicationBuilder applicationBuilder)
|
public void Use(IServiceProvider serviceProvider)
|
||||||
{
|
{
|
||||||
//检查ConfigId
|
//检查ConfigId
|
||||||
var configIdGroup = DbContext.DbConfigs.GroupBy(it => it.ConfigId);
|
var configIdGroup = DbContext.DbConfigs.GroupBy(it => it.ConfigId);
|
||||||
@@ -79,7 +78,7 @@ public class Startup : AppStartup
|
|||||||
//遍历配置
|
//遍历配置
|
||||||
DbContext.DbConfigs?.ForEach(it =>
|
DbContext.DbConfigs?.ForEach(it =>
|
||||||
{
|
{
|
||||||
var connection = DbContext.Db.GetConnection(it.ConfigId);//获取数据库连接对象
|
var connection = DbContext.GetDB().GetConnection(it.ConfigId);//获取数据库连接对象
|
||||||
if (it.InitDatabase == true)
|
if (it.InitDatabase == true)
|
||||||
connection.DbMaintenance.CreateDatabase();//创建数据库,如果存在则不创建
|
connection.DbMaintenance.CreateDatabase();//创建数据库,如果存在则不创建
|
||||||
});
|
});
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<Import Project="$(SolutionDir)Version.props" />
|
<Import Project="..\..\Version.props" />
|
||||||
<Import Project="$(SolutionDir)PackNuget.props" />
|
<Import Project="..\..\PackNuget.props" />
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<GenerateDocumentationFile>True</GenerateDocumentationFile>
|
<GenerateDocumentationFile>True</GenerateDocumentationFile>
|
||||||
@@ -18,7 +18,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Rougamo.Fody" Version="5.0.0" />
|
<PackageReference Include="Rougamo.Fody" Version="5.0.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup Condition=" '$(TargetFramework)' == 'net8.0' ">
|
<ItemGroup Condition=" '$(TargetFramework)' == 'net8.0' ">
|
||||||
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.1" />
|
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.1" />
|
||||||
@@ -41,13 +41,20 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="..\README.md" Pack="true" PackagePath="\" />
|
<None Include="..\README.md" Pack="true" PackagePath="\" />
|
||||||
<None Include="..\README.zh-CN.md" Pack="true" PackagePath="\" />
|
<None Include="..\README.zh-CN.md" Pack="true" PackagePath="\" />
|
||||||
<None Remove="$(SolutionDir)..\README.md" Pack="false" PackagePath="\" />
|
<None Remove="..\..\..\README.md" Pack="false" PackagePath="\" />
|
||||||
<None Remove="$(SolutionDir)..\README.zh-CN.md" Pack="false" PackagePath="\" />
|
<None Remove="..\..\..\README.zh-CN.md" Pack="false" PackagePath="\" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\ThingsGateway.Razor\ThingsGateway.Razor.csproj" />
|
|
||||||
<ProjectReference Include="..\ThingsGateway.DB\ThingsGateway.DB.csproj" />
|
<ProjectReference Include="..\ThingsGateway.DB\ThingsGateway.DB.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
||||||
|
<!--<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>
|
</Project>
|
||||||
|
@@ -40,7 +40,7 @@ public static class ClearTokenUtil
|
|||||||
public static async Task DeleteUserTokenByOrgIds(HashSet<long> orgIds)
|
public static async Task DeleteUserTokenByOrgIds(HashSet<long> orgIds)
|
||||||
{
|
{
|
||||||
// 获取用户ID列表
|
// 获取用户ID列表
|
||||||
var userIds = await DbContext.Db.CopyNew().QueryableWithAttr<SysUser>().Where(it => orgIds.Contains(it.OrgId)).Select(it => it.Id).ToListAsync().ConfigureAwait(false);
|
var userIds = await DbContext.GetDB<SysUser>().Queryable<SysUser>().Where(it => orgIds.Contains(it.OrgId)).Select(it => it.Id).ToListAsync().ConfigureAwait(false);
|
||||||
//从redis中删除所属机构的用户token
|
//从redis中删除所属机构的用户token
|
||||||
App.CacheService.HashDel<VerificatInfo>(CacheConst.Cache_Token, userIds.Select(it => it.ToString()).ToArray());
|
App.CacheService.HashDel<VerificatInfo>(CacheConst.Cache_Token, userIds.Select(it => it.ToString()).ToArray());
|
||||||
}
|
}
|
||||||
|
@@ -5,6 +5,9 @@
|
|||||||
@<div>
|
@<div>
|
||||||
<span class="mx-3">@item.ConfirmMessage</span>
|
<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>;
|
</div>;
|
||||||
}
|
}
|
||||||
|
@@ -156,7 +156,7 @@ public class BlazorAppContext
|
|||||||
CurrentUser = (await SysUserService.GetUserByIdAsync(UserManager.UserId))!;
|
CurrentUser = (await SysUserService.GetUserByIdAsync(UserManager.UserId))!;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TimeTick timeTick = new("50000");
|
TimeTick timeTick = new("60000");
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 是否拥有按钮授权
|
/// 是否拥有按钮授权
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@@ -19,3 +19,4 @@ global using System.Diagnostics.CodeAnalysis;
|
|||||||
global using ThingsGateway.Razor;
|
global using ThingsGateway.Razor;
|
||||||
|
|
||||||
[assembly: SuppressMessage("Reliability", "CA2007", Justification = "<挂起>", Scope = "module")]
|
[assembly: SuppressMessage("Reliability", "CA2007", Justification = "<挂起>", Scope = "module")]
|
||||||
|
[assembly: GlobalGenerateSetParametersAsync(true)]
|
@@ -33,7 +33,7 @@
|
|||||||
</PopConfirmButton>
|
</PopConfirmButton>
|
||||||
<PopConfirmButton Color=Color.Warning IsDisabled="SelectedRows.Count!=1||!AuthorizeButton(AdminOperConst.Edit)" Text=@OperDescLocalizer["ChangeParentResource"] Icon="fa fa-copy" OnConfirm="OnChangeParent">
|
<PopConfirmButton Color=Color.Warning IsDisabled="SelectedRows.Count!=1||!AuthorizeButton(AdminOperConst.Edit)" Text=@OperDescLocalizer["ChangeParentResource"] Icon="fa fa-copy" OnConfirm="OnChangeParent">
|
||||||
<BodyTemplate>
|
<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;}" />
|
<TreeView Items="MenuTreeItems" IsVirtualize="true" OnTreeItemClick="a=>{ChangeParentId=a.Value.Id;return Task.CompletedTask;}" />
|
||||||
</div>
|
</div>
|
||||||
</BodyTemplate>
|
</BodyTemplate>
|
||||||
|
@@ -22,12 +22,11 @@ public partial class SessionPage
|
|||||||
|
|
||||||
#region 查询
|
#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 SessionService.PageAsync(options);
|
||||||
return data;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -39,6 +39,7 @@ public partial class SysUserEdit
|
|||||||
var items = await SysPositionService.SelectorAsync(new PositionSelectorInput() { });
|
var items = await SysPositionService.SelectorAsync(new PositionSelectorInput() { });
|
||||||
Items = PositionUtil.BuildCascaderItemList(items);
|
Items = PositionUtil.BuildCascaderItemList(items);
|
||||||
ModuleSelectedItems = ResourceUtil.BuildModuleSelectList((await SysResourceService.GetAllAsync())).ToList();
|
ModuleSelectedItems = ResourceUtil.BuildModuleSelectList((await SysResourceService.GetAllAsync())).ToList();
|
||||||
|
await InvokeAsync(StateHasChanged);
|
||||||
await base.OnInitializedAsync();
|
await base.OnInitializedAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk.Razor">
|
<Project Sdk="Microsoft.NET.Sdk.Razor">
|
||||||
|
|
||||||
<Import Project="$(SolutionDir)Version.props" />
|
<Import Project="..\..\Version.props" />
|
||||||
<Import Project="$(SolutionDir)PackNuget.props" />
|
<Import Project="..\..\PackNuget.props" />
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\ThingsGateway.Admin.Application\ThingsGateway.Admin.Application.csproj" />
|
<ProjectReference Include="..\ThingsGateway.Admin.Application\ThingsGateway.Admin.Application.csproj" />
|
||||||
@@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
|
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
|
||||||
|
<!--<UseRazorSourceGenerator>false</UseRazorSourceGenerator>-->
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Content Remove="Locales\*.json" />
|
<Content Remove="Locales\*.json" />
|
||||||
@@ -29,9 +30,15 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="..\README.md" Pack="true" PackagePath="\" />
|
<None Include="..\README.md" Pack="true" PackagePath="\" />
|
||||||
<None Include="..\README.zh-CN.md" Pack="true" PackagePath="\" />
|
<None Include="..\README.zh-CN.md" Pack="true" PackagePath="\" />
|
||||||
<None Remove="$(SolutionDir)..\README.md" Pack="false" PackagePath="\" />
|
<None Remove="..\..\..\README.md" Pack="false" PackagePath="\" />
|
||||||
<None Remove="$(SolutionDir)..\README.zh-CN.md" Pack="false" PackagePath="\" />
|
<None Remove="..\..\..\README.zh-CN.md" Pack="false" PackagePath="\" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\BlazorSetParametersAsyncGenerator\BlazorSetParametersAsyncGenerator.csproj" PrivateAssets="all" OutputItemType="Analyzer" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
||||||
|
|
||||||
|
@@ -14,6 +14,7 @@
|
|||||||
"ThingsGateway.SqlSugar",
|
"ThingsGateway.SqlSugar",
|
||||||
"ThingsGateway.Admin.Application",
|
"ThingsGateway.Admin.Application",
|
||||||
"ThingsGateway.Admin.Razor",
|
"ThingsGateway.Admin.Razor",
|
||||||
|
"ThingsGateway.DB",
|
||||||
"ThingsGateway.Razor"
|
"ThingsGateway.Razor"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@@ -14,6 +14,7 @@
|
|||||||
"ThingsGateway.SqlSugar",
|
"ThingsGateway.SqlSugar",
|
||||||
"ThingsGateway.Admin.Application",
|
"ThingsGateway.Admin.Application",
|
||||||
"ThingsGateway.Admin.Razor",
|
"ThingsGateway.Admin.Razor",
|
||||||
|
"ThingsGateway.DB",
|
||||||
"ThingsGateway.Razor"
|
"ThingsGateway.Razor"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@@ -40,6 +40,7 @@ public class SingleFilePublish : ISingleFilePublish
|
|||||||
"ThingsGateway.NewLife.X",
|
"ThingsGateway.NewLife.X",
|
||||||
"ThingsGateway.Razor",
|
"ThingsGateway.Razor",
|
||||||
"ThingsGateway.Admin.Razor" ,
|
"ThingsGateway.Admin.Razor" ,
|
||||||
|
"ThingsGateway.DB",
|
||||||
"ThingsGateway.Admin.Application",
|
"ThingsGateway.Admin.Application",
|
||||||
"ThingsGateway.SqlSugar",
|
"ThingsGateway.SqlSugar",
|
||||||
];
|
];
|
||||||
|
@@ -48,11 +48,11 @@ public class Startup : AppStartup
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// 事件总线
|
//// 事件总线
|
||||||
services.AddEventBus(options =>
|
//services.AddEventBus(options =>
|
||||||
{
|
//{
|
||||||
|
|
||||||
});
|
//});
|
||||||
|
|
||||||
// 任务调度
|
// 任务调度
|
||||||
services.AddSchedule(options =>
|
services.AddSchedule(options =>
|
||||||
@@ -151,8 +151,6 @@ public class Startup : AppStartup
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
services.AddHealthChecks();
|
|
||||||
|
|
||||||
|
|
||||||
#region 控制台美化
|
#region 控制台美化
|
||||||
|
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
|
||||||
<Import Project="$(SolutionDir)Version.props" />
|
<Import Project="..\..\Version.props" />
|
||||||
|
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
<!--动态适用GC-->
|
<!--动态适用GC-->
|
||||||
<GarbageCollectionAdaptationMode>1</GarbageCollectionAdaptationMode>
|
<GarbageCollectionAdaptationMode>1</GarbageCollectionAdaptationMode>
|
||||||
|
<CETCompat>false</CETCompat>
|
||||||
<!--使用自托管线程池-->
|
<!--使用自托管线程池-->
|
||||||
<!--<UseWindowsThreadPool>false</UseWindowsThreadPool> -->
|
<!--<UseWindowsThreadPool>false</UseWindowsThreadPool> -->
|
||||||
|
|
||||||
|
@@ -41,19 +41,19 @@ public abstract class PrimaryKeyEntity : PrimaryIdEntity
|
|||||||
[SugarColumn(ColumnDescription = "扩展信息", ColumnDataType = StaticConfig.CodeFirst_BigString, IsNullable = true)]
|
[SugarColumn(ColumnDescription = "扩展信息", ColumnDataType = StaticConfig.CodeFirst_BigString, IsNullable = true)]
|
||||||
[IgnoreExcel]
|
[IgnoreExcel]
|
||||||
[AutoGenerateColumn(Ignore = true)]
|
[AutoGenerateColumn(Ignore = true)]
|
||||||
public virtual string? ExtJson { get; set; }
|
public virtual string ExtJson { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface IBaseEntity
|
public interface IBaseEntity
|
||||||
{
|
{
|
||||||
DateTime? CreateTime { get; set; }
|
DateTime CreateTime { get; set; }
|
||||||
string? CreateUser { get; set; }
|
string CreateUser { get; set; }
|
||||||
long CreateUserId { get; set; }
|
long CreateUserId { get; set; }
|
||||||
bool IsDelete { get; set; }
|
bool IsDelete { get; set; }
|
||||||
int? SortCode { get; set; }
|
int SortCode { get; set; }
|
||||||
DateTime? UpdateTime { get; set; }
|
DateTime UpdateTime { get; set; }
|
||||||
string? UpdateUser { get; set; }
|
string UpdateUser { get; set; }
|
||||||
long? UpdateUserId { get; set; }
|
long UpdateUserId { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -61,13 +61,22 @@ public interface IBaseEntity
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class BaseEntity : PrimaryKeyEntity, IBaseEntity
|
public abstract class BaseEntity : PrimaryKeyEntity, IBaseEntity
|
||||||
{
|
{
|
||||||
|
private long createUserId;
|
||||||
|
private long updateUserId;
|
||||||
|
private DateTime createTime;
|
||||||
|
private DateTime updateTime;
|
||||||
|
private int sortCode;
|
||||||
|
private bool isDelete = false;
|
||||||
|
private string createUser;
|
||||||
|
private string updateUser;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 创建时间
|
/// 创建时间
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[SugarColumn(ColumnDescription = "创建时间", IsOnlyIgnoreUpdate = true, IsNullable = true)]
|
[SugarColumn(ColumnDescription = "创建时间", IsOnlyIgnoreUpdate = true, IsNullable = true)]
|
||||||
[IgnoreExcel]
|
[IgnoreExcel]
|
||||||
[AutoGenerateColumn(Visible = false, IsVisibleWhenAdd = false, IsVisibleWhenEdit = false)]
|
[AutoGenerateColumn(Visible = false, IsVisibleWhenAdd = false, IsVisibleWhenEdit = false)]
|
||||||
public virtual DateTime? CreateTime { get; set; }
|
public virtual DateTime CreateTime { get => createTime; set => createTime = value; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 创建人
|
/// 创建人
|
||||||
@@ -76,7 +85,7 @@ public abstract class BaseEntity : PrimaryKeyEntity, IBaseEntity
|
|||||||
[IgnoreExcel]
|
[IgnoreExcel]
|
||||||
[NotNull]
|
[NotNull]
|
||||||
[AutoGenerateColumn(Ignore = true)]
|
[AutoGenerateColumn(Ignore = true)]
|
||||||
public virtual string? CreateUser { get; set; }
|
public virtual string CreateUser { get => createUser; set => createUser = value; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 创建者Id
|
/// 创建者Id
|
||||||
@@ -84,7 +93,7 @@ public abstract class BaseEntity : PrimaryKeyEntity, IBaseEntity
|
|||||||
[SugarColumn(ColumnDescription = "创建者Id", IsOnlyIgnoreUpdate = true, IsNullable = true)]
|
[SugarColumn(ColumnDescription = "创建者Id", IsOnlyIgnoreUpdate = true, IsNullable = true)]
|
||||||
[IgnoreExcel]
|
[IgnoreExcel]
|
||||||
[AutoGenerateColumn(Ignore = true)]
|
[AutoGenerateColumn(Ignore = true)]
|
||||||
public virtual long CreateUserId { get; set; }
|
public virtual long CreateUserId { get => createUserId; set => createUserId = value; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 软删除
|
/// 软删除
|
||||||
@@ -92,8 +101,7 @@ public abstract class BaseEntity : PrimaryKeyEntity, IBaseEntity
|
|||||||
[SugarColumn(ColumnDescription = "软删除", IsNullable = true)]
|
[SugarColumn(ColumnDescription = "软删除", IsNullable = true)]
|
||||||
[IgnoreExcel]
|
[IgnoreExcel]
|
||||||
[AutoGenerateColumn(Ignore = true)]
|
[AutoGenerateColumn(Ignore = true)]
|
||||||
public virtual bool IsDelete { get; set; } = false;
|
public virtual bool IsDelete { get => isDelete; set => isDelete = value; }
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 更新时间
|
/// 更新时间
|
||||||
@@ -101,7 +109,7 @@ public abstract class BaseEntity : PrimaryKeyEntity, IBaseEntity
|
|||||||
[SugarColumn(ColumnDescription = "更新时间", IsOnlyIgnoreInsert = true, IsNullable = true)]
|
[SugarColumn(ColumnDescription = "更新时间", IsOnlyIgnoreInsert = true, IsNullable = true)]
|
||||||
[IgnoreExcel]
|
[IgnoreExcel]
|
||||||
[AutoGenerateColumn(Visible = false, IsVisibleWhenAdd = false, IsVisibleWhenEdit = false)]
|
[AutoGenerateColumn(Visible = false, IsVisibleWhenAdd = false, IsVisibleWhenEdit = false)]
|
||||||
public virtual DateTime? UpdateTime { get; set; }
|
public virtual DateTime UpdateTime { get => updateTime; set => updateTime = value; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 更新人
|
/// 更新人
|
||||||
@@ -109,7 +117,7 @@ public abstract class BaseEntity : PrimaryKeyEntity, IBaseEntity
|
|||||||
[SugarColumn(ColumnDescription = "更新人", IsOnlyIgnoreInsert = true, IsNullable = true)]
|
[SugarColumn(ColumnDescription = "更新人", IsOnlyIgnoreInsert = true, IsNullable = true)]
|
||||||
[IgnoreExcel]
|
[IgnoreExcel]
|
||||||
[AutoGenerateColumn(Ignore = true)]
|
[AutoGenerateColumn(Ignore = true)]
|
||||||
public virtual string? UpdateUser { get; set; }
|
public virtual string UpdateUser { get => updateUser; set => updateUser = value; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 修改者Id
|
/// 修改者Id
|
||||||
@@ -117,7 +125,7 @@ public abstract class BaseEntity : PrimaryKeyEntity, IBaseEntity
|
|||||||
[SugarColumn(ColumnDescription = "修改者Id", IsOnlyIgnoreInsert = true, IsNullable = true)]
|
[SugarColumn(ColumnDescription = "修改者Id", IsOnlyIgnoreInsert = true, IsNullable = true)]
|
||||||
[IgnoreExcel]
|
[IgnoreExcel]
|
||||||
[AutoGenerateColumn(Ignore = true)]
|
[AutoGenerateColumn(Ignore = true)]
|
||||||
public virtual long? UpdateUserId { get; set; }
|
public virtual long UpdateUserId { get => updateUserId; set => updateUserId = value; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 排序码
|
/// 排序码
|
||||||
@@ -125,7 +133,7 @@ public abstract class BaseEntity : PrimaryKeyEntity, IBaseEntity
|
|||||||
[SugarColumn(ColumnDescription = "排序码", IsNullable = true)]
|
[SugarColumn(ColumnDescription = "排序码", IsNullable = true)]
|
||||||
[AutoGenerateColumn(Visible = false, DefaultSort = true, Sortable = true, DefaultSortOrder = SortOrder.Asc)]
|
[AutoGenerateColumn(Visible = false, DefaultSort = true, Sortable = true, DefaultSortOrder = SortOrder.Asc)]
|
||||||
[IgnoreExcel]
|
[IgnoreExcel]
|
||||||
public virtual int? SortCode { get; set; }
|
public virtual int SortCode { get => sortCode; set => sortCode = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface IBaseDataEntity
|
public interface IBaseDataEntity
|
||||||
|
@@ -124,16 +124,8 @@ public class SugarAopService : ISugarAopService
|
|||||||
//执行时间超过1秒
|
//执行时间超过1秒
|
||||||
if (db.Ado.SqlExecutionTime.TotalSeconds > 1)
|
if (db.Ado.SqlExecutionTime.TotalSeconds > 1)
|
||||||
{
|
{
|
||||||
//代码CS文件名
|
DbContext.WriteLog($"SQL执行时间超过1秒");
|
||||||
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.WriteLogWithSql(UtilMethods.GetNativeSql(sql, pars));
|
DbContext.WriteLogWithSql(UtilMethods.GetNativeSql(sql, pars));
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@@ -161,7 +161,7 @@ public class BaseService<T> : IDataService<T>, IDisposable where T : class, new(
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
protected SqlSugarClient GetDB()
|
protected SqlSugarClient GetDB()
|
||||||
{
|
{
|
||||||
return DbContext.Db.GetConnectionScopeWithAttr<T>().CopyNew();
|
return DbContext.GetDB<T>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -55,7 +55,7 @@ public static class CodeFirstUtils
|
|||||||
var entityType = seedType.GetInterfaces().First().GetGenericArguments().First();//获取实体类型
|
var entityType = seedType.GetInterfaces().First().GetGenericArguments().First();//获取实体类型
|
||||||
var tenantAtt = entityType.GetCustomAttribute<TenantAttribute>();//获取sqlSugar多库特性
|
var tenantAtt = entityType.GetCustomAttribute<TenantAttribute>();//获取sqlSugar多库特性
|
||||||
if (tenantAtt == null) continue;//如果没有多库特性就下一个
|
if (tenantAtt == null) continue;//如果没有多库特性就下一个
|
||||||
using var db = DbContext.Db.GetConnectionScope(tenantAtt.configId.ToString()).CopyNew();//获取数据库对象
|
using var db = DbContext.GetDB(tenantAtt.configId.ToString());//获取数据库对象
|
||||||
var config = DbContext.DbConfigs.FirstOrDefault(u => u.ConfigId.ToString() == tenantAtt.configId.ToString());//获取数据库配置
|
var config = DbContext.DbConfigs.FirstOrDefault(u => u.ConfigId.ToString() == tenantAtt.configId.ToString());//获取数据库配置
|
||||||
if (config?.InitSeedData != true) continue;
|
if (config?.InitSeedData != true) continue;
|
||||||
var entityInfo = db.EntityMaintenance.GetEntityInfo(entityType);
|
var entityInfo = db.EntityMaintenance.GetEntityInfo(entityType);
|
||||||
@@ -66,7 +66,8 @@ public static class CodeFirstUtils
|
|||||||
{
|
{
|
||||||
// 按主键进行批量增加和更新
|
// 按主键进行批量增加和更新
|
||||||
var storage = db.StorageableByObject(seedData.ToList()).ToStorage();
|
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();//只有没有忽略更新的特性才执行更新
|
if (ignoreUpdate == null && config.IsUpdateSeedData) storage.AsUpdateable.ExecuteCommand();//只有没有忽略更新的特性才执行更新
|
||||||
}
|
}
|
||||||
else// 没有主键或者不是预定义的主键(有重复的可能)
|
else// 没有主键或者不是预定义的主键(有重复的可能)
|
||||||
@@ -98,7 +99,7 @@ public static class CodeFirstUtils
|
|||||||
var ignoreInit = entityType.GetCustomAttribute<IgnoreInitTableAttribute>();//获取忽略初始化特性
|
var ignoreInit = entityType.GetCustomAttribute<IgnoreInitTableAttribute>();//获取忽略初始化特性
|
||||||
if (ignoreInit != null) continue;//如果有忽略初始化特性
|
if (ignoreInit != null) continue;//如果有忽略初始化特性
|
||||||
if (tenantAtt == null) continue;//如果没有多库特性就下一个
|
if (tenantAtt == null) continue;//如果没有多库特性就下一个
|
||||||
using var db = DbContext.Db.GetConnectionScope(tenantAtt.configId.ToString()).CopyNew();//获取数据库对象
|
using var db = DbContext.GetDB(tenantAtt.configId.ToString());//获取数据库对象
|
||||||
var splitTable = entityType.GetCustomAttribute<SplitTableAttribute>();//获取自动分表特性
|
var splitTable = entityType.GetCustomAttribute<SplitTableAttribute>();//获取自动分表特性
|
||||||
if (splitTable == null)//如果特性是空
|
if (splitTable == null)//如果特性是空
|
||||||
db.CodeFirst.InitTables(entityType);//普通创建
|
db.CodeFirst.InitTables(entityType);//普通创建
|
||||||
|
@@ -24,7 +24,7 @@ public static class DbContext
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// SqlSugar 数据库实例
|
/// SqlSugar 数据库实例
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static readonly SqlSugarScope Db;
|
private static readonly SqlSugarClient Db;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 读取配置文件中的 ConnectionStrings:Sqlsugar 配置节点
|
/// 读取配置文件中的 ConnectionStrings:Sqlsugar 配置节点
|
||||||
@@ -37,9 +37,28 @@ public static class DbContext
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static SqlSugarClient GetDB<T>()
|
public static SqlSugarClient GetDB<T>()
|
||||||
{
|
{
|
||||||
return Db.GetConnectionScopeWithAttr<T>().CopyNew();
|
return Db.GetConnectionWithAttr<T>().CopyNew();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取数据库连接
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static SqlSugarClient GetDB()
|
||||||
|
{
|
||||||
|
return Db;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取数据库连接
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static SqlSugarClient GetDB(string tenant)
|
||||||
|
{
|
||||||
|
return Db.GetConnection(tenant).CopyNew();//获取数据库对象
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private static ISugarAopService sugarAopService;
|
private static ISugarAopService sugarAopService;
|
||||||
private static ISugarAopService SugarAopService
|
private static ISugarAopService SugarAopService
|
||||||
{
|
{
|
||||||
@@ -62,7 +81,7 @@ public static class DbContext
|
|||||||
{
|
{
|
||||||
DbConfigs.ForEach(it =>
|
DbConfigs.ForEach(it =>
|
||||||
{
|
{
|
||||||
var sqlsugarScope = db.GetConnectionScope(it.ConfigId);//获取当前库
|
var sqlsugarScope = db.GetConnection(it.ConfigId);//获取当前库
|
||||||
MoreSetting(sqlsugarScope);//更多设置
|
MoreSetting(sqlsugarScope);//更多设置
|
||||||
SugarAopService.AopSetting(sqlsugarScope, it.IsShowSql);//aop配置
|
SugarAopService.AopSetting(sqlsugarScope, it.IsShowSql);//aop配置
|
||||||
}
|
}
|
||||||
@@ -75,7 +94,7 @@ public static class DbContext
|
|||||||
/// 实体更多配置
|
/// 实体更多配置
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="db"></param>
|
/// <param name="db"></param>
|
||||||
private static void MoreSetting(SqlSugarScopeProvider db)
|
private static void MoreSetting(SqlSugarProvider db)
|
||||||
{
|
{
|
||||||
db.CurrentConnectionConfig.MoreSettings = new ConnMoreSettings
|
db.CurrentConnectionConfig.MoreSettings = new ConnMoreSettings
|
||||||
{
|
{
|
||||||
|
@@ -24,7 +24,7 @@ namespace ThingsGateway.Admin.Application;
|
|||||||
/// 种子数据工具类
|
/// 种子数据工具类
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[ThingsGateway.DependencyInjection.SuppressSniffer]
|
[ThingsGateway.DependencyInjection.SuppressSniffer]
|
||||||
public static class SeedDataUtil
|
public static partial class SeedDataUtil
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取List列表
|
/// 获取List列表
|
||||||
@@ -53,9 +53,7 @@ public static class SeedDataUtil
|
|||||||
if (!string.IsNullOrEmpty(json))//如果有内容
|
if (!string.IsNullOrEmpty(json))//如果有内容
|
||||||
{
|
{
|
||||||
//字段没有数据的替换成null
|
//字段没有数据的替换成null
|
||||||
json = Regex.Replace(json, "\\\"[^\"]+?\\\": \\\"\\\"", match => match.Value.Replace("\"\"", "null"));
|
json = SeedDataRegex().Replace(json, match => match.Value.Replace("\"\"", "null"));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var jtoken = JToken.Parse(json);
|
var jtoken = JToken.Parse(json);
|
||||||
jtoken = jtoken.SelectToken("Records") ?? jtoken.SelectToken("RECORDS");
|
jtoken = jtoken.SelectToken("Records") ?? jtoken.SelectToken("RECORDS");
|
||||||
@@ -96,6 +94,9 @@ public static class SeedDataUtil
|
|||||||
|
|
||||||
return seedData;
|
return seedData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[GeneratedRegex("\\\"[^\"]+?\\\": \\\"\\\"")]
|
||||||
|
private static partial Regex SeedDataRegex();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@@ -10,7 +10,6 @@
|
|||||||
|
|
||||||
using BootstrapBlazor.Components;
|
using BootstrapBlazor.Components;
|
||||||
|
|
||||||
using Microsoft.AspNetCore.Builder;
|
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
using ThingsGateway.SqlSugar;
|
using ThingsGateway.SqlSugar;
|
||||||
@@ -32,11 +31,10 @@ public class Startup : AppStartup
|
|||||||
|
|
||||||
StaticConfig.EnableAllWhereIF = true;
|
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">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<Import Project="$(SolutionDir)Version.props" />
|
<Import Project="..\..\Version.props" />
|
||||||
<Import Project="$(SolutionDir)PackNuget.props" />
|
<Import Project="..\..\PackNuget.props" />
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<GenerateDocumentationFile>True</GenerateDocumentationFile>
|
<GenerateDocumentationFile>True</GenerateDocumentationFile>
|
||||||
@@ -11,17 +11,18 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="BootstrapBlazor.TableExport" Version="9.2.5" />
|
<PackageReference Include="BootstrapBlazor.TableExport" Version="9.2.6" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="..\README.md" Pack="true" PackagePath="\" />
|
<None Include="..\README.md" Pack="true" PackagePath="\" />
|
||||||
<None Include="..\README.zh-CN.md" Pack="true" PackagePath="\" />
|
<None Include="..\README.zh-CN.md" Pack="true" PackagePath="\" />
|
||||||
<None Remove="$(SolutionDir)..\README.md" Pack="false" PackagePath="\" />
|
<None Remove="..\..\..\README.md" Pack="false" PackagePath="\" />
|
||||||
<None Remove="$(SolutionDir)..\README.zh-CN.md" Pack="false" PackagePath="\" />
|
<None Remove="..\..\..\README.zh-CN.md" Pack="false" PackagePath="\" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<!--<PackageReference Include="ThingsGateway.Razor" Version="$(SourceGeneratorVersion)" />-->
|
||||||
<ProjectReference Include="..\ThingsGateway.Razor\ThingsGateway.Razor.csproj" />
|
<ProjectReference Include="..\ThingsGateway.Razor\ThingsGateway.Razor.csproj" />
|
||||||
<ProjectReference Include="..\ThingsGateway.SqlSugar\ThingsGateway.SqlSugar.csproj" />
|
<ProjectReference Include="..\ThingsGateway.SqlSugar\ThingsGateway.SqlSugar.csproj" />
|
||||||
<!--<PackageReference Include="SqlSugarCore" Version="5.1.4.195" />-->
|
<!--<PackageReference Include="SqlSugarCore" Version="5.1.4.195" />-->
|
||||||
|
@@ -67,13 +67,13 @@ internal static class Penetrates
|
|||||||
["patch"] = "PATCH"
|
["patch"] = "PATCH"
|
||||||
};
|
};
|
||||||
|
|
||||||
IsApiControllerCached = new ConcurrentDictionary<Type, bool>();
|
//IsApiControllerCached = new ConcurrentDictionary<Type, bool>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
///// <summary>
|
||||||
/// <see cref="IsApiController(Type)"/> 缓存集合
|
///// <see cref="IsApiController(Type)"/> 缓存集合
|
||||||
/// </summary>
|
///// </summary>
|
||||||
private static readonly ConcurrentDictionary<Type, bool> IsApiControllerCached;
|
//private static readonly ConcurrentDictionary<Type, bool> IsApiControllerCached;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 是否是Api控制器
|
/// 是否是Api控制器
|
||||||
@@ -82,13 +82,13 @@ internal static class Penetrates
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
internal static bool IsApiController(Type type)
|
internal static bool IsApiController(Type type)
|
||||||
{
|
{
|
||||||
return IsApiControllerCached.GetOrAdd(type, Function);
|
//return IsApiControllerCached.GetOrAdd(type, Function);
|
||||||
|
return Function(type);
|
||||||
// 本地静态方法
|
// 本地静态方法
|
||||||
static bool Function(Type type)
|
static bool Function(Type type)
|
||||||
{
|
{
|
||||||
// 排除 OData 控制器
|
//// 排除 OData 控制器
|
||||||
if (type.Assembly.GetName().Name.StartsWith("Microsoft.AspNetCore.OData")) return false;
|
//if (type.Assembly.GetName().Name.StartsWith("Microsoft.AspNetCore.OData")) return false;
|
||||||
|
|
||||||
// 不能是非公开、基元类型、值类型、抽象类、接口、泛型类
|
// 不能是非公开、基元类型、值类型、抽象类、接口、泛型类
|
||||||
if (!type.IsPublic || type.IsPrimitive || type.IsValueType || type.IsAbstract || type.IsInterface || type.IsGenericType) return false;
|
if (!type.IsPublic || type.IsPrimitive || type.IsValueType || type.IsAbstract || type.IsInterface || type.IsGenericType) return false;
|
||||||
|
@@ -37,15 +37,15 @@ public sealed class Retry
|
|||||||
{
|
{
|
||||||
if (action == null) throw new ArgumentNullException(nameof(action));
|
if (action == null) throw new ArgumentNullException(nameof(action));
|
||||||
|
|
||||||
InvokeAsync(async () =>
|
InvokeAsync(() =>
|
||||||
{
|
{
|
||||||
action();
|
action();
|
||||||
await Task.CompletedTask.ConfigureAwait(false);
|
return Task.CompletedTask;
|
||||||
}, numRetries, retryTimeout, finalThrow, exceptionTypes, fallbackPolicy == null ? null
|
}, numRetries, retryTimeout, finalThrow, exceptionTypes, fallbackPolicy == null ? null
|
||||||
: async (ex) =>
|
: (ex) =>
|
||||||
{
|
{
|
||||||
fallbackPolicy?.Invoke(ex);
|
fallbackPolicy?.Invoke(ex);
|
||||||
await Task.CompletedTask.ConfigureAwait(false);
|
return Task.CompletedTask;
|
||||||
}, retryAction).GetAwaiter().GetResult();
|
}, retryAction).GetAwaiter().GetResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -15,6 +15,7 @@ using Microsoft.Extensions.Logging;
|
|||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
|
|
||||||
using ThingsGateway.NewLife.Caching;
|
using ThingsGateway.NewLife.Caching;
|
||||||
|
using ThingsGateway.NewLife.Log;
|
||||||
|
|
||||||
namespace ThingsGateway.Logging;
|
namespace ThingsGateway.Logging;
|
||||||
|
|
||||||
@@ -33,7 +34,7 @@ public sealed class DatabaseLoggerProvider : ILoggerProvider, ISupportExternalSc
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 日志消息队列(线程安全)
|
/// 日志消息队列(线程安全)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly BlockingCollection<LogMessage> _logMessageQueue = new(12000);
|
private readonly BlockingCollection<LogMessage> _logMessageQueue = new(20000);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 日志作用域提供器
|
/// 日志作用域提供器
|
||||||
@@ -135,7 +136,10 @@ public sealed class DatabaseLoggerProvider : ILoggerProvider, ISupportExternalSc
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_logMessageQueue.Add(logMsg);
|
if (!_logMessageQueue.TryAdd(logMsg, 5000))
|
||||||
|
{
|
||||||
|
XTrace.Log.Warn($"{nameof(DatabaseLoggerProvider)} queue add fail");
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
catch (InvalidOperationException) { }
|
catch (InvalidOperationException) { }
|
||||||
@@ -160,8 +164,8 @@ public sealed class DatabaseLoggerProvider : ILoggerProvider, ISupportExternalSc
|
|||||||
_databaseLoggingWriter = _serviceScope.ServiceProvider.GetRequiredService(databaseLoggingWriterType) as IDatabaseLoggingWriter;
|
_databaseLoggingWriter = _serviceScope.ServiceProvider.GetRequiredService(databaseLoggingWriterType) as IDatabaseLoggingWriter;
|
||||||
|
|
||||||
// 创建长时间运行的后台任务,并将日志消息队列中数据写入存储中
|
// 创建长时间运行的后台任务,并将日志消息队列中数据写入存储中
|
||||||
_processQueueTask = Task.Factory.StartNew(async state => await ((DatabaseLoggerProvider)state).ProcessQueueAsync().ConfigureAwait(false)
|
_processQueueTask = Task.Factory.StartNew(ProcessQueueAsync
|
||||||
, this, TaskCreationOptions.LongRunning);
|
, TaskCreationOptions.LongRunning);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@@ -14,6 +14,7 @@ using Microsoft.Extensions.Logging;
|
|||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
|
|
||||||
using ThingsGateway.NewLife.Caching;
|
using ThingsGateway.NewLife.Caching;
|
||||||
|
using ThingsGateway.NewLife.Log;
|
||||||
|
|
||||||
namespace ThingsGateway.Logging;
|
namespace ThingsGateway.Logging;
|
||||||
|
|
||||||
@@ -32,7 +33,7 @@ public sealed class FileLoggerProvider : ILoggerProvider, ISupportExternalScope
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 日志消息队列(线程安全)
|
/// 日志消息队列(线程安全)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly BlockingCollection<LogMessage> _logMessageQueue = new(12000);
|
private readonly BlockingCollection<LogMessage> _logMessageQueue = new(20000);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 日志作用域提供器
|
/// 日志作用域提供器
|
||||||
@@ -90,8 +91,7 @@ public sealed class FileLoggerProvider : ILoggerProvider, ISupportExternalScope
|
|||||||
_fileLoggingWriter = new FileLoggingWriter(this);
|
_fileLoggingWriter = new FileLoggingWriter(this);
|
||||||
|
|
||||||
// 创建长时间运行的后台任务,并将日志消息队列中数据写入文件中
|
// 创建长时间运行的后台任务,并将日志消息队列中数据写入文件中
|
||||||
_processQueueTask = Task.Factory.StartNew(async state => await ((FileLoggerProvider)state).ProcessQueueAsync().ConfigureAwait(false)
|
_processQueueTask = Task.Factory.StartNew(ProcessQueueAsync, TaskCreationOptions.LongRunning);
|
||||||
, this, TaskCreationOptions.LongRunning);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -171,8 +171,10 @@ public sealed class FileLoggerProvider : ILoggerProvider, ISupportExternalScope
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_logMessageQueue.Add(logMsg);
|
if (!_logMessageQueue.TryAdd(logMsg, 5000))
|
||||||
return;
|
{
|
||||||
|
XTrace.Log.Warn($"{nameof(DatabaseLoggerProvider)} queue add fail");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (InvalidOperationException) { }
|
catch (InvalidOperationException) { }
|
||||||
catch { }
|
catch { }
|
||||||
|
@@ -46,6 +46,8 @@ public static class ObjectMapperServiceCollectionExtensions
|
|||||||
// 获取全局映射配置
|
// 获取全局映射配置
|
||||||
var config = TypeAdapterConfig.GlobalSettings;
|
var config = TypeAdapterConfig.GlobalSettings;
|
||||||
|
|
||||||
|
//config.Compiler = exp => exp.CompileFast();
|
||||||
|
|
||||||
// 扫描所有继承 IRegister 接口的对象映射配置
|
// 扫描所有继承 IRegister 接口的对象映射配置
|
||||||
if (assemblies?.Length > 0) config.Scan(assemblies);
|
if (assemblies?.Length > 0) config.Scan(assemblies);
|
||||||
|
|
||||||
|
@@ -76,7 +76,7 @@ internal sealed partial class SchedulerFactory : ISchedulerFactory
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 作业持久化记录消息队列(线程安全)
|
/// 作业持久化记录消息队列(线程安全)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly BlockingCollection<PersistenceContext> _persistenceMessageQueue = new(12000);
|
private readonly BlockingCollection<PersistenceContext> _persistenceMessageQueue = new(20000);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 不受控的作业 Id 集合
|
/// 不受控的作业 Id 集合
|
||||||
@@ -110,8 +110,7 @@ internal sealed partial class SchedulerFactory : ISchedulerFactory
|
|||||||
if (Persistence is not null)
|
if (Persistence is not null)
|
||||||
{
|
{
|
||||||
// 创建长时间运行的后台任务,并将作业运行消息写入持久化中
|
// 创建长时间运行的后台任务,并将作业运行消息写入持久化中
|
||||||
_processQueueTask = Task.Factory.StartNew(async state => await ((SchedulerFactory)state).ProcessQueueAsync().ConfigureAwait(false)
|
_processQueueTask = Task.Factory.StartNew(ProcessQueueAsync, TaskCreationOptions.LongRunning);
|
||||||
, this, TaskCreationOptions.LongRunning);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<Import Project="$(SolutionDir)Version.props" />
|
<Import Project="..\..\Version.props" />
|
||||||
<Import Project="$(SolutionDir)PackNuget.props" />
|
<Import Project="..\..\PackNuget.props" />
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFrameworks>net8.0;net9.0;</TargetFrameworks>
|
<TargetFrameworks>net8.0;net9.0;</TargetFrameworks>
|
||||||
@@ -36,10 +36,11 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Ben.Demystifier" Version="0.4.1" />
|
<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="System.Text.RegularExpressions" Version="4.3.1" />
|
||||||
<PackageReference Include="Mapster" Version="7.4.0" />
|
<PackageReference Include="Mapster" Version="7.4.0" />
|
||||||
<PackageReference Include="MiniProfiler.AspNetCore.Mvc" Version="4.5.4" />
|
<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>
|
||||||
|
|
||||||
<ItemGroup Condition=" '$(TargetFramework)' == 'net8.0' ">
|
<ItemGroup Condition=" '$(TargetFramework)' == 'net8.0' ">
|
||||||
@@ -61,8 +62,8 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="README.md" Pack="true" PackagePath="\" />
|
<None Include="README.md" Pack="true" PackagePath="\" />
|
||||||
<None Include="README.zh-CN.md" Pack="true" PackagePath="\" />
|
<None Include="README.zh-CN.md" Pack="true" PackagePath="\" />
|
||||||
<None Remove="$(SolutionDir)..\README.md" Pack="false" PackagePath="\" />
|
<None Remove="..\..\..\README.md" Pack="false" PackagePath="\" />
|
||||||
<None Remove="$(SolutionDir)..\README.zh-CN.md" Pack="false" PackagePath="\" />
|
<None Remove="..\..\..\README.zh-CN.md" Pack="false" PackagePath="\" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
@@ -79,11 +79,6 @@ public abstract class DisposeBase : IDisposable2
|
|||||||
OnDisposed?.Invoke(this, EventArgs.Empty);
|
OnDisposed?.Invoke(this, EventArgs.Empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
///// <summary>释放资源,参数表示是否由Dispose调用。该方法保证OnDispose只被调用一次!</summary>
|
|
||||||
///// <param name="disposing"></param>
|
|
||||||
//[Obsolete("=>Dispose")]
|
|
||||||
//protected virtual void OnDispose(Boolean disposing) { }
|
|
||||||
|
|
||||||
/// <summary>析构函数</summary>
|
/// <summary>析构函数</summary>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// 如果忘记调用Dispose,这里会释放非托管资源。
|
/// 如果忘记调用Dispose,这里会释放非托管资源。
|
||||||
|
@@ -127,63 +127,57 @@ public class MachineInfo
|
|||||||
|
|
||||||
//static MachineInfo() => RegisterAsync().Wait(100);
|
//static MachineInfo() => RegisterAsync().Wait(100);
|
||||||
|
|
||||||
private static Task<MachineInfo>? _task;
|
|
||||||
/// <summary>异步注册一个初始化后的机器信息实例</summary>
|
/// <summary>异步注册一个初始化后的机器信息实例</summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static Task<MachineInfo> RegisterAsync()
|
public static MachineInfo Register()
|
||||||
{
|
{
|
||||||
|
if (Current != null) return Current;
|
||||||
if (_task != null) return _task;
|
// 文件缓存,加快机器信息获取。在Linux下,可能StarAgent以root权限写入缓存文件,其它应用以普通用户访问
|
||||||
|
var file = Path.GetTempPath().CombinePath("machine_info.json");
|
||||||
return _task = Task.Factory.StartNew(() =>
|
var json = "";
|
||||||
|
if (Current == null)
|
||||||
{
|
{
|
||||||
// 文件缓存,加快机器信息获取。在Linux下,可能StarAgent以root权限写入缓存文件,其它应用以普通用户访问
|
var f = file;
|
||||||
var file = Path.GetTempPath().CombinePath("machine_info.json");
|
if (File.Exists(f))
|
||||||
var json = "";
|
|
||||||
if (Current == null)
|
|
||||||
{
|
{
|
||||||
var f = file;
|
try
|
||||||
if (File.Exists(f))
|
|
||||||
{
|
{
|
||||||
try
|
//XTrace.WriteLine("Load MachineInfo {0}", f);
|
||||||
{
|
json = File.ReadAllText(f);
|
||||||
//XTrace.WriteLine("Load MachineInfo {0}", f);
|
Current = json.FromJsonNetString<MachineInfo>();
|
||||||
json = File.ReadAllText(f);
|
}
|
||||||
Current = json.FromJsonNetString<MachineInfo>();
|
catch (Exception ex)
|
||||||
}
|
{
|
||||||
catch (Exception ex)
|
if (XTrace.Log.Level <= LogLevel.Debug) NewLife.Log.XTrace.WriteException(ex);
|
||||||
{
|
|
||||||
if (XTrace.Log.Level <= LogLevel.Debug) NewLife.Log.XTrace.WriteException(ex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var mi = Current ?? new MachineInfo();
|
var mi = Current ?? new MachineInfo();
|
||||||
|
|
||||||
mi.Init();
|
mi.Init();
|
||||||
Current = mi;
|
Current = mi;
|
||||||
|
|
||||||
try
|
try
|
||||||
|
{
|
||||||
|
var json2 = mi.ToJsonNetString();
|
||||||
|
if (json != json2)
|
||||||
{
|
{
|
||||||
var json2 = mi.ToJsonNetString();
|
File.WriteAllText(file.EnsureDirectory(true), json2);
|
||||||
if (json != json2)
|
|
||||||
{
|
|
||||||
File.WriteAllText(file.EnsureDirectory(true), json2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
if (XTrace.Log.Level <= LogLevel.Debug) NewLife.Log.XTrace.WriteException(ex);
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
if (XTrace.Log.Level <= LogLevel.Debug) NewLife.Log.XTrace.WriteException(ex);
|
||||||
|
}
|
||||||
|
|
||||||
return mi;
|
return mi;
|
||||||
});
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>获取当前信息,如果未设置则等待异步注册结果</summary>
|
/// <summary>获取当前信息,如果未设置则等待异步注册结果</summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static MachineInfo GetCurrent() => Current ?? RegisterAsync().ConfigureAwait(false).GetAwaiter().GetResult();
|
public static MachineInfo GetCurrent() => Current ?? Register();
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -1160,7 +1154,7 @@ public class MachineInfo
|
|||||||
public static String GetInfo(String path, String property, String? nameSpace = null)
|
public static String GetInfo(String path, String property, String? nameSpace = null)
|
||||||
{
|
{
|
||||||
// Linux Mono不支持WMI
|
// Linux Mono不支持WMI
|
||||||
if (Runtime.Mono) return "";
|
if (Runtime.Mono) return string.Empty;
|
||||||
|
|
||||||
var bbs = new List<String>();
|
var bbs = new List<String>();
|
||||||
try
|
try
|
||||||
@@ -1181,7 +1175,7 @@ public class MachineInfo
|
|||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
if (XTrace.Log.Level <= LogLevel.Debug) XTrace.WriteLine("WMI.GetInfo({0})失败!{1}", path, ex.Message);
|
if (XTrace.Log.Level <= LogLevel.Debug) XTrace.WriteLine("WMI.GetInfo({0})失败!{1}", path, ex.Message);
|
||||||
return "";
|
return string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
bbs.Sort();
|
bbs.Sort();
|
||||||
|
@@ -95,7 +95,6 @@ public class Config<TConfig> where TConfig : Config<TConfig>, new()
|
|||||||
#region 属性
|
#region 属性
|
||||||
/// <summary>是否新的配置文件</summary>
|
/// <summary>是否新的配置文件</summary>
|
||||||
[XmlIgnore, IgnoreDataMember]
|
[XmlIgnore, IgnoreDataMember]
|
||||||
//[Obsolete("=>_Provider.IsNew")]
|
|
||||||
public Boolean IsNew => Provider?.IsNew ?? false;
|
public Boolean IsNew => Provider?.IsNew ?? false;
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -104,7 +103,6 @@ public class Config<TConfig> where TConfig : Config<TConfig>, new()
|
|||||||
protected virtual void OnLoaded() { }
|
protected virtual void OnLoaded() { }
|
||||||
|
|
||||||
/// <summary>保存到配置文件中去</summary>
|
/// <summary>保存到配置文件中去</summary>
|
||||||
//[Obsolete("=>Provider.Save")]
|
|
||||||
public virtual void Save() => Provider?.Save(this);
|
public virtual void Save() => Provider?.Save(this);
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
@@ -41,12 +41,6 @@ public static class ProcessHelper
|
|||||||
return pname;
|
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>
|
///// <summary>根据名称获取进程。支持dotnet/java</summary>
|
||||||
///// <param name="name"></param>
|
///// <param name="name"></param>
|
||||||
///// <returns></returns>
|
///// <returns></returns>
|
||||||
|
@@ -236,25 +236,6 @@ public static class StringHelper
|
|||||||
return sb.Return(true);
|
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>
|
/// <summary>把一个列表组合成为一个字符串,默认逗号分隔</summary>
|
||||||
/// <param name="value"></param>
|
/// <param name="value"></param>
|
||||||
@@ -301,28 +282,6 @@ public static class StringHelper
|
|||||||
return encoding.GetBytes(value);
|
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>
|
/// <summary>指定输入是否匹配目标表达式,支持*匹配</summary>
|
||||||
/// <param name="pattern">匹配表达式</param>
|
/// <param name="pattern">匹配表达式</param>
|
||||||
/// <param name="input">输入字符串</param>
|
/// <param name="input">输入字符串</param>
|
||||||
|
@@ -854,13 +854,13 @@ public static class IOHelper
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static String ToHex(this Byte[]? data, Int32 offset = 0, Int32 count = -1)
|
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)
|
if (count < 0)
|
||||||
count = data.Length - offset;
|
count = data.Length - offset;
|
||||||
else if (offset + count > data.Length)
|
else if (offset + count > data.Length)
|
||||||
count = data.Length - offset;
|
count = data.Length - offset;
|
||||||
if (count == 0) return "";
|
if (count == 0) return string.Empty;
|
||||||
|
|
||||||
//return BitConverter.ToString(data).Replace("-", null);
|
//return BitConverter.ToString(data).Replace("-", null);
|
||||||
// 上面的方法要替换-,效率太低
|
// 上面的方法要替换-,效率太低
|
||||||
@@ -883,7 +883,7 @@ public static class IOHelper
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static String ToHex(this Byte[]? data, String? separate, Int32 groupSize = 0, Int32 maxLength = -1)
|
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;
|
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>
|
/// <returns></returns>
|
||||||
public static IEnumerable<Type> GetAllSubclasses(this Type baseType) => Provider.GetAllSubclasses(baseType);
|
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
|
#endregion
|
||||||
|
|
||||||
#region 辅助方法
|
#region 辅助方法
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<Import Project="$(SolutionDir)Version.props" />
|
<Import Project="..\..\Version.props" />
|
||||||
<Import Project="$(SolutionDir)PackNuget.props" />
|
<Import Project="..\..\PackNuget.props" />
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFrameworks>net462;netstandard2.0;net6.0;net6.0-windows;net8.0;net8.0-windows;</TargetFrameworks>
|
<TargetFrameworks>net462;netstandard2.0;net6.0;net6.0-windows;net8.0;net8.0-windows;</TargetFrameworks>
|
||||||
@@ -16,8 +16,8 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="README.md" Pack="true" PackagePath="\" />
|
<None Include="README.md" Pack="true" PackagePath="\" />
|
||||||
<None Include="README.zh-CN.md" Pack="true" PackagePath="\" />
|
<None Include="README.zh-CN.md" Pack="true" PackagePath="\" />
|
||||||
<None Remove="$(SolutionDir)..\README.md" Pack="false" PackagePath="\" />
|
<None Remove="..\..\..\README.md" Pack="false" PackagePath="\" />
|
||||||
<None Remove="$(SolutionDir)..\README.zh-CN.md" Pack="false" PackagePath="\" />
|
<None Remove="..\..\..\README.zh-CN.md" Pack="false" PackagePath="\" />
|
||||||
</ItemGroup>
|
</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'">
|
<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)
|
else if (!timer.Async)
|
||||||
Execute(timer);
|
Execute(timer);
|
||||||
else
|
else
|
||||||
//Task.Factory.StartNew(() => ProcessItem(timer));
|
|
||||||
// 不需要上下文流动,捕获所有异常
|
// 不需要上下文流动,捕获所有异常
|
||||||
ThreadPool.UnsafeQueueUserWorkItem(s =>
|
ThreadPool.UnsafeQueueUserWorkItem(s =>
|
||||||
{
|
{
|
||||||
@@ -231,8 +230,6 @@ public class TimerScheduler : ILogFeature
|
|||||||
{
|
{
|
||||||
if (state is not TimerX timer) return;
|
if (state is not TimerX timer) return;
|
||||||
|
|
||||||
TimerX.Current = timer;
|
|
||||||
|
|
||||||
// 控制日志显示
|
// 控制日志显示
|
||||||
WriteLogEventArgs.CurrentThreadName = Name == "Default" ? "T" : Name;
|
WriteLogEventArgs.CurrentThreadName = Name == "Default" ? "T" : Name;
|
||||||
|
|
||||||
@@ -274,7 +271,6 @@ public class TimerScheduler : ILogFeature
|
|||||||
{
|
{
|
||||||
if (state is not TimerX timer) return;
|
if (state is not TimerX timer) return;
|
||||||
|
|
||||||
TimerX.Current = timer;
|
|
||||||
|
|
||||||
// 控制日志显示
|
// 控制日志显示
|
||||||
WriteLogEventArgs.CurrentThreadName = Name == "Default" ? "T" : Name;
|
WriteLogEventArgs.CurrentThreadName = Name == "Default" ? "T" : Name;
|
||||||
@@ -322,8 +318,6 @@ public class TimerScheduler : ILogFeature
|
|||||||
|
|
||||||
timer.Calling = false;
|
timer.Calling = false;
|
||||||
|
|
||||||
TimerX.Current = null;
|
|
||||||
|
|
||||||
// 控制日志显示
|
// 控制日志显示
|
||||||
WriteLogEventArgs.CurrentThreadName = null;
|
WriteLogEventArgs.CurrentThreadName = null;
|
||||||
|
|
||||||
|
@@ -84,15 +84,7 @@ public class TimerX : ITimer, IDisposable
|
|||||||
private readonly Cron[]? _crons;
|
private readonly Cron[]? _crons;
|
||||||
#endregion
|
#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 构造
|
#region 构造
|
||||||
private TimerX(Object? target, MethodInfo method, Object? state, String? scheduler = null)
|
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>
|
/// <param name="period">构造 Timer 时指定的回调方法调用之间的时间间隔。 指定 InfiniteTimeSpan 可以禁用定期终止。</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public Boolean Change(TimeSpan dueTime, TimeSpan period)
|
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 (Absolutely) return false;
|
||||||
if (Crons?.Length > 0) return false;
|
if (Crons?.Length > 0) return false;
|
||||||
|
|
||||||
if (period.TotalMilliseconds <= 0)
|
if (period <= 0)
|
||||||
{
|
{
|
||||||
Dispose();
|
Dispose();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Period = (Int32)period.TotalMilliseconds;
|
Period = period;
|
||||||
|
|
||||||
if (dueTime.TotalMilliseconds >= 0) SetNext((Int32)dueTime.TotalMilliseconds);
|
if (dueTime >= 0) SetNext(dueTime);
|
||||||
|
|
||||||
return true;
|
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")]
|
[DllImport("user32.dll")]
|
||||||
private static extern Int32 SendMessage(IntPtr hwnd, Int32 wMsg, Int32 wParam, Int32 lParam);
|
private static extern Int32 SendMessage(IntPtr hwnd, Int32 wMsg, Int32 wParam, Int32 lParam);
|
||||||
private const Int32 SB_TOP = 6;
|
private const Int32 SB_TOP = 6;
|
||||||
|
@@ -20,7 +20,6 @@ namespace ThingsGateway.NewLife.Xml;
|
|||||||
/// 用户也可以通过配置实体类的静态构造函数修改基类的<see cref="_.ConfigFile"/>和<see cref="_.ReloadTime"/>来动态配置加载信息。
|
/// 用户也可以通过配置实体类的静态构造函数修改基类的<see cref="_.ConfigFile"/>和<see cref="_.ReloadTime"/>来动态配置加载信息。
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
/// <typeparam name="TConfig"></typeparam>
|
/// <typeparam name="TConfig"></typeparam>
|
||||||
//[Obsolete("=>Config<TConfig>")]
|
|
||||||
public class XmlConfig<TConfig> : DisposeBase where TConfig : XmlConfig<TConfig>, new()
|
public class XmlConfig<TConfig> : DisposeBase where TConfig : XmlConfig<TConfig>, new()
|
||||||
{
|
{
|
||||||
#region 静态
|
#region 静态
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk.Razor">
|
<Project Sdk="Microsoft.NET.Sdk.Razor">
|
||||||
<Import Project="$(SolutionDir)Version.props" />
|
<Import Project="..\..\Version.props" />
|
||||||
<Import Project="$(SolutionDir)PackNuget.props" />
|
<Import Project="..\..\PackNuget.props" />
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFrameworks>net8.0;net9.0;</TargetFrameworks>
|
<TargetFrameworks>net8.0;net9.0;</TargetFrameworks>
|
||||||
|
@@ -13,6 +13,7 @@ namespace ThingsGateway.Razor;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 母版页基类
|
/// 母版页基类
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[DoNotGenerateSetParametersAsync]
|
||||||
public partial class BaseLayout
|
public partial class BaseLayout
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@@ -11,7 +11,7 @@
|
|||||||
namespace ThingsGateway.Razor;
|
namespace ThingsGateway.Razor;
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public abstract class WebSiteModuleComponentBase : BootstrapModuleComponentBase
|
public abstract partial class WebSiteModuleComponentBase : BootstrapModuleComponentBase
|
||||||
{
|
{
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
protected override void OnLoadJSModule()
|
protected override void OnLoadJSModule()
|
||||||
|
@@ -41,14 +41,16 @@
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
<PopConfirmButton IsAsync IsDisabled=@_importPreviews.Any(it => it.Value.HasError) Color=Color.Warning class="mt-2" OnConfirm=@(SaveDeviceImport)>@Localizer["Import"]</PopConfirmButton>
|
||||||
|
|
||||||
<Button IsAsync class="mt-2" IsDisabled=@_importPreviews.Any(it => it.Value.HasError) OnClick="() => step.Next()">@Localizer["Next"]</Button>
|
@*
|
||||||
|
<Button IsAsync class="mt-2" IsDisabled=@_importPreviews.Any(it => it.Value.HasError) OnClick="() => step.Next()">@Localizer["Next"]</Button> *@
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</StepItem>
|
</StepItem>
|
||||||
<StepItem Text=@Localizer["Third"] Title=@Localizer["Import"]>
|
@* <StepItem Text=@Localizer["Third"] Title=@Localizer["Import"]>
|
||||||
<PopConfirmButton IsAsync Color=Color.Warning class="mt-2" OnConfirm=@(SaveDeviceImport)>@Localizer["Import"]</PopConfirmButton>
|
<PopConfirmButton IsAsync Color=Color.Warning class="mt-2" OnConfirm=@(SaveDeviceImport)>@Localizer["Import"]</PopConfirmButton>
|
||||||
</StepItem>
|
</StepItem> *@
|
||||||
</Step>
|
</Step>
|
||||||
@code {
|
@code {
|
||||||
[NotNull]
|
[NotNull]
|
||||||
|
@@ -10,16 +10,12 @@
|
|||||||
|
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
|
||||||
using ThingsGateway.NewLife.Caching;
|
|
||||||
|
|
||||||
namespace ThingsGateway.Extension.Generic;
|
namespace ThingsGateway.Extension.Generic;
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
[ThingsGateway.DependencyInjection.SuppressSniffer]
|
[ThingsGateway.DependencyInjection.SuppressSniffer]
|
||||||
public static class GenericExtensions
|
public static class GenericExtensions
|
||||||
{
|
{
|
||||||
private static MemoryCache Instance { get; set; } = new MemoryCache();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 把已修改的属性赋值到列表中,并返回字典
|
/// 把已修改的属性赋值到列表中,并返回字典
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@@ -8,6 +8,8 @@
|
|||||||
// QQ群:605534569
|
// QQ群:605534569
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
using System.Collections.Concurrent;
|
||||||
|
|
||||||
namespace ThingsGateway;
|
namespace ThingsGateway;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -22,7 +24,7 @@ public static class ParallelExtensions
|
|||||||
/// <typeparam name="T">集合元素类型</typeparam>
|
/// <typeparam name="T">集合元素类型</typeparam>
|
||||||
/// <param name="source">要操作的集合</param>
|
/// <param name="source">要操作的集合</param>
|
||||||
/// <param name="body">要执行的操作</param>
|
/// <param name="body">要执行的操作</param>
|
||||||
public static void ParallelForEach<T>(this IEnumerable<T> source, Action<T> body)
|
public static void ParallelForEach<T>(this IList<T> source, Action<T> body)
|
||||||
{
|
{
|
||||||
ParallelOptions options = new();
|
ParallelOptions options = new();
|
||||||
options.MaxDegreeOfParallelism = Environment.ProcessorCount;
|
options.MaxDegreeOfParallelism = Environment.ProcessorCount;
|
||||||
@@ -39,7 +41,7 @@ public static class ParallelExtensions
|
|||||||
/// <typeparam name="T">集合元素类型</typeparam>
|
/// <typeparam name="T">集合元素类型</typeparam>
|
||||||
/// <param name="source">要操作的集合</param>
|
/// <param name="source">要操作的集合</param>
|
||||||
/// <param name="body">要执行的操作</param>
|
/// <param name="body">要执行的操作</param>
|
||||||
public static void ParallelForEach<T>(this IEnumerable<T> source, Action<T, ParallelLoopState, long> body)
|
public static void ParallelForEach<T>(this IList<T> source, Action<T, ParallelLoopState, long> body)
|
||||||
{
|
{
|
||||||
ParallelOptions options = new();
|
ParallelOptions options = new();
|
||||||
options.MaxDegreeOfParallelism = Environment.ProcessorCount;
|
options.MaxDegreeOfParallelism = Environment.ProcessorCount;
|
||||||
@@ -57,7 +59,7 @@ public static class ParallelExtensions
|
|||||||
/// <param name="source">要操作的集合</param>
|
/// <param name="source">要操作的集合</param>
|
||||||
/// <param name="body">要执行的操作</param>
|
/// <param name="body">要执行的操作</param>
|
||||||
/// <param name="parallelCount">最大并行度</param>
|
/// <param name="parallelCount">最大并行度</param>
|
||||||
public static void ParallelForEach<T>(this IEnumerable<T> source, Action<T> body, int parallelCount)
|
public static void ParallelForEach<T>(this IList<T> source, Action<T> body, int parallelCount)
|
||||||
{
|
{
|
||||||
// 创建并行操作的选项对象,设置最大并行度为指定的值
|
// 创建并行操作的选项对象,设置最大并行度为指定的值
|
||||||
var options = new ParallelOptions();
|
var options = new ParallelOptions();
|
||||||
@@ -69,6 +71,47 @@ public static class ParallelExtensions
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 使用默认的并行设置执行指定的操作(Partitioner 分区)
|
||||||
|
/// </summary>
|
||||||
|
public static void ParallelForEachStreamed<T>(this IEnumerable<T> source, Action<T> body)
|
||||||
|
{
|
||||||
|
var partitioner = Partitioner.Create<T>(source, EnumerablePartitionerOptions.NoBuffering);
|
||||||
|
Parallel.ForEach(partitioner, new ParallelOptions
|
||||||
|
{
|
||||||
|
MaxDegreeOfParallelism = Environment.ProcessorCount
|
||||||
|
}, body);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 使用默认的并行设置执行指定的操作(带索引和 LoopState,Partitioner 分区)
|
||||||
|
/// </summary>
|
||||||
|
public static void ParallelForEachStreamed<T>(this IEnumerable<T> source, Action<T, ParallelLoopState, long> body)
|
||||||
|
{
|
||||||
|
var partitioner = Partitioner.Create<T>(source, EnumerablePartitionerOptions.NoBuffering);
|
||||||
|
Parallel.ForEach(partitioner, new ParallelOptions
|
||||||
|
{
|
||||||
|
MaxDegreeOfParallelism = Environment.ProcessorCount
|
||||||
|
}, (item, state, index) => body(item, state, index));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 执行指定的操作,并指定最大并行度(Partitioner 分区)
|
||||||
|
/// </summary>
|
||||||
|
public static void ParallelForEachStreamed<T>(this IEnumerable<T> source, Action<T> body, int parallelCount)
|
||||||
|
{
|
||||||
|
var options = new ParallelOptions
|
||||||
|
{
|
||||||
|
MaxDegreeOfParallelism = parallelCount <= 0 ? 1 : parallelCount
|
||||||
|
};
|
||||||
|
|
||||||
|
var partitioner = Partitioner.Create<T>(source, EnumerablePartitionerOptions.NoBuffering);
|
||||||
|
Parallel.ForEach(partitioner, options, body);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 异步执行指定的操作,并指定最大并行度和取消标志
|
/// 异步执行指定的操作,并指定最大并行度和取消标志
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -78,7 +121,7 @@ public static class ParallelExtensions
|
|||||||
/// <param name="parallelCount">最大并行度</param>
|
/// <param name="parallelCount">最大并行度</param>
|
||||||
/// <param name="cancellationToken">取消操作的标志</param>
|
/// <param name="cancellationToken">取消操作的标志</param>
|
||||||
/// <returns>表示异步操作的任务</returns>
|
/// <returns>表示异步操作的任务</returns>
|
||||||
public static Task ParallelForEachAsync<T>(this IEnumerable<T> source, Func<T, CancellationToken, ValueTask> body, int parallelCount, CancellationToken cancellationToken = default)
|
public static Task ParallelForEachAsync<T>(this IList<T> source, Func<T, CancellationToken, ValueTask> body, int parallelCount, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
// 创建并行操作的选项对象,设置最大并行度和取消标志
|
// 创建并行操作的选项对象,设置最大并行度和取消标志
|
||||||
var options = new ParallelOptions();
|
var options = new ParallelOptions();
|
||||||
@@ -95,8 +138,10 @@ public static class ParallelExtensions
|
|||||||
/// <param name="body">异步执行的操作</param>
|
/// <param name="body">异步执行的操作</param>
|
||||||
/// <param name="cancellationToken">取消操作的标志</param>
|
/// <param name="cancellationToken">取消操作的标志</param>
|
||||||
/// <returns>表示异步操作的任务</returns>
|
/// <returns>表示异步操作的任务</returns>
|
||||||
public static Task ParallelForEachAsync<T>(this IEnumerable<T> source, Func<T, CancellationToken, ValueTask> body, CancellationToken cancellationToken = default)
|
public static Task ParallelForEachAsync<T>(this IList<T> source, Func<T, CancellationToken, ValueTask> body, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
return ParallelForEachAsync(source, body, Environment.ProcessorCount, cancellationToken);
|
return ParallelForEachAsync(source, body, Environment.ProcessorCount, cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -21,3 +21,4 @@ global using System.Globalization;
|
|||||||
|
|
||||||
|
|
||||||
[assembly: SuppressMessage("Reliability", "CA2007", Justification = "<挂起>", Scope = "module")]
|
[assembly: SuppressMessage("Reliability", "CA2007", Justification = "<挂起>", Scope = "module")]
|
||||||
|
[assembly: GlobalGenerateSetParametersAsync(true)]
|
@@ -5,10 +5,11 @@
|
|||||||
|
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
using System.Collections.Concurrent;
|
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Resources;
|
using System.Resources;
|
||||||
|
|
||||||
|
using ThingsGateway.NewLife.Collections;
|
||||||
|
|
||||||
namespace ThingsGateway;
|
namespace ThingsGateway;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -107,14 +108,14 @@ internal class JsonStringLocalizer(Assembly assembly, string typeName, string ba
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly ConcurrentDictionary<string, object?> _missingManifestCache = [];
|
private readonly ConcurrentHashSet<string> _missingManifestCache = [];
|
||||||
private string? GetStringFromJson(string name)
|
private string? GetStringFromJson(string name)
|
||||||
{
|
{
|
||||||
// get string from json localization file
|
// get string from json localization file
|
||||||
var localizerStrings = MegerResolveLocalizers(CacheManager.GetAllStringsByTypeName(Assembly, typeName));
|
var localizerStrings = MegerResolveLocalizers(CacheManager.GetAllStringsByTypeName(Assembly, typeName));
|
||||||
var cacheKey = $"name={name}&culture={CultureInfo.CurrentUICulture.Name}";
|
var cacheKey = $"name={name}&culture={CultureInfo.CurrentUICulture.Name}";
|
||||||
string? ret = null;
|
string? ret = null;
|
||||||
if (!_missingManifestCache.ContainsKey(cacheKey))
|
if (!_missingManifestCache.Contain(cacheKey))
|
||||||
{
|
{
|
||||||
var l = localizerStrings.Find(i => i.Name == name);
|
var l = localizerStrings.Find(i => i.Name == name);
|
||||||
if (l is { ResourceNotFound: false })
|
if (l is { ResourceNotFound: false })
|
||||||
@@ -161,6 +162,7 @@ internal class JsonStringLocalizer(Assembly assembly, string typeName, string ba
|
|||||||
private List<LocalizedString> MegerResolveLocalizers(IEnumerable<LocalizedString>? localizerStrings)
|
private List<LocalizedString> MegerResolveLocalizers(IEnumerable<LocalizedString>? localizerStrings)
|
||||||
{
|
{
|
||||||
var localizers = new List<LocalizedString>(CacheManager.GetTypeStringsFromResolve(typeName));
|
var localizers = new List<LocalizedString>(CacheManager.GetTypeStringsFromResolve(typeName));
|
||||||
|
|
||||||
if (localizerStrings != null)
|
if (localizerStrings != null)
|
||||||
{
|
{
|
||||||
localizers.AddRange(localizerStrings);
|
localizers.AddRange(localizerStrings);
|
||||||
@@ -175,7 +177,7 @@ internal class JsonStringLocalizer(Assembly assembly, string typeName, string ba
|
|||||||
{
|
{
|
||||||
Logger.LogInformation("{JsonStringLocalizerName} searched for '{Name}' in '{TypeName}' with culture '{CultureName}' not found.", nameof(JsonStringLocalizer), name, typeName, CultureInfo.CurrentUICulture.Name);
|
Logger.LogInformation("{JsonStringLocalizerName} searched for '{Name}' in '{TypeName}' with culture '{CultureName}' not found.", nameof(JsonStringLocalizer), name, typeName, CultureInfo.CurrentUICulture.Name);
|
||||||
}
|
}
|
||||||
_missingManifestCache.TryAdd($"name={name}&culture={CultureInfo.CurrentUICulture.Name}", null);
|
_missingManifestCache.TryAdd($"name={name}&culture={CultureInfo.CurrentUICulture.Name}");
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<LocalizedString>? _allLocalizerdStrings;
|
private List<LocalizedString>? _allLocalizerdStrings;
|
||||||
|
@@ -8,7 +8,6 @@
|
|||||||
// QQ群:605534569
|
// QQ群:605534569
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
using Microsoft.AspNetCore.Builder;
|
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
using ThingsGateway.NewLife;
|
using ThingsGateway.NewLife;
|
||||||
@@ -48,7 +47,7 @@ public class Startup : AppStartup
|
|||||||
// 缓存
|
// 缓存
|
||||||
services.AddSingleton<ICache, MemoryCache>();
|
services.AddSingleton<ICache, MemoryCache>();
|
||||||
|
|
||||||
MachineInfo.RegisterAsync();
|
MachineInfo.Register();
|
||||||
|
|
||||||
// 配置雪花Id算法机器码
|
// 配置雪花Id算法机器码
|
||||||
YitIdHelper.SetIdGenerator(new IdGeneratorOptions
|
YitIdHelper.SetIdGenerator(new IdGeneratorOptions
|
||||||
@@ -59,7 +58,7 @@ public class Startup : AppStartup
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public void Use(IApplicationBuilder applicationBuilder)
|
public void Use(IServiceProvider serviceProvider)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,35 +1,43 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk.Razor">
|
<Project Sdk="Microsoft.NET.Sdk.Razor">
|
||||||
|
<Import Project="..\..\Version.props" />
|
||||||
<Import Project="$(SolutionDir)Version.props" />
|
<Import Project="..\..\PackNuget.props" />
|
||||||
<Import Project="$(SolutionDir)PackNuget.props" />
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFrameworks>net8.0;</TargetFrameworks>
|
<TargetFrameworks>net8.0</TargetFrameworks>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="BootstrapBlazor.FontAwesome" Version="9.0.2" />
|
<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" />
|
<PackageReference Include="Yitter.IdGenerator" Version="1.0.14" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Content Remove="Locales\*.json" />
|
|
||||||
<EmbeddedResource Include="Locales\*.json">
|
<EmbeddedResource Include="Locales\*.json">
|
||||||
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
|
||||||
</EmbeddedResource>
|
</EmbeddedResource>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="..\README.md" Pack="true" PackagePath="\" />
|
<None Include="..\README.md" Pack="true" PackagePath="\" />
|
||||||
<None Include="..\README.zh-CN.md" Pack="true" PackagePath="\" />
|
<None Include="..\README.zh-CN.md" Pack="true" PackagePath="\" />
|
||||||
<None Remove="$(SolutionDir)..\README.md" Pack="false" PackagePath="\" />
|
<None Remove="..\..\..\README.md" Pack="false" PackagePath="\" />
|
||||||
<None Remove="$(SolutionDir)..\README.zh-CN.md" Pack="false" PackagePath="\" />
|
<None Remove="..\..\..\README.zh-CN.md" Pack="false" PackagePath="\" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\ThingsGateway.Furion\ThingsGateway.Furion.csproj" />
|
<ProjectReference Include="..\ThingsGateway.Furion\ThingsGateway.Furion.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
||||||
|
<!--<ItemGroup Condition="'$(Configuration)' != 'Debug' ">
|
||||||
|
<None Include="..\BlazorSetParametersAsyncGenerator\tools\*.ps1" PackagePath="tools" Pack="true" Visible="false" />
|
||||||
|
<None Include="..\BlazorSetParametersAsyncGenerator\bin\$(Configuration)\netstandard2.0\BlazorSetParametersAsyncGenerator.dll" PackagePath="analyzers\dotnet\cs" Pack="true" Visible="false" />
|
||||||
|
</ItemGroup>-->
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\BlazorSetParametersAsyncGenerator\BlazorSetParametersAsyncGenerator.csproj" PrivateAssets="all" OutputItemType="Analyzer" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
||||||
|
|
||||||
|
@@ -1,5 +1,4 @@
|
|||||||
|
@using System.Net.Http
|
||||||
@using System.Net.Http
|
|
||||||
@using System.Net.Http.Json
|
@using System.Net.Http.Json
|
||||||
@using Microsoft.AspNetCore.Components.Forms
|
@using Microsoft.AspNetCore.Components.Forms
|
||||||
@using Microsoft.AspNetCore.Components.Routing
|
@using Microsoft.AspNetCore.Components.Routing
|
||||||
@@ -16,4 +15,5 @@
|
|||||||
@using BootstrapBlazor.Components
|
@using BootstrapBlazor.Components
|
||||||
|
|
||||||
|
|
||||||
@using ThingsGateway.Razor;
|
@using ThingsGateway.Razor
|
||||||
|
|
||||||
|
@@ -26,6 +26,10 @@
|
|||||||
height: var(--line-chart-table-height);
|
height: var(--line-chart-table-height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.wb-control .wb-full {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
.dialog-table {
|
.dialog-table {
|
||||||
height: calc(100vh - 200px);
|
height: calc(100vh - 200px);
|
||||||
}
|
}
|
||||||
|
@@ -355,7 +355,7 @@ namespace ThingsGateway.SqlSugar
|
|||||||
{
|
{
|
||||||
var querybulder = InstanceFactory.GetSqlbuilder(this.Context.CurrentConnectionConfig);
|
var querybulder = InstanceFactory.GetSqlbuilder(this.Context.CurrentConnectionConfig);
|
||||||
querybulder.Context = this.Context;
|
querybulder.Context = this.Context;
|
||||||
var fileds = item.IndexFields
|
var fields = item.IndexFields
|
||||||
.Select(it =>
|
.Select(it =>
|
||||||
{
|
{
|
||||||
var dbColumn = entityInfo.Columns.FirstOrDefault(z => z.PropertyName == it.Key);
|
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);
|
return new KeyValuePair<string, OrderByType>(dbColumn.DbColumnName, it.Value);
|
||||||
})
|
})
|
||||||
.Select(it => querybulder.GetTranslationColumnName(it.Key) + " " + it.Value).ToArray();
|
.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);
|
DbColumnInfo dbColumnInfo = EntityColumnToDbColumn(entityInfo, tableName, item);
|
||||||
columns.Add(dbColumnInfo);
|
columns.Add(dbColumnInfo);
|
||||||
}
|
}
|
||||||
if (entityInfo.IsCreateTableFiledSort)
|
if (entityInfo.IsCreateTableFieldSort)
|
||||||
{
|
{
|
||||||
columns = columns.OrderBy(c => c.CreateTableFieldSort).ToList();
|
columns = columns.OrderBy(c => c.CreateTableFieldSort).ToList();
|
||||||
columns = columns.OrderBy(it => it.IsPrimarykey ? 0 : 1).ToList();
|
columns = columns.OrderBy(it => it.IsPrimarykey ? 0 : 1).ToList();
|
||||||
|
@@ -154,7 +154,7 @@ namespace ThingsGateway.SqlSugar
|
|||||||
if (DeleteBuilder.BigDataInValues == null)
|
if (DeleteBuilder.BigDataInValues == null)
|
||||||
DeleteBuilder.BigDataInValues = new List<object>();
|
DeleteBuilder.BigDataInValues = new List<object>();
|
||||||
DeleteBuilder.BigDataInValues.AddRange(primaryKeyValues);
|
DeleteBuilder.BigDataInValues.AddRange(primaryKeyValues);
|
||||||
DeleteBuilder.BigDataFiled = primaryField;
|
DeleteBuilder.BigDataField = primaryField;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -520,7 +520,7 @@ namespace ThingsGateway.SqlSugar
|
|||||||
if (DeleteBuilder.BigDataInValues == null)
|
if (DeleteBuilder.BigDataInValues == null)
|
||||||
DeleteBuilder.BigDataInValues = new List<object>();
|
DeleteBuilder.BigDataInValues = new List<object>();
|
||||||
DeleteBuilder.BigDataInValues.AddRange(primaryKeyValues.Select(it => (object)it));
|
DeleteBuilder.BigDataInValues.AddRange(primaryKeyValues.Select(it => (object)it));
|
||||||
DeleteBuilder.BigDataFiled = primaryField;
|
DeleteBuilder.BigDataField = primaryField;
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@@ -35,7 +35,7 @@ namespace ThingsGateway.SqlSugar
|
|||||||
attributeType.GetProperty(nameof(SugarTable.TableDescription)) ,
|
attributeType.GetProperty(nameof(SugarTable.TableDescription)) ,
|
||||||
attributeType.GetProperty(nameof(SugarTable.IsDisabledUpdateAll)) ,
|
attributeType.GetProperty(nameof(SugarTable.IsDisabledUpdateAll)) ,
|
||||||
attributeType.GetProperty(nameof(SugarTable.IsDisabledDelete)),
|
attributeType.GetProperty(nameof(SugarTable.IsDisabledDelete)),
|
||||||
attributeType.GetProperty(nameof(SugarTable.IsCreateTableFiledSort)),
|
attributeType.GetProperty(nameof(SugarTable.IsCreateTableFieldSort)),
|
||||||
attributeType.GetProperty(nameof(SugarTable.Discrimator))
|
attributeType.GetProperty(nameof(SugarTable.Discrimator))
|
||||||
}
|
}
|
||||||
, new object[] {
|
, new object[] {
|
||||||
@@ -43,7 +43,7 @@ namespace ThingsGateway.SqlSugar
|
|||||||
sugarTable.TableDescription ,
|
sugarTable.TableDescription ,
|
||||||
sugarTable.IsDisabledUpdateAll,
|
sugarTable.IsDisabledUpdateAll,
|
||||||
sugarTable.IsDisabledDelete,
|
sugarTable.IsDisabledDelete,
|
||||||
sugarTable.IsCreateTableFiledSort,
|
sugarTable.IsCreateTableFieldSort,
|
||||||
sugarTable.Discrimator
|
sugarTable.Discrimator
|
||||||
});
|
});
|
||||||
return attributeBuilder;
|
return attributeBuilder;
|
||||||
|
@@ -63,7 +63,7 @@ namespace ThingsGateway.SqlSugar
|
|||||||
result.TableDescription = sugarTable.TableDescription.ToSqlFilter();
|
result.TableDescription = sugarTable.TableDescription.ToSqlFilter();
|
||||||
result.IsDisabledUpdateAll = sugarTable.IsDisabledUpdateAll;
|
result.IsDisabledUpdateAll = sugarTable.IsDisabledUpdateAll;
|
||||||
result.IsDisabledDelete = sugarTable.IsDisabledDelete;
|
result.IsDisabledDelete = sugarTable.IsDisabledDelete;
|
||||||
result.IsCreateTableFiledSort = sugarTable.IsCreateTableFiledSort;
|
result.IsCreateTableFieldSort = sugarTable.IsCreateTableFieldSort;
|
||||||
result.Discrimator = sugarTable.Discrimator;
|
result.Discrimator = sugarTable.Discrimator;
|
||||||
}
|
}
|
||||||
var indexs = type.GetCustomAttributes(typeof(SugarIndexAttribute));
|
var indexs = type.GetCustomAttributes(typeof(SugarIndexAttribute));
|
||||||
@@ -201,9 +201,9 @@ namespace ThingsGateway.SqlSugar
|
|||||||
try
|
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"))
|
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))))
|
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 fielddName = item.DbColumnName;
|
||||||
var filedObject = this.EntityInfo.Columns.FirstOrDefault(it => it.PropertyName == item.PropertyName).PropertyInfo.GetValue(this.InsertObjs.Last(), null);
|
var fieldObject = this.EntityInfo.Columns.FirstOrDefault(it => it.PropertyName == item.PropertyName).PropertyInfo.GetValue(this.InsertObjs.Last(), null);
|
||||||
var fieldValue = filedObject.ObjToString();
|
var fieldValue = fieldObject.ObjToString();
|
||||||
if (filedObject != null && filedObject.GetType() != typeof(string) && this.Context.CurrentConnectionConfig.DbType == DbType.PostgreSQL)
|
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
|
else
|
||||||
{
|
{
|
||||||
|
@@ -73,11 +73,6 @@ namespace ThingsGateway.SqlSugar
|
|||||||
return resul;
|
return resul;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Obsolete("use ExecuteCommand")]
|
|
||||||
public object ExecuteReturnPrimaryKey()
|
|
||||||
{
|
|
||||||
return ExecuteCommand();
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<object> ExecuteCommandAsync()
|
public async Task<object> ExecuteCommandAsync()
|
||||||
{
|
{
|
||||||
@@ -137,11 +132,7 @@ namespace ThingsGateway.SqlSugar
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
[Obsolete("use ExecuteCommandAsync")]
|
|
||||||
public Task<object> ExecuteReturnPrimaryKeyAsync()
|
|
||||||
{
|
|
||||||
return Task.FromResult(ExecuteReturnPrimaryKey());
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool IsIdEntity(EntityInfo entity)
|
private bool IsIdEntity(EntityInfo entity)
|
||||||
{
|
{
|
||||||
|
@@ -9,17 +9,17 @@ namespace ThingsGateway.SqlSugar
|
|||||||
public EntityInfo NavEntity { get; set; }
|
public EntityInfo NavEntity { get; set; }
|
||||||
public EntityInfo RootEntity { 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();
|
MappingFieldsInfo mappingFields = new MappingFieldsInfo();
|
||||||
var pkName = "";
|
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
|
else
|
||||||
{
|
{
|
||||||
pkName = ((mappingFiled as LambdaExpression).Body as MemberExpression).Member.Name;
|
pkName = ((mappingField as LambdaExpression).Body as MemberExpression).Member.Name;
|
||||||
}
|
}
|
||||||
return mappingFields;
|
return mappingFields;
|
||||||
}
|
}
|
||||||
|
@@ -577,7 +577,7 @@ namespace ThingsGateway.SqlSugar
|
|||||||
var result = new List<T>();
|
var result = new List<T>();
|
||||||
throw new Exception("开发中");
|
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)
|
if (parameter == null)
|
||||||
{
|
{
|
||||||
@@ -588,15 +588,15 @@ namespace ThingsGateway.SqlSugar
|
|||||||
var queryableContext = this.Context.TempItems["Queryable_To_Context"] as MapperContext<ParameterT>;
|
var queryableContext = this.Context.TempItems["Queryable_To_Context"] as MapperContext<ParameterT>;
|
||||||
var list = queryableContext.list;
|
var list = queryableContext.list;
|
||||||
var pkName = "";
|
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
|
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();
|
var ids = list.Where(it => it != null).Select(it => it.GetType().GetProperty(pkName).GetValue(it)).Distinct().ToArray();
|
||||||
if (queryableContext.TempChildLists == null)
|
if (queryableContext.TempChildLists == null)
|
||||||
queryableContext.TempChildLists = new Dictionary<string, object>();
|
queryableContext.TempChildLists = new Dictionary<string, object>();
|
||||||
@@ -610,25 +610,25 @@ namespace ThingsGateway.SqlSugar
|
|||||||
queryableContext.TempChildLists = new Dictionary<string, object>();
|
queryableContext.TempChildLists = new Dictionary<string, object>();
|
||||||
this.Context.Utilities.PageEach(ids, 200, pageIds =>
|
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;
|
queryableContext.TempChildLists[key] = result;
|
||||||
}
|
}
|
||||||
var name = "";
|
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
|
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);
|
var pkValue = parameter.GetType().GetProperty(pkName).GetValue(parameter);
|
||||||
result = result.Where(it => it.GetType().GetProperty(name).GetValue(it).ObjToString() == pkValue.ObjToString()).ToList();
|
result = result.Where(it => it.GetType().GetProperty(name).GetValue(it).ObjToString() == pkValue.ObjToString()).ToList();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
public List<T> SetContext<ParameterT>(Expression<Func<T, object>> thisFiled1, Expression<Func<object>> mappingFiled1,
|
public List<T> SetContext<ParameterT>(Expression<Func<T, object>> thisField1, Expression<Func<object>> mappingField1,
|
||||||
Expression<Func<T, object>> thisFiled2, Expression<Func<object>> mappingFiled2,
|
Expression<Func<T, object>> thisField2, Expression<Func<object>> mappingField2,
|
||||||
ParameterT parameter)
|
ParameterT parameter)
|
||||||
{
|
{
|
||||||
if (parameter == null)
|
if (parameter == null)
|
||||||
@@ -640,22 +640,22 @@ namespace ThingsGateway.SqlSugar
|
|||||||
List<T> result = new List<T>();
|
List<T> result = new List<T>();
|
||||||
var queryableContext = this.Context.TempItems["Queryable_To_Context"] as MapperContext<ParameterT>;
|
var queryableContext = this.Context.TempItems["Queryable_To_Context"] as MapperContext<ParameterT>;
|
||||||
var list = queryableContext.list;
|
var list = queryableContext.list;
|
||||||
var key = thisFiled1.ToString() + mappingFiled1.ToString() +
|
var key = thisField1.ToString() + mappingField1.ToString() +
|
||||||
thisFiled2.ToString() + mappingFiled2.ToString() +
|
thisField2.ToString() + mappingField2.ToString() +
|
||||||
typeof(ParameterT).FullName + typeof(T).FullName;
|
typeof(ParameterT).FullName + typeof(T).FullName;
|
||||||
MappingFieldsHelper<ParameterT> fieldsHelper = new MappingFieldsHelper<ParameterT>();
|
MappingFieldsHelper<ParameterT> fieldsHelper = new MappingFieldsHelper<ParameterT>();
|
||||||
var mappings = new List<MappingFieldsExpression>() {
|
var mappings = new List<MappingFieldsExpression>() {
|
||||||
new MappingFieldsExpression(){
|
new MappingFieldsExpression(){
|
||||||
LeftColumnExpression=thisFiled1,
|
LeftColumnExpression=thisField1,
|
||||||
LeftEntityColumn=leftEntity.Columns.First(it=>it.PropertyName==ExpressionTool.GetMemberName(thisFiled1)),
|
LeftEntityColumn=leftEntity.Columns.First(it=>it.PropertyName==ExpressionTool.GetMemberName(thisField1)),
|
||||||
RightColumnExpression=mappingFiled1,
|
RightColumnExpression=mappingField1,
|
||||||
RightEntityColumn=rightEntity.Columns.First(it=>it.PropertyName==ExpressionTool.GetMemberName(mappingFiled1))
|
RightEntityColumn=rightEntity.Columns.First(it=>it.PropertyName==ExpressionTool.GetMemberName(mappingField1))
|
||||||
},
|
},
|
||||||
new MappingFieldsExpression(){
|
new MappingFieldsExpression(){
|
||||||
LeftColumnExpression=thisFiled2,
|
LeftColumnExpression=thisField2,
|
||||||
LeftEntityColumn=leftEntity.Columns.First(it=>it.PropertyName==ExpressionTool.GetMemberName(thisFiled2)),
|
LeftEntityColumn=leftEntity.Columns.First(it=>it.PropertyName==ExpressionTool.GetMemberName(thisField2)),
|
||||||
RightColumnExpression=mappingFiled2,
|
RightColumnExpression=mappingField2,
|
||||||
RightEntityColumn=rightEntity.Columns.First(it=>it.PropertyName==ExpressionTool.GetMemberName(mappingFiled2))
|
RightEntityColumn=rightEntity.Columns.First(it=>it.PropertyName==ExpressionTool.GetMemberName(mappingField2))
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
var conditionals = fieldsHelper.GetMppingSql(list.Cast<object>().ToList(), mappings);
|
var conditionals = fieldsHelper.GetMppingSql(list.Cast<object>().ToList(), mappings);
|
||||||
|
@@ -502,8 +502,8 @@ namespace ThingsGateway.SqlSugar
|
|||||||
totalNumber.Value = count;
|
totalNumber.Value = count;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<List<T>> SetContextAsync<ParameterT>(Expression<Func<T, object>> thisFiled1, Expression<Func<object>> mappingFiled1,
|
public async Task<List<T>> SetContextAsync<ParameterT>(Expression<Func<T, object>> thisField1, Expression<Func<object>> mappingField1,
|
||||||
Expression<Func<T, object>> thisFiled2, Expression<Func<object>> mappingFiled2,
|
Expression<Func<T, object>> thisField2, Expression<Func<object>> mappingField2,
|
||||||
ParameterT parameter)
|
ParameterT parameter)
|
||||||
{
|
{
|
||||||
if (parameter == null)
|
if (parameter == null)
|
||||||
@@ -515,22 +515,22 @@ ParameterT parameter)
|
|||||||
List<T> result = new List<T>();
|
List<T> result = new List<T>();
|
||||||
var queryableContext = this.Context.TempItems["Queryable_To_Context"] as MapperContext<ParameterT>;
|
var queryableContext = this.Context.TempItems["Queryable_To_Context"] as MapperContext<ParameterT>;
|
||||||
var list = queryableContext.list;
|
var list = queryableContext.list;
|
||||||
var key = thisFiled1.ToString() + mappingFiled1.ToString() +
|
var key = thisField1.ToString() + mappingField1.ToString() +
|
||||||
thisFiled2.ToString() + mappingFiled2.ToString() +
|
thisField2.ToString() + mappingField2.ToString() +
|
||||||
typeof(ParameterT).FullName + typeof(T).FullName;
|
typeof(ParameterT).FullName + typeof(T).FullName;
|
||||||
MappingFieldsHelper<ParameterT> fieldsHelper = new MappingFieldsHelper<ParameterT>();
|
MappingFieldsHelper<ParameterT> fieldsHelper = new MappingFieldsHelper<ParameterT>();
|
||||||
var mappings = new List<MappingFieldsExpression>() {
|
var mappings = new List<MappingFieldsExpression>() {
|
||||||
new MappingFieldsExpression(){
|
new MappingFieldsExpression(){
|
||||||
LeftColumnExpression=thisFiled1,
|
LeftColumnExpression=thisField1,
|
||||||
LeftEntityColumn=leftEntity.Columns.First(it=>it.PropertyName==ExpressionTool.GetMemberName(thisFiled1)),
|
LeftEntityColumn=leftEntity.Columns.First(it=>it.PropertyName==ExpressionTool.GetMemberName(thisField1)),
|
||||||
RightColumnExpression=mappingFiled1,
|
RightColumnExpression=mappingField1,
|
||||||
RightEntityColumn=rightEntity.Columns.First(it=>it.PropertyName==ExpressionTool.GetMemberName(mappingFiled1))
|
RightEntityColumn=rightEntity.Columns.First(it=>it.PropertyName==ExpressionTool.GetMemberName(mappingField1))
|
||||||
},
|
},
|
||||||
new MappingFieldsExpression(){
|
new MappingFieldsExpression(){
|
||||||
LeftColumnExpression=thisFiled2,
|
LeftColumnExpression=thisField2,
|
||||||
LeftEntityColumn=leftEntity.Columns.First(it=>it.PropertyName==ExpressionTool.GetMemberName(thisFiled2)),
|
LeftEntityColumn=leftEntity.Columns.First(it=>it.PropertyName==ExpressionTool.GetMemberName(thisField2)),
|
||||||
RightColumnExpression=mappingFiled2,
|
RightColumnExpression=mappingField2,
|
||||||
RightEntityColumn=rightEntity.Columns.First(it=>it.PropertyName==ExpressionTool.GetMemberName(mappingFiled2))
|
RightEntityColumn=rightEntity.Columns.First(it=>it.PropertyName==ExpressionTool.GetMemberName(mappingField2))
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
var conditionals = fieldsHelper.GetMppingSql(list.Cast<object>().ToList(), mappings);
|
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();
|
var newResult = fieldsHelper.GetSetList(obj, listObj, mappings).Select(it => (T)it).ToList();
|
||||||
return newResult;
|
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>();
|
List<T> result = new List<T>();
|
||||||
var entity = this.Context.EntityMaintenance.GetEntityInfo<ParameterT>();
|
var entity = this.Context.EntityMaintenance.GetEntityInfo<ParameterT>();
|
||||||
var queryableContext = this.Context.TempItems["Queryable_To_Context"] as MapperContext<ParameterT>;
|
var queryableContext = this.Context.TempItems["Queryable_To_Context"] as MapperContext<ParameterT>;
|
||||||
var list = queryableContext.list;
|
var list = queryableContext.list;
|
||||||
var pkName = "";
|
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
|
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();
|
var ids = list.Select(it => it.GetType().GetProperty(pkName).GetValue(it)).ToArray();
|
||||||
if (queryableContext.TempChildLists == null)
|
if (queryableContext.TempChildLists == null)
|
||||||
queryableContext.TempChildLists = new Dictionary<string, object>();
|
queryableContext.TempChildLists = new Dictionary<string, object>();
|
||||||
@@ -579,18 +579,18 @@ ParameterT parameter)
|
|||||||
queryableContext.TempChildLists = new Dictionary<string, object>();
|
queryableContext.TempChildLists = new Dictionary<string, object>();
|
||||||
await Context.Utilities.PageEachAsync(ids, 200, async pageIds =>
|
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);
|
}).ConfigureAwait(false);
|
||||||
queryableContext.TempChildLists[key] = result;
|
queryableContext.TempChildLists[key] = result;
|
||||||
}
|
}
|
||||||
var name = "";
|
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
|
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);
|
var pkValue = parameter.GetType().GetProperty(pkName).GetValue(parameter);
|
||||||
result = result.Where(it => it.GetType().GetProperty(name).GetValue(it).ObjToString() == pkValue.ObjToString()).ToList();
|
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;
|
var mapperFieldExp = mapperField as MemberExpression;
|
||||||
Check.Exception(mapperFieldExp.Type.IsClass(), ".Mapper() parameter error");
|
Check.Exception(mapperFieldExp.Type.IsClass(), ".Mapper() parameter error");
|
||||||
var objType = mapperObjectExp.Type;
|
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");
|
Check.Exception(objType != typeof(TObject) && objType != typeof(List<TObject>), ".Mapper() parameter error");
|
||||||
if (objType == typeof(List<TObject>))
|
if (objType == typeof(List<TObject>))
|
||||||
{
|
{
|
||||||
objType = typeof(TObject);
|
objType = typeof(TObject);
|
||||||
}
|
}
|
||||||
var filedName = mapperFieldExp.Member.Name;
|
var fieldName = mapperFieldExp.Member.Name;
|
||||||
var objName = mapperObjectExp.Member.Name;
|
var objName = mapperObjectExp.Member.Name;
|
||||||
var filedEntity = this.Context.EntityMaintenance.GetEntityInfo(objType);
|
var fieldEntity = this.Context.EntityMaintenance.GetEntityInfo(objType);
|
||||||
var objEntity = this.Context.EntityMaintenance.GetEntityInfo(filedType);
|
var objEntity = this.Context.EntityMaintenance.GetEntityInfo(fieldType);
|
||||||
var isSelf = filedType == typeof(T);
|
var isSelf = fieldType == typeof(T);
|
||||||
if (Mappers == null)
|
if (Mappers == null)
|
||||||
Mappers = new List<Action<List<T>>>();
|
Mappers = new List<Action<List<T>>>();
|
||||||
if (isSelf)
|
if (isSelf)
|
||||||
@@ -971,29 +971,29 @@ namespace ThingsGateway.SqlSugar
|
|||||||
{
|
{
|
||||||
if (entitys.IsNullOrEmpty() || entitys.Count == 0) return;
|
if (entitys.IsNullOrEmpty() || entitys.Count == 0) return;
|
||||||
var entity = entitys.First();
|
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)
|
if (whereCol == null)
|
||||||
{
|
{
|
||||||
whereCol = filedEntity.Columns.FirstOrDefault(it => it.IsPrimarykey == true);
|
whereCol = fieldEntity.Columns.FirstOrDefault(it => it.IsPrimarykey == true);
|
||||||
}
|
}
|
||||||
if (whereCol == null)
|
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)
|
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)
|
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)
|
if (whereCol == null)
|
||||||
{
|
{
|
||||||
Check.Exception(true, ".Mapper() parameter error");
|
Check.Exception(true, ".Mapper() parameter error");
|
||||||
}
|
}
|
||||||
List<string> inValues = entitys.Select(it => it.GetType().GetProperty(filedName).GetValue(it, null).ObjToString()).ToList();
|
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(filedName).PropertyType) == UtilConstants.GuidType)
|
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();
|
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();
|
var list = this.Context.Queryable<TObject>().Where(wheres).ToList();
|
||||||
foreach (var item in entitys)
|
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 setValue = list.Where(x => x.GetType().GetProperty(whereCol.PropertyName).GetValue(x, null).ObjToString() == whereValue.ObjToString()).ToList();
|
||||||
var setObject = item.GetType().GetProperty(objName);
|
var setObject = item.GetType().GetProperty(objName);
|
||||||
if (setObject.PropertyType.FullName.IsCollectionsList())
|
if (setObject.PropertyType.FullName.IsCollectionsList())
|
||||||
@@ -1032,7 +1032,7 @@ namespace ThingsGateway.SqlSugar
|
|||||||
if (entitys.IsNullOrEmpty() || entitys.Count == 0) return;
|
if (entitys.IsNullOrEmpty() || entitys.Count == 0) return;
|
||||||
var entity = entitys.First();
|
var entity = entitys.First();
|
||||||
var tEntity = this.Context.EntityMaintenance.GetEntityInfo<T>();
|
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)
|
if (whereCol == null)
|
||||||
{
|
{
|
||||||
whereCol = tEntity.Columns.FirstOrDefault(it => it.IsPrimarykey == true);
|
whereCol = tEntity.Columns.FirstOrDefault(it => it.IsPrimarykey == true);
|
||||||
@@ -1054,7 +1054,7 @@ namespace ThingsGateway.SqlSugar
|
|||||||
Check.Exception(true, ".Mapper() parameter error");
|
Check.Exception(true, ".Mapper() parameter error");
|
||||||
}
|
}
|
||||||
List<string> inValues = entitys.Select(it => it.GetType().GetProperty(whereCol.PropertyName).GetValue(it, null).ObjToString()).ToList();
|
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>()
|
List<IConditionalModel> wheres = new List<IConditionalModel>()
|
||||||
{
|
{
|
||||||
new ConditionalModel()
|
new ConditionalModel()
|
||||||
@@ -1068,7 +1068,7 @@ namespace ThingsGateway.SqlSugar
|
|||||||
foreach (var item in entitys)
|
foreach (var item in entitys)
|
||||||
{
|
{
|
||||||
var whereValue = item.GetType().GetProperty(whereCol.PropertyName).GetValue(item, null);
|
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);
|
var setObject = item.GetType().GetProperty(objName);
|
||||||
if (setObject.PropertyType.FullName.IsCollectionsList())
|
if (setObject.PropertyType.FullName.IsCollectionsList())
|
||||||
{
|
{
|
||||||
@@ -1118,18 +1118,18 @@ namespace ThingsGateway.SqlSugar
|
|||||||
Check.Exception(mainFieldExp.Type.IsClass(), ".Mapper() parameter error");
|
Check.Exception(mainFieldExp.Type.IsClass(), ".Mapper() parameter error");
|
||||||
Check.Exception(childFieldExp.Type.IsClass(), ".Mapper() parameter error");
|
Check.Exception(childFieldExp.Type.IsClass(), ".Mapper() parameter error");
|
||||||
var objType = mapperObjectExp.Type;
|
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");
|
Check.Exception(objType != typeof(TObject) && objType != typeof(List<TObject>), ".Mapper() parameter error");
|
||||||
if (objType == typeof(List<TObject>))
|
if (objType == typeof(List<TObject>))
|
||||||
{
|
{
|
||||||
objType = typeof(TObject);
|
objType = typeof(TObject);
|
||||||
}
|
}
|
||||||
var mainFiledName = mainFieldExp.Member.Name;
|
var mainFieldName = mainFieldExp.Member.Name;
|
||||||
var childFiledName = childFieldExp.Member.Name;
|
var childFieldName = childFieldExp.Member.Name;
|
||||||
var objName = mapperObjectExp.Member.Name;
|
var objName = mapperObjectExp.Member.Name;
|
||||||
var filedEntity = this.Context.EntityMaintenance.GetEntityInfo(objType);
|
var fieldEntity = this.Context.EntityMaintenance.GetEntityInfo(objType);
|
||||||
var objEntity = this.Context.EntityMaintenance.GetEntityInfo(filedType);
|
var objEntity = this.Context.EntityMaintenance.GetEntityInfo(fieldType);
|
||||||
var isSelf = filedType == typeof(T);
|
var isSelf = fieldType == typeof(T);
|
||||||
if (Mappers == null)
|
if (Mappers == null)
|
||||||
Mappers = new List<Action<List<T>>>();
|
Mappers = new List<Action<List<T>>>();
|
||||||
if (isSelf)
|
if (isSelf)
|
||||||
@@ -1138,28 +1138,28 @@ namespace ThingsGateway.SqlSugar
|
|||||||
{
|
{
|
||||||
if (entitys.IsNullOrEmpty() || entitys.Count == 0) return;
|
if (entitys.IsNullOrEmpty() || entitys.Count == 0) return;
|
||||||
var entity = entitys.First();
|
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)
|
if (whereCol == null)
|
||||||
{
|
{
|
||||||
whereCol = filedEntity.Columns.FirstOrDefault(it => it.IsPrimarykey == true);
|
whereCol = fieldEntity.Columns.FirstOrDefault(it => it.IsPrimarykey == true);
|
||||||
}
|
}
|
||||||
if (whereCol == null)
|
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)
|
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)
|
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)
|
if (whereCol == null)
|
||||||
{
|
{
|
||||||
Check.Exception(true, ".Mapper() parameter error");
|
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>()
|
List<IConditionalModel> wheres = new List<IConditionalModel>()
|
||||||
{
|
{
|
||||||
new ConditionalModel()
|
new ConditionalModel()
|
||||||
@@ -1172,7 +1172,7 @@ namespace ThingsGateway.SqlSugar
|
|||||||
var list = this.Context.Queryable<TObject>().Where(wheres).ToList();
|
var list = this.Context.Queryable<TObject>().Where(wheres).ToList();
|
||||||
foreach (var item in entitys)
|
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 setValue = list.Where(x => x.GetType().GetProperty(whereCol.PropertyName).GetValue(x, null).ObjToString() == whereValue.ObjToString()).ToList();
|
||||||
var setObject = item.GetType().GetProperty(objName);
|
var setObject = item.GetType().GetProperty(objName);
|
||||||
if (setObject.PropertyType.FullName.IsCollectionsList())
|
if (setObject.PropertyType.FullName.IsCollectionsList())
|
||||||
@@ -1194,7 +1194,7 @@ namespace ThingsGateway.SqlSugar
|
|||||||
if (entitys.IsNullOrEmpty() || entitys.Count == 0) return;
|
if (entitys.IsNullOrEmpty() || entitys.Count == 0) return;
|
||||||
var entity = entitys.First();
|
var entity = entitys.First();
|
||||||
var tEntity = this.Context.EntityMaintenance.GetEntityInfo<T>();
|
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)
|
if (whereCol == null)
|
||||||
{
|
{
|
||||||
whereCol = tEntity.Columns.FirstOrDefault(it => it.IsPrimarykey == true);
|
whereCol = tEntity.Columns.FirstOrDefault(it => it.IsPrimarykey == true);
|
||||||
@@ -1216,7 +1216,7 @@ namespace ThingsGateway.SqlSugar
|
|||||||
Check.Exception(true, ".Mapper() parameter error");
|
Check.Exception(true, ".Mapper() parameter error");
|
||||||
}
|
}
|
||||||
List<string> inValues = entitys.Select(it => it.GetType().GetProperty(whereCol.PropertyName).GetValue(it, null).ObjToString()).ToList();
|
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>()
|
List<IConditionalModel> wheres = new List<IConditionalModel>()
|
||||||
{
|
{
|
||||||
new ConditionalModel()
|
new ConditionalModel()
|
||||||
@@ -1230,7 +1230,7 @@ namespace ThingsGateway.SqlSugar
|
|||||||
foreach (var item in entitys)
|
foreach (var item in entitys)
|
||||||
{
|
{
|
||||||
var whereValue = item.GetType().GetProperty(whereCol.PropertyName).GetValue(item, null);
|
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);
|
var setObject = item.GetType().GetProperty(objName);
|
||||||
if (setObject.PropertyType.FullName.IsCollectionsList())
|
if (setObject.PropertyType.FullName.IsCollectionsList())
|
||||||
{
|
{
|
||||||
@@ -1612,8 +1612,8 @@ namespace ThingsGateway.SqlSugar
|
|||||||
result.SqlBuilder = this.SqlBuilder;
|
result.SqlBuilder = this.SqlBuilder;
|
||||||
result.SqlBuilder.QueryBuilder.Parameters = QueryBuilder.Parameters;
|
result.SqlBuilder.QueryBuilder.Parameters = QueryBuilder.Parameters;
|
||||||
result.SqlBuilder.QueryBuilder.SelectValue = expression;
|
result.SqlBuilder.QueryBuilder.SelectValue = expression;
|
||||||
result.SqlBuilder.QueryBuilder.IsSelectSingleFiledJson = UtilMethods.IsJsonMember(expression, this.Context);
|
result.SqlBuilder.QueryBuilder.IsSelectSingleFieldJson = UtilMethods.IsJsonMember(expression, this.Context);
|
||||||
result.SqlBuilder.QueryBuilder.IsSelectSingleFiledArray = UtilMethods.IsArrayMember(expression, this.Context);
|
result.SqlBuilder.QueryBuilder.IsSelectSingleFieldArray = UtilMethods.IsArrayMember(expression, this.Context);
|
||||||
if (this.IsCache)
|
if (this.IsCache)
|
||||||
{
|
{
|
||||||
result.WithCache(this.CacheTime);
|
result.WithCache(this.CacheTime);
|
||||||
@@ -1949,11 +1949,11 @@ namespace ThingsGateway.SqlSugar
|
|||||||
{
|
{
|
||||||
result = this.Context.Utilities.DataReaderToExpandoObjectList(dataReader).Select(it => ((TResult)(object)it)).ToList();
|
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);
|
result = this.Context.Utilities.DataReaderToSelectJsonList<TResult>(dataReader);
|
||||||
}
|
}
|
||||||
else if (QueryBuilder.IsSelectSingleFiledArray)
|
else if (QueryBuilder.IsSelectSingleFieldArray)
|
||||||
{
|
{
|
||||||
result = this.Context.Utilities.DataReaderToSelectArrayList<TResult>(dataReader);
|
result = this.Context.Utilities.DataReaderToSelectArrayList<TResult>(dataReader);
|
||||||
}
|
}
|
||||||
@@ -1995,11 +1995,11 @@ namespace ThingsGateway.SqlSugar
|
|||||||
var expObj = await Context.Utilities.DataReaderToExpandoObjectListAsync(dataReader).ConfigureAwait(false);
|
var expObj = await Context.Utilities.DataReaderToExpandoObjectListAsync(dataReader).ConfigureAwait(false);
|
||||||
result = expObj.Select(it => ((TResult)(object)it)).ToList();
|
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);
|
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);
|
result = await Context.Utilities.DataReaderToSelectArrayListAsync<TResult>(dataReader).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
@@ -474,7 +474,7 @@ namespace ThingsGateway.SqlSugar
|
|||||||
var bEntity = this.Context.EntityMaintenance.GetEntityInfo(bType);
|
var bEntity = this.Context.EntityMaintenance.GetEntityInfo(bType);
|
||||||
var bProperty = bEntity.Columns.FirstOrDefault(it => it.IsPrimarykey == true)?.PropertyName;
|
var bProperty = bEntity.Columns.FirstOrDefault(it => it.IsPrimarykey == true)?.PropertyName;
|
||||||
Check.Exception(bProperty == null, bEntity.EntityName + " no primary key");
|
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) =>
|
this.Mapper((it, cache) =>
|
||||||
{
|
{
|
||||||
var list = cache.Get<Dictionary<object, List<BType>>>(oldList =>
|
var list = cache.Get<Dictionary<object, List<BType>>>(oldList =>
|
||||||
@@ -496,7 +496,7 @@ namespace ThingsGateway.SqlSugar
|
|||||||
cons = new List<IConditionalModel>() {
|
cons = new List<IConditionalModel>() {
|
||||||
new ConditionalModel(){
|
new ConditionalModel(){
|
||||||
ConditionalType=ConditionalType.In,
|
ConditionalType=ConditionalType.In,
|
||||||
FieldName= bDbFiled,
|
FieldName= bDbField,
|
||||||
FieldValue=string.Join(",",mappingList.Select(z=>UtilMethods.GetPropertyValue(z,m_bPropertyName)).Distinct())
|
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();
|
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");
|
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 + ".");
|
string shortName = QueryBuilder.TableShortName == null ? null : (QueryBuilder.TableShortName + ".");
|
||||||
filed = shortName + filed;
|
field = shortName + field;
|
||||||
return In(filed, pkValues);
|
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)
|
if (inValues.Length == 1)
|
||||||
{
|
{
|
||||||
@@ -1153,7 +1153,7 @@ namespace ThingsGateway.SqlSugar
|
|||||||
var whereIndex = QueryBuilder.WhereIndex;
|
var whereIndex = QueryBuilder.WhereIndex;
|
||||||
string parameterName = this.SqlBuilder.SqlParameterKeyWord + "InPara" + whereIndex;
|
string parameterName = this.SqlBuilder.SqlParameterKeyWord + "InPara" + whereIndex;
|
||||||
this.AddParameters(new SugarParameter(parameterName, inValues[0]));
|
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++;
|
QueryBuilder.WhereIndex++;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -1166,7 +1166,7 @@ namespace ThingsGateway.SqlSugar
|
|||||||
values.Add(item.ToString().ToSqlValue());
|
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
|
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;
|
return this;
|
||||||
@@ -1395,15 +1395,15 @@ namespace ThingsGateway.SqlSugar
|
|||||||
return this;
|
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;
|
var croupByValue = QueryBuilder.GroupByValue;
|
||||||
if (QueryBuilder.GroupByValue.IsNullOrEmpty())
|
if (QueryBuilder.GroupByValue.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
QueryBuilder.GroupByValue = QueryBuilder.GroupByTemplate;
|
QueryBuilder.GroupByValue = QueryBuilder.GroupByTemplate;
|
||||||
}
|
}
|
||||||
QueryBuilder.GroupByValue += string.IsNullOrEmpty(croupByValue) ? groupFileds : ("," + groupFileds);
|
QueryBuilder.GroupByValue += string.IsNullOrEmpty(croupByValue) ? groupFields : ("," + groupFields);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1415,14 +1415,14 @@ namespace ThingsGateway.SqlSugar
|
|||||||
QueryBuilder.DisableTop = true;
|
QueryBuilder.DisableTop = true;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
public virtual ISugarQueryable<T> PartitionBy(string groupFileds)
|
public virtual ISugarQueryable<T> PartitionBy(string groupFields)
|
||||||
{
|
{
|
||||||
var partitionByValue = QueryBuilder.PartitionByValue;
|
var partitionByValue = QueryBuilder.PartitionByValue;
|
||||||
if (QueryBuilder.PartitionByValue.IsNullOrEmpty())
|
if (QueryBuilder.PartitionByValue.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
QueryBuilder.PartitionByValue = QueryBuilder.PartitionByTemplate;
|
QueryBuilder.PartitionByValue = QueryBuilder.PartitionByTemplate;
|
||||||
}
|
}
|
||||||
QueryBuilder.PartitionByValue += string.IsNullOrEmpty(partitionByValue) ? groupFileds : ("," + groupFileds);
|
QueryBuilder.PartitionByValue += string.IsNullOrEmpty(partitionByValue) ? groupFields : ("," + groupFields);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -435,9 +435,9 @@ namespace ThingsGateway.SqlSugar
|
|||||||
QueryBuilder.DisableTop = true;
|
QueryBuilder.DisableTop = true;
|
||||||
return this;
|
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;
|
return this;
|
||||||
}
|
}
|
||||||
public new virtual ISugarQueryable<T, T2> GroupByIF(bool isGroupBy, Expression<Func<T, object>> expression)
|
public new virtual ISugarQueryable<T, T2> GroupByIF(bool isGroupBy, Expression<Func<T, object>> expression)
|
||||||
@@ -1010,9 +1010,9 @@ namespace ThingsGateway.SqlSugar
|
|||||||
QueryBuilder.DisableTop = true;
|
QueryBuilder.DisableTop = true;
|
||||||
return this;
|
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;
|
return this;
|
||||||
}
|
}
|
||||||
public new virtual ISugarQueryable<T, T2, T3> GroupByIF(bool isGroupBy, Expression<Func<T, object>> expression)
|
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; }
|
set { _WhereInfos = value; }
|
||||||
}
|
}
|
||||||
public virtual List<object> BigDataInValues { get; set; }
|
public virtual List<object> BigDataInValues { get; set; }
|
||||||
public virtual string BigDataFiled { get; set; }
|
public virtual string BigDataField { get; set; }
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Sql Template
|
#region Sql Template
|
||||||
@@ -136,7 +136,7 @@ namespace ThingsGateway.SqlSugar
|
|||||||
while (pageCount >= pageIndex)
|
while (pageCount >= pageIndex)
|
||||||
{
|
{
|
||||||
var inValues = this.BigDataInValues.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
|
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(';');
|
batchDeleteSql.Append(';');
|
||||||
pageIndex++;
|
pageIndex++;
|
||||||
}
|
}
|
||||||
|
@@ -13,7 +13,7 @@ namespace ThingsGateway.SqlSugar
|
|||||||
this.Parameters = new List<SugarParameter>();
|
this.Parameters = new List<SugarParameter>();
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Private Fileds
|
#region Private Fields
|
||||||
protected List<JoinQueryInfo> _JoinQueryInfos;
|
protected List<JoinQueryInfo> _JoinQueryInfos;
|
||||||
protected Dictionary<string, string> _EasyJoinInfos;
|
protected Dictionary<string, string> _EasyJoinInfos;
|
||||||
private List<string> _WhereInfos;
|
private List<string> _WhereInfos;
|
||||||
@@ -42,8 +42,8 @@ namespace ThingsGateway.SqlSugar
|
|||||||
internal List<List<QueryableAppendColumn>> AppendValues { get; set; }
|
internal List<List<QueryableAppendColumn>> AppendValues { get; set; }
|
||||||
public bool IsCrossQueryWithAttr { get; set; }
|
public bool IsCrossQueryWithAttr { get; set; }
|
||||||
public Dictionary<string, string> CrossQueryItems { get; set; }
|
public Dictionary<string, string> CrossQueryItems { get; set; }
|
||||||
public bool IsSelectSingleFiledJson { get; set; }
|
public bool IsSelectSingleFieldJson { get; set; }
|
||||||
public bool IsSelectSingleFiledArray { get; set; }
|
public bool IsSelectSingleFieldArray { get; set; }
|
||||||
public string TranLock { get; set; }
|
public string TranLock { get; set; }
|
||||||
public bool IsDisableMasterSlaveSeparation { get; set; }
|
public bool IsDisableMasterSlaveSeparation { get; set; }
|
||||||
public bool IsEnableMasterSlaveSeparation { get; set; }
|
public bool IsEnableMasterSlaveSeparation { get; set; }
|
||||||
|
@@ -7,8 +7,8 @@ namespace ThingsGateway.SqlSugar
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class SqlSugarScope : ISqlSugarClient, ITenant
|
public partial class SqlSugarScope : ISqlSugarClient, ITenant
|
||||||
{
|
{
|
||||||
private List<ConnectionConfig> _configs;
|
protected List<ConnectionConfig> _configs;
|
||||||
private Action<SqlSugarClient> _configAction;
|
protected Action<SqlSugarClient> _configAction;
|
||||||
|
|
||||||
protected virtual SqlSugarClient GetContext()
|
protected virtual SqlSugarClient GetContext()
|
||||||
{
|
{
|
||||||
|
@@ -54,12 +54,7 @@ namespace ThingsGateway.SqlSugar
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Util Methods
|
#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
|
public virtual IContextMethods Utilities
|
||||||
{
|
{
|
||||||
get
|
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不能使用");
|
Check.ExceptionEasy(" var childDb=Db.GetConnection(configId); use Db.CreateContext ", " 例如 var childDb=Db.GetConnection(configId);其中Db才能使用CreateContext,childDb不能使用");
|
||||||
return null;
|
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()
|
public virtual SimpleClient<T> GetSimpleClient<T>() where T : class, new()
|
||||||
{
|
{
|
||||||
return new SimpleClient<T>(this);
|
return new SimpleClient<T>(this);
|
||||||
|
@@ -445,7 +445,7 @@ namespace ThingsGateway.SqlSugar
|
|||||||
}
|
}
|
||||||
return this;
|
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)
|
if (UpdateParameterIsNull == true)
|
||||||
{
|
{
|
||||||
@@ -453,10 +453,10 @@ namespace ThingsGateway.SqlSugar
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var name = ExpressionTool.GetMemberName(filedNameExpression);
|
var name = ExpressionTool.GetMemberName(fieldNameExpression);
|
||||||
if (name == null)
|
if (name == null)
|
||||||
{
|
{
|
||||||
Check.ExceptionEasy(filedNameExpression + " format error ", filedNameExpression + "参数格式错误");
|
Check.ExceptionEasy(fieldNameExpression + " format error ", fieldNameExpression + "参数格式错误");
|
||||||
}
|
}
|
||||||
//var value = this.UpdateBuilder.GetExpressionValue(ValueExpExpression, ResolveExpressType.WhereSingle).GetResultString();
|
//var value = this.UpdateBuilder.GetExpressionValue(ValueExpExpression, ResolveExpressType.WhereSingle).GetResultString();
|
||||||
if (this.UpdateBuilder.ReSetValueBySqlExpList == null)
|
if (this.UpdateBuilder.ReSetValueBySqlExpList == null)
|
||||||
@@ -476,18 +476,18 @@ namespace ThingsGateway.SqlSugar
|
|||||||
return this;
|
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)
|
if (UpdateParameterIsNull == true)
|
||||||
{
|
{
|
||||||
return SetColumns(filedNameExpression, ValueExpExpression);
|
return SetColumns(fieldNameExpression, ValueExpExpression);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var name = ExpressionTool.GetMemberName(filedNameExpression);
|
var name = ExpressionTool.GetMemberName(fieldNameExpression);
|
||||||
if (name == null)
|
if (name == null)
|
||||||
{
|
{
|
||||||
Check.ExceptionEasy(filedNameExpression + " format error ", filedNameExpression + "参数格式错误");
|
Check.ExceptionEasy(fieldNameExpression + " format error ", fieldNameExpression + "参数格式错误");
|
||||||
}
|
}
|
||||||
var value = this.UpdateBuilder.GetExpressionValue(ValueExpExpression, ResolveExpressType.WhereSingle).GetResultString();
|
var value = this.UpdateBuilder.GetExpressionValue(ValueExpExpression, ResolveExpressType.WhereSingle).GetResultString();
|
||||||
if (this.UpdateBuilder.ReSetValueBySqlExpList == null)
|
if (this.UpdateBuilder.ReSetValueBySqlExpList == null)
|
||||||
@@ -712,24 +712,24 @@ namespace ThingsGateway.SqlSugar
|
|||||||
AppendSets();
|
AppendSets();
|
||||||
return this;
|
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)
|
if (isUpdateColumns)
|
||||||
{
|
{
|
||||||
return SetColumns(filedNameExpression, fieldValue);
|
return SetColumns(fieldNameExpression, fieldValue);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return this;
|
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)
|
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);
|
name = UpdateBuilder.Builder.GetTranslationColumnName(name);
|
||||||
var exp = ExpressionTool.RemoveConvert((valueExpression as LambdaExpression).Body);
|
var exp = ExpressionTool.RemoveConvert((valueExpression as LambdaExpression).Body);
|
||||||
var value = UpdateBuilder.GetExpressionValue(exp, ResolveExpressType.WhereSingle).GetString();
|
var value = UpdateBuilder.GetExpressionValue(exp, ResolveExpressType.WhereSingle).GetString();
|
||||||
@@ -749,9 +749,9 @@ namespace ThingsGateway.SqlSugar
|
|||||||
}
|
}
|
||||||
return this;
|
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);
|
name = UpdateBuilder.Builder.GetNoTranslationColumnName(name);
|
||||||
return SetColumns(name, fieldValue);
|
return SetColumns(name, fieldValue);
|
||||||
}
|
}
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user