NotificationService.cs 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using System.Threading.Tasks;
  2. using WingServerCommon.Service;
  3. using WingServerCommon.Config;
  4. using WingServerCommon.Config.Parameters;
  5. using WingInterfaceLibrary.Interface;
  6. using WingInterfaceLibrary.Interface.DBInterface;
  7. using WingInterfaceLibrary.Request.Notification;
  8. using System.Collections.Generic;
  9. using WingInterfaceLibrary.DTO.Common;
  10. using JsonRpcLite.Services;
  11. using WingInterfaceLibrary.Enum;
  12. using WingInterfaceLibrary.Notifications;
  13. namespace WingNotificationModule.Service
  14. {
  15. /// <summary>
  16. /// 通知服务
  17. /// </summary>
  18. public class NotificationService : JsonRpcService, INotificationService
  19. {
  20. private NotificationServer _notificationServer;
  21. private IAuthenticationService _authenticationService;
  22. private IStorageDBService _storageDBService;
  23. /// <summary>
  24. /// 构造函数
  25. /// </summary>
  26. public NotificationService()
  27. {
  28. var host = ConfigurationManager.GetParammeter<StringParameter>("Notification", "Host");
  29. var maxQueueCount = ConfigurationManager.GetParammeter<IntParameter>("Notification", "MaxQueueCount").Value;
  30. _notificationServer = new NotificationServer(host.Value, maxQueueCount);
  31. }
  32. public override void Load(JsonRpcClientPool jsonRpcClientPool)
  33. {
  34. base.Load(jsonRpcClientPool);
  35. _authenticationService = GetProxy<IAuthenticationService>();
  36. _notificationServer.Start(_authenticationService);
  37. _storageDBService = GetProxy<IStorageDBService>();
  38. }
  39. /// <summary>
  40. /// 发送通知,等待发送完消息返回是否成功
  41. /// </summary>
  42. /// <param name="request">发送通知请求</param>
  43. /// <returns>是否成功</returns>
  44. /// <value>true</value>
  45. public async Task<bool> SendMessageAsync(SendNotificationRequest request)
  46. {
  47. return await _notificationServer.SendMessageAsync(request);
  48. }
  49. /// <summary>
  50. /// 发送通知,消息进入发送队列,返回是否成功进入发送队列
  51. /// </summary>
  52. /// <param name="request">发送通知请求</param>
  53. /// <returns>是否成功</returns>
  54. /// <value>true</value>
  55. public async Task<bool> PostMessageAsync(SendNotificationRequest request)
  56. {
  57. return await _notificationServer.PostMessageAsync(request);
  58. }
  59. public async Task<bool> BroadcastMessageAsync(BroadcastNotificationRequest request)
  60. {
  61. return await _notificationServer.BroadcastMessageAsync(request);
  62. }
  63. public async Task<string> OpenNotifyQueueAsync(OpenNotifyQueueRequest request)
  64. {
  65. return _notificationServer.OpenNotifyQueueAsync(request.Module);
  66. }
  67. public async Task<bool> CloseNotifyQueueAsync(CloseNotifyQueueRequest request)
  68. {
  69. return _notificationServer.CloseNotifyQueueAsync(request.MsgQueueId);
  70. }
  71. }
  72. }