| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- 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<LogSplicingComponent>
- {
- public override void Awake(LogSplicingComponent self)
- {
- }
- }
- public class LogSplicingComponentDestroySystem : DestroySystem<LogSplicingComponent>
- {
- public override void Destroy(LogSplicingComponent self)
- {
- }
- }
- public static class LogSplicingComponentSystem
- {
- /// <summary>
- /// 拼接日志数据
- /// </summary>
- /// <param name="baseObj"></param>
- /// <returns></returns>
- public static string LogObjectToStr(this LogSplicingComponent self, ILogBase baseObj)
- {
- return JsonHelper.ToJson(baseObj);
- }
- // 注释不删除
- // /// <summary>
- // /// 拼接日志数据
- // /// </summary>
- // /// <param name="baseObj"></param>
- // /// <returns></returns>
- // public static string LogObjectToStr(this LogSplicingComponent self, ILogBase baseObj)
- // {
- // string logData = string.Empty;
- // Type baseObjType = baseObj.GetType();
- // //表名
- // var loggerTypeName = baseObjType.GetCustomAttribute<LogNameAttribute>().Name;
- //
- // //检索表示在指定类型上定义的所有字段的集合
- // IEnumerable<FieldInfo> fieldInfos = baseObjType.GetRuntimeFields();
- //
- // fieldInfos = fieldInfos.OrderBy(a => a.Name).Where(a => a.GetCustomAttribute<LogColumnAttribute>() != null).OrderBy(a => a.Name);
- //
- // self.keyFieldInfos.Clear();
- // foreach (var item in fieldInfos)
- // {
- // LogColumnAttribute logAtt = item.GetCustomAttribute<LogColumnAttribute>();
- // 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();
- // }
- }
- }
|