1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- using System.Collections.Concurrent;
- using System.Reflection;
- using NetCore;
- using NetServerCore.Attribute;
- using NetServerCore.Tool;
- namespace NetServerCore.NetLink;
- public class LogicManagerBaisc<T> : ILogicalParsing
- {
- private ConcurrentDictionary<int, LogicBaisc<T>> _allLogic = new ConcurrentDictionary<int, LogicBaisc<T>>();
- public void Init(string assemblyName, int groid)
- {
- Assembly[] ass = AppDomain.CurrentDomain.GetAssemblies();
- for (int i = 0; i < ass.Length; i++)
- {
- Assembly assembly = ass[i];
- if (!assembly.GetName().Name.Equals(assemblyName))
- {
- continue;
- }
- Type[] allType = assembly.GetTypes();
- for (int j = 0; j < allType.Length; j++)
- {
- Type type = allType[j];
- LogicEnrollAtt logicEnrollAtt = type.GetCustomAttribute<LogicEnrollAtt>();
- if (logicEnrollAtt != null && logicEnrollAtt.group == groid)
- {
- LogicBaisc<T> logicBasic = Activator.CreateInstance(type) as LogicBaisc<T>;
- logicBasic.Init(this);
- _allLogic.TryAdd(logicEnrollAtt.index, logicBasic);
- }
- }
- }
- }
- public LogicBaisc<T> GetLogicBaisc(int type)
- {
- LogicBaisc<T> logicBaisc;
- if (_allLogic.TryGetValue(type, out logicBaisc))
- {
- return logicBaisc;
- }
- return null;
- }
- public virtual void Logic(object data, IConnection iConnection)
- {
- }
- public virtual void AddConnection(IConnection iConnection)
- {
- }
- public virtual void RemoveConnection(IConnection iConnection)
- {
- }
- }
|