From 6778472e04ec092e566fb950d0427095dabcae18 Mon Sep 17 00:00:00 2001
From: hutongqing <hutongqing@hnkhzn.com>
Date: 星期五, 08 十一月 2024 19:37:36 +0800
Subject: [PATCH] Create WIDESEAWCS_Communicator.DLL使用说明文档2024-11-08.pdf
---
WIDESEAWCS_Server/WIDESEAWCS_Core/AOP/LogAOP.cs | 46 ++++------------------------------------------
1 files changed, 4 insertions(+), 42 deletions(-)
diff --git a/WIDESEAWCS_Server/WIDESEAWCS_Core/AOP/LogAOP.cs b/WIDESEAWCS_Server/WIDESEAWCS_Core/AOP/LogAOP.cs
index 6b22f40..9ee515d 100644
--- a/WIDESEAWCS_Server/WIDESEAWCS_Core/AOP/LogAOP.cs
+++ b/WIDESEAWCS_Server/WIDESEAWCS_Core/AOP/LogAOP.cs
@@ -27,7 +27,6 @@
_accessor = accessor;
}
-
/// <summary>
/// 瀹炰緥鍖朓Interceptor鍞竴鏂规硶
/// </summary>
@@ -38,7 +37,7 @@
string json;
try
{
- if(invocation.Arguments.Any())
+ if (invocation.Arguments.Any())
{
json = JsonConvert.SerializeObject(invocation.Arguments);
}
@@ -73,9 +72,6 @@
// 寮傛鑾峰彇寮傚父锛屽厛鎵ц
if (IsAsyncMethod(invocation.Method))
{
- #region 鏂规涓�
-
- //Wait task execution and modify return value
if (invocation.Method.ReturnType == typeof(Task))
{
invocation.ReturnValue = InternalAsyncHelper.AwaitTaskWithPostActionAndFinally(
@@ -86,45 +82,17 @@
LogEx(ex, apiLogAopInfo);
});
}
- //Task<TResult>
else
{
invocation.ReturnValue = InternalAsyncHelper.CallAwaitTaskWithPostActionAndFinallyAndGetResult(
invocation.Method.ReturnType.GenericTypeArguments[0],
invocation.ReturnValue,
- //async () => await SuccessAction(invocation, dataIntercept),/*鎴愬姛鏃舵墽琛�*/
async (o) => await SuccessAction(invocation, apiLogAopInfo, startTime, o), /*鎴愬姛鏃舵墽琛�*/
ex =>
{
LogEx(ex, apiLogAopInfo);
});
}
-
- #endregion
-
-
- // 濡傛灉鏂规涓�涓嶈锛岃瘯璇曡繖涓柟妗�
- //#region 鏂规浜�
-
- //var type = invocation.Method.ReturnType;
- //var resultProperty = type.GetProperty("Result");
- //DateTime endTime = DateTime.Now;
- //string ResponseTime = (endTime - startTime).Milliseconds.ToString();
- //apiLogAopInfo.ResponseTime = endTime.ToString("yyyy-MM-dd hh:mm:ss fff");
- //apiLogAopInfo.ResponseIntervalTime = ResponseTime + "ms";
- //apiLogAopInfo.ResponseJsonData = JsonConvert.SerializeObject(resultProperty.GetValue(invocation.ReturnValue));
-
- ////dataIntercept += ($"銆愬搷搴旀椂闂淬�戯細{ResponseTime}ms\r\n");
- ////dataIntercept += ($"銆愭墽琛屽畬鎴愭椂闂淬�戯細{endTime.ToString("yyyy-MM-dd hh:mm:ss fff")}\r\n");
- ////dataIntercept += ($"銆愭墽琛屽畬鎴愮粨鏋溿�戯細{JsonConvert.SerializeObject(resultProperty.GetValue(invocation.ReturnValue))}\r\n");
-
- //Parallel.For(0, 1, e =>
- //{
- // //LogLock.OutLogAOP("AOPLog", new string[] { dataIntercept });
- // LogLock.OutLogAOP("AOPLog", new string[] { apiLogAopInfo.GetType().ToString() + " - ResponseJsonDataType:" + type, JsonConvert.SerializeObject(apiLogAopInfo) });
- //});
-
- //#endregion
}
else
{
@@ -157,7 +125,6 @@
LogEx(ex, apiLogAopInfo);
throw;
}
-
}
private async Task SuccessAction(IInvocation invocation, AOPLogInfo apiLogAopInfo, DateTime startTime, object o = null)
@@ -168,12 +135,10 @@
apiLogAopInfo.ResponseIntervalTime = ResponseTime + "ms";
apiLogAopInfo.ResponseJsonData = JsonConvert.SerializeObject(o);
-
await Task.Run(() =>
{
Parallel.For(0, 1, e =>
{
- //LogLock.OutSql2Log("AOPLog", new string[] { JsonConvert.SerializeObject(apiLogAopInfo) });
LogLock.OutLogAOP("AOPLog", new string[] { apiLogAopInfo.GetType().ToString(), JsonConvert.SerializeObject(apiLogAopInfo) });
});
});
@@ -204,10 +169,7 @@
public static bool IsAsyncMethod(MethodInfo method)
{
- return
- method.ReturnType == typeof(Task) ||
- method.ReturnType.IsGenericType && method.ReturnType.GetGenericTypeDefinition() == typeof(Task<>)
- ;
+ return method.ReturnType == typeof(Task) || method.ReturnType.IsGenericType && method.ReturnType.GetGenericTypeDefinition() == typeof(Task<>);
}
}
@@ -258,7 +220,7 @@
Func<object, Task> action, Action<Exception> finalAction)
{
return typeof(InternalAsyncHelper)
- .GetMethod("AwaitTaskWithPostActionAndFinallyAndGetResult", BindingFlags.Public | BindingFlags.Static)
+ .GetMethod(nameof(AwaitTaskWithPostActionAndFinallyAndGetResult), BindingFlags.Public | BindingFlags.Static)
.MakeGenericMethod(taskReturnType)
.Invoke(null, new object[] { actualReturnValue, action, finalAction });
}
@@ -289,7 +251,7 @@
/// <summary>
/// 璇锋眰鍙傛暟鏁版嵁JSON
/// </summary>
- [Description("璇锋眰鍙傛暟鏁版嵁JSON")]
+ [Description("璇锋眰鍙傛暟鏁版嵁JSON")]
public string RequestParamsData { get; set; } = string.Empty;
/// <summary>
/// 璇锋眰鍝嶅簲闂撮殧鏃堕棿
--
Gitblit v1.9.3