From de6c98b42fa16a681fb633b145e93d986b8e1175 Mon Sep 17 00:00:00 2001 From: Denis Stankovski Date: Mon, 20 Jul 2020 17:49:44 -0700 Subject: [PATCH] Extracted interface for NotificationHubClient and NamespaceManager --- .../INamespaceManager.cs | 43 +++++ .../INotificationHubClient.cs | 177 ++++++++++++++++++ .../NamespaceManager.cs | 2 +- .../NotificationHubClient.cs | 2 +- 4 files changed, 222 insertions(+), 2 deletions(-) create mode 100644 src/Microsoft.Azure.NotificationHubs/INamespaceManager.cs create mode 100644 src/Microsoft.Azure.NotificationHubs/INotificationHubClient.cs diff --git a/src/Microsoft.Azure.NotificationHubs/INamespaceManager.cs b/src/Microsoft.Azure.NotificationHubs/INamespaceManager.cs new file mode 100644 index 0000000..799dd2b --- /dev/null +++ b/src/Microsoft.Azure.NotificationHubs/INamespaceManager.cs @@ -0,0 +1,43 @@ +//------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for +// license information. +//------------------------------------------------------------ + +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; + +namespace Microsoft.Azure.NotificationHubs +{ + public interface INamespaceManager + { + NotificationHubDescription CreateNotificationHub(NotificationHubDescription description); + NotificationHubDescription CreateNotificationHub(string hubName); + Task CreateNotificationHubAsync(NotificationHubDescription description); + Task CreateNotificationHubAsync(NotificationHubDescription description, CancellationToken cancellationToken); + Task CreateNotificationHubAsync(string hubName); + Task CreateNotificationHubAsync(string hubName, CancellationToken cancellationToken); + void DeleteNotificationHub(string path); + Task DeleteNotificationHubAsync(string path); + Task DeleteNotificationHubAsync(string path, CancellationToken cancellationToken); + NotificationHubDescription GetNotificationHub(string path); + Task GetNotificationHubAsync(string path); + Task GetNotificationHubAsync(string path, CancellationToken cancellationToken); + Task GetNotificationHubJobAsync(string jobId, string notificationHubPath); + Task GetNotificationHubJobAsync(string jobId, string notificationHubPath, CancellationToken cancellationToken); + Task> GetNotificationHubJobsAsync(string notificationHubPath); + Task> GetNotificationHubJobsAsync(string notificationHubPath, CancellationToken cancellationToken); + IEnumerable GetNotificationHubs(); + Task> GetNotificationHubsAsync(); + Task> GetNotificationHubsAsync(CancellationToken cancellationToken); + bool NotificationHubExists(string path); + Task NotificationHubExistsAsync(string path); + Task NotificationHubExistsAsync(string path, CancellationToken cancellationToken); + Task SubmitNotificationHubJobAsync(NotificationHubJob job, string notificationHubPath); + Task SubmitNotificationHubJobAsync(NotificationHubJob job, string notificationHubPath, CancellationToken cancellationToken); + NotificationHubDescription UpdateNotificationHub(NotificationHubDescription description); + Task UpdateNotificationHubAsync(NotificationHubDescription description); + Task UpdateNotificationHubAsync(NotificationHubDescription description, CancellationToken cancellationToken); + } +} \ No newline at end of file diff --git a/src/Microsoft.Azure.NotificationHubs/INotificationHubClient.cs b/src/Microsoft.Azure.NotificationHubs/INotificationHubClient.cs new file mode 100644 index 0000000..70d4e33 --- /dev/null +++ b/src/Microsoft.Azure.NotificationHubs/INotificationHubClient.cs @@ -0,0 +1,177 @@ +//---------------------------------------------------------------- +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for +// license information. +//---------------------------------------------------------------- + +using System; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; + +namespace Microsoft.Azure.NotificationHubs +{ + public interface INotificationHubClient + { + bool EnableTestSend { get; } + + Task CancelNotificationAsync(string scheduledNotificationId); + Task CancelNotificationAsync(string scheduledNotificationId, CancellationToken cancellationToken); + Task CreateAdmNativeRegistrationAsync(string admRegistrationId); + Task CreateAdmNativeRegistrationAsync(string admRegistrationId, CancellationToken cancellationToken); + Task CreateAdmNativeRegistrationAsync(string admRegistrationId, IEnumerable tags); + Task CreateAdmNativeRegistrationAsync(string admRegistrationId, IEnumerable tags, CancellationToken cancellationToken); + Task CreateAdmTemplateRegistrationAsync(string admRegistrationId, string jsonPayload); + Task CreateAdmTemplateRegistrationAsync(string admRegistrationId, string jsonPayload, CancellationToken cancellationToken); + Task CreateAdmTemplateRegistrationAsync(string admRegistrationId, string jsonPayload, IEnumerable tags); + Task CreateAdmTemplateRegistrationAsync(string admRegistrationId, string jsonPayload, IEnumerable tags, CancellationToken cancellationToken); + Task CreateAppleNativeRegistrationAsync(string deviceToken); + Task CreateAppleNativeRegistrationAsync(string deviceToken, CancellationToken cancellationToken); + Task CreateAppleNativeRegistrationAsync(string deviceToken, IEnumerable tags); + Task CreateAppleNativeRegistrationAsync(string deviceToken, IEnumerable tags, CancellationToken cancellationToken); + Task CreateAppleTemplateRegistrationAsync(string deviceToken, string jsonPayload); + Task CreateAppleTemplateRegistrationAsync(string deviceToken, string jsonPayload, CancellationToken cancellationToken); + Task CreateAppleTemplateRegistrationAsync(string deviceToken, string jsonPayload, IEnumerable tags); + Task CreateAppleTemplateRegistrationAsync(string deviceToken, string jsonPayload, IEnumerable tags, CancellationToken cancellationToken); + Task CreateBaiduNativeRegistrationAsync(string userId, string channelId); + Task CreateBaiduNativeRegistrationAsync(string userId, string channelId, IEnumerable tags); + Task CreateBaiduTemplateRegistrationAsync(string userId, string channelId, string jsonPayload); + Task CreateBaiduTemplateRegistrationAsync(string userId, string channelId, string jsonPayload, IEnumerable tags); + Task CreateFcmNativeRegistrationAsync(string fcmRegistrationId); + Task CreateFcmNativeRegistrationAsync(string fcmRegistrationId, CancellationToken cancellationToken); + Task CreateFcmNativeRegistrationAsync(string fcmRegistrationId, IEnumerable tags); + Task CreateFcmNativeRegistrationAsync(string fcmRegistrationId, IEnumerable tags, CancellationToken cancellationToken); + Task CreateFcmTemplateRegistrationAsync(string fcmRegistrationId, string jsonPayload); + Task CreateFcmTemplateRegistrationAsync(string fcmRegistrationId, string jsonPayload, CancellationToken cancellationToken); + Task CreateFcmTemplateRegistrationAsync(string fcmRegistrationId, string jsonPayload, IEnumerable tags); + Task CreateFcmTemplateRegistrationAsync(string fcmRegistrationId, string jsonPayload, IEnumerable tags, CancellationToken cancellationToken); + Task CreateMpnsNativeRegistrationAsync(string channelUri); + Task CreateMpnsNativeRegistrationAsync(string channelUri, IEnumerable tags); + Task CreateMpnsTemplateRegistrationAsync(string channelUri, string xmlTemplate); + Task CreateMpnsTemplateRegistrationAsync(string channelUri, string xmlTemplate, IEnumerable tags); + void CreateOrUpdateInstallation(Installation installation); + Task CreateOrUpdateInstallationAsync(Installation installation); + Task CreateOrUpdateInstallationAsync(Installation installation, CancellationToken cancellationToken); + Task CreateOrUpdateRegistrationAsync(T registration) where T : RegistrationDescription; + Task CreateOrUpdateRegistrationAsync(T registration, CancellationToken cancellationToken) where T : RegistrationDescription; + Task CreateRegistrationAsync(T registration) where T : RegistrationDescription; + Task CreateRegistrationAsync(T registration, CancellationToken cancellationToken) where T : RegistrationDescription; + Task CreateRegistrationIdAsync(); + Task CreateRegistrationIdAsync(CancellationToken cancellationToken); + Task CreateWindowsNativeRegistrationAsync(string channelUri); + Task CreateWindowsNativeRegistrationAsync(string channelUri, CancellationToken cancellationToken); + Task CreateWindowsNativeRegistrationAsync(string channelUri, IEnumerable tags); + Task CreateWindowsNativeRegistrationAsync(string channelUri, IEnumerable tags, CancellationToken cancellationToken); + Task CreateWindowsTemplateRegistrationAsync(string channelUri, string xmlTemplate); + Task CreateWindowsTemplateRegistrationAsync(string channelUri, string xmlTemplate, CancellationToken cancellationToken); + Task CreateWindowsTemplateRegistrationAsync(string channelUri, string xmlTemplate, IEnumerable tags); + Task CreateWindowsTemplateRegistrationAsync(string channelUri, string xmlTemplate, IEnumerable tags, CancellationToken cancellationToken); + void DeleteInstallation(string installationId); + Task DeleteInstallationAsync(string installationId); + Task DeleteInstallationAsync(string installationId, CancellationToken cancellationToken); + Task DeleteRegistrationAsync(RegistrationDescription registration); + Task DeleteRegistrationAsync(RegistrationDescription registration, CancellationToken cancellationToken); + Task DeleteRegistrationAsync(string registrationId); + Task DeleteRegistrationAsync(string registrationId, CancellationToken cancellationToken); + Task DeleteRegistrationAsync(string registrationId, string etag); + Task DeleteRegistrationAsync(string registrationId, string etag, CancellationToken cancellationToken); + Task DeleteRegistrationsByChannelAsync(string pnsHandle); + Task DeleteRegistrationsByChannelAsync(string pnsHandle, CancellationToken cancellationToken); + Task> GetAllRegistrationsAsync(int top); + Task> GetAllRegistrationsAsync(int top, CancellationToken cancellationToken); + Task> GetAllRegistrationsAsync(string continuationToken, int top); + Task> GetAllRegistrationsAsync(string continuationToken, int top, CancellationToken cancellationToken); + Uri GetBaseUri(); + Task GetFeedbackContainerUriAsync(); + Task GetFeedbackContainerUriAsync(CancellationToken cancellationToken); + Installation GetInstallation(string installationId); + Task GetInstallationAsync(string installationId); + Task GetInstallationAsync(string installationId, CancellationToken cancellationToken); + Task GetNotificationHubJobAsync(string jobId); + Task GetNotificationHubJobAsync(string jobId, CancellationToken cancellationToken); + Task> GetNotificationHubJobsAsync(); + Task> GetNotificationHubJobsAsync(CancellationToken cancellationToken); + Task GetNotificationOutcomeDetailsAsync(string notificationId); + Task GetNotificationOutcomeDetailsAsync(string notificationId, CancellationToken cancellationToken); + Task GetRegistrationAsync(string registrationId) where TRegistrationDescription : RegistrationDescription; + Task GetRegistrationAsync(string registrationId, CancellationToken cancellationToken) where TRegistrationDescription : RegistrationDescription; + Task> GetRegistrationsByChannelAsync(string pnsHandle, int top); + Task> GetRegistrationsByChannelAsync(string pnsHandle, int top, CancellationToken cancellationToken); + Task> GetRegistrationsByChannelAsync(string pnsHandle, string continuationToken, int top); + Task> GetRegistrationsByChannelAsync(string pnsHandle, string continuationToken, int top, CancellationToken cancellationToken); + Task> GetRegistrationsByTagAsync(string tag, int top); + Task> GetRegistrationsByTagAsync(string tag, int top, CancellationToken cancellationToken); + Task> GetRegistrationsByTagAsync(string tag, string continuationToken, int top); + Task> GetRegistrationsByTagAsync(string tag, string continuationToken, int top, CancellationToken cancellationToken); + bool InstallationExists(string installationId); + Task InstallationExistsAsync(string installationId); + Task InstallationExistsAsync(string installationId, CancellationToken cancellationToken); + void PatchInstallation(string installationId, IList operations); + Task PatchInstallationAsync(string installationId, IList operations); + Task PatchInstallationAsync(string installationId, IList operations, CancellationToken cancellationToken); + Task RegistrationExistsAsync(string registrationId); + Task RegistrationExistsAsync(string registrationId, CancellationToken cancellationToken); + Task ScheduleNotificationAsync(Notification notification, DateTimeOffset scheduledTime); + Task ScheduleNotificationAsync(Notification notification, DateTimeOffset scheduledTime, CancellationToken cancellationToken); + Task ScheduleNotificationAsync(Notification notification, DateTimeOffset scheduledTime, IEnumerable tags); + Task ScheduleNotificationAsync(Notification notification, DateTimeOffset scheduledTime, IEnumerable tags, CancellationToken cancellationToken); + Task ScheduleNotificationAsync(Notification notification, DateTimeOffset scheduledTime, string tagExpression); + Task ScheduleNotificationAsync(Notification notification, DateTimeOffset scheduledTime, string tagExpression, CancellationToken cancellationToken); + Task SendAdmNativeNotificationAsync(string jsonPayload); + Task SendAdmNativeNotificationAsync(string jsonPayload, CancellationToken cancellationToken); + Task SendAdmNativeNotificationAsync(string jsonPayload, IEnumerable tags); + Task SendAdmNativeNotificationAsync(string jsonPayload, IEnumerable tags, CancellationToken cancellationToken); + Task SendAdmNativeNotificationAsync(string jsonPayload, string tagExpression); + Task SendAdmNativeNotificationAsync(string jsonPayload, string tagExpression, CancellationToken cancellationToken); + Task SendAppleNativeNotificationAsync(string jsonPayload); + Task SendAppleNativeNotificationAsync(string jsonPayload, CancellationToken cancellationToken); + Task SendAppleNativeNotificationAsync(string jsonPayload, IEnumerable tags); + Task SendAppleNativeNotificationAsync(string jsonPayload, IEnumerable tags, CancellationToken cancellationToken); + Task SendAppleNativeNotificationAsync(string jsonPayload, string tagExpression); + Task SendAppleNativeNotificationAsync(string jsonPayload, string tagExpression, CancellationToken cancellationToken); + Task SendBaiduNativeNotificationAsync(string message); + Task SendBaiduNativeNotificationAsync(string message, CancellationToken cancellationToken); + Task SendBaiduNativeNotificationAsync(string message, IEnumerable tags); + Task SendBaiduNativeNotificationAsync(string message, IEnumerable tags, CancellationToken cancellationToken); + Task SendBaiduNativeNotificationAsync(string message, string tagExpression); + Task SendBaiduNativeNotificationAsync(string message, string tagExpression, CancellationToken cancellationToken); + Task SendDirectNotificationAsync(Notification notification, IList deviceHandles); + Task SendDirectNotificationAsync(Notification notification, IList deviceHandles, CancellationToken cancellationToken); + Task SendDirectNotificationAsync(Notification notification, string deviceHandle); + Task SendDirectNotificationAsync(Notification notification, string deviceHandle, CancellationToken cancellationToken); + Task SendFcmNativeNotificationAsync(string jsonPayload); + Task SendFcmNativeNotificationAsync(string jsonPayload, CancellationToken cancellationToken); + Task SendFcmNativeNotificationAsync(string jsonPayload, IEnumerable tags); + Task SendFcmNativeNotificationAsync(string jsonPayload, IEnumerable tags, CancellationToken cancellationToken); + Task SendFcmNativeNotificationAsync(string jsonPayload, string tagExpression); + Task SendFcmNativeNotificationAsync(string jsonPayload, string tagExpression, CancellationToken cancellationToken); + Task SendMpnsNativeNotificationAsync(string nativePayload); + Task SendMpnsNativeNotificationAsync(string nativePayload, CancellationToken cancellationToken); + Task SendMpnsNativeNotificationAsync(string nativePayload, IEnumerable tags); + Task SendMpnsNativeNotificationAsync(string nativePayload, IEnumerable tags, CancellationToken cancellationToken); + Task SendMpnsNativeNotificationAsync(string nativePayload, string tagExpression); + Task SendMpnsNativeNotificationAsync(string nativePayload, string tagExpression, CancellationToken cancellationToken); + Task SendNotificationAsync(Notification notification); + Task SendNotificationAsync(Notification notification, CancellationToken cancellationToken); + Task SendNotificationAsync(Notification notification, IEnumerable tags); + Task SendNotificationAsync(Notification notification, IEnumerable tags, CancellationToken cancellationToken); + Task SendNotificationAsync(Notification notification, string tagExpression); + Task SendNotificationAsync(Notification notification, string tagExpression, CancellationToken cancellationToken); + Task SendTemplateNotificationAsync(IDictionary properties); + Task SendTemplateNotificationAsync(IDictionary properties, CancellationToken cancellationToken); + Task SendTemplateNotificationAsync(IDictionary properties, IEnumerable tags); + Task SendTemplateNotificationAsync(IDictionary properties, IEnumerable tags, CancellationToken cancellationToken); + Task SendTemplateNotificationAsync(IDictionary properties, string tagExpression); + Task SendTemplateNotificationAsync(IDictionary properties, string tagExpression, CancellationToken cancellationToken); + Task SendWindowsNativeNotificationAsync(string windowsNativePayload); + Task SendWindowsNativeNotificationAsync(string windowsNativePayload, CancellationToken cancellationToken); + Task SendWindowsNativeNotificationAsync(string windowsNativePayload, IEnumerable tags); + Task SendWindowsNativeNotificationAsync(string windowsNativePayload, IEnumerable tags, CancellationToken cancellationToken); + Task SendWindowsNativeNotificationAsync(string windowsNativePayload, string tagExpression); + Task SendWindowsNativeNotificationAsync(string windowsNativePayload, string tagExpression, CancellationToken cancellationToken); + Task SubmitNotificationHubJobAsync(NotificationHubJob job); + Task SubmitNotificationHubJobAsync(NotificationHubJob job, CancellationToken cancellationToken); + Task UpdateRegistrationAsync(T registration) where T : RegistrationDescription; + Task UpdateRegistrationAsync(T registration, CancellationToken cancellationToken) where T : RegistrationDescription; + } +} \ No newline at end of file diff --git a/src/Microsoft.Azure.NotificationHubs/NamespaceManager.cs b/src/Microsoft.Azure.NotificationHubs/NamespaceManager.cs index de5fbe5..b37ef18 100644 --- a/src/Microsoft.Azure.NotificationHubs/NamespaceManager.cs +++ b/src/Microsoft.Azure.NotificationHubs/NamespaceManager.cs @@ -23,7 +23,7 @@ namespace Microsoft.Azure.NotificationHubs /// /// Represents a namespace manager /// - public sealed class NamespaceManager + public sealed class NamespaceManager : INamespaceManager { private const string ApiVersion = "2017-04"; private const string Header = ""; diff --git a/src/Microsoft.Azure.NotificationHubs/NotificationHubClient.cs b/src/Microsoft.Azure.NotificationHubs/NotificationHubClient.cs index a7a03aa..90ca6d4 100644 --- a/src/Microsoft.Azure.NotificationHubs/NotificationHubClient.cs +++ b/src/Microsoft.Azure.NotificationHubs/NotificationHubClient.cs @@ -27,7 +27,7 @@ namespace Microsoft.Azure.NotificationHubs /// /// Represents a notification hub client. /// - public class NotificationHubClient + public class NotificationHubClient : INotificationHubClient { private const int EntitiesPerRequest = 100; private readonly HttpClient _httpClient;