示例#1
0
 public void SendNotification(string message, int? badge, IEnumerable<string> deviceTokens)
 {
     using (var pushClient = new PushServiceClient())
     {
         pushClient.EnqueueNotification(
             CoreContext.TenantManager.GetCurrentTenant().TenantId,
             SecurityContext.CurrentAccount.ID.ToString(),
             PushNotification.ApiNotification(message, badge),
             deviceTokens.ToList());
     }
 }
示例#2
0
 public void SendNotification(string message, int?badge, IEnumerable <string> deviceTokens)
 {
     using (var pushClient = new PushServiceClient())
     {
         pushClient.EnqueueNotification(
             CoreContext.TenantManager.GetCurrentTenant().TenantId,
             SecurityContext.CurrentAccount.ID.ToString(),
             PushNotification.ApiNotification(message, badge),
             deviceTokens.ToList());
     }
 }
示例#3
0
        public override SendResponse ProcessMessage(INoticeMessage message)
        {
            try
            {
                using var scope = ServiceProvider.CreateScope();
                var tenantManager = scope.ServiceProvider.GetService <TenantManager>();

                var notification = new PushNotification
                {
                    Module       = GetTagValue <PushModule>(message, PushConstants.PushModuleTagName),
                    Action       = GetTagValue <PushAction>(message, PushConstants.PushActionTagName),
                    Item         = GetTagValue <PushItem>(message, PushConstants.PushItemTagName),
                    ParentItem   = GetTagValue <PushItem>(message, PushConstants.PushParentItemTagName),
                    Message      = message.Body,
                    ShortMessage = message.Subject
                };

                if (configured)
                {
                    try
                    {
                        using var pushClient = new PushServiceClient();
                        pushClient.EnqueueNotification(
                            tenantManager.GetCurrentTenant().TenantId,
                            message.Recipient.ID,
                            notification,
                            new List <string>());
                    }
                    catch (InvalidOperationException)
                    {
                        configured = false;
                        _log.Debug("push sender endpoint is not configured!");
                    }
                }
                else
                {
                    _log.Debug("push sender endpoint is not configured!");
                }

                return(new SendResponse(message, Constants.NotifyPushSenderSysName, SendResult.OK));
            }
            catch (Exception error)
            {
                return(new SendResponse(message, Constants.NotifyPushSenderSysName, error));
            }
        }
示例#4
0
        public override SendResponse ProcessMessage(INoticeMessage message)
        {
            try
            {
                var notification = new PushNotification
                {
                    Module       = GetTagValue <PushModule>(message, PushConstants.PushModuleTagName),
                    Action       = GetTagValue <PushAction>(message, PushConstants.PushActionTagName),
                    Item         = GetTagValue <PushItem>(message, PushConstants.PushItemTagName),
                    ParentItem   = GetTagValue <PushItem>(message, PushConstants.PushParentItemTagName),
                    Message      = message.Body,
                    ShortMessage = message.Subject
                };

                if (IsServiceConfigured)
                {
                    using (var pushClient = new PushServiceClient())
                    {
                        pushClient.EnqueueNotification(
                            CoreContext.TenantManager.GetCurrentTenant().TenantId,
                            message.Recipient.ID,
                            notification,
                            new List <string>());
                    }
                }
                else
                {
                    _log.Debug("push sender endpoint is not configured!");
                }

                return(new SendResponse(message, Constants.NotifyPushSenderSysName, SendResult.OK));
            }
            catch (Exception error)
            {
                return(new SendResponse(message, Constants.NotifyPushSenderSysName, error));
            }
        }