Compare commits

...

8 Commits

Author SHA1 Message Date
Diego
f7f8802272 2025-05-27 13:19:39 +08:00
Diego
c6910dff02 update src/Gateway/ThingsGateway.Gateway.Application/ThingsGateway.Gateway.Application.csproj.
Signed-off-by: Diego <2248356998@qq.com>
2025-05-27 01:37:29 +00:00
Diego
ad299d0dbb 2025-05-27 08:52:06 +08:00
2248356998 qq.com
8b124d1050 日志统计查询性能增强 2025-05-27 00:03:30 +08:00
Diego
ff41080dbd 更新授权类 2025-05-26 19:51:21 +08:00
Diego
0e28606e3d 10.6.23 2025-05-26 18:43:42 +08:00
Diego
6a025ceee5 序列化配置增加nan的情况 2025-05-26 17:41:13 +08:00
Diego
6b2e53d6dc 更新配置 2025-05-26 09:17:59 +08:00
32 changed files with 351 additions and 197 deletions

View File

@@ -21,29 +21,36 @@ using System.Logging;
using ThingsGateway.FriendlyException;
using ThingsGateway.Logging;
using ThingsGateway.NewLife.Json.Extension;
using ThingsGateway.UnifyResult;
namespace ThingsGateway.Admin.Application;
public class RequestAuditFilter : IAsyncActionFilter
public class RequestAuditFilter : IAsyncActionFilter, IOrderedFilter
{
private const int FilterOrder = -3000;
public int Order => FilterOrder;
public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
{
var timeOperation = Stopwatch.StartNew();
var resultContext = await next().ConfigureAwait(false);
// 计算接口执行时间
timeOperation.Stop();
var controllerActionDescriptor = (context.ActionDescriptor as ControllerActionDescriptor);
// 获取动作方法描述器
var actionMethod = controllerActionDescriptor?.MethodInfo;
// 处理 Blazor Server
if (actionMethod == null)
{
_ = await next.Invoke().ConfigureAwait(false);
return;
}
// 排除 WebSocket 请求处理
if (context.HttpContext.IsWebSocketRequest())
{
_ = await next().ConfigureAwait(false);
return;
}
@@ -51,7 +58,6 @@ public class RequestAuditFilter : IAsyncActionFilter
if (actionMethod.IsDefined(typeof(SuppressRequestAuditAttribute), true)
|| actionMethod.DeclaringType.IsDefined(typeof(SuppressRequestAuditAttribute), true))
{
_ = await next().ConfigureAwait(false);
return;
}
@@ -65,10 +71,7 @@ public class RequestAuditFilter : IAsyncActionFilter
return;
}
// 计算接口执行时间
var timeOperation = Stopwatch.StartNew();
var resultContext = await next().ConfigureAwait(false);
timeOperation.Stop();
var logData = new RequestAuditData();
@@ -88,21 +91,29 @@ public class RequestAuditFilter : IAsyncActionFilter
var requestUrl = Uri.UnescapeDataString(httpRequest.GetRequestUrlAddress());
logData.RequestUrl = requestUrl;
object returnValue = null;
Type finalReturnType;
var result = resultContext.Result as IActionResult;
var data = result switch
// 解析返回值
if (UnifyContext.CheckVaildResult(result, out var data))
{
// 处理内容结果
ContentResult content => content.Content,
// 处理对象结果
ObjectResult obj => obj.Value,
// 处理 JSON 对象
JsonResult json => json.Value,
_ => null,
};
logData.ReturnInformation = data;
returnValue = data;
finalReturnType = data?.GetType();
}
// 处理文件类型
else if (result is FileResult fresult)
{
returnValue = new
{
FileName = fresult.FileDownloadName,
fresult.ContentType,
Length = fresult is FileContentResult cresult ? (object)cresult.FileContents.Length : null
};
finalReturnType = fresult?.GetType();
}
else finalReturnType = result?.GetType();
logData.ReturnInformation = returnValue;
//获取客户端信息
var client = App.GetService<IAppService>().UserAgent;

View File

@@ -16,7 +16,6 @@ using ThingsGateway.Extension;
using ThingsGateway.FriendlyException;
using ThingsGateway.Logging;
using ThingsGateway.NewLife.Json.Extension;
using ThingsGateway.Razor;
namespace ThingsGateway.Admin.Application;
@@ -160,8 +159,7 @@ public class DatabaseLoggingWriter : IDatabaseLoggingWriter
if (path == "/api/auth/login")
{
//如果是登录,用户信息就从返回值里拿
var result = requestAuditData.ReturnInformation?.ToSystemTextJsonString();//返回值转json
var userInfo = result.FromJsonNetString<UnifyResult<LoginOutput>>();//格式化成user表
dynamic userInfo = requestAuditData.ReturnInformation;
opAccount = userInfo.Data.Account;//赋值账号
verificatId = userInfo.Data.VerificatId;
}

View File

@@ -117,6 +117,25 @@ public class SugarAopService : ISugarAopService
db.Aop.DataExecuted = (value, entity) =>
{
};
db.Aop.OnLogExecuted = (sql, pars) =>
{
//执行时间超过1秒
if (db.Ado.SqlExecutionTime.TotalSeconds > 1)
{
//代码CS文件名
var fileName = db.Ado.SqlStackTrace.FirstFileName;
//代码行数
var fileLine = db.Ado.SqlStackTrace.FirstLine;
//方法名
var FirstMethodName = db.Ado.SqlStackTrace.FirstMethodName;
DbContext.WriteLog($"{fileName}-{FirstMethodName}-{fileLine} 执行时间超过1秒");
DbContext.WriteLogWithSql(UtilMethods.GetNativeSql(sql, pars));
}
};
}
}

View File

@@ -37,7 +37,7 @@ public sealed class SqlSugarOption : ConnectionConfig
/// <summary>
/// 是否控制台显示Sql语句
/// </summary>
public bool IsShowSql { get; set; }
public bool? IsShowSql { get; set; }
/// <summary>
/// 更新数据

View File

@@ -98,6 +98,21 @@ public class Startup : AppStartup
CodeFirstUtils.CodeFirst(fullName!);//CodeFirst
try
{
using var db = DbContext.GetDB<SysOperateLog>();
if (db.CurrentConnectionConfig.DbType == SqlSugar.DbType.Sqlite)
{
if (!db.DbMaintenance.IsAnyIndex("idx_operatelog_optime_date"))
{
var indexsql = "CREATE INDEX idx_operatelog_optime_date ON sys_operatelog(strftime('%Y-%m-%d', OpTime));";
db.Ado.ExecuteCommand(indexsql);
}
}
}
catch { }
//删除在线用户统计
var verificatInfoService = App.RootServices.GetService<IVerificatInfoService>();
verificatInfoService.RemoveAllClientId();

View File

@@ -88,6 +88,7 @@ public class Startup : AppStartup
}
;
services.AddMvcFilter<RequestAuditFilter>();
services.AddControllers()
.AddNewtonsoftJson(options => SetNewtonsoftJsonSetting(options.SerializerSettings))
//.AddXmlSerializerFormatters()
@@ -237,7 +238,6 @@ public class Startup : AppStartup
// logContext.Set(LoggingConst.Method, httpContext.Request.Method);//请求方法
// });
//});
services.AddMvcFilter<RequestAuditFilter>();
//日志写入数据库配置
services.AddDatabaseLogging<DatabaseLoggingWriter>(options =>

View File

@@ -25,7 +25,7 @@ public static class ILoggerExtensions
/// <param name="logger"></param>
/// <param name="properties">建议使用 ConcurrentDictionary 类型</param>
/// <returns></returns>
public static IDisposable ScopeContext(this ILogger logger, IDictionary<object, object> properties)
public static IDisposable ScopeContext(this ILogger logger, IDictionary<string, object> properties)
{
if (logger == null) throw new ArgumentNullException(nameof(logger));

View File

@@ -26,11 +26,11 @@ public static class LogContextExtensions
/// <param name="key">键</param>
/// <param name="value">值</param>
/// <returns></returns>
public static LogContext Set(this LogContext logContext, object key, object value)
public static LogContext Set(this LogContext logContext, string key, object value)
{
if (logContext == null || key == null) return logContext;
logContext.Properties ??= new Dictionary<object, object>();
logContext.Properties ??= new Dictionary<string, object>();
logContext.Properties.Remove(key);
logContext.Properties.Add(key, value);
@@ -43,7 +43,7 @@ public static class LogContextExtensions
/// <param name="logContext"></param>
/// <param name="properties"></param>
/// <returns></returns>
public static LogContext SetRange(this LogContext logContext, IDictionary<object, object> properties)
public static LogContext SetRange(this LogContext logContext, IDictionary<string, object> properties)
{
if (logContext == null
|| properties == null
@@ -63,7 +63,7 @@ public static class LogContextExtensions
/// <param name="logContext"></param>
/// <param name="key">键</param>
/// <returns></returns>
public static object Get(this LogContext logContext, object key)
public static object Get(this LogContext logContext, string key)
{
if (logContext == null
|| key == null
@@ -80,7 +80,7 @@ public static class LogContextExtensions
/// <param name="logContext"></param>
/// <param name="key">键</param>
/// <returns></returns>
public static T Get<T>(this LogContext logContext, object key)
public static T Get<T>(this LogContext logContext, string key)
{
var value = logContext.Get(key);
return value.ChangeType<T>();

View File

@@ -84,7 +84,7 @@ public static class StringLoggingExtensions
/// <param name="message"></param>
/// <param name="properties">建议使用 ConcurrentDictionary 类型</param>
/// <returns></returns>
public static StringLoggingPart ScopeContext(this string message, IDictionary<object, object> properties)
public static StringLoggingPart ScopeContext(this string message, IDictionary<string, object> properties)
{
return StringLoggingPart.Default().SetMessage(message).ScopeContext(properties);
}

View File

@@ -20,7 +20,7 @@ public sealed class LogContext : IDisposable
/// <summary>
/// 日志上下文数据
/// </summary>
public IDictionary<object, object> Properties { get; set; }
public IDictionary<string, object> Properties { get; set; }
/// <summary>
/// 原生日志上下文数据

View File

@@ -96,7 +96,7 @@ public sealed partial class StringLoggingPart
/// </summary>
/// <param name="properties">建议使用 ConcurrentDictionary 类型</param>
/// <returns></returns>
public StringLoggingPart ScopeContext(IDictionary<object, object> properties)
public StringLoggingPart ScopeContext(IDictionary<string, object> properties)
{
if (properties == null) return this;
LogContext = new LogContext { Properties = properties };

View File

@@ -59,7 +59,7 @@ public static class Log
/// </summary>
/// <param name="properties">建议使用 ConcurrentDictionary 类型</param>
/// <returns></returns>
public static (ILogger logger, IDisposable scope) ScopeContext(IDictionary<object, object> properties)
public static (ILogger logger, IDisposable scope) ScopeContext(IDictionary<string, object> properties)
{
return GetLogger(StringLoggingPart.Default().ScopeContext(properties));
}

View File

@@ -349,7 +349,7 @@ public static class UnifyContext
/// <param name="result"></param>
/// <param name="data"></param>
/// <returns></returns>
internal static bool CheckVaildResult(IActionResult result, out object data)
public static bool CheckVaildResult(IActionResult result, out object data)
{
data = default;

View File

@@ -37,7 +37,8 @@ public static class SystemTextJsonExtension
{
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
WriteIndented = true, // 缩进
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull // 忽略 null
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, // 忽略 null
NumberHandling = JsonNumberHandling.AllowNamedFloatingPointLiterals,
};
// 如有自定义Converter这里添加
// IndentedOptions.Converters.Add(new ByteArrayJsonConverter());
@@ -50,7 +51,8 @@ public static class SystemTextJsonExtension
{
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
WriteIndented = false, // 不缩进
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
NumberHandling = JsonNumberHandling.AllowNamedFloatingPointLiterals,
};
NoneIndentedOptions.Converters.Add(new ByteArrayToNumberArrayConverterSystemTextJson());
NoneIndentedOptions.Converters.Add(new JTokenSystemTextJsonConverter());

View File

@@ -27,6 +27,13 @@ public class Startup : AppStartup
{
services.AddBootstrapBlazor(
option => option.JSModuleVersion = Random.Shared.Next(10000).ToString()
, jsonLocalizationOptions =>
{
jsonLocalizationOptions.DisableGetLocalizerFromResourceManager = true;
jsonLocalizationOptions.DisableGetLocalizerFromService = true;
jsonLocalizationOptions.IgnoreLocalizerMissing = true;
jsonLocalizationOptions.UseKeyWhenValueIsNull = true;
}
);
services.AddConfigurableOptions<MenuOptions>();
services.ConfigureIconThemeOptions(options => options.ThemeKey = "fa");

View File

@@ -1,5 +1,5 @@
//下载文件
export function blazor_downloadFile(url, fileName, dtoObject) {
export async function blazor_downloadFile(url, fileName, dtoObject) {
const params = new URLSearchParams();
// 将 dtoObject 的属性添加到 URLSearchParams 中
@@ -12,97 +12,92 @@ export function blazor_downloadFile(url, fileName, dtoObject) {
// 构建完整的 URL
const fullUrl = `${url}?${params.toString()}`;
// 发起 fetch 请求
fetch(fullUrl)
.then(response => {
// 获取响应头中的 content-disposition
const dispositionHeader = response.headers.get('content-disposition');
let resolvedFileName = fileName;
try {
// 发起 fetch 请求
const response = await fetch(fullUrl);
if (dispositionHeader) {
// 解析出文件名
const match = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/.exec(dispositionHeader);
const serverFileName = match && match[1] ? match[1].replace(/['"]/g, '') : null;
if (serverFileName) {
resolvedFileName = serverFileName;
}
// 获取响应头中的 content-disposition
const dispositionHeader = response.headers.get('content-disposition');
let resolvedFileName = fileName;
if (dispositionHeader) {
// 解析出文件名
const match = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/.exec(dispositionHeader);
const serverFileName = match && match[1] ? match[1].replace(/['"]/g, '') : null;
if (serverFileName) {
resolvedFileName = serverFileName;
}
}
// 将响应转换为 blob 对象
return response.blob().then(blob => {
// 创建临时的文件 URL
const fileUrl = window.URL.createObjectURL(blob);
// 将响应转换为 blob 对象
const blob = await response.blob();
// 创建一个 <a> 元素并设置下载链接和文件名
const anchorElement = document.createElement('a');
anchorElement.href = fileUrl;
anchorElement.download = resolvedFileName;
anchorElement.style.display = 'none';
// 创建临时的文件 URL
const fileUrl = window.URL.createObjectURL(blob);
// <a> 元素添加到 body 中并触发下载
document.body.appendChild(anchorElement);
anchorElement.click();
document.body.removeChild(anchorElement);
// 创建一个 <a> 元素并设置下载链接和文件名
const anchorElement = document.createElement('a');
anchorElement.href = fileUrl;
anchorElement.download = resolvedFileName;
anchorElement.style.display = 'none';
// 撤销临时的文件 URL
window.URL.revokeObjectURL(fileUrl);
});
})
.catch(error => {
console.error('DownFile error ', error);
});
// 将 <a> 元素添加到 body 中并触发下载
document.body.appendChild(anchorElement);
anchorElement.click();
document.body.removeChild(anchorElement);
// 撤销临时的文件 URL
window.URL.revokeObjectURL(fileUrl);
return true;
} catch (error) {
console.error('DownFile error ', error);
throw error;
}
}
//下载文件
export function postJson_downloadFile(url, fileName, jsonBody) {
const params = new URLSearchParams();
export async function postJson_downloadFile(url, fileName, jsonBody) {
// 发起 fetch 请求
fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: jsonBody
})
.then(response => {
// 获取响应头中的 content-disposition
const dispositionHeader = response.headers.get('content-disposition');
let resolvedFileName = fileName;
if (dispositionHeader) {
// 解析出文件名
const match = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/.exec(dispositionHeader);
const serverFileName = match && match[1] ? match[1].replace(/['"]/g, '') : null;
if (serverFileName) {
resolvedFileName = serverFileName;
}
}
// 将响应转换为 blob 对象
return response.blob().then(blob => {
// 创建临时的文件 URL
const fileUrl = window.URL.createObjectURL(blob);
// 创建一个 <a> 元素并设置下载链接和文件名
const anchorElement = document.createElement('a');
anchorElement.href = fileUrl;
anchorElement.download = resolvedFileName;
anchorElement.style.display = 'none';
// 将 <a> 元素添加到 body 中并触发下载
document.body.appendChild(anchorElement);
anchorElement.click();
document.body.removeChild(anchorElement);
// 撤销临时的文件 URL
window.URL.revokeObjectURL(fileUrl);
});
})
.catch(error => {
console.error('downfile error ', error);
try {
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: jsonBody
});
const dispositionHeader = response.headers.get('content-disposition');
let resolvedFileName = fileName;
if (dispositionHeader) {
const match = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/.exec(dispositionHeader);
const serverFileName = match && match[1] ? match[1].replace(/['"]/g, '') : null;
if (serverFileName) {
resolvedFileName = serverFileName;
}
}
const blob = await response.blob();
const fileUrl = window.URL.createObjectURL(blob);
const anchorElement = document.createElement('a');
anchorElement.href = fileUrl;
anchorElement.download = resolvedFileName;
anchorElement.style.display = 'none';
document.body.appendChild(anchorElement);
anchorElement.click();
document.body.removeChild(anchorElement);
window.URL.revokeObjectURL(fileUrl);
return true; // 唯一新增的返回值
} catch (error) {
console.error('downfile error ', error);
}
}

View File

@@ -1,9 +1,9 @@
<Project>
<PropertyGroup>
<PluginVersion>10.6.21</PluginVersion>
<ProPluginVersion>10.6.21</ProPluginVersion>
<AuthenticationVersion>2.1.7</AuthenticationVersion>
<PluginVersion>10.6.27</PluginVersion>
<ProPluginVersion>10.6.27</ProPluginVersion>
<AuthenticationVersion>2.1.8</AuthenticationVersion>
</PropertyGroup>
<PropertyGroup>

View File

@@ -90,6 +90,7 @@ public class RuntimeInfoController : ControllerBase
/// </summary>
/// <returns></returns>
[HttpPost("checkRealAlarm")]
[RequestAudit]
[DisplayName("确认实时报警")]
public async Task CheckRealAlarm(long variableId)
{

View File

@@ -26,28 +26,53 @@ internal sealed class GatewayExportService : IGatewayExportService
private IJSRuntime JSRuntime { get; set; }
public async Task OnChannelExport(ExportFilter exportFilter)
public async Task<bool> OnChannelExport(ExportFilter exportFilter)
{
await using var ajaxJS = await JSRuntime.InvokeAsync<IJSObjectReference>("import", $"/_content/ThingsGateway.Razor/js/downloadFile.js");
string url = "api/gatewayExport/channel";
string fileName = $"{DateTime.Now.ToFileDateTimeFormat()}.xlsx";
await ajaxJS.InvokeVoidAsync("postJson_downloadFile", url, fileName, exportFilter.ToJsonString());
try
{
await using var ajaxJS = await JSRuntime.InvokeAsync<IJSObjectReference>("import", $"/_content/ThingsGateway.Razor/js/downloadFile.js");
string url = "api/gatewayExport/channel";
string fileName = $"{DateTime.Now.ToFileDateTimeFormat()}.xlsx";
return await ajaxJS.InvokeAsync<bool>("postJson_downloadFile", url, fileName, exportFilter.ToJsonString());
}
catch
{
return false;
}
}
public async Task OnDeviceExport(ExportFilter exportFilter)
public async Task<bool> OnDeviceExport(ExportFilter exportFilter)
{
await using var ajaxJS = await JSRuntime.InvokeAsync<IJSObjectReference>("import", $"/_content/ThingsGateway.Razor/js/downloadFile.js");
string url = "api/gatewayExport/device";
string fileName = $"{DateTime.Now.ToFileDateTimeFormat()}.xlsx";
await ajaxJS.InvokeVoidAsync("postJson_downloadFile", url, fileName, exportFilter.ToJsonString());
try
{
await using var ajaxJS = await JSRuntime.InvokeAsync<IJSObjectReference>("import", $"/_content/ThingsGateway.Razor/js/downloadFile.js");
string url = "api/gatewayExport/device";
string fileName = $"{DateTime.Now.ToFileDateTimeFormat()}.xlsx";
return await ajaxJS.InvokeAsync<bool>("postJson_downloadFile", url, fileName, exportFilter.ToJsonString());
}
catch
{
return false;
}
}
public async Task OnVariableExport(ExportFilter exportFilter)
public async Task<bool> OnVariableExport(ExportFilter exportFilter)
{
await using var ajaxJS = await JSRuntime.InvokeAsync<IJSObjectReference>("import", $"/_content/ThingsGateway.Razor/js/downloadFile.js");
string url = "api/gatewayExport/variable";
string fileName = $"{DateTime.Now.ToFileDateTimeFormat()}.xlsx";
await ajaxJS.InvokeVoidAsync("postJson_downloadFile", url, fileName, exportFilter.ToJsonString());
try
{
await using var ajaxJS = await JSRuntime.InvokeAsync<IJSObjectReference>("import", $"/_content/ThingsGateway.Razor/js/downloadFile.js");
string url = "api/gatewayExport/variable";
string fileName = $"{DateTime.Now.ToFileDateTimeFormat()}.xlsx";
return await ajaxJS.InvokeAsync<bool>("postJson_downloadFile", url, fileName, exportFilter.ToJsonString());
}
catch
{
return false;
}
}
}

View File

@@ -35,18 +35,30 @@ public sealed class HybridGatewayExportService : IGatewayExportService
}
public async Task OnChannelExport(ExportFilter exportFilter)
public async Task<bool> OnChannelExport(ExportFilter exportFilter)
{
exportFilter.QueryPageOptions.IsPage = false;
exportFilter.QueryPageOptions.IsVirtualScroll = false;
try
{
var sheets = await _channelService.ExportChannelAsync(exportFilter).ConfigureAwait(false);
var path = await _importExportService.CreateFileAsync<Device>(sheets, "Channel", false).ConfigureAwait(false);
Open(path);
exportFilter.QueryPageOptions.IsPage = false;
exportFilter.QueryPageOptions.IsVirtualScroll = false;
var sheets = await _channelService.ExportChannelAsync(exportFilter).ConfigureAwait(false);
var path = await _importExportService.CreateFileAsync<Device>(sheets, "Channel", false).ConfigureAwait(false);
Open(path);
return true;
}
catch
{
return false;
}
}
private static void Open(string path)
private static bool Open(string path)
{
path = System.IO.Path.GetDirectoryName(path); // Ensure the path is absolute
@@ -63,25 +75,47 @@ public sealed class HybridGatewayExportService : IGatewayExportService
{
System.Diagnostics.Process.Start("open", path);
}
return true;
}
public async Task OnDeviceExport(ExportFilter exportFilter)
public async Task<bool> OnDeviceExport(ExportFilter exportFilter)
{
exportFilter.QueryPageOptions.IsPage = false;
exportFilter.QueryPageOptions.IsVirtualScroll = false;
var sheets = await _deviceService.ExportDeviceAsync(exportFilter).ConfigureAwait(false);
var path = await _importExportService.CreateFileAsync<Device>(sheets, "Device", false).ConfigureAwait(false);
Open(path);
try
{
exportFilter.QueryPageOptions.IsPage = false;
exportFilter.QueryPageOptions.IsVirtualScroll = false;
var sheets = await _deviceService.ExportDeviceAsync(exportFilter).ConfigureAwait(false);
var path = await _importExportService.CreateFileAsync<Device>(sheets, "Device", false).ConfigureAwait(false);
Open(path);
return true;
}
catch
{
return false;
}
}
public async Task OnVariableExport(ExportFilter exportFilter)
public async Task<bool> OnVariableExport(ExportFilter exportFilter)
{
exportFilter.QueryPageOptions.IsPage = false;
exportFilter.QueryPageOptions.IsVirtualScroll = false;
var sheets = await _variableService.ExportVariableAsync(exportFilter).ConfigureAwait(false);
var path = await _importExportService.CreateFileAsync<Variable>(sheets, "Variable", false).ConfigureAwait(false);
Open(path);
try
{
exportFilter.QueryPageOptions.IsPage = false;
exportFilter.QueryPageOptions.IsVirtualScroll = false;
var sheets = await _variableService.ExportVariableAsync(exportFilter).ConfigureAwait(false);
var path = await _importExportService.CreateFileAsync<Variable>(sheets, "Variable", false).ConfigureAwait(false);
Open(path);
return true;
}
catch
{
return false;
}
}
}

View File

@@ -12,7 +12,7 @@ namespace ThingsGateway.Gateway.Application;
public interface IGatewayExportService
{
Task OnChannelExport(ExportFilter exportFilter);
Task OnDeviceExport(ExportFilter exportFilter);
Task OnVariableExport(ExportFilter exportFilter);
Task<bool> OnChannelExport(ExportFilter exportFilter);
Task<bool> OnDeviceExport(ExportFilter exportFilter);
Task<bool> OnVariableExport(ExportFilter exportFilter);
}

View File

@@ -18,6 +18,8 @@ using SqlSugar;
using System.Reflection;
using ThingsGateway.Authentication;
namespace ThingsGateway.Gateway.Application;
[AppStartup(-100)]
@@ -25,6 +27,9 @@ public class Startup : AppStartup
{
public void Configure(IServiceCollection services)
{
ProAuthentication.TryGetAuthorizeInfo(out var authorizeInfo);
services.AddConfigurableOptions<ChannelThreadOptions>();
services.AddConfigurableOptions<GatewayLogOptions>();
services.AddConfigurableOptions<RpcLogOptions>();
@@ -125,8 +130,35 @@ public class Startup : AppStartup
}
catch { }
try
{
using var db = DbContext.GetDB<BackendLog>();
if (db.CurrentConnectionConfig.DbType == SqlSugar.DbType.Sqlite)
{
if (!db.DbMaintenance.IsAnyIndex("idx_backendlog_logtime_date"))
{
var indexsql = "CREATE INDEX idx_backendlog_logtime_date ON backend_log(strftime('%Y-%m-%d', LogTime));";
db.Ado.ExecuteCommand(indexsql);
}
}
}
catch { }
try
{
using var db = DbContext.GetDB<RpcLog>();
if (db.CurrentConnectionConfig.DbType == SqlSugar.DbType.Sqlite)
{
if (!db.DbMaintenance.IsAnyIndex("idx_rpclog_logtime_date"))
{
var indexsql = "CREATE INDEX idx_rpclog_logtime_date ON rpc_log(strftime('%Y-%m-%d', LogTime));";
db.Ado.ExecuteCommand(indexsql);
}
}
}
catch { }
serviceProvider.GetService<IHostApplicationLifetime>().ApplicationStarted.Register(() =>
{

View File

@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="$(SolutionDir)Version.props" />
<Import Project="$(SolutionDir)PackNuget.props" />

View File

@@ -220,9 +220,10 @@ public partial class ChannelTable : IDisposable
private async Task ExcelExportAsync(ITableExportContext<ChannelRuntime> tableExportContext, bool all = false)
{
bool ret;
if (all)
{
await GatewayExportService.OnChannelExport(new() { QueryPageOptions = new() });
ret = await GatewayExportService.OnChannelExport(new() { QueryPageOptions = new() });
}
else
{
@@ -230,16 +231,16 @@ public partial class ChannelTable : IDisposable
{
case ChannelDevicePluginTypeEnum.PluginName:
await GatewayExportService.OnChannelExport(new() { QueryPageOptions = new(), PluginName = SelectModel.PluginName });
ret = await GatewayExportService.OnChannelExport(new() { QueryPageOptions = new(), PluginName = SelectModel.PluginName });
break;
case ChannelDevicePluginTypeEnum.Channel:
await GatewayExportService.OnChannelExport(new() { QueryPageOptions = new(), ChannelId = SelectModel.ChannelRuntime.Id });
ret = await GatewayExportService.OnChannelExport(new() { QueryPageOptions = new(), ChannelId = SelectModel.ChannelRuntime.Id });
break;
case ChannelDevicePluginTypeEnum.Device:
await GatewayExportService.OnChannelExport(new() { QueryPageOptions = new(), DeviceId = SelectModel.DeviceRuntime.Id, PluginType = SelectModel.DeviceRuntime.PluginType });
ret = await GatewayExportService.OnChannelExport(new() { QueryPageOptions = new(), DeviceId = SelectModel.DeviceRuntime.Id, PluginType = SelectModel.DeviceRuntime.PluginType });
break;
default:
await GatewayExportService.OnChannelExport(new() { QueryPageOptions = new() });
ret = await GatewayExportService.OnChannelExport(new() { QueryPageOptions = new() });
break;
}
@@ -247,7 +248,8 @@ public partial class ChannelTable : IDisposable
}
// 返回 true 时自动弹出提示框
await ToastService.Default();
if (ret)
await ToastService.Default();
}
async Task ExcelChannelAsync(ITableExportContext<ChannelRuntime> tableExportContext)

View File

@@ -530,20 +530,21 @@ EventCallback.Factory.Create<MouseEventArgs>(this, async e =>
}
async Task ExportCurrentChannel(ContextMenuItem item, object value)
{
bool ret;
if (value is not ChannelDeviceTreeItem channelDeviceTreeItem) return;
if (channelDeviceTreeItem.TryGetChannelRuntime(out var channelRuntime))
{
await GatewayExportService.OnChannelExport(new() { QueryPageOptions = new(), DeviceId = channelRuntime.Id });
ret = await GatewayExportService.OnChannelExport(new() { QueryPageOptions = new(), DeviceId = channelRuntime.Id });
}
else if (channelDeviceTreeItem.TryGetPluginName(out var pluginName))
{
//插件名称
await GatewayExportService.OnChannelExport(new() { QueryPageOptions = new(), PluginName = pluginName });
ret = await GatewayExportService.OnChannelExport(new() { QueryPageOptions = new(), PluginName = pluginName });
}
else if (channelDeviceTreeItem.TryGetPluginType(out var pluginType))
{
await GatewayExportService.OnChannelExport(new ExportFilter() { QueryPageOptions = new(), PluginType = pluginType });
ret = await GatewayExportService.OnChannelExport(new ExportFilter() { QueryPageOptions = new(), PluginType = pluginType });
}
else
{
@@ -551,14 +552,17 @@ EventCallback.Factory.Create<MouseEventArgs>(this, async e =>
}
// 返回 true 时自动弹出提示框
await ToastService.Default();
if (ret)
await ToastService.Default();
}
async Task ExportAllChannel(ContextMenuItem item, object value)
{
await GatewayExportService.OnChannelExport(new() { QueryPageOptions = new() });
bool ret;
ret = await GatewayExportService.OnChannelExport(new() { QueryPageOptions = new() });
// 返回 true 时自动弹出提示框
await ToastService.Default();
if (ret)
await ToastService.Default();
}
@@ -1065,25 +1069,26 @@ EventCallback.Factory.Create<MouseEventArgs>(this, async e =>
async Task ExportCurrentDevice(ContextMenuItem item, object value)
{
bool ret;
if (value is not ChannelDeviceTreeItem channelDeviceTreeItem) return;
if (channelDeviceTreeItem.TryGetDeviceRuntime(out var deviceRuntime))
{
await GatewayExportService.OnDeviceExport(new() { QueryPageOptions = new(), DeviceId = deviceRuntime.Id });
ret = await GatewayExportService.OnDeviceExport(new() { QueryPageOptions = new(), DeviceId = deviceRuntime.Id });
}
else if (channelDeviceTreeItem.TryGetChannelRuntime(out var channelRuntime))
{
await GatewayExportService.OnDeviceExport(new() { QueryPageOptions = new(), ChannelId = channelRuntime.Id });
ret = await GatewayExportService.OnDeviceExport(new() { QueryPageOptions = new(), ChannelId = channelRuntime.Id });
}
else if (channelDeviceTreeItem.TryGetPluginName(out var pluginName))
{
//插件名称
await GatewayExportService.OnDeviceExport(new() { QueryPageOptions = new(), PluginName = pluginName });
ret = await GatewayExportService.OnDeviceExport(new() { QueryPageOptions = new(), PluginName = pluginName });
}
else if (channelDeviceTreeItem.TryGetPluginType(out var pluginType))
{
//采集
await GatewayExportService.OnDeviceExport(new() { QueryPageOptions = new(), PluginType = pluginType });
ret = await GatewayExportService.OnDeviceExport(new() { QueryPageOptions = new(), PluginType = pluginType });
}
else
{
@@ -1091,14 +1096,17 @@ EventCallback.Factory.Create<MouseEventArgs>(this, async e =>
}
// 返回 true 时自动弹出提示框
await ToastService.Default();
if (ret)
await ToastService.Default();
}
async Task ExportAllDevice(ContextMenuItem item, object value)
{
await GatewayExportService.OnDeviceExport(new() { QueryPageOptions = new() });
bool ret;
ret = await GatewayExportService.OnDeviceExport(new() { QueryPageOptions = new() });
// 返回 true 时自动弹出提示框
await ToastService.Default();
if (ret)
await ToastService.Default();
}
async Task ImportDevice(ContextMenuItem item, object value)
@@ -1299,7 +1307,6 @@ EventCallback.Factory.Create<MouseEventArgs>(this, async e =>
try
{
if (Disposed) return;
await Task.Delay(1000);
await OnClickSearch(SearchText);
Value = GetValue(Value);
@@ -1311,6 +1318,7 @@ EventCallback.Factory.Create<MouseEventArgs>(this, async e =>
}
finally
{
await Task.Delay(1000);
_isExecuting = false;
}
}

View File

@@ -221,9 +221,10 @@ public partial class DeviceTable : IDisposable
private async Task ExcelExportAsync(ITableExportContext<DeviceRuntime> tableExportContext, bool all = false)
{
bool ret;
if (all)
{
await GatewayExportService.OnDeviceExport(new() { QueryPageOptions = new() });
ret = await GatewayExportService.OnDeviceExport(new() { QueryPageOptions = new() });
}
else
{
@@ -231,16 +232,16 @@ public partial class DeviceTable : IDisposable
{
case ChannelDevicePluginTypeEnum.PluginName:
await GatewayExportService.OnDeviceExport(new() { QueryPageOptions = new(), PluginName = SelectModel.PluginName });
ret = await GatewayExportService.OnDeviceExport(new() { QueryPageOptions = new(), PluginName = SelectModel.PluginName });
break;
case ChannelDevicePluginTypeEnum.Channel:
await GatewayExportService.OnDeviceExport(new() { QueryPageOptions = new(), ChannelId = SelectModel.ChannelRuntime.Id });
ret = await GatewayExportService.OnDeviceExport(new() { QueryPageOptions = new(), ChannelId = SelectModel.ChannelRuntime.Id });
break;
case ChannelDevicePluginTypeEnum.Device:
await GatewayExportService.OnDeviceExport(new() { QueryPageOptions = new(), DeviceId = SelectModel.DeviceRuntime.Id, PluginType = SelectModel.DeviceRuntime.PluginType });
ret = await GatewayExportService.OnDeviceExport(new() { QueryPageOptions = new(), DeviceId = SelectModel.DeviceRuntime.Id, PluginType = SelectModel.DeviceRuntime.PluginType });
break;
default:
await GatewayExportService.OnDeviceExport(new() { QueryPageOptions = new() });
ret = await GatewayExportService.OnDeviceExport(new() { QueryPageOptions = new() });
break;
}
@@ -248,7 +249,8 @@ public partial class DeviceTable : IDisposable
}
// 返回 true 时自动弹出提示框
await ToastService.Default();
if (ret)
await ToastService.Default();
}
async Task ExcelDeviceAsync(ITableExportContext<DeviceRuntime> tableExportContext)

View File

@@ -268,9 +268,10 @@ public partial class VariableRuntimeInfo : IDisposable
private async Task ExcelExportAsync(ITableExportContext<VariableRuntime> tableExportContext, bool all = false)
{
bool ret;
if (all)
{
await GatewayExportService.OnVariableExport(new() { QueryPageOptions = new() });
ret = await GatewayExportService.OnVariableExport(new() { QueryPageOptions = new() });
}
else
{
@@ -278,16 +279,16 @@ public partial class VariableRuntimeInfo : IDisposable
{
case ChannelDevicePluginTypeEnum.PluginName:
await GatewayExportService.OnVariableExport(new() { QueryPageOptions = new(), PluginName = SelectModel.PluginName });
ret = await GatewayExportService.OnVariableExport(new() { QueryPageOptions = new(), PluginName = SelectModel.PluginName });
break;
case ChannelDevicePluginTypeEnum.Channel:
await GatewayExportService.OnVariableExport(new() { QueryPageOptions = new(), ChannelId = SelectModel.ChannelRuntime.Id });
ret = await GatewayExportService.OnVariableExport(new() { QueryPageOptions = new(), ChannelId = SelectModel.ChannelRuntime.Id });
break;
case ChannelDevicePluginTypeEnum.Device:
await GatewayExportService.OnVariableExport(new() { QueryPageOptions = new(), DeviceId = SelectModel.DeviceRuntime.Id, PluginType = SelectModel.DeviceRuntime.PluginType });
ret = await GatewayExportService.OnVariableExport(new() { QueryPageOptions = new(), DeviceId = SelectModel.DeviceRuntime.Id, PluginType = SelectModel.DeviceRuntime.PluginType });
break;
default:
await GatewayExportService.OnVariableExport(new() { QueryPageOptions = new() });
ret = await GatewayExportService.OnVariableExport(new() { QueryPageOptions = new() });
break;
}
@@ -295,7 +296,8 @@ public partial class VariableRuntimeInfo : IDisposable
}
// 返回 true 时自动弹出提示框
await ToastService.Default();
if (ret)
await ToastService.Default();
}
async Task ExcelVariableAsync(ITableExportContext<VariableRuntime> tableExportContext)

View File

@@ -357,7 +357,7 @@ public partial class OpcUaServer : BusinessBase
{
StoreType = CertificateStoreType.X509Store,
StorePath = "CurrentUser\\UAServer_ThingsGateway",
SubjectName = _driverPropertys.BigTextSubjectName,
SubjectName = $"{_driverPropertys.BigTextSubjectName}{_driverPropertys.OpcUaStringUrl}",
//ValidationOptions = CertificateValidationOptions.SuppressHostNameInvalid,
},

View File

@@ -109,6 +109,7 @@ public class Startup : AppStartup
// setting.Converters.Add(new IsoDateTimeConverter { DateTimeStyles = DateTimeStyles.AssumeUniversal }); // 解决DateTimeOffset异常
}
;
services.AddMvcFilter<RequestAuditFilter>();
services.AddControllers()
.AddNewtonsoftJson(options => SetNewtonsoftJsonSetting(options.SerializerSettings))
@@ -215,7 +216,6 @@ public class Startup : AppStartup
// });
//});
services.AddMvcFilter<RequestAuditFilter>();
//日志写入数据库配置
services.AddDatabaseLogging<DatabaseLoggingWriter>(options =>

View File

@@ -88,6 +88,8 @@ public class Startup : AppStartup
}
;
services.AddMvcFilter<RequestAuditFilter>();
services.AddControllers()
.AddNewtonsoftJson(options => SetNewtonsoftJsonSetting(options.SerializerSettings))
//.AddXmlSerializerFormatters()
@@ -237,7 +239,6 @@ public class Startup : AppStartup
// logContext.Set(LoggingConst.Method, httpContext.Request.Method);//请求方法
// });
//});
services.AddMvcFilter<RequestAuditFilter>();
//日志写入数据库配置
services.AddDatabaseLogging<DatabaseLoggingWriter>(options =>

View File

@@ -83,6 +83,7 @@ public class Startup : AppStartup
// setting.Converters.Add(new IsoDateTimeConverter { DateTimeStyles = DateTimeStyles.AssumeUniversal }); // 解决DateTimeOffset异常
}
;
services.AddMvcFilter<RequestAuditFilter>();
services.AddControllers()
.AddNewtonsoftJson(options => SetNewtonsoftJsonSetting(options.SerializerSettings))
@@ -233,7 +234,6 @@ public class Startup : AppStartup
// logContext.Set(LoggingConst.Method, httpContext.Request.Method);//请求方法
// });
//});
services.AddMvcFilter<RequestAuditFilter>();
//日志写入数据库配置
services.AddDatabaseLogging<DatabaseLoggingWriter>(options =>

View File

@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>10.6.21</Version>
<Version>10.6.27</Version>
</PropertyGroup>
<ItemGroup>