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.

94 lines
2.9 KiB

2 years ago
  1. using System.Collections.Generic;
  2. using System.Configuration;
  3. using WebApp.Models.Hub;
  4. namespace WebApp.Hubs
  5. {
  6. public class HubsTool
  7. {
  8. #region GetAppSettings
  9. /// <summary>
  10. /// 獲取WebService的配置信息
  11. /// </summary>
  12. /// <param name="sKey">appSettings中配置的Key值</param>
  13. /// <example></example>
  14. /// <returns>appSettings中配置的value值</returns>
  15. public static string GetAppSettings(string sKey)
  16. {
  17. return ConfigurationManager.AppSettings[sKey].ToString();
  18. }
  19. #endregion GetAppSettings
  20. #region GetConnectionId
  21. /// <summary>
  22. /// 獲取人員連線id
  23. /// </summary>
  24. /// <param name="orgId">todo: describe orgId parameter on GetConnectionId</param>
  25. /// <param name="userId">todo: describe userId parameter on GetConnectionId</param>
  26. /// <example></example>
  27. /// <returns>appSettings中配置的value值</returns>
  28. public static string GetConnectionId(string orgId, string userId)
  29. {
  30. var sConnectionId = "";
  31. foreach (UserInfo user in MsgHub.Euro_Online.Users)
  32. {
  33. if (userId == user.UserId && orgId == user.OrgId)
  34. {
  35. sConnectionId = user.ConnectionId;
  36. break;
  37. }
  38. }
  39. return sConnectionId;
  40. }
  41. #endregion GetConnectionId
  42. #region GetConnectionIds
  43. /// <summary>
  44. /// 獲取多人員連線id
  45. /// </summary>
  46. /// <param name="userIds">todo: describe userIds parameter on GetConnectionIds</param>
  47. /// <example></example>
  48. /// <returns>appSettings中配置的value值</returns>
  49. public static IList<string> GetConnectionIds(IList<string> userIds)
  50. {
  51. var ConnectionIds = new List<string>();
  52. foreach (UserInfo user in MsgHub.Euro_Online.Users)
  53. {
  54. if (userIds.Contains(user.OrgId + user.UserId))
  55. {
  56. ConnectionIds.Add(user.ConnectionId);
  57. }
  58. }
  59. return ConnectionIds;
  60. }
  61. #endregion GetConnectionIds
  62. #region GetConnectionIdsByOrgID
  63. /// <summary>
  64. /// 獲取多人員連線id
  65. /// </summary>
  66. /// <param name="OrgID">組織ID</param>
  67. /// <example></example>
  68. /// <returns>appSettings中配置的value值</returns>
  69. public static IList<string> GetConnectionIdsByOrgID(string OrgID)
  70. {
  71. var ConnectionIds = new List<string>();
  72. foreach (UserInfo user in MsgHub.Euro_Online.Users)
  73. {
  74. if (user.OrgId == OrgID)
  75. {
  76. ConnectionIds.Add(user.ConnectionId);
  77. }
  78. }
  79. return ConnectionIds;
  80. }
  81. #endregion GetConnectionIdsByOrgID
  82. }
  83. }