using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; using System.Security.Cryptography; using System.Text; using System.Text.RegularExpressions; namespace ET { public class LogSplicingComponentAwakeSystem : AwakeSystem { public override void Awake(LogSplicingComponent self) { } } public class LogSplicingComponentDestroySystem : DestroySystem { public override void Destroy(LogSplicingComponent self) { } } public static class LogSplicingComponentSystem { /// /// 拼接日志数据 /// /// /// public static string LogObjectToStr(this LogSplicingComponent self, ILogBase baseObj) { return JsonHelper.ToJson(baseObj); } // 注释不删除 // /// // /// 拼接日志数据 // /// // /// // /// // public static string LogObjectToStr(this LogSplicingComponent self, ILogBase baseObj) // { // string logData = string.Empty; // Type baseObjType = baseObj.GetType(); // //表名 // var loggerTypeName = baseObjType.GetCustomAttribute().Name; // // //检索表示在指定类型上定义的所有字段的集合 // IEnumerable fieldInfos = baseObjType.GetRuntimeFields(); // // fieldInfos = fieldInfos.OrderBy(a => a.Name).Where(a => a.GetCustomAttribute() != null).OrderBy(a => a.Name); // // self.keyFieldInfos.Clear(); // foreach (var item in fieldInfos) // { // LogColumnAttribute logAtt = item.GetCustomAttribute(); // string fieldName = self.GetOrDefualt(logAtt.name, item.Name); // if (self.keyFieldInfos.ContainsKey(fieldName)) // { // self.keyFieldInfos[fieldName] = item; // } // else // { // self.keyFieldInfos.Add(fieldName, item); // } // } // // var keyFieldInfoss = self.keyFieldInfos.OrderBy(a => a.Key); // // if (keyFieldInfoss != null) // { // int index = 0; // foreach (var item in keyFieldInfoss) //全部统一使用字段名进行 升序 排序--结构亦如此 // { // var fieldValue = item.Value.GetValue(baseObj); // // if (fieldValue != null) // { // fieldValue = Regex.Replace(fieldValue.ToString(), @"[\n`|$@]", "", // RegexOptions.IgnoreCase); // } // // index++; // //最后一个不拼接"|" // if (index == fieldInfos.Count()) // { // logData += fieldValue; // } // else // { // logData += fieldValue + "|"; // } // } // } // // logData = InsertSpaceBeforeUpperCase(loggerTypeName.ToString()) + "|" + logData; // return logData; // } // private static string GetOrDefualt(this LogSplicingComponent self, string value, // string defualt) // { // if (string.IsNullOrEmpty(value)) // { // return defualt; // } // // return value; // } // // private static string InsertSpaceBeforeUpperCase(string str) // { // var sb = new StringBuilder(); // // char previousChar = char.MinValue; // Unicode '\0' // // foreach (char c in str) // { // if (char.IsUpper(c)) // { // // If not the first character and previous character is not a space, insert a space before uppercase // // if (sb.Length != 0 && previousChar != ' ') // { // sb.Append('_'); // } // } // // sb.Append(c); // // previousChar = c; // } // // return sb.ToString(); // } } }