LogicManagerBaisc.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using System.Collections.Concurrent;
  2. using System.Reflection;
  3. using NetCore;
  4. using NetServerCore.Attribute;
  5. using NetServerCore.Tool;
  6. namespace NetServerCore.NetLink;
  7. public class LogicManagerBaisc<T> : ILogicalParsing
  8. {
  9. private ConcurrentDictionary<int, LogicBaisc<T>> _allLogic = new ConcurrentDictionary<int, LogicBaisc<T>>();
  10. public void Init(string assemblyName, int groid)
  11. {
  12. Assembly[] ass = AppDomain.CurrentDomain.GetAssemblies();
  13. for (int i = 0; i < ass.Length; i++)
  14. {
  15. Assembly assembly = ass[i];
  16. if (!assembly.GetName().Name.Equals(assemblyName))
  17. {
  18. continue;
  19. }
  20. Type[] allType = assembly.GetTypes();
  21. for (int j = 0; j < allType.Length; j++)
  22. {
  23. Type type = allType[j];
  24. LogicEnrollAtt logicEnrollAtt = type.GetCustomAttribute<LogicEnrollAtt>();
  25. if (logicEnrollAtt != null && logicEnrollAtt.group == groid)
  26. {
  27. LogicBaisc<T> logicBasic = Activator.CreateInstance(type) as LogicBaisc<T>;
  28. logicBasic.Init(this);
  29. _allLogic.TryAdd(logicEnrollAtt.index, logicBasic);
  30. }
  31. }
  32. }
  33. }
  34. public LogicBaisc<T> GetLogicBaisc(int type)
  35. {
  36. LogicBaisc<T> logicBaisc;
  37. if (_allLogic.TryGetValue(type, out logicBaisc))
  38. {
  39. return logicBaisc;
  40. }
  41. return null;
  42. }
  43. public virtual void Logic(object data, IConnection iConnection)
  44. {
  45. }
  46. public virtual void AddConnection(IConnection iConnection)
  47. {
  48. }
  49. public virtual void RemoveConnection(IConnection iConnection)
  50. {
  51. }
  52. }