You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

LuHubConnectionTracker.cs 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. using System;
  2. using System.Collections.Generic;
  3. namespace Luticate2.Utils.Hubs
  4. {
  5. public class LuHubConnectionTracker
  6. {
  7. protected IDictionary<string, IList<string>> ConnectionIds { get; set; }
  8. public LuHubConnectionTracker()
  9. {
  10. ConnectionIds = new Dictionary<string, IList<string>>();
  11. }
  12. public static string GetNameFromType(Type type)
  13. {
  14. return type.FullName;
  15. }
  16. public void Add(string name, string id)
  17. {
  18. GetReal(name).Add(id);
  19. }
  20. public void Add(Type type, string id)
  21. {
  22. Add(GetNameFromType(type), id);
  23. }
  24. public void Add(object obj, string id)
  25. {
  26. Add(obj.GetType(), id);
  27. }
  28. public void Add<T>(string id)
  29. {
  30. Add(typeof(T), id);
  31. }
  32. public void Remove(string name, string id)
  33. {
  34. GetReal(name).Remove(id);
  35. }
  36. public void Remove(Type type, string id)
  37. {
  38. Remove(GetNameFromType(type), id);
  39. }
  40. public void Remove(object obj, string id)
  41. {
  42. Remove(obj.GetType(), id);
  43. }
  44. public void Remove<T>(string id)
  45. {
  46. Remove(typeof(T), id);
  47. }
  48. public IList<string> GetReal(string name)
  49. {
  50. if (!ConnectionIds.ContainsKey(name))
  51. {
  52. ConnectionIds.Add(name, new List<string>());
  53. }
  54. return ConnectionIds[name];
  55. }
  56. public IList<string> Get(string name)
  57. {
  58. return new List<string>(GetReal(name));
  59. }
  60. public IList<string> Get(Type type)
  61. {
  62. return Get(GetNameFromType(type));
  63. }
  64. public IList<string> Get(object obj)
  65. {
  66. return Get(GetNameFromType(obj.GetType()));
  67. }
  68. public IList<string> Get<T>()
  69. {
  70. return Get(GetNameFromType(typeof(T)));
  71. }
  72. }
  73. }