示例#1
0
        /// <summary>
        ///     Formats a <see cref="FcmContentWrapper"/> for Google Firebase based
        ///     on a given <paramref name="swabbrNotification"/>.
        /// </summary>
        /// <param name="swabbrNotification"><see cref="SwabbrNotification"/></param>
        /// <returns><see cref="FcmContentWrapper"/></returns>
        public static NotificationWrapperJsonBase Extract(SwabbrNotification swabbrNotification)
        {
            if (swabbrNotification == null)
            {
                throw new ArgumentNullException(nameof(swabbrNotification));
            }

            return(new FcmContentWrapper
            {
                Data = new SubData
                {
                    Payload = swabbrNotification
                }
            });
        }
示例#2
0
        /// <summary>
        ///     Formats a notifcation for Apple Push Notification Platform
        ///     usage through our Azure Notification Hub.
        /// </summary>
        /// <param name="swabbrNotification">The notification.</param>
        /// <returns>Formatted notification.</returns>
        public static NotificationWrapperJsonBase Extract(SwabbrNotification swabbrNotification)
        {
            if (swabbrNotification == null)
            {
                throw new ArgumentNullException(nameof(swabbrNotification));
            }

            return(new ApnsContentWrapper
            {
                Aps = new ApnsContentAps
                {
                    Alert = new ApnsContentAlert
                    {
                        // FUTURE Implement and test
                    }
                }
            });

            throw new NotImplementedException();
        }
        /// <summary>
        ///     Sends a <see cref="ScheduledNotification"/> to a specified user.
        /// </summary>
        /// <param name="pushDetails">Details on how to reach the user.</param>
        /// <param name="notification">The notification object.</param>
        public async Task SendNotificationAsync(UserPushNotificationDetails pushDetails, SwabbrNotification notification)
        {
            if (pushDetails is null)
            {
                throw new ArgumentNullException(nameof(pushDetails));
            }

            switch (pushDetails.PushNotificationPlatform)
            {
            case PushNotificationPlatform.APNS:
                var objApns  = NotificationJsonExtractor.Extract(PushNotificationPlatform.APNS, notification);
                var jsonApns = JsonConvert.SerializeObject(objApns, jsonSettings);
                await _hubClient.SendAppleNativeNotificationAsync(jsonApns, pushDetails.UserId.ToString());

                return;

            case PushNotificationPlatform.FCM:
                var objFcm  = NotificationJsonExtractor.Extract(PushNotificationPlatform.FCM, notification);
                var jsonFcm = JsonConvert.SerializeObject(objFcm, jsonSettings);
                await _hubClient.SendFcmNativeNotificationAsync(jsonFcm, pushDetails.UserId.ToString());

                return;

            default:
                throw new InvalidOperationException(nameof(pushDetails.PushNotificationPlatform));
            }
        }
示例#4
0
 /// <summary>
 ///     Does nothing and returns <see cref="Task.CompletedTask"/>;
 /// </summary>
 public Task SendNotificationAsync(UserPushNotificationDetails pushDetails, SwabbrNotification notification) => Task.CompletedTask;
 /// <summary>
 ///     Extracts a <see cref="PushNotificationPlatform"/> specific template
 ///     for json from a <see cref="SwabbrNotification"/>.
 /// </summary>
 /// <param name="platform"><see cref="PushNotificationPlatform"/></param>
 /// <param name="notification"><see cref="SwabbrNotification"/></param>
 /// <returns><see cref="NotificationWrapperJsonBase"/></returns>
 public static NotificationWrapperJsonBase Extract(PushNotificationPlatform platform, SwabbrNotification notification)
 => platform switch
 {