|
@@ -8,32 +8,14 @@ using System.Threading.Channels;
|
|
|
|
|
|
namespace WCS.Core
|
|
|
{
|
|
|
- public static class Ltc
|
|
|
- {
|
|
|
- public static T GetWorld<T>() where T : World
|
|
|
- {
|
|
|
- return (T)World.Worlds.Where(v => v.GetType() == typeof(T)).First();
|
|
|
- }
|
|
|
-
|
|
|
- public static T GetSystem<T>() where T : SystemBase
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
- return (T)World.Worlds.SelectMany(v => v.Systems).Where(v => v.GetType() == typeof(T)).First();
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- throw new Exception($"系统:{typeof(T).Name}未设置BelongToAttribute");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
+ internal static class Ltc
|
|
|
+ {
|
|
|
private static ConcurrentDictionary<Thread, Channel> Channels = new ConcurrentDictionary<Thread, Channel>();
|
|
|
|
|
|
public static void SetChannel(Channel channel)
|
|
|
{
|
|
|
Channels[Thread.CurrentThread] = channel;
|
|
|
- ClearChannel();
|
|
|
+ //ClearChannel();
|
|
|
}
|
|
|
|
|
|
public static Channel GetChannel()
|
|
@@ -41,182 +23,182 @@ namespace WCS.Core
|
|
|
return Channels[Thread.CurrentThread];
|
|
|
}
|
|
|
|
|
|
- static ConcurrentDictionary<Channel, List<LogInfo>> Msgs = new ConcurrentDictionary<Channel, List<LogInfo>>();
|
|
|
-
|
|
|
-
|
|
|
- static void ClearChannel()
|
|
|
- {
|
|
|
- if (Msgs.TryGetValue(GetChannel(), out var list))
|
|
|
- list.Clear();
|
|
|
- }
|
|
|
-
|
|
|
- public static string GetLogStr()
|
|
|
- {
|
|
|
- var channel = GetChannel();
|
|
|
- if (Msgs.TryGetValue(channel, out var list))
|
|
|
- {
|
|
|
- var msg = "-------------------"+channel + "--------------------\n" + string.Join('\n', list.Select(v => $"{string.Join('\n', v)}"));
|
|
|
- return msg;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- return "";
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public static List<LogInfo> GetLogInfo()
|
|
|
- {
|
|
|
- var channel = GetChannel();
|
|
|
- if (Msgs.TryGetValue(channel, out var list))
|
|
|
- {
|
|
|
- return list;
|
|
|
- }
|
|
|
- return new List<LogInfo>();
|
|
|
- }
|
|
|
-
|
|
|
- public static void Log(string msg,LogLevel level,ErrorType type)
|
|
|
- {
|
|
|
- var channel = GetChannel();
|
|
|
+ //static ConcurrentDictionary<Channel, List<LogInfo>> Msgs = new ConcurrentDictionary<Channel, List<LogInfo>>();
|
|
|
+
|
|
|
+
|
|
|
+ //static void ClearChannel()
|
|
|
+ //{
|
|
|
+ // if (Msgs.TryGetValue(GetChannel(), out var list))
|
|
|
+ // list.Clear();
|
|
|
+ //}
|
|
|
+
|
|
|
+ //public static string GetLogStr()
|
|
|
+ //{
|
|
|
+ // var channel = GetChannel();
|
|
|
+ // if (Msgs.TryGetValue(channel, out var list))
|
|
|
+ // {
|
|
|
+ // var msg = "-------------------"+channel + "--------------------\n" + string.Join('\n', list.Select(v => $"{string.Join('\n', v)}"));
|
|
|
+ // return msg;
|
|
|
+ // }
|
|
|
+ // else
|
|
|
+ // {
|
|
|
+ // return "";
|
|
|
+ // }
|
|
|
+ //}
|
|
|
+
|
|
|
+ //public static List<LogInfo> GetLogInfo()
|
|
|
+ //{
|
|
|
+ // var channel = GetChannel();
|
|
|
+ // if (Msgs.TryGetValue(channel, out var list))
|
|
|
+ // {
|
|
|
+ // return list;
|
|
|
+ // }
|
|
|
+ // return new List<LogInfo>();
|
|
|
+ //}
|
|
|
+
|
|
|
+ //public static void Log(string msg,LogLevel level,ErrorType type)
|
|
|
+ //{
|
|
|
+ // var channel = GetChannel();
|
|
|
|
|
|
- if (!Msgs.TryGetValue(channel, out var list))
|
|
|
- {
|
|
|
- list = new List<LogInfo>();
|
|
|
- Msgs[channel] = list;
|
|
|
- }
|
|
|
- list.Add(new LogInfo { Message = msg, Level = level, Type = type, Channel = channel });
|
|
|
- }
|
|
|
+ // if (!Msgs.TryGetValue(channel, out var list))
|
|
|
+ // {
|
|
|
+ // list = new List<LogInfo>();
|
|
|
+ // Msgs[channel] = list;
|
|
|
+ // }
|
|
|
+ // list.Add(new LogInfo { Message = msg, Level = level, Type = type, Channel = channel });
|
|
|
+ //}
|
|
|
|
|
|
- public static void Publish(World world)
|
|
|
- {
|
|
|
- var channel = GetChannel();
|
|
|
- if (Msgs.TryGetValue(channel, out var list))
|
|
|
- {
|
|
|
- var msg = string.Join('\n', list);
|
|
|
- world.Ex().Publish(channel, msg);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private static string ResultString<T>(T obj)
|
|
|
- {
|
|
|
- if (obj == null)
|
|
|
- {
|
|
|
- return "null";
|
|
|
- }
|
|
|
- else if (obj is bool)
|
|
|
- {
|
|
|
- var b = obj as Boolean?;
|
|
|
- return b.Value ? "成立" : "不成立";
|
|
|
- }
|
|
|
- else if (obj is System.Collections.ICollection)
|
|
|
- {
|
|
|
- var coll = obj as System.Collections.ICollection;
|
|
|
- return coll.Count.ToString() + "元素";
|
|
|
- }
|
|
|
-
|
|
|
- return obj.ToString();
|
|
|
- }
|
|
|
-
|
|
|
- public static T Do<T>(Expression<Func<T>> exp)
|
|
|
- {
|
|
|
- var msg = exp.ExpToString();
|
|
|
- msg += " 结果:";
|
|
|
- try
|
|
|
- {
|
|
|
- var res = exp.Compile().Invoke();
|
|
|
- msg += res;
|
|
|
- return res;
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- throw;
|
|
|
- }
|
|
|
- finally
|
|
|
- {
|
|
|
- Log(msg, LogLevel.Low, ErrorType.Kown);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public static T Do<T1, T>(T1 obj, Expression<Func<T1, T>> exp)
|
|
|
- {
|
|
|
- var msg = "";
|
|
|
- try
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
- msg = exp.ExpToString();
|
|
|
- }
|
|
|
- catch (Exception ex2)
|
|
|
- {
|
|
|
- }
|
|
|
- msg += " 结果:";
|
|
|
- var res = exp.Compile().Invoke(obj);
|
|
|
- msg += ResultString(res);
|
|
|
- return res;
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- throw;
|
|
|
- }
|
|
|
- finally
|
|
|
- {
|
|
|
- Log(msg, LogLevel.Low, ErrorType.Kown);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public static T Do<T1, T2, T>(T1 obj, T2 obj2, Expression<Func<T1, T2, T>> exp)
|
|
|
- {
|
|
|
- var msg = exp.ExpToString();
|
|
|
- msg += " 结果:";
|
|
|
- try
|
|
|
- {
|
|
|
- var res = exp.Compile().Invoke(obj, obj2);
|
|
|
- msg += ResultString(res);
|
|
|
- return res;
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- throw;
|
|
|
- }
|
|
|
- finally
|
|
|
- {
|
|
|
- Log(msg, LogLevel.Low, ErrorType.Kown);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public static T Do<T1, T2, T3, T>(T1 obj, T2 obj2, T3 obj3, Expression<Func<T1, T2, T3, T>> exp)
|
|
|
- {
|
|
|
- var msg = exp.ExpToString();
|
|
|
- msg += " 结果:";
|
|
|
- try
|
|
|
- {
|
|
|
- var res = exp.Compile().Invoke(obj, obj2, obj3);
|
|
|
- msg += ResultString(res);
|
|
|
- return res;
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- throw;
|
|
|
- }
|
|
|
- finally
|
|
|
- {
|
|
|
- Log(msg, LogLevel.Low, ErrorType.Kown);
|
|
|
- }
|
|
|
- }
|
|
|
+ //public static void Publish(World world)
|
|
|
+ //{
|
|
|
+ // var channel = GetChannel();
|
|
|
+ // if (Msgs.TryGetValue(channel, out var list))
|
|
|
+ // {
|
|
|
+ // var msg = string.Join('\n', list);
|
|
|
+ // world.Ex().Publish(channel, msg);
|
|
|
+ // }
|
|
|
+ //}
|
|
|
+
|
|
|
+ //private static string ResultString<T>(T obj)
|
|
|
+ //{
|
|
|
+ // if (obj == null)
|
|
|
+ // {
|
|
|
+ // return "null";
|
|
|
+ // }
|
|
|
+ // else if (obj is bool)
|
|
|
+ // {
|
|
|
+ // var b = obj as Boolean?;
|
|
|
+ // return b.Value ? "成立" : "不成立";
|
|
|
+ // }
|
|
|
+ // else if (obj is System.Collections.ICollection)
|
|
|
+ // {
|
|
|
+ // var coll = obj as System.Collections.ICollection;
|
|
|
+ // return coll.Count.ToString() + "元素";
|
|
|
+ // }
|
|
|
+
|
|
|
+ // return obj.ToString();
|
|
|
+ //}
|
|
|
+
|
|
|
+ //public static T Do<T>(Expression<Func<T>> exp)
|
|
|
+ //{
|
|
|
+ // var msg = exp.ExpToString();
|
|
|
+ // msg += " 结果:";
|
|
|
+ // try
|
|
|
+ // {
|
|
|
+ // var res = exp.Compile().Invoke();
|
|
|
+ // msg += res;
|
|
|
+ // return res;
|
|
|
+ // }
|
|
|
+ // catch (Exception ex)
|
|
|
+ // {
|
|
|
+ // throw;
|
|
|
+ // }
|
|
|
+ // finally
|
|
|
+ // {
|
|
|
+ // Log(msg, LogLevel.Low, ErrorType.Kown);
|
|
|
+ // }
|
|
|
+ //}
|
|
|
+
|
|
|
+ //public static T Do<T1, T>(T1 obj, Expression<Func<T1, T>> exp)
|
|
|
+ //{
|
|
|
+ // var msg = "";
|
|
|
+ // try
|
|
|
+ // {
|
|
|
+ // try
|
|
|
+ // {
|
|
|
+ // msg = exp.ExpToString();
|
|
|
+ // }
|
|
|
+ // catch (Exception ex2)
|
|
|
+ // {
|
|
|
+ // }
|
|
|
+ // msg += " 结果:";
|
|
|
+ // var res = exp.Compile().Invoke(obj);
|
|
|
+ // msg += ResultString(res);
|
|
|
+ // return res;
|
|
|
+ // }
|
|
|
+ // catch (Exception ex)
|
|
|
+ // {
|
|
|
+ // throw;
|
|
|
+ // }
|
|
|
+ // finally
|
|
|
+ // {
|
|
|
+ // Log(msg, LogLevel.Low, ErrorType.Kown);
|
|
|
+ // }
|
|
|
+ //}
|
|
|
+
|
|
|
+ //public static T Do<T1, T2, T>(T1 obj, T2 obj2, Expression<Func<T1, T2, T>> exp)
|
|
|
+ //{
|
|
|
+ // var msg = exp.ExpToString();
|
|
|
+ // msg += " 结果:";
|
|
|
+ // try
|
|
|
+ // {
|
|
|
+ // var res = exp.Compile().Invoke(obj, obj2);
|
|
|
+ // msg += ResultString(res);
|
|
|
+ // return res;
|
|
|
+ // }
|
|
|
+ // catch (Exception ex)
|
|
|
+ // {
|
|
|
+ // throw;
|
|
|
+ // }
|
|
|
+ // finally
|
|
|
+ // {
|
|
|
+ // Log(msg, LogLevel.Low, ErrorType.Kown);
|
|
|
+ // }
|
|
|
+ //}
|
|
|
+
|
|
|
+ //public static T Do<T1, T2, T3, T>(T1 obj, T2 obj2, T3 obj3, Expression<Func<T1, T2, T3, T>> exp)
|
|
|
+ //{
|
|
|
+ // var msg = exp.ExpToString();
|
|
|
+ // msg += " 结果:";
|
|
|
+ // try
|
|
|
+ // {
|
|
|
+ // var res = exp.Compile().Invoke(obj, obj2, obj3);
|
|
|
+ // msg += ResultString(res);
|
|
|
+ // return res;
|
|
|
+ // }
|
|
|
+ // catch (Exception ex)
|
|
|
+ // {
|
|
|
+ // throw;
|
|
|
+ // }
|
|
|
+ // finally
|
|
|
+ // {
|
|
|
+ // Log(msg, LogLevel.Low, ErrorType.Kown);
|
|
|
+ // }
|
|
|
+ //}
|
|
|
}
|
|
|
|
|
|
- public class LogInfo
|
|
|
- {
|
|
|
- public ErrorType Type { get; set; }
|
|
|
- public LogLevel Level { get; set; }
|
|
|
- public Channel Channel { get; set; }
|
|
|
- public string Message { get; set; }
|
|
|
+ //public class LogInfo
|
|
|
+ //{
|
|
|
+ // public ErrorType Type { get; set; }
|
|
|
+ // public LogLevel Level { get; set; }
|
|
|
+ // public Channel Channel { get; set; }
|
|
|
+ // public string Message { get; set; }
|
|
|
|
|
|
- public override string ToString()
|
|
|
- {
|
|
|
- //var a = ErrorType.Unkown;
|
|
|
- return $"类型:{Type.Description()},级别:{Level.Description()},内容:{Message}";
|
|
|
- }
|
|
|
- }
|
|
|
+ // public override string ToString()
|
|
|
+ // {
|
|
|
+ // //var a = ErrorType.Unkown;
|
|
|
+ // return $"类型:{Type.Description()},级别:{Level.Description()},内容:{Message}";
|
|
|
+ // }
|
|
|
+ //}
|
|
|
|
|
|
public class Channel
|
|
|
{
|
|
@@ -232,31 +214,31 @@ namespace WCS.Core
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public enum ErrorType
|
|
|
- {
|
|
|
- [Description("未知")]
|
|
|
- Unkown = 0,
|
|
|
- [Description("已知")]
|
|
|
- Kown = 1
|
|
|
- }
|
|
|
-
|
|
|
- public enum LogLevel
|
|
|
- {
|
|
|
- [Description("低")]
|
|
|
- Low = 0,
|
|
|
- [Description("中")]
|
|
|
- Mid = 1,
|
|
|
- [Description("高")]
|
|
|
- High = 2
|
|
|
- }
|
|
|
-
|
|
|
- public class KnownException : Exception
|
|
|
- {
|
|
|
- public LogLevel Level { get; set; }
|
|
|
-
|
|
|
- public KnownException(string msg, LogLevel level) : base(msg)
|
|
|
- {
|
|
|
- this.Level = level;
|
|
|
- }
|
|
|
- }
|
|
|
+ //public enum ErrorType
|
|
|
+ //{
|
|
|
+ // [Description("未知")]
|
|
|
+ // Unkown = 0,
|
|
|
+ // [Description("已知")]
|
|
|
+ // Kown = 1
|
|
|
+ //}
|
|
|
+
|
|
|
+ //public enum LogLevel
|
|
|
+ //{
|
|
|
+ // [Description("低")]
|
|
|
+ // Low = 0,
|
|
|
+ // [Description("中")]
|
|
|
+ // Mid = 1,
|
|
|
+ // [Description("高")]
|
|
|
+ // High = 2
|
|
|
+ //}
|
|
|
+
|
|
|
+ //public class KnownException : Exception
|
|
|
+ //{
|
|
|
+ // public LogLevel Level { get; set; }
|
|
|
+
|
|
|
+ // public KnownException(string msg, LogLevel level) : base(msg)
|
|
|
+ // {
|
|
|
+ // this.Level = level;
|
|
|
+ // }
|
|
|
+ //}
|
|
|
}
|