Compare commits

...

18 Commits

Author SHA1 Message Date
2248356998 qq.com
aad0f0e8c3 fix: orm批量插入 2025-10-10 11:19:14 +08:00
2248356998 qq.com
e74eae50a7 build: 10.11.87 2025-10-09 20:58:16 +08:00
2248356998 qq.com
3b16d7019f feat: 优化orm 批量插入 2025-10-09 20:57:18 +08:00
2248356998 qq.com
3e038028c2 feat: 优化orm 批量插入 2025-10-09 19:19:18 +08:00
2248356998 qq.com
b1d8041f7e feat: 优化orm BulkCopy 2025-10-09 19:05:33 +08:00
2248356998 qq.com
53a98b26cd fix: 数据库插件保留天数逻辑错误 2025-10-09 08:52:02 +08:00
2248356998 qq.com
42c740fa1b 更新依赖 2025-10-07 22:25:38 +08:00
2248356998 qq.com
556819c90c 10.11.83 2025-09-30 15:25:15 +08:00
2248356998 qq.com
2522333a9c 更新依赖 2025-09-29 23:16:34 +08:00
2248356998 qq.com
bd4ce7c09b 适配net10 2025-09-29 17:47:24 +08:00
2248356998 qq.com
156ed88bd6 10.11.80 2025-09-29 17:09:12 +08:00
2248356998 qq.com
2416226eb0 10.11.78 2025-09-28 17:01:19 +08:00
2248356998 qq.com
976323a716 适配net10 2025-09-28 13:06:39 +08:00
2248356998 qq.com
3c9e397403 10.11.76 2025-09-28 00:33:56 +08:00
2248356998 qq.com
79406ad4a0 更新依赖 2025-09-27 23:59:38 +08:00
2248356998 qq.com
20c44f10ca 10.11.73 2025-09-27 20:18:56 +08:00
2248356998 qq.com
31d6b2a9e6 添加FastMapper 2025-09-26 15:24:37 +08:00
2248356998 qq.com
68e5a9c546 build: 10.11.71 2025-09-26 11:51:05 +08:00
370 changed files with 2731 additions and 1556 deletions

View File

@@ -45,6 +45,7 @@ public class VerificatInfo : PrimaryIdEntity
/// 登录IP
/// </summary>
[AutoGenerateColumn(Filterable = true, Sortable = true, Width = 200)]
[SugarColumn(IsNullable = true)]
public string LoginIp { get; set; }
/// <summary>
@@ -78,5 +79,6 @@ public class VerificatInfo : PrimaryIdEntity
/// 登录设备
/// </summary>
[AutoGenerateColumn(Filterable = true, Sortable = true, Width = 100)]
[SugarColumn(IsNullable = true)]
public string Device { get; set; }
}

View File

@@ -145,7 +145,7 @@ public class AdminOAuthHandler<TOptions>(
var loginEvent = new LoginEvent
{
Ip = appService.RemoteIpAddress,
Device = appService.UserAgent?.Platform,
Device = appService.UserAgent?.Platform ?? "Unknown",
Expire = expire,
SysUser = sysUser,
VerificatId = CommonUtils.GetSingleId()
@@ -156,7 +156,7 @@ public class AdminOAuthHandler<TOptions>(
//生成verificat信息
var verificatInfo = new VerificatInfo
{
Device = loginEvent.Device,
Device = loginEvent.Device ?? "Unknown",
Expire = loginEvent.Expire,
VerificatTimeout = tokenTimeout,
Id = loginEvent.VerificatId,

View File

@@ -26,7 +26,7 @@
"Module": 2,
"Title": "权限管理",
"Code": "System",
"NavLinkMatch": "All",
"NavLinkMatch": "Prefix",
"Category": "MENU",
"Target": "_self",
"Href": null,
@@ -47,7 +47,7 @@
"ParentId": 0,
"Module": 2,
"Title": "系统运维",
"NavLinkMatch": "All",
"NavLinkMatch": "Prefix",
"Code": "System",
"Category": "MENU",
"Target": "_self",

View File

@@ -235,7 +235,7 @@ public class AuthService : IAuthService
var logingEvent = new LoginEvent
{
Ip = _appService.RemoteIpAddress,
Device = _appService.UserAgent?.Platform,
Device = _appService.UserAgent?.Platform ?? "Unknown",
Expire = expire,
SysUser = sysUser,
VerificatId = verificatId
@@ -344,7 +344,7 @@ public class AuthService : IAuthService
//生成verificat信息
var verificatInfo = new VerificatInfo
{
Device = loginEvent.Device,
Device = loginEvent.Device ?? "Unknown",
Expire = loginEvent.Expire,
VerificatTimeout = tokenTimeout,
Id = loginEvent.VerificatId,

View File

@@ -125,13 +125,22 @@ public class BlazorAppContext
var ownMenus = OwnMenus.Where(a => a.Module == CurrentModuleId);
OwnMenuItems = AdminResourceUtil.BuildMenuTrees(ownMenus).ToList();
AllOwnMenuItems = AdminResourceUtil.BuildMenuTrees(OwnMenus).ToList();
OwnSameLevelMenuItems = ownMenus.Where(a => !a.Href.IsNullOrWhiteSpace()).Select(item => new MenuItem()
OwnSameLevelMenuItems = ownMenus.Where(a => !a.Href.IsNullOrWhiteSpace()).Select(item =>
{
Match = item.NavLinkMatch ?? Microsoft.AspNetCore.Components.Routing.NavLinkMatch.All,
Text = item.Title,
Icon = item.Icon,
Url = item.Href,
Target = item.Target.ToString(),
var menu = new MenuItem()
{
Match = item.NavLinkMatch ?? Microsoft.AspNetCore.Components.Routing.NavLinkMatch.Prefix,
Text = item.Title,
Icon = item.Icon,
Url = item.Href,
Target = item.Target.ToString(),
};
if (menu.Url.IsNullOrEmpty())
{
menu.Match = Microsoft.AspNetCore.Components.Routing.NavLinkMatch.Prefix;
}
return menu;
}).ToList();
UserWorkbenchOutputs = AllMenus.Where(it => UserWorkBench.Shortcuts.Contains(it.Id)).ToList();
}

View File

@@ -41,15 +41,22 @@ public static class AdminResourceUtil
return items
.Where(it => it.ParentId == parentId)
.Select((item, index) =>
new MenuItem()
{
var menu = new MenuItem()
{
Match = item.NavLinkMatch ?? Microsoft.AspNetCore.Components.Routing.NavLinkMatch.All,
Match = item.NavLinkMatch ?? Microsoft.AspNetCore.Components.Routing.NavLinkMatch.Prefix,
Text = item.Title,
Icon = item.Icon,
Url = item.Href,
Target = item.Target.ToString(),
Items = BuildMenuTrees(items, item.Id).ToList()
};
if (menu.Url.IsNullOrEmpty())
{
menu.Match = Microsoft.AspNetCore.Components.Routing.NavLinkMatch.Prefix;
}
return menu;
}
);
}

View File

@@ -21,12 +21,12 @@
<link rel="apple-touch-icon" href="favicon.png">
<base href="/" />
<title>ThingsGateway</title>
<link rel="stylesheet" href=@($"_content/BootstrapBlazor.FontAwesome/css/font-awesome.min.css?v={this.GetType().Assembly.GetName().Version}") />
<link rel="stylesheet" href=@($"_content/BootstrapBlazor/css/bootstrap.blazor.bundle.min.css?v={this.GetType().Assembly.GetName().Version}") />
<link rel="stylesheet" href=@($"_content/BootstrapBlazor/css/motronic.min.css?v={this.GetType().Assembly.GetName().Version}") />
<link rel="stylesheet" href=@($"ThingsGateway.AdminServer.styles.css?v={this.GetType().Assembly.GetName().Version}") />
<link rel="stylesheet" href=@($"{WebsiteConst.DefaultResourceUrl}css/site.css?v={this.GetType().Assembly.GetName().Version}") />
<link rel="stylesheet" href=@($"{WebsiteConst.DefaultResourceUrl}css/devui.css?v={this.GetType().Assembly.GetName().Version}") />
<link rel="stylesheet" href=@($"_content/BootstrapBlazor.FontAwesome/css/font-awesome.min.css") />
<link rel="stylesheet" href=@($"_content/BootstrapBlazor/css/bootstrap.blazor.bundle.min.css") />
<link rel="stylesheet" href=@($"_content/BootstrapBlazor/css/motronic.min.css") />
<link rel="stylesheet" href=@($"ThingsGateway.AdminServer.styles.css") />
<link rel="stylesheet" href=@($"{WebsiteConst.DefaultResourceUrl}css/site.css") />
<link rel="stylesheet" href=@($"{WebsiteConst.DefaultResourceUrl}css/devui.css") />
@* <script src=@($"{WebsiteConst.DefaultResourceUrl}js/theme.js") type="module"></script><!-- 初始主题 --> *@
<!-- PWA Manifest -->
@@ -40,8 +40,8 @@
<BlazorReconnector @rendermode="new InteractiveServerRenderMode(false)" />
<script src=@($"_content/BootstrapBlazor/js/bootstrap.blazor.bundle.min.js?v={this.GetType().Assembly.GetName().Version}")></script>
<script src=@($"{WebsiteConst.DefaultResourceUrl}js/localStorageUtil.js?v={this.GetType().Assembly.GetName().Version}")></script>
<script src=@($"_content/BootstrapBlazor/js/bootstrap.blazor.bundle.min.js")></script>
<script src=@($"{WebsiteConst.DefaultResourceUrl}js/localStorageUtil.js")></script>
<script src="_framework/blazor.web.js"></script>
<!-- PWA Service Worker -->
<script type="text/javascript">'serviceWorker' in navigator && navigator.serviceWorker.register('./service-worker.js')</script>

View File

@@ -70,7 +70,7 @@
<Button @onclick="ShowAbout" class="layout-header-bar d-none d-lg-flex px-2" Icon="fa fa-info" Color="Color.None" TooltipText="@Localizer[nameof(About)]" />
}
@* 版本号 *@
<div class="px-1 navbar-header-text d-none d-lg-block">@_versionString</div>
<div class="px-1 navbar-header-text text-nowrap d-none d-lg-block">@_versionString</div>
@* 主题切换 *@
@* <ThemeToggle /> *@

View File

@@ -16,6 +16,8 @@ using System.Runtime.CompilerServices;
using System.Text.Json;
using System.Text.RegularExpressions;
using ThingsGateway.Extension;
namespace ThingsGateway.Common.Extension;
/// <summary>
/// 对象拓展类
@@ -48,113 +50,7 @@ public static class ObjectExtensions
bool IsTheRawGenericType(Type type) => generic == (type.IsGenericType ? type.GetGenericTypeDefinition() : type);
}
/// <summary>
/// 将 DateTimeOffset 转换成本地 DateTime
/// </summary>
/// <param name="dateTime"></param>
/// <returns></returns>
public static DateTime ConvertToDateTime(this DateTimeOffset dateTime)
{
if (dateTime.Offset.Equals(TimeSpan.Zero))
return dateTime.UtcDateTime;
if (dateTime.Offset.Equals(TimeZoneInfo.Local.GetUtcOffset(dateTime.DateTime)))
return dateTime.ToLocalTime().DateTime;
else
return dateTime.DateTime;
}
/// <summary>
/// 将 DateTimeOffset? 转换成本地 DateTime?
/// </summary>
/// <param name="dateTime"></param>
/// <returns></returns>
public static DateTime? ConvertToDateTime(this DateTimeOffset? dateTime)
{
return dateTime.HasValue ? dateTime.Value.ConvertToDateTime() : null;
}
/// <summary>
/// 将 DateTime 转换成 DateTimeOffset
/// </summary>
/// <param name="dateTime"></param>
/// <returns></returns>
public static DateTimeOffset ConvertToDateTimeOffset(this DateTime dateTime)
{
return DateTime.SpecifyKind(dateTime, DateTimeKind.Local);
}
/// <summary>
/// 将 DateTime? 转换成 DateTimeOffset?
/// </summary>
/// <param name="dateTime"></param>
/// <returns></returns>
public static DateTimeOffset? ConvertToDateTimeOffset(this DateTime? dateTime)
{
return dateTime.HasValue ? dateTime.Value.ConvertToDateTimeOffset() : null;
}
/// <summary>
/// 将流保存到本地磁盘
/// </summary>
/// <param name="stream"></param>
/// <param name="path"></param>
/// <returns></returns>
public static void CopyToSave(this Stream stream, string path)
{
// 空检查
if (string.IsNullOrWhiteSpace(path)) throw new ArgumentNullException(nameof(path));
using var fileStream = File.Create(path);
stream.CopyTo(fileStream);
}
/// <summary>
/// 将字节数组保存到本地磁盘
/// </summary>
/// <param name="bytes"></param>
/// <param name="path"></param>
/// <returns></returns>
public static void CopyToSave(this byte[] bytes, string path)
{
using var stream = new MemoryStream(bytes);
stream.CopyToSave(path);
}
/// <summary>
/// 将流保存到本地磁盘
/// </summary>
/// <param name="stream"></param>
/// <param name="path">需包含文件名完整路径</param>
/// <returns></returns>
public static async Task CopyToSaveAsync(this Stream stream, string path)
{
// 空检查
if (string.IsNullOrWhiteSpace(path))
{
throw new ArgumentNullException(nameof(path));
}
// 文件名判断
if (string.IsNullOrWhiteSpace(Path.GetFileName(path)))
{
throw new ArgumentException("The parameter of <path> parameter must include the complete file name.");
}
using var fileStream = File.Create(path);
await stream.CopyToAsync(fileStream).ConfigureAwait(false);
}
/// <summary>
/// 将字节数组保存到本地磁盘
/// </summary>
/// <param name="bytes"></param>
/// <param name="path"></param>
/// <returns></returns>
public static async Task CopyToSaveAsync(this byte[] bytes, string path)
{
using var stream = new MemoryStream(bytes);
await stream.CopyToSaveAsync(path).ConfigureAwait(false);
}
/// <summary>
/// 合并两个字典

View File

@@ -12,9 +12,9 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="BootstrapBlazor.TableExport" Version="9.2.6" />
<PackageReference Include="BootstrapBlazor.TableExport" Version="9.2.7" />
<PackageReference Include="Yitter.IdGenerator" Version="1.0.14" />
<PackageReference Include="BootstrapBlazor" Version="9.10.2" />
<PackageReference Include="BootstrapBlazor" Version="9.11.1" />
</ItemGroup>
<ItemGroup>

View File

@@ -12,7 +12,7 @@
using Microsoft.AspNetCore.Hosting;
using ThingsGateway;
using ThingsGateway.Extensions;
using ThingsGateway.Extension;
using ThingsGateway.Reflection;
namespace Microsoft.Extensions.Hosting;

View File

@@ -20,7 +20,7 @@ using System.Text.RegularExpressions;
using ThingsGateway.NewLife;
namespace ThingsGateway.Extensions;
namespace ThingsGateway.Extension;
/// <summary>
/// 对象拓展类
@@ -28,70 +28,10 @@ namespace ThingsGateway.Extensions;
[SuppressSniffer]
public static class ObjectExtensions
{
/// <summary>
/// 将 DateTimeOffset 转换成本地 DateTime
/// </summary>
/// <param name="dateTime"></param>
/// <returns></returns>
public static DateTime ConvertToDateTime(this DateTimeOffset dateTime)
{
if (dateTime.Offset.Equals(TimeSpan.Zero))
return dateTime.UtcDateTime;
if (dateTime.Offset.Equals(TimeZoneInfo.Local.GetUtcOffset(dateTime.DateTime)))
return dateTime.ToLocalTime().DateTime;
else
return dateTime.DateTime;
}
/// <summary>
/// 将 DateTimeOffset? 转换成本地 DateTime?
/// </summary>
/// <param name="dateTime"></param>
/// <returns></returns>
public static DateTime? ConvertToDateTime(this DateTimeOffset? dateTime)
{
return dateTime.HasValue ? dateTime.Value.ConvertToDateTime() : null;
}
/// <summary>
/// 将 DateTime 转换成 DateTimeOffset
/// </summary>
/// <param name="dateTime"></param>
/// <returns></returns>
public static DateTimeOffset ConvertToDateTimeOffset(this DateTime dateTime)
{
return DateTime.SpecifyKind(dateTime, DateTimeKind.Local);
}
/// <summary>
/// 将 DateTime? 转换成 DateTimeOffset?
/// </summary>
/// <param name="dateTime"></param>
/// <returns></returns>
public static DateTimeOffset? ConvertToDateTimeOffset(this DateTime? dateTime)
{
return dateTime.HasValue ? dateTime.Value.ConvertToDateTimeOffset() : null;
}
/// <summary>
/// 将时间戳转换为 DateTime
/// </summary>
/// <param name="timestamp"></param>
/// <returns></returns>
internal static DateTime ConvertToDateTime(this long timestamp)
{
var timeStampDateTime = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
var digitCount = (int)Math.Floor(Math.Log10(timestamp) + 1);
if (digitCount != 13 && digitCount != 10)
{
throw new ArgumentException("Data is not a valid timestamp format.");
}
return (digitCount == 13
? timeStampDateTime.AddMilliseconds(timestamp) // 13 位时间戳
: timeStampDateTime.AddSeconds(timestamp)).ToLocalTime(); // 10 位时间戳
}
/// <summary>
/// 将 IFormFile 转换成 byte[]

View File

@@ -11,7 +11,7 @@
using Microsoft.AspNetCore.Mvc.ModelBinding;
using ThingsGateway.Extensions;
using ThingsGateway.Extension;
namespace ThingsGateway.AspNetCore;

View File

@@ -11,7 +11,7 @@
using Microsoft.AspNetCore.Mvc.ModelBinding;
using ThingsGateway.Extensions;
using ThingsGateway.Extension;
namespace ThingsGateway.AspNetCore;

View File

@@ -12,7 +12,7 @@
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.AspNetCore.Mvc.ModelBinding.Metadata;
using ThingsGateway.Extensions;
using ThingsGateway.Extension;
namespace ThingsGateway.AspNetCore;

View File

@@ -18,7 +18,7 @@ using System.Reflection;
using ThingsGateway;
using ThingsGateway.ConfigurableOptions;
using ThingsGateway.Extensions;
using ThingsGateway.Extension;
namespace Microsoft.Extensions.DependencyInjection;

View File

@@ -10,7 +10,6 @@
// ------------------------------------------------------------------------
using System.Security.Cryptography;
using System.Text;
namespace ThingsGateway.DataEncryption;
@@ -36,7 +35,7 @@ public static class PBKDF2Encryption
var salt = new byte[saltSize];
rng.GetBytes(salt);
#if NET10_0_OR_GREATER
var hash = Rfc2898DeriveBytes.Pbkdf2(Encoding.UTF8.GetBytes(text), salt, iterationCount, HashAlgorithmName.SHA256, derivedKeyLength);
var hash = Rfc2898DeriveBytes.Pbkdf2(System.Text.Encoding.UTF8.GetBytes(text), salt, iterationCount, HashAlgorithmName.SHA256, derivedKeyLength);
#else
using var pbkdf2 = new Rfc2898DeriveBytes(text, salt, iterationCount, HashAlgorithmName.SHA256);
var hash = pbkdf2.GetBytes(derivedKeyLength);
@@ -70,10 +69,10 @@ public static class PBKDF2Encryption
return false;
#if NET10_0_OR_GREATER
var computedHash = Rfc2898DeriveBytes.Pbkdf2(Encoding.UTF8.GetBytes(text), saltBytes, iterationCount, HashAlgorithmName.SHA256, derivedKeyLength);
var computedHash = Rfc2898DeriveBytes.Pbkdf2(System.Text.Encoding.UTF8.GetBytes(text), saltBytes, iterationCount, HashAlgorithmName.SHA256, derivedKeyLength);
#else
using var pbkdf2 = new Rfc2898DeriveBytes(text, saltBytes, iterationCount, HashAlgorithmName.SHA256);
var computedHash = pbkdf2.GetBytes(derivedKeyLength);
using var pbkdf2 = new Rfc2898DeriveBytes(text, saltBytes, iterationCount, HashAlgorithmName.SHA256);
var computedHash = pbkdf2.GetBytes(derivedKeyLength);
#endif
return computedHash.SequenceEqual(storedHashBytes);

View File

@@ -16,7 +16,7 @@ using System.ComponentModel.DataAnnotations;
using System.Reflection;
using System.Text.RegularExpressions;
using ThingsGateway.Extensions;
using ThingsGateway.Extension;
using ThingsGateway.Templates.Extensions;
namespace ThingsGateway.DataValidation;

View File

@@ -21,7 +21,7 @@ using System.Collections.Concurrent;
using System.Reflection;
using System.Text.RegularExpressions;
using ThingsGateway.Extensions;
using ThingsGateway.Extension;
using ThingsGateway.UnifyResult;
namespace ThingsGateway.DynamicApiController;

View File

@@ -17,7 +17,7 @@ using System.ComponentModel.DataAnnotations;
using System.Diagnostics;
using System.Reflection;
using ThingsGateway.Extensions;
using ThingsGateway.Extension;
using ThingsGateway.Templates.Extensions;
namespace ThingsGateway.FriendlyException;

View File

@@ -16,7 +16,7 @@ using Microsoft.AspNetCore.SignalR;
using System.Reflection;
using ThingsGateway;
using ThingsGateway.Extensions;
using ThingsGateway.Extension;
using ThingsGateway.InstantMessaging;
namespace Microsoft.AspNetCore.Builder;

View File

@@ -9,7 +9,7 @@
// 许可证的完整文本可以在源代码树根目录中的 LICENSE-APACHE 和 LICENSE-MIT 文件中找到。
// ------------------------------------------------------------------------
using ThingsGateway.Extensions;
using ThingsGateway.Extension;
namespace ThingsGateway.Logging;

View File

@@ -36,7 +36,7 @@ using System.Text.Json;
using ThingsGateway;
using ThingsGateway.DataValidation;
using ThingsGateway.Extensions;
using ThingsGateway.Extension;
using ThingsGateway.FriendlyException;
using ThingsGateway.JsonSerialization;
using ThingsGateway.Logging;

View File

@@ -16,7 +16,7 @@ using Microsoft.Extensions.DependencyInjection.Extensions;
using System.Linq.Expressions;
using System.Reflection;
using ThingsGateway.Extensions;
using ThingsGateway.Extension;
using ThingsGateway.Options;
namespace Microsoft.Extensions.Options;

View File

@@ -204,7 +204,7 @@ internal sealed partial class SchedulerFactory : ISchedulerFactory
}
else
{
_logger.LogWarning("Schedule hosted service preload completed, and a total of <{Count}> schedulers are appended.", _schedulers.Count);
_logger.LogInformation("Schedule hosted service preload completed, and a total of <{Count}> schedulers are appended.", _schedulers.Count);
}
}
}

View File

@@ -31,7 +31,7 @@ using System.Xml.Linq;
using System.Xml.XPath;
using ThingsGateway.DynamicApiController;
using ThingsGateway.Extensions;
using ThingsGateway.Extension;
using ThingsGateway.Reflection;
namespace ThingsGateway.SpecificationDocument;

View File

@@ -20,7 +20,7 @@ using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using ThingsGateway.Extensions;
using ThingsGateway.Extension;
namespace ThingsGateway.SpecificationDocument;

View File

@@ -11,7 +11,7 @@
using System.Text.RegularExpressions;
using ThingsGateway.Extensions;
using ThingsGateway.Extension;
namespace ThingsGateway.Templates.Extensions;

View File

@@ -29,7 +29,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore" Version="9.0.4" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="9.0.6" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="$(NET10Version)" />
</ItemGroup>

View File

@@ -13,7 +13,7 @@ using Microsoft.AspNetCore.Http;
using System.Reflection;
using ThingsGateway.Extensions;
using ThingsGateway.Extension;
using ThingsGateway.UnifyResult;
namespace Microsoft.AspNetCore.Mvc;

View File

@@ -22,7 +22,7 @@ using Microsoft.Extensions.Options;
using System.Collections.Concurrent;
using System.Reflection;
using ThingsGateway.Extensions;
using ThingsGateway.Extension;
using ThingsGateway.FriendlyException;
namespace ThingsGateway.UnifyResult;

View File

@@ -12,7 +12,7 @@
using System.Text.Json;
using System.Text.Json.Serialization;
using ThingsGateway.Extensions;
using ThingsGateway.Extension;
namespace ThingsGateway.Converters.Json;

View File

@@ -11,7 +11,7 @@
using System.Reflection;
namespace ThingsGateway.Extensions;
namespace ThingsGateway.Extension;
/// <summary>
/// <see cref="Assembly" /> 拓展类

View File

@@ -11,7 +11,7 @@
using System.Collections.Concurrent;
namespace ThingsGateway.Extensions;
namespace ThingsGateway.Extension;
/// <summary>
/// <see cref="ConcurrentDictionary{TKey, TValue}" /> 拓展类

View File

@@ -15,7 +15,7 @@ using Microsoft.Extensions.Hosting;
using System.Reflection;
namespace ThingsGateway.Extensions;
namespace ThingsGateway.Extension;
/// <summary>
/// 核心模块 <see cref="IServiceCollection" /> 拓展类

View File

@@ -11,7 +11,7 @@
using System.Data;
namespace ThingsGateway.Extensions;
namespace ThingsGateway.Extension;
/// <summary>
/// <see cref="DataTable" /> 和 <see cref="DataSet" /> 拓展类

View File

@@ -9,7 +9,7 @@
// 许可证的完整文本可以在源代码树根目录中的 LICENSE-APACHE 和 LICENSE-MIT 文件中找到。
// ------------------------------------------------------------------------
namespace ThingsGateway.Extensions;
namespace ThingsGateway.Extension;
/// <summary>
/// 委托拓展类

View File

@@ -12,7 +12,7 @@
using System.ComponentModel;
using System.Reflection;
namespace ThingsGateway.Extensions;
namespace ThingsGateway.Extension;
/// <summary>
/// 枚举拓展类

View File

@@ -9,7 +9,7 @@
// 许可证的完整文本可以在源代码树根目录中的 LICENSE-APACHE 和 LICENSE-MIT 文件中找到。
// ------------------------------------------------------------------------
namespace ThingsGateway.Extensions;
namespace ThingsGateway.Extension;
/// <summary>
/// <see cref="EventHandler{TEventArgs}" /> 拓展类

View File

@@ -11,7 +11,7 @@
using System.Diagnostics.CodeAnalysis;
namespace ThingsGateway.Extensions;
namespace ThingsGateway.Extension;
/// <summary>
/// <see cref="ICollection{T}" /> 拓展类

View File

@@ -11,7 +11,7 @@
using System.Collections.Concurrent;
namespace ThingsGateway.Extensions;
namespace ThingsGateway.Extension;
/// <summary>
/// <see cref="IDictionary{TKey, TValue}" /> 拓展类

View File

@@ -9,7 +9,7 @@
// 许可证的完整文本可以在源代码树根目录中的 LICENSE-APACHE 和 LICENSE-MIT 文件中找到。
// ------------------------------------------------------------------------
namespace ThingsGateway.Extensions;
namespace ThingsGateway.Extension;
/// <summary>
/// <see cref="IEnumerable" /> 拓展类

View File

@@ -18,7 +18,7 @@ using System.Text.RegularExpressions;
using System.Xml;
using System.Xml.Linq;
namespace ThingsGateway.Extensions;
namespace ThingsGateway.Extension;
/// <summary>
/// System.Text.Json 拓展类

View File

@@ -12,7 +12,7 @@
using System.Linq.Expressions;
using System.Reflection;
namespace ThingsGateway.Extensions;
namespace ThingsGateway.Extension;
/// <summary>
/// <see cref="Expression" /> 拓展类

View File

@@ -12,7 +12,7 @@
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
namespace ThingsGateway.Extensions;
namespace ThingsGateway.Extension;
/// <summary>
/// <see cref="MethodInfo" /> 拓展类

View File

@@ -9,7 +9,7 @@
// 许可证的完整文本可以在源代码树根目录中的 LICENSE-APACHE 和 LICENSE-MIT 文件中找到。
// ------------------------------------------------------------------------
namespace ThingsGateway.Extensions;
namespace ThingsGateway.Extension;
/// <summary>
/// 数值类型拓展类

View File

@@ -17,7 +17,7 @@ using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
namespace ThingsGateway.Extensions;
namespace ThingsGateway.Extension;
/// <summary>
/// <see cref="string" /> 拓展类

View File

@@ -15,7 +15,7 @@ using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
namespace ThingsGateway.Extensions;
namespace ThingsGateway.Extension;
/// <summary>
/// <see cref="Type" /> 拓展类

View File

@@ -13,7 +13,7 @@ using System.Buffers;
using System.Text;
using System.Text.Json;
namespace ThingsGateway.Extensions;
namespace ThingsGateway.Extension;
/// <summary>
/// <see cref="Utf8JsonReader" /> 拓展类

View File

@@ -16,7 +16,7 @@ using System.Text.Json;
using ThingsGateway.Utilities;
namespace ThingsGateway.Extensions;
namespace ThingsGateway.Extension;
/// <summary>
/// <see cref="object" /> 拓展类

View File

@@ -13,7 +13,7 @@ using System.Collections.Concurrent;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using ThingsGateway.Extensions;
using ThingsGateway.Extension;
namespace ThingsGateway.Reflection;

View File

@@ -13,7 +13,7 @@ using System.Collections.Concurrent;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using ThingsGateway.Extensions;
using ThingsGateway.Extension;
namespace ThingsGateway.Reflection;

View File

@@ -11,7 +11,7 @@
using System.Diagnostics.CodeAnalysis;
using ThingsGateway.Extensions;
using ThingsGateway.Extension;
namespace ThingsGateway.Utilities;

View File

@@ -11,7 +11,7 @@
using System.Text;
using ThingsGateway.Extensions;
using ThingsGateway.Extension;
namespace ThingsGateway.Utilities;

View File

@@ -18,7 +18,7 @@ using Microsoft.Net.Http.Headers;
using System.Net.Mime;
using ThingsGateway.AspNetCore.Extensions;
using ThingsGateway.Extensions;
using ThingsGateway.Extension;
using MediaTypeHeaderValue = System.Net.Http.Headers.MediaTypeHeaderValue;

View File

@@ -12,7 +12,7 @@
using System.Net.Http.Headers;
using System.Threading.Channels;
using ThingsGateway.Extensions;
using ThingsGateway.Extension;
using ThingsGateway.Utilities;
namespace ThingsGateway.HttpRemote;

View File

@@ -16,7 +16,7 @@ using System.Text;
using System.Text.Json;
using System.Threading.Channels;
using ThingsGateway.Extensions;
using ThingsGateway.Extension;
using ThingsGateway.Utilities;
namespace ThingsGateway.HttpRemote;

View File

@@ -16,7 +16,7 @@ using Microsoft.Extensions.Logging;
using System.Reflection;
using System.Text;
using ThingsGateway.Extensions;
using ThingsGateway.Extension;
namespace ThingsGateway.HttpRemote;

View File

@@ -17,7 +17,7 @@ using System.Net.Mime;
using System.Text;
using System.Text.Json;
using ThingsGateway.Extensions;
using ThingsGateway.Extension;
using ThingsGateway.Utilities;
using MediaTypeHeaderValue = System.Net.Http.Headers.MediaTypeHeaderValue;

View File

@@ -16,7 +16,7 @@ using System.Globalization;
using System.Net.Http.Headers;
using System.Net.Mime;
using ThingsGateway.Extensions;
using ThingsGateway.Extension;
using CacheControlHeaderValue = System.Net.Http.Headers.CacheControlHeaderValue;
using StringWithQualityHeaderValue = System.Net.Http.Headers.StringWithQualityHeaderValue;

View File

@@ -14,7 +14,7 @@
using System.Collections.Concurrent;
using System.Reflection;
using ThingsGateway.Extensions;
using ThingsGateway.Extension;
namespace ThingsGateway.HttpRemote;

View File

@@ -12,7 +12,7 @@
using System.Net.Mime;
using System.Reflection;
using ThingsGateway.Extensions;
using ThingsGateway.Extension;
namespace ThingsGateway.HttpRemote;

View File

@@ -11,7 +11,7 @@
using System.Reflection;
using ThingsGateway.Extensions;
using ThingsGateway.Extension;
using ThingsGateway.Utilities;
namespace ThingsGateway.HttpRemote;

View File

@@ -11,7 +11,7 @@
using System.Reflection;
using ThingsGateway.Extensions;
using ThingsGateway.Extension;
using ThingsGateway.Utilities;
namespace ThingsGateway.HttpRemote;

View File

@@ -14,7 +14,7 @@ using System.Net.Mime;
using System.Reflection;
using System.Text;
using ThingsGateway.Extensions;
using ThingsGateway.Extension;
namespace ThingsGateway.HttpRemote;

View File

@@ -9,7 +9,7 @@
// 许可证的完整文本可以在源代码树根目录中的 LICENSE-APACHE 和 LICENSE-MIT 文件中找到。
// ------------------------------------------------------------------------
using ThingsGateway.Extensions;
using ThingsGateway.Extension;
using ThingsGateway.Utilities;
namespace ThingsGateway.HttpRemote;

View File

@@ -11,7 +11,7 @@
using System.Reflection;
using ThingsGateway.Extensions;
using ThingsGateway.Extension;
using ThingsGateway.Utilities;
namespace ThingsGateway.HttpRemote;

View File

@@ -11,7 +11,7 @@
using System.Reflection;
using ThingsGateway.Extensions;
using ThingsGateway.Extension;
using ThingsGateway.Utilities;
namespace ThingsGateway.HttpRemote;

View File

@@ -12,7 +12,7 @@
using System.ComponentModel.DataAnnotations;
using System.Reflection;
using ThingsGateway.Extensions;
using ThingsGateway.Extension;
namespace ThingsGateway.HttpRemote;

View File

@@ -12,7 +12,7 @@
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using ThingsGateway.Extensions;
using ThingsGateway.Extension;
namespace ThingsGateway.HttpRemote;

View File

@@ -14,7 +14,7 @@ using Microsoft.Extensions.DependencyInjection;
using System.Net.Http.Headers;
using ThingsGateway.Extensions;
using ThingsGateway.Extension;
namespace ThingsGateway.HttpRemote.Extensions;

View File

@@ -18,7 +18,7 @@ using System.Net.Http.Headers;
using System.Text;
using System.Text.RegularExpressions;
using ThingsGateway.Extensions;
using ThingsGateway.Extension;
using ThingsGateway.Utilities;
using StringWithQualityHeaderValue = System.Net.Http.Headers.StringWithQualityHeaderValue;

View File

@@ -11,7 +11,7 @@
using Microsoft.Extensions.DependencyInjection;
using ThingsGateway.Extensions;
using ThingsGateway.Extension;
namespace ThingsGateway.HttpRemote;

View File

@@ -11,7 +11,7 @@
using System.Text;
using ThingsGateway.Extensions;
using ThingsGateway.Extension;
namespace ThingsGateway.HttpRemote;

View File

@@ -14,7 +14,7 @@ using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Controllers;
using Microsoft.AspNetCore.Mvc.Filters;
using ThingsGateway.Extensions;
using ThingsGateway.Extension;
using ThingsGateway.HttpRemote.Extensions;
namespace ThingsGateway.HttpRemote;

View File

@@ -11,7 +11,7 @@
using System.Globalization;
using ThingsGateway.Extensions;
using ThingsGateway.Extension;
namespace ThingsGateway.HttpRemote;

View File

@@ -15,7 +15,7 @@ using Microsoft.Extensions.Options;
using System.Diagnostics;
using System.Threading.Channels;
using ThingsGateway.Extensions;
using ThingsGateway.Extension;
namespace ThingsGateway.HttpRemote;

View File

@@ -15,7 +15,7 @@ using Microsoft.Extensions.Options;
using System.Diagnostics;
using System.Threading.Channels;
using ThingsGateway.Extensions;
using ThingsGateway.Extension;
namespace ThingsGateway.HttpRemote;

View File

@@ -14,7 +14,7 @@ using Microsoft.Extensions.Options;
using System.Threading.Channels;
using ThingsGateway.Extensions;
using ThingsGateway.Extension;
namespace ThingsGateway.HttpRemote;

View File

@@ -16,7 +16,7 @@ using System.Diagnostics.CodeAnalysis;
using System.Text;
using System.Threading.Channels;
using ThingsGateway.Extensions;
using ThingsGateway.Extension;
namespace ThingsGateway.HttpRemote;

View File

@@ -9,7 +9,7 @@
// 许可证的完整文本可以在源代码树根目录中的 LICENSE-APACHE 和 LICENSE-MIT 文件中找到。
// ------------------------------------------------------------------------
using ThingsGateway.Extensions;
using ThingsGateway.Extension;
using ThingsGateway.Utilities;
namespace ThingsGateway.HttpRemote;

View File

@@ -14,7 +14,7 @@ using System.Net.Http.Headers;
using System.Net.Mime;
using System.Text;
using ThingsGateway.Extensions;
using ThingsGateway.Extension;
namespace ThingsGateway.HttpRemote;

View File

@@ -14,7 +14,7 @@ using System.Net.Http.Headers;
using System.Reflection;
using System.Text;
using ThingsGateway.Extensions;
using ThingsGateway.Extension;
namespace ThingsGateway.HttpRemote;

View File

@@ -12,7 +12,7 @@
using System.Net.Mime;
using System.Text;
using ThingsGateway.Extensions;
using ThingsGateway.Extension;
namespace ThingsGateway.HttpRemote;

View File

@@ -13,7 +13,7 @@ using System.Globalization;
using System.Net.Http.Headers;
using System.Text;
using ThingsGateway.Extensions;
using ThingsGateway.Extension;
namespace ThingsGateway.HttpRemote;

View File

@@ -20,7 +20,7 @@ using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;
using ThingsGateway.Extensions;
using ThingsGateway.Extension;
namespace ThingsGateway.HttpRemote;

View File

@@ -18,7 +18,7 @@ using System.Net;
using System.Reflection;
using System.Text.RegularExpressions;
using ThingsGateway.Extensions;
using ThingsGateway.Extension;
namespace ThingsGateway.HttpRemote;

View File

@@ -9,7 +9,7 @@
// 许可证的完整文本可以在源代码树根目录中的 LICENSE-APACHE 和 LICENSE-MIT 文件中找到。
// ------------------------------------------------------------------------
using ThingsGateway.Extensions;
using ThingsGateway.Extension;
namespace ThingsGateway.HttpRemote;

View File

@@ -12,7 +12,7 @@
using System.Net.WebSockets;
using System.Text;
using ThingsGateway.Extensions;
using ThingsGateway.Extension;
namespace ThingsGateway.HttpRemote;

View File

@@ -19,7 +19,7 @@ using System.Net.Mime;
using System.Reflection;
using System.Web;
using ThingsGateway.Extensions;
using ThingsGateway.Extension;
namespace ThingsGateway.Shapeless;

View File

@@ -17,7 +17,7 @@ using System.Text.Json.Nodes;
using System.Xml;
using System.Xml.Linq;
using ThingsGateway.Extensions;
using ThingsGateway.Extension;
namespace ThingsGateway.Shapeless;

View File

@@ -13,7 +13,7 @@ using System.Dynamic;
using System.Reflection;
using System.Text.Json;
using ThingsGateway.Extensions;
using ThingsGateway.Extension;
using ThingsGateway.Shapeless.Extensions;
using Binder = Microsoft.CSharp.RuntimeBinder.Binder;

View File

@@ -15,7 +15,7 @@ using System.Dynamic;
using System.Text.Json;
using System.Text.Json.Nodes;
using ThingsGateway.Extensions;
using ThingsGateway.Extension;
namespace ThingsGateway.Shapeless;

View File

@@ -0,0 +1,169 @@
using System.Collections.Concurrent;
using System.Linq.Expressions;
using System.Reflection;
namespace ThingsGateway.NewLife;
public class FastMapperOption
{
public Dictionary<string, string> MapperProperties { get; set; } = new();
public HashSet<string> IgnoreProperties { get; set; } = new();
}
public static class FastMapper
{
// 泛型 + 非泛型共用缓存
private static readonly ConcurrentDictionary<(Type Source, Type Target), Delegate> _mapCache
= new ConcurrentDictionary<(Type, Type), Delegate>();
#region
public static TTarget Mapper<TSource, TTarget>(TSource source, FastMapperOption option = null)
where TTarget : class, new()
{
if (source == null) return null;
var key = (typeof(TSource), typeof(TTarget));
if (!_mapCache.TryGetValue(key, out var del))
{
del = CreateMapFunc<TSource, TTarget>();
_mapCache[key] = del;
}
var func = (Func<TSource, FastMapperOption, TTarget>)del;
return func(source, option);
}
#endregion
#region
public static object Mapper(object source, Type targetType, FastMapperOption option = null)
{
if (source == null) return null;
var sourceType = source.GetType();
var key = (sourceType, targetType);
if (!_mapCache.TryGetValue(key, out var del))
{
// 动态生成泛型委托并缓存
var method = typeof(FastMapper).GetMethod(nameof(CreateMapFunc), BindingFlags.NonPublic | BindingFlags.Static);
var genericMethod = method.MakeGenericMethod(sourceType, targetType);
del = genericMethod.Invoke(null, null) as Delegate;
_mapCache[key] = del;
}
return del.DynamicInvoke(source, option);
}
#endregion
#region Expression Tree
private static Func<TSource, FastMapperOption, TTarget> CreateMapFunc<TSource, TTarget>()
where TTarget : class, new()
{
var sourceType = typeof(TSource);
var targetType = typeof(TTarget);
var sourceParam = Expression.Parameter(sourceType, "src");
var optionParam = Expression.Parameter(typeof(FastMapperOption), "opt");
var targetVar = Expression.Variable(targetType, "dest");
var expressions = new List<Expression>
{
Expression.Assign(targetVar, Expression.New(targetType))
};
var sourceProperties = sourceType.GetProperties(BindingFlags.Public | BindingFlags.Instance);
var targetProperties = targetType.GetProperties(BindingFlags.Public | BindingFlags.Instance);
var targetDict = targetProperties.Where(p => p.CanWrite).ToDictionary(p => p.Name);
foreach (var sp in sourceProperties)
{
if (!sp.CanRead) continue;
// FastMapperOption 重命名
var pNameExpr = Expression.Constant(sp.Name);
if (targetDict.TryGetValue(sp.Name, out PropertyInfo? tp))
{
// Ignore check
Expression ignoreCheck = Expression.Call(
Expression.Property(optionParam, nameof(FastMapperOption.IgnoreProperties)),
nameof(HashSet<string>.Contains),
null,
pNameExpr
);
Expression assign;
// 1⃣ 简单类型直接赋值
if (IsSimpleType(sp.PropertyType))
{
assign = Expression.Assign(
Expression.Property(targetVar, tp),
Expression.Convert(Expression.Property(sourceParam, sp), tp.PropertyType)
);
}
// 2⃣ 集合类型
else if (typeof(System.Collections.IEnumerable).IsAssignableFrom(sp.PropertyType) && sp.PropertyType != typeof(string))
{
var elementSourceType = sp.PropertyType.IsArray
? sp.PropertyType.GetElementType()
: sp.PropertyType.GetGenericArguments().FirstOrDefault();
var elementTargetType = tp.PropertyType.IsArray
? tp.PropertyType.GetElementType()
: tp.PropertyType.GetGenericArguments().FirstOrDefault();
if (elementSourceType != null && elementTargetType != null)
{
var mapListMethod = typeof(FastMapper).GetMethod(nameof(MapList), BindingFlags.Public | BindingFlags.Static)
.MakeGenericMethod(elementSourceType, elementTargetType);
assign = Expression.Assign(
Expression.Property(targetVar, tp),
Expression.Call(mapListMethod, Expression.Property(sourceParam, sp), optionParam)
);
}
else continue;
}
// 3⃣ 引用类型/嵌套对象
else
{
var mapMethod = typeof(FastMapper).GetMethod(nameof(Mapper), new Type[] { typeof(object), typeof(Type), typeof(FastMapperOption) });
var arg0 = Expression.Convert(Expression.Property(sourceParam, sp), typeof(object)); // ✅ fix Nullable/ValueType
assign = Expression.Assign(
Expression.Property(targetVar, tp),
Expression.Convert(
Expression.Call(mapMethod, arg0, Expression.Constant(tp.PropertyType), optionParam),
tp.PropertyType
)
);
}
expressions.Add(assign);
}
}
expressions.Add(targetVar);
var body = Expression.Block(new[] { targetVar }, expressions);
return Expression.Lambda<Func<TSource, FastMapperOption, TTarget>>(body, sourceParam, optionParam).Compile();
}
#endregion
#region
public static IEnumerable<TTarget> MapList<TSource, TTarget>(IEnumerable<TSource> list, FastMapperOption option = null)
where TTarget : class, new()
{
if (list == null) yield break;
foreach (var item in list)
yield return Mapper<TSource, TTarget>(item, option);
}
#endregion
private static bool IsSimpleType(Type type)
{
return type.IsPrimitive
|| type.IsEnum
|| type == typeof(string)
|| type == typeof(decimal)
|| type == typeof(DateTime)
|| (Nullable.GetUnderlyingType(type) != null && IsSimpleType(Nullable.GetUnderlyingType(type)));
}
}

View File

@@ -66,7 +66,7 @@ public sealed class WaitLock : IDisposable
}
catch (SemaphoreFullException)
{
XTrace.WriteException(new Exception($"WaitLock {_name} 释放失败,当前信号量无需释放"));
//XTrace.WriteException(new Exception($"WaitLock {_name} 释放失败,当前信号量无需释放"));
}
}
}

View File

@@ -155,7 +155,7 @@ public static class DateExtensions
/// </summary>
/// <param name="timestamp"></param>
/// <returns></returns>
internal static DateTime ConvertToDateTime(this long timestamp)
public static DateTime ConvertToDateTime(this long timestamp)
{
var timeStampDateTime = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
var digitCount = (int)Math.Floor(Math.Log10(timestamp) + 1);
@@ -169,4 +169,5 @@ public static class DateExtensions
? timeStampDateTime.AddMilliseconds(timestamp) // 13 位时间戳
: timeStampDateTime.AddSeconds(timestamp)).ToLocalTime(); // 10 位时间戳
}
}

View File

@@ -8,13 +8,14 @@
// 项目主要遵循 MIT 许可证和 Apache 许可证(版本 2.0)进行分发和使用。
// 许可证的完整文本可以在源代码树根目录中的 LICENSE-APACHE 和 LICENSE-MIT 文件中找到。
// ------------------------------------------------------------------------
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
#if NET6_0_OR_GREATER
using System.Text.Json;
#endif
using ThingsGateway.Extensions;
using ThingsGateway.Extension;
namespace ThingsGateway.JsonSerialization;
@@ -23,6 +24,7 @@ namespace ThingsGateway.JsonSerialization;
/// </summary>
internal static class Penetrates
{
#if NET6_0_OR_GREATER
/// <summary>
/// 转换
/// </summary>
@@ -35,7 +37,6 @@ internal static class Penetrates
{
return longValue.ConvertToDateTime();
}
var stringValue = reader.GetString();
// 处理时间戳自动转换
@@ -46,6 +47,9 @@ internal static class Penetrates
return Convert.ToDateTime(stringValue);
}
#endif
/// <summary>
/// 转换
@@ -69,4 +73,6 @@ internal static class Penetrates
return Convert.ToDateTime(stringValue);
}
}
}

View File

@@ -53,12 +53,16 @@ public static class LinqExtensions
/// <inheritdoc/>
public static void RemoveWhere<T>(this ICollection<T> @this, Func<T, bool> @where)
{
foreach (var obj in @this.Where(where).ToList())
var del = new List<T>();
foreach (var obj in @this.Where(where))
{
del.Add(obj);
}
foreach (var obj in del)
{
@this.Remove(obj);
}
}
/// <inheritdoc/>
public static IEnumerable<T> WhereIf<T>(this IEnumerable<T> thisValue, bool isOk, Func<T, bool> predicate)
{

View File

@@ -0,0 +1,34 @@
//------------------------------------------------------------------------------
// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
// 此代码版权除特别声明外的代码归作者本人Diego所有
// 源代码使用协议遵循本仓库的开源协议及附加协议
// Gitee源代码仓库https://gitee.com/diego2098/ThingsGateway
// Github源代码仓库https://github.com/kimdiego2098/ThingsGateway
// 使用文档https://thingsgateway.cn/
// QQ群605534569
//------------------------------------------------------------------------------
using Newtonsoft.Json;
using System.Text;
namespace ThingsGateway.Foundation;
/// <inheritdoc/>
public class NewtonsoftEncodingConverter : Newtonsoft.Json.JsonConverter<Encoding>
{
/// <inheritdoc/>
public override Encoding? ReadJson(JsonReader reader, Type objectType, Encoding? existingValue, bool hasExistingValue, Newtonsoft.Json.JsonSerializer serializer)
{
// 从 JSON 字符串中读取编码名称,并创建相应的 Encoding 对象
string? encodingName = reader.Value as string;
return Encoding.GetEncoding(encodingName ?? Encoding.UTF8.WebName);
}
/// <inheritdoc/>
public override void WriteJson(JsonWriter writer, Encoding? value, Newtonsoft.Json.JsonSerializer serializer)
{
writer.WriteValue(value.WebName);
}
}

View File

@@ -8,6 +8,7 @@
// 项目主要遵循 MIT 许可证和 Apache 许可证(版本 2.0)进行分发和使用。
// 许可证的完整文本可以在源代码树根目录中的 LICENSE-APACHE 和 LICENSE-MIT 文件中找到。
// ------------------------------------------------------------------------
#if NET6_0_OR_GREATER
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
@@ -17,7 +18,6 @@ namespace ThingsGateway.JsonSerialization;
/// <summary>
/// DateOnly 类型序列化
/// </summary>
[SuppressSniffer]
public class NewtonsoftJsonDateOnlyJsonConverter : JsonConverter<DateOnly>
{
/// <summary>
@@ -72,7 +72,6 @@ public class NewtonsoftJsonDateOnlyJsonConverter : JsonConverter<DateOnly>
/// <summary>
/// DateOnly? 类型序列化
/// </summary>
[SuppressSniffer]
public class NewtonsoftJsonNullableDateOnlyJsonConverter : JsonConverter<DateOnly?>
{
/// <summary>
@@ -123,4 +122,6 @@ public class NewtonsoftJsonNullableDateOnlyJsonConverter : JsonConverter<DateOnl
if (value == null) writer.WriteNull();
else writer.WriteValue(value.Value.ToString(Format));
}
}
}
#endif

Some files were not shown because too many files have changed in this diff Show More