2024年1月15日发(作者:)

private string GetExceptionRequestBody(ExceptionContext context) { string requestBody = ""; if (context != null) { var request = context?.HttpContext?.Request; if (request != null) { on = 0; StreamReader stream = new StreamReader(); requestBody = End(); on = 0; } } return requestBody; } }   public class ActionFilter : IActionFilter { private Stopwatch timer; [Import] private IAduitService aduitService { get; set; } public ActionFilter(IoC ioc) { e(this); } public void OnActionExecuting(ActionExecutingContext context) { = new Stopwatch(); (); } public void OnActionExecuted(ActionExecutedContext context) { (); ApiAction(GetActionDescriptor(context)); } private ApiActionDescriptorModel GetActionDescriptor(ActionExecutedContext context) { ApiActionDescriptorModel descriptor = new ApiActionDescriptorModel();

var userInfo= ((Identity)ty).Claims?.ToList(); if (context != null) { Name = ((ControllerActionDescriptor)Descriptor)?.ActionName; llerName = ((ControllerActionDescriptor)Descriptor)?.ControllerName; tIp = ng(); tPort = ng(); thod = ng(); Time = dMilliseconds; or = userInfo?.Where(t => == "UserName")?.FirstOrDefault()?.Value; = userInfo?.Where(t => == "UserId")?.FirstOrDefault()?.Value; ime = ; tBody = ReadActionExcutedRequestBody(context); tring = t?.ng(); eBody = GetActionExcutedResponseBody(context); eStatusCode = Code; } return descriptor; } private string ReadActionExcutedRequestBody(ActionExecutedContext context) { string requestBody = ""; if (context != null) { var request = t; on = 0; StreamReader stream = new StreamReader(); requestBody = End(); on = 0; } return requestBody; }

e = ime; = e("localhost", "127.0.0.1"); seCode = responseCode; ype = ype; = (eType); nceLevel = (nceLevel); = audits[i]; = ; me = or; (auditModel); } return auditModels; } private List GetAudits(ApiActionDescriptorModel apiActionDescriptorModel, AuditRuleModel auditRuleModel) { var jsonDics = GetKeyValues(tBody); var urlDics = GetKeyValues(tring); foreach (var item in urlDics) { if (item != null && > 0) { foreach (var keyValue in item) h(t => (, )); } } List audits = new List(); foreach (var item in jsonDics) { var ruleStr = uleDescr; string[] rules = RegexRemoveRegexs(ruleStr, "【${.*?}】", "[【】${}]+"); if ( > 0) { for (int i = 0; i < ; i++) { if (!ns(rules[i])) continue; string value = item[rules[i]]; if (rules[i] == dMappingField) value = etCacheByCode(value).Name; ruleStr = e("${" + rules[i] + "}", value); } } (ruleStr); } return audits; } private List> GetKeyValues(string txt) { List> dics = new List>(); if (IsJson(txt)) { string text = rstByRegex(txt, @"^[.*?]$"); List jObjects = OrEmpty(text) new List() { alizeObject(txt) } : alizeObject>(txt); foreach (var item in jObjects) (ties().ToDictionary(x => , y => ng())); } else { NameValueCollection collection = ueryString(txt); var dic = new Dictionary(); foreach (var item in s) (item, collection[item]); (dic); } return dics; } private static int GetResponseCode(string resposeBody) { int responseCode = -1;

se(ntentBetweenTwoRegex(resposeBody, "code":", ","), out responseCode); return responseCode; } private List HandleIsJsonActionToAudit(ApiActionDescriptorModel apiActionDescriptorModel, AuditRuleModel auditRuleModel) { string text = rstByRegex(tBody, @"^[.*?]$"); List jObjects = null; if (!OrEmpty(text)) jObjects = alizeObject>(tBody); else jObjects = new List() { alizeObject(tBody) }; string[] rules = yRegex(uleDescr, "【.*?】"); List list = null; for (int i = 0; i < ; i++) { list = new List(){ new AuditModel() { UserName=or, ModelType=ype, Type =(eType), IncidenceLevel =(nceLevel), UserId=, Detail = GetAuditDetailByRuleRule(jObjects[i], rules).ToString(), AddTime = ime, Ip = e("localhost","127.0.0.1"), ResponseCode=GetResponseCode(apiActionDescriptorModel?.ResposeBody), } }; } return list; } private List HandleNotJsonActionToAduit(ApiActionDescriptorModel apiActionDescriptorModel, AuditRuleModel auditRuleModel) { string[] rules = yRegex(uleDescr, "【.*?】"); List list = null; if ( >= 2) { list = new List(){ new AuditModel() { UserName=or, ModelType=ype, Type =(eType), IncidenceLevel =(nceLevel), Detail = GetAuditDetailByRuleRule(tBody,rules).ToString(), AddTime = ime, Ip = e("localhost","127.0.0.1"), ResponseCode=GetResponseCode(apiActionDescriptorModel?.ResposeBody), } }; } return list; } private StringBuilder GetAuditDetailByRuleRule(string text, string[] rules) { StringBuilder sb = new StringBuilder(); (rules[0]); for (int i = 1; i < ; i++) ( eplace( rules[i], "【.*?】", "【" + ntentBetweenTwoRegex( text, "[?&]" + ntentBetweenTwoRegex(rules[i], @"【${", "}】") + "=", "(&|$)") + "】" )); return sb; } private StringBuilder GetAuditDetailByRuleRule(JObject jObject, string[] rules) { StringBuilder sb = new StringBuilder(); (rules[0]);

for (int i = 1; i < ; i++) { try { ( eplace(rules[i], "【.*?】", "【" + jObject[ntentBetweenTwoRegex(rules[i], @"【${", "}】")].ToString() + "】" )); } catch (Exception ex) { ("在" + rules[i] + "查找失败,具体原因:" + ng()); throw; } } return sb; }   public static string[] FindByRegexRemoveRegexs(string html, string strReg, string remReg) { string[] strs = FindByRegex(html, strReg); List result = new List(); if ( > 0) { for (int i = 0; i < ; i++) (RemoveByRegex(strs[i], remReg)); } return y(); }