Beispiel #1
0
        /// <inheritdoc/>
        public async Task Register(string deviceId, string pnsHandle, DevicePlatform devicePlatform, IList <string> tags)
        {
            if (string.IsNullOrEmpty(deviceId))
            {
                throw new ArgumentNullException(nameof(deviceId));
            }
            if (!(tags?.Count > 0))
            {
                throw new ArgumentException("Tags list is empty.");
            }
            var installationRequest = new Installation {
                InstallationId = deviceId,
                PushChannel    = pnsHandle,
                Tags           = tags,
                Templates      = new Dictionary <string, InstallationTemplate>()
            };

            switch (devicePlatform)
            {
            case DevicePlatform.iOS:
                installationRequest.Platform = NotificationPlatform.Apns;
                // If silent notifications are not set, then default to generic notifications for iOS.
                installationRequest.Templates.Add("DefaultMessage", new InstallationTemplate {
                    Body = PushNotificationAzureOptions.SilentNotifications ?? false ? PushNotificationServiceAzureTemplates.Silent.IOS : PushNotificationServiceAzureTemplates.Generic.IOS
                });
                break;

            case DevicePlatform.Android:
                installationRequest.Platform = NotificationPlatform.Fcm;
                installationRequest.Templates.Add("DefaultMessage", new InstallationTemplate {
                    // If silent notifications are not set, then default to silent notifications for Android.
                    Body = PushNotificationAzureOptions.SilentNotifications ?? true ? PushNotificationServiceAzureTemplates.Silent.ANDROID : PushNotificationServiceAzureTemplates.Generic.ANDROID
                });
                break;

            default:
                throw new ArgumentException("Device platform not supported.", nameof(devicePlatform));
            }
            await NotificationHub.CreateOrUpdateInstallationAsync(installationRequest);
        }
        ///<inheritdoc/>
        public async Task Register(string deviceId, string pnsHandle, DevicePlatform devicePlatform, IList <string> tags)
        {
            if (string.IsNullOrEmpty(deviceId))
            {
                throw new ArgumentNullException(nameof(deviceId));
            }
            if (!(tags?.Count > 0))
            {
                throw new ArgumentException("Tags list is empty");
            }
            var installationRequest = new Installation {
                InstallationId = deviceId,
                PushChannel    = pnsHandle,
                Tags           = tags,
                Templates      = new Dictionary <string, InstallationTemplate>()
            };

            switch (devicePlatform)
            {
            case DevicePlatform.WindowsPhone:
                installationRequest.Platform = NotificationPlatform.Mpns;
                installationRequest.Templates.Add(
                    "DefaultMessage", new InstallationTemplate {
                    Body = WindowsPhoneTemplate
                }
                    );
                break;

            case DevicePlatform.UWP:
                installationRequest.Platform = NotificationPlatform.Wns;
                installationRequest.Templates.Add(
                    "DefaultMessage", new InstallationTemplate {
                    Body = WindowsPhoneTemplate
                }
                    );
                break;

            case DevicePlatform.iOS:
                installationRequest.Platform = NotificationPlatform.Apns;
                installationRequest.Templates.Add(
                    "DefaultMessage", new InstallationTemplate {
                    Body = IOSTemplate
                }
                    );
                break;

            case DevicePlatform.Android:
                installationRequest.Platform = NotificationPlatform.Fcm;
                installationRequest.Templates.Add(
                    "DefaultMessage", new InstallationTemplate {
                    Body = AndroidTemplate
                }
                    );
                break;

            case DevicePlatform.None:
            default:
                throw new ArgumentException("Device platform not supported", nameof(devicePlatform));
            }
            await NotificationHub.CreateOrUpdateInstallationAsync(installationRequest);
        }