OnlineClient.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. using System;
  2. using System.Collections.Generic;
  3. using Abp.Json;
  4. using Abp.Timing;
  5. namespace Abp.RealTime
  6. {
  7. /// <summary>
  8. /// Implements <see cref="IOnlineClient"/>.
  9. /// </summary>
  10. [Serializable]
  11. public class OnlineClient : IOnlineClient
  12. {
  13. /// <summary>
  14. /// Unique connection Id for this client.
  15. /// </summary>
  16. public string ConnectionId { get; set; }
  17. /// <summary>
  18. /// IP address of this client.
  19. /// </summary>
  20. public string IpAddress { get; set; }
  21. /// <summary>
  22. /// Tenant Id.
  23. /// </summary>
  24. public int? TenantId { get; set; }
  25. /// <summary>
  26. /// User Id.
  27. /// </summary>
  28. public long? UserId { get; set; }
  29. /// <summary>
  30. /// Connection establishment time for this client.
  31. /// </summary>
  32. public DateTime ConnectTime { get; set; }
  33. /// <summary>
  34. /// Shortcut to set/get <see cref="Properties"/>.
  35. /// </summary>
  36. public object this[string key]
  37. {
  38. get { return Properties[key]; }
  39. set { Properties[key] = value; }
  40. }
  41. /// <summary>
  42. /// Can be used to add custom properties for this client.
  43. /// </summary>
  44. public Dictionary<string, object> Properties
  45. {
  46. get { return _properties; }
  47. set
  48. {
  49. if (value == null)
  50. {
  51. throw new ArgumentNullException(nameof(value));
  52. }
  53. _properties = value;
  54. }
  55. }
  56. private Dictionary<string, object> _properties;
  57. /// <summary>
  58. /// Initializes a new instance of the <see cref="OnlineClient"/> class.
  59. /// </summary>
  60. public OnlineClient()
  61. {
  62. ConnectTime = Clock.Now;
  63. }
  64. /// <summary>
  65. /// Initializes a new instance of the <see cref="OnlineClient"/> class.
  66. /// </summary>
  67. /// <param name="connectionId">The connection identifier.</param>
  68. /// <param name="ipAddress">The ip address.</param>
  69. /// <param name="tenantId">The tenant identifier.</param>
  70. /// <param name="userId">The user identifier.</param>
  71. public OnlineClient(string connectionId, string ipAddress, int? tenantId, long? userId)
  72. : this()
  73. {
  74. ConnectionId = connectionId;
  75. IpAddress = ipAddress;
  76. TenantId = tenantId;
  77. UserId = userId;
  78. Properties = new Dictionary<string, object>();
  79. }
  80. public override string ToString()
  81. {
  82. return this.ToJsonString();
  83. }
  84. }
  85. }