123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- using System;
- using System.Collections.Generic;
-
- namespace Luticate2.Utils.Hubs
- {
- public class LuHubConnectionTracker
- {
- protected IDictionary<string, IList<string>> ConnectionIds { get; set; }
-
- public LuHubConnectionTracker()
- {
- ConnectionIds = new Dictionary<string, IList<string>>();
- }
-
- public static string GetNameFromType(Type type)
- {
- return type.FullName;
- }
-
-
-
- public void Add(string name, string id)
- {
- GetReal(name).Add(id);
- }
-
- public void Add(Type type, string id)
- {
- Add(GetNameFromType(type), id);
- }
-
- public void Add(object obj, string id)
- {
- Add(obj.GetType(), id);
- }
-
- public void Add<T>(string id)
- {
- Add(typeof(T), id);
- }
-
-
-
- public void Remove(string name, string id)
- {
- GetReal(name).Remove(id);
- }
-
- public void Remove(Type type, string id)
- {
- Remove(GetNameFromType(type), id);
- }
-
- public void Remove(object obj, string id)
- {
- Remove(obj.GetType(), id);
- }
-
- public void Remove<T>(string id)
- {
- Remove(typeof(T), id);
- }
-
-
-
- public IList<string> GetReal(string name)
- {
- if (!ConnectionIds.ContainsKey(name))
- {
- ConnectionIds.Add(name, new List<string>());
- }
- return ConnectionIds[name];
- }
-
- public IList<string> Get(string name)
- {
- return new List<string>(GetReal(name));
- }
-
- public IList<string> Get(Type type)
- {
- return Get(GetNameFromType(type));
- }
-
- public IList<string> Get(object obj)
- {
- return Get(GetNameFromType(obj.GetType()));
- }
-
- public IList<string> Get<T>()
- {
- return Get(GetNameFromType(typeof(T)));
- }
-
- }
- }
|