Creates per type Installation Classes (#221)
* Adding new classes for installations * Adding tests for new installations * Updating readme * Adding TOC to readme
This commit is contained in:
Родитель
a3ebeafad3
Коммит
8fcfcd73b9
|
@ -5,7 +5,7 @@ VisualStudioVersion = 15.0.27004.2009
|
|||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.NotificationHubs", "src\Microsoft.Azure.NotificationHubs\Microsoft.Azure.NotificationHubs.csproj", "{9E6F70D4-7861-450F-BF5F-DE3AC867001E}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Azure.NotificationHubs.Tests", "src\Microsoft.Azure.NotificationHubs.Tests\Microsoft.Azure.NotificationHubs.Tests.csproj", "{AEB433DC-B5D3-4122-A540-EA15E6E75C6F}"
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Azure.NotificationHubs.Tests", "src\Microsoft.Azure.NotificationHubs.Tests\Microsoft.Azure.NotificationHubs.Tests.csproj", "{5F3E8BC6-654D-4557-BE6A-962AEE50E062}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
|
@ -17,10 +17,10 @@ Global
|
|||
{9E6F70D4-7861-450F-BF5F-DE3AC867001E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{9E6F70D4-7861-450F-BF5F-DE3AC867001E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{9E6F70D4-7861-450F-BF5F-DE3AC867001E}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{AEB433DC-B5D3-4122-A540-EA15E6E75C6F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{AEB433DC-B5D3-4122-A540-EA15E6E75C6F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{AEB433DC-B5D3-4122-A540-EA15E6E75C6F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{AEB433DC-B5D3-4122-A540-EA15E6E75C6F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{5F3E8BC6-654D-4557-BE6A-962AEE50E062}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{5F3E8BC6-654D-4557-BE6A-962AEE50E062}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{5F3E8BC6-654D-4557-BE6A-962AEE50E062}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{5F3E8BC6-654D-4557-BE6A-962AEE50E062}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
|
347
README.md
347
README.md
|
@ -4,6 +4,43 @@
|
|||
|
||||
This repository contains source code for Azure Notification Hubs .NET SDK as well as samples for using the client. This library is also available via NuGet as part of [`Microsoft.Azure.NotificationHubs`](https://www.nuget.org/packages/Microsoft.Azure.NotificationHubs/).
|
||||
|
||||
Table of Contents:
|
||||
|
||||
- [Building Code](#building-code)
|
||||
- [Getting Started](#getting-started)
|
||||
- [Azure Notification Hubs Management Operations](#azure-notification-hubs-management-operations)
|
||||
- [Create a namespace manager](#create-a-namespace-manager)
|
||||
- [Create an Azure Notification Hub](#create-an-azure-notification-hub)
|
||||
- [Get a Azure Notification Hub](#get-a-azure-notification-hub)
|
||||
- [Update an Azure Notification Hub](#update-an-azure-notification-hub)
|
||||
- [Delete an Azure Notification Hub](#delete-an-azure-notification-hub)
|
||||
- [Azure Notification Hubs Operations](#azure-notification-hubs-operations)
|
||||
- [Azure Notification Hubs Installation API](#azure-notification-hubs-installation-api)
|
||||
- [Delete an Installation](#delete-an-installation)
|
||||
- [Azure Notification Hub Registration API](#azure-notification-hub-registration-api)
|
||||
- [Create an Apple Registration](#create-an-apple-registration)
|
||||
- [Create Template Registrations](#create-template-registrations)
|
||||
- [Update a Registration](#update-a-registration)
|
||||
- [Delete a Registration](#delete-a-registration)
|
||||
- [Get a Single Registration](#get-a-single-registration)
|
||||
- [Get Registrations With a Given Tag](#get-registrations-with-a-given-tag)
|
||||
- [Get Registrations By Channel](#get-registrations-by-channel)
|
||||
- [Send Notifications](#send-notifications)
|
||||
- [Send an Apple Push Notification](#send-an-apple-push-notification)
|
||||
- [Send a Template Notification](#send-a-template-notification)
|
||||
- [Send To An Installation ID](#send-to-an-installation-id)
|
||||
- [Send to a User ID](#send-to-a-user-id)
|
||||
- [Send To An Installation Template For An Installation](#send-to-an-installation-template-for-an-installation)
|
||||
- [Scheduled Send Operations](#scheduled-send-operations)
|
||||
- [Schedule Apple Native Send Operation](#schedule-apple-native-send-operation)
|
||||
- [Cancel Scheduled Notification](#cancel-scheduled-notification)
|
||||
- [Import and Export Registrations](#import-and-export-registrations)
|
||||
- [Submit an Export Job](#submit-an-export-job)
|
||||
- [Submit an Import Job](#submit-an-import-job)
|
||||
- [Wait for Job Completion](#wait-for-job-completion)
|
||||
- [Get All jobs](#get-all-jobs)
|
||||
- [References](#references)
|
||||
|
||||
## Building Code
|
||||
|
||||
To build the `Microsoft.Azure.NotificationHubs`, you need support for [.NET Standard 2.0](https://docs.microsoft.com/en-us/dotnet/standard/net-standard). This requires a minimum of .NET Core 3.1, .NET Framework 4.6.2 or Mono 5.4. This project ships with two unit test files, one for .NET Core 6.0, and one for .NET Framework 4.6.2 or Mono. This library ships binaries for .NET Standard 2.0, .NET Standard 2.1 and .NET 6.0.
|
||||
|
@ -16,20 +53,6 @@ To get started, you can find all the classes in the `Microsoft.Azure.Notificatio
|
|||
using Microsoft.Azure.NotificationHubs;
|
||||
```
|
||||
|
||||
The Azure Notification Hubs SDK for .NET support both synchronous and asynchronous operations on `NotificationHubClient` and `/NamespaceManagerClient`. The asynchronous APIs have the `Async` suffix returning `Task` objects.
|
||||
|
||||
```csharp
|
||||
// Synchronous
|
||||
var hub = new NotificationHubDescription("hubname");
|
||||
hub.WnsCredential = new WnsCredential("sid","key");
|
||||
hub = namespaceManager.CreateNotificationHub(hub);
|
||||
|
||||
// Asynchronous
|
||||
var hub = new NotificationHubDescription("hubname");
|
||||
hub.WnsCredential = new WnsCredential("sid","key");
|
||||
hub = await namespaceManager.CreateNotificationHubAsync(hub, CancellationToken.None);
|
||||
```
|
||||
|
||||
## Azure Notification Hubs Management Operations
|
||||
|
||||
This section details the usage of the Azure Notification Hubs SDK for .NET management operations for CRUD operations on Notification Hubs and Notification Hub Namespaces.
|
||||
|
@ -51,7 +74,7 @@ hub = await namespaceManager.CreateNotificationHubAsync(hub);
|
|||
### Get a Azure Notification Hub
|
||||
|
||||
```csharp
|
||||
NotificationHubDescription hub = await namespaceManager.GetNotificationHubAsync("hubname", CancellationToken.None);
|
||||
var hub = await namespaceManager.GetNotificationHubAsync("hubname", CancellationToken.None);
|
||||
```
|
||||
|
||||
### Update an Azure Notification Hub
|
||||
|
@ -67,6 +90,300 @@ hub = await namespaceManager.UpdateNotificationHubAsync(hub, CancellationToken.N
|
|||
await namespaceManager.DeleteNotificationHubAsync("hubname", CancellationToken.None);
|
||||
```
|
||||
|
||||
## Azure Notification Hubs Operations
|
||||
|
||||
The `NotificationHubClient` class and `INotificationHubClient` interface is the main entry point for installations/registrations, but also sending push notifications. To create a `NotificationHubClient`, you need the connection string from your Access Policy with the desired permissions such as `Listen`, `Manage` and `Send`, and in addition, the hub name to use.
|
||||
|
||||
```csharp
|
||||
INotificationHubClient hub = new NotificationHubClient("connection string", "hubname");
|
||||
```
|
||||
|
||||
## Azure Notification Hubs Installation API
|
||||
|
||||
An Installation is an enhanced registration that includes a bag of push related properties. It is the latest and best approach to registering your devices.
|
||||
|
||||
The following are some key advantages to using installations:
|
||||
|
||||
- Creating or updating an installation is fully idempotent. So you can retry it without any concerns about duplicate registrations.
|
||||
- The installation model supports a special tag format `($InstallationId:{INSTALLATION_ID})` that enables sending a notification directly to the specific device. For example, if the app's code sets an installation ID of `joe93developer` for this particular device, a developer can target this device when sending a notification to the `$InstallationId:{joe93developer}` tag. This enables you to target a specific device without having to do any additional coding.
|
||||
- Using installations also enables you to do partial registration updates. The partial update of an installation is requested with a PATCH method using the JSON-Patch standard. This is useful when you want to update tags on the registration. You don't have to pull down the entire registration and then resend all the previous tags again.
|
||||
|
||||
Using this SDK, you can do these Installation API operations. For example, we can create an installation for an Amazon Kindle Fire using the `Installation` class.
|
||||
|
||||
```csharp
|
||||
var installation = new Installation
|
||||
{
|
||||
InstallationId = "installation-id",
|
||||
PushChannel = "adm-push-channel",
|
||||
Platform = NotificationPlatform.Adm
|
||||
};
|
||||
await hub.CreateOrUpdateInstallationAsync(installation);
|
||||
```
|
||||
|
||||
Alternatively, we can use specific installation classes per type for example `AdmInstallation` for Amazon Kindle Fire devices.
|
||||
|
||||
```csharp
|
||||
var installation = new AdmInstallation("installation-id", "adm-push-channel");
|
||||
await hub.CreateOrUpdateInstallationAsync(installation);
|
||||
```
|
||||
|
||||
An installation can have multiple tags and multiple templates with its own set of tags and headers.
|
||||
|
||||
```csharp
|
||||
installation.Tags = new List<string> { "foo" };
|
||||
installation.Templates = new Dictionary<string, InstallationTemplate>
|
||||
{
|
||||
{ "template1", new InstallationTemplate { Body = "{\"data\":{\"key1\":\"$(value1)\"}}" } },
|
||||
{ "template2", new InstallationTemplate { Body = "{\"data\":{\"key2\":\"$(value2)\"}}" } }
|
||||
};
|
||||
await hub.CreateOrUpdateInstallationAsync(installation);
|
||||
```
|
||||
|
||||
For advanced scenarios we have partial update capability which allows to modify only particular properties of the installation object. Basically partial update is subset of [JSON Patch](https://tools.ietf.org/html/rfc6902/) operations you can run against Installation object.
|
||||
|
||||
```csharp
|
||||
var addChannel = new PartialUpdateOperation
|
||||
{
|
||||
Operation = UpdateOperationType.Add, ,
|
||||
Path = "/pushChannel",
|
||||
Value = "adm-push-channel2"
|
||||
};
|
||||
var addTag = new PartialUpdateOperation
|
||||
{
|
||||
Operation = UpdateOperationType.Add,
|
||||
Path = "/tags",
|
||||
Value = "bar"
|
||||
};
|
||||
var replaceTemplate = new PartialUpdateOperation
|
||||
{
|
||||
Operation = UpdateOperationType.Replace,
|
||||
Path = "/templates/template1",
|
||||
Value = new InstallationTemplate { Body = "{\"data\":{\"key3\":\"$(value3)\"}}" }.ToJson()
|
||||
};
|
||||
await hub.PatchInstallationAsync(
|
||||
"installation-id",
|
||||
new List<PartialUpdateOperation> { addChannel, addTag, replaceTemplate }
|
||||
);
|
||||
```
|
||||
|
||||
### Delete an Installation
|
||||
|
||||
```csharp
|
||||
await hub.DeleteinstallationAsync("installation-id");
|
||||
```
|
||||
|
||||
Keep in mind that `CreateOrUpdateInstallationAsync`, `PatchInstallationAsync` and `DeleteInstallationAsync` are eventually consistent with `GetInstallationAsync`. In fact operation just goes to the system queue during the call and will be executed in background. Moreover Get is not designed for main runtime scenario but just for debug and troubleshooting purposes, it is tightly throttled by the service.
|
||||
|
||||
## Azure Notification Hub Registration API
|
||||
|
||||
A registration associates the Platform Notification Service (PNS) handle for a device with tags and possibly a template. The PNS handle could be a ChannelURI, device token, or FCM registration ID. Tags are used to route notifications to the correct set of device handles. Templates are used to implement per-registration transformation. The Registration API handles requests for these operations.
|
||||
|
||||
### Create an Apple Registration
|
||||
|
||||
```csharp
|
||||
var deviceToken = "device-token";
|
||||
var tags = new HashSet<string> { "platform_ios", "os_tvos" };
|
||||
AppleRegistrationDescription created = await hub.CreateAppleNativeRegistrationAsync(deviceToken, tags);
|
||||
```
|
||||
|
||||
Analogous for Android (FCM), Windows Phone (MPNS), and Kindle Fire (ADM).
|
||||
|
||||
### Create Template Registrations
|
||||
|
||||
```csharp
|
||||
var deviceToken = "device-token";
|
||||
var jsonBody = "{\"aps\": {\"alert\": \"$(message)\"}}";
|
||||
AppleTemplateRegistrationDescription created = await hub.CreateAppleTemplateRegistrationAsync(deviceToken, jsonBody);
|
||||
```
|
||||
|
||||
Create registrations using create registrationid+upsert pattern (removes duplicates deriving from lost responses if registration ids are stored on the device):
|
||||
|
||||
```csharp
|
||||
var deviceToken = "device-token";
|
||||
var registrationId = await hub.CreateRegistrationIdAsync();
|
||||
var jsonBody = "{\"aps\": {\"alert\": \"$(message)\"}}";
|
||||
var reg = new AppleTemplateRegistrationDescription(deviceToken, jsonBody) { RegistrationId = registrationId };
|
||||
AppleTemplateRegistrationDescription upserted = await hub.CreateOrUpdateRegistrationAsync(reg);
|
||||
```
|
||||
|
||||
### Update a Registration
|
||||
|
||||
```csharp
|
||||
await hub.UpdateRegistrationAsync(reg);
|
||||
```
|
||||
|
||||
### Delete a Registration
|
||||
|
||||
```csharp
|
||||
await hub.DeleteRegistrationAsync(registrationId);
|
||||
```
|
||||
|
||||
### Get a Single Registration
|
||||
|
||||
```csharp
|
||||
AppleRegistrationDescription registration = hub.GetRegistrationAsync(registrationId);
|
||||
```
|
||||
|
||||
### Get Registrations With a Given Tag
|
||||
|
||||
This query support $top and continuation tokens.
|
||||
|
||||
```csharp
|
||||
var registrations = await hub.GetRegistrationsByTagAsync("platform_ios");
|
||||
```
|
||||
|
||||
### Get Registrations By Channel
|
||||
|
||||
This query support $top and continuation tokens.
|
||||
|
||||
```csharp
|
||||
var registrations = await hub.GetRegistrationsByChannelAsync("devicetoken");
|
||||
```
|
||||
|
||||
## Send Notifications
|
||||
|
||||
The Notification object is simply a body with headers, some utility methods help in building the native and template notifications objects.
|
||||
|
||||
### Send an Apple Push Notification
|
||||
|
||||
```csharp
|
||||
var jsonBody = "{\"aps\":{\"alert\":\"Notification Hub test notification\"}}";
|
||||
var n = new AppleNotification(jsonBody);
|
||||
NotificationOutcome outcome = await hub.SendNotificationAsync(n);
|
||||
```
|
||||
|
||||
Analogous for Android, Windows, Windows Phone, Kindle Fire and Baidu PNS.
|
||||
|
||||
### Send a Template Notification
|
||||
|
||||
```csharp
|
||||
var props = new Dictionary<string, string>
|
||||
{
|
||||
{ "prop1", "v1" },
|
||||
{ "prop2", "v2" }
|
||||
};
|
||||
var n = new TemplateNotification(props);
|
||||
NotificationOutcome outcome = hub.SendNotificationAsync(n);
|
||||
```
|
||||
|
||||
### Send To An Installation ID
|
||||
|
||||
Send flow for Installations is the same as for Registrations. We've just introduced an option to target notification to the particular Installation - just use tag "$InstallationId:{desired-id}". For case above it would look like this:
|
||||
|
||||
```csharp
|
||||
var jsonBody = "{\"aps\":{\"alert\":\"Notification Hub test notification\"}}";
|
||||
var n = new AppleNotification(jsonBody);
|
||||
var tags = new List<string> { "$InstallationId:{installation-id}" };
|
||||
NotificationOutcome outcome = await hub.SendNotificationAsync(n, tags);
|
||||
```
|
||||
|
||||
### Send to a User ID
|
||||
|
||||
With the [Installation API](https://docs.microsoft.com/en-us/azure/notification-hubs/notification-hubs-push-notification-registration-management#installations) we now have a new feature that allows you to associate a user ID with an installation and then be able to target it with a send to all devices for that user. To set the user ID for the installation, set the `UserId` property of the `Installation`.
|
||||
|
||||
```csharp
|
||||
var installation = new AppleInstallation("installation-id", "device-token");
|
||||
installation.UserId = "user1234";
|
||||
|
||||
await hub.CreateOrUpdateInstallationAsync(installation);
|
||||
```
|
||||
|
||||
The user can then be targeted to send a notification with the tag format of `$UserId:{USER_ID}`, for example like the following:
|
||||
|
||||
```csharp
|
||||
var jsonPayload = "{\"aps\":{\"alert\":\"Notification Hub test notification\"}}";
|
||||
var n = new AppleNotification(jsonPayload);
|
||||
NotificationOutcome outcome = await hub.SendNotificationAsync(n, "$UserId:user1234");
|
||||
```
|
||||
|
||||
### Send To An Installation Template For An Installation
|
||||
|
||||
```csharp
|
||||
var props = new Dictionary<string, string>
|
||||
{
|
||||
{ "value3", "some value" }
|
||||
};
|
||||
var n = new TemplateNotification(prop);
|
||||
NotificationOutcome outcome = await hub.SendNotificationAsync(n, "$InstallationId:{installation-id} && template1");
|
||||
```
|
||||
|
||||
## Scheduled Send Operations
|
||||
|
||||
**Note: This feature is only available for [STANDARD Tier](http://azure.microsoft.com/en-us/pricing/details/notification-hubs/).**
|
||||
|
||||
Scheduled send operations are similar to a normal send operations, with a scheduledTime parameter which says when notification should be delivered. The Azure Notification Hubs Service accepts any point of time between now + 5 minutes and now + 7 days.
|
||||
|
||||
### Schedule Apple Native Send Operation
|
||||
|
||||
```csharp
|
||||
var scheduledDate = DateTimeOffset.UtcNow.AddHours(12);
|
||||
|
||||
var jsonPayload = "{\"aps\":{\"alert\":\"Notification Hub test notification\"}}";
|
||||
var n = new AppleNotification(jsonPayload);
|
||||
|
||||
ScheduledNotification outcome = await hub.ScheduleNotificationAsync(n, scheduledDate);
|
||||
```
|
||||
|
||||
### Cancel Scheduled Notification
|
||||
|
||||
```csharp
|
||||
await hub.CancelNotificationAsync(outcome.ScheduledNotificationId);
|
||||
```
|
||||
|
||||
## Import and Export Registrations
|
||||
|
||||
**Note: This feature is only available for [STANDARD Tier](http://azure.microsoft.com/en-us/pricing/details/notification-hubs/).**
|
||||
|
||||
Sometimes it is required to perform bulk operation against registrations. Usually it is for integration with another system or just to update the tags. It is strongly not recommended to use Get/Update flow if you are modifying thousands of registrations. Import/Export capability is designed to cover the scenario. You provide an access to some blob container under your storage account as a source of incoming data and location for output.
|
||||
|
||||
### Submit an Export Job
|
||||
|
||||
```csharp
|
||||
var job = new NotificationHubJob
|
||||
{
|
||||
JobType = NotificationHubJobType.ExportRegistrations,
|
||||
OutputContainerUri = new Uri("container uri with SAS signature"),
|
||||
};
|
||||
|
||||
job = await hub.SubmitNotificationHubJobAsync(job);
|
||||
```
|
||||
|
||||
### Submit an Import Job
|
||||
|
||||
```csharp
|
||||
var job = new NotificationHubJob
|
||||
{
|
||||
JobType = NotificationHubJobType.ImportCreateRegistrations,
|
||||
ImportFileUri = new Uri("input file uri with SAS signature"),
|
||||
OutputContainerUri = new Uri("container uri with SAS signature")
|
||||
};
|
||||
|
||||
job = await hub.SubmitNotificationHubJobAsync(job);
|
||||
|
||||
```
|
||||
|
||||
### Wait for Job Completion
|
||||
|
||||
```csharp
|
||||
while (true) {
|
||||
await Task.Delay(1000);
|
||||
job = await hub.GetNotificationHubJobAsync(job.JobId);
|
||||
if (job.Status == NotificationHubJobStatus.Completed) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Get All jobs
|
||||
|
||||
```csharp
|
||||
var allJobs = await hub.GetNotificationHubJobsAsync()
|
||||
```
|
||||
|
||||
## References
|
||||
|
||||
[Microsoft Azure Notification Hubs Docs](https://docs.microsoft.com/en-us/azure/notification-hubs/)
|
||||
|
||||
## Contributing
|
||||
|
||||
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.
|
||||
|
|
|
@ -0,0 +1,136 @@
|
|||
//------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See License.txt in the project root for
|
||||
// license information.
|
||||
//------------------------------------------------------------
|
||||
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.Azure.NotificationHubs.Tests
|
||||
{
|
||||
public class InstallationTests
|
||||
{
|
||||
private const string InstallationId = "13EADDC4-00DE-46A5-955F-E200E25CA66C";
|
||||
|
||||
[Fact]
|
||||
public void CanCreateAppleInstallation()
|
||||
{
|
||||
var installation = new AppleInstallation();
|
||||
|
||||
Assert.Equal(NotificationPlatform.Apns, installation.Platform);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CanCreateAppleInstallationWithToken()
|
||||
{
|
||||
const string AppleDeviceToken = "00fc13adff785122b4ad28809a3420982341241421348097878e577c991de8f0";
|
||||
|
||||
var installation = new AppleInstallation(InstallationId, AppleDeviceToken);
|
||||
|
||||
Assert.Equal(InstallationId, installation.InstallationId);
|
||||
Assert.Equal(AppleDeviceToken, installation.PushChannel);
|
||||
Assert.Equal(NotificationPlatform.Apns, installation.Platform);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CanCreateAdmInstallation()
|
||||
{
|
||||
var installation = new AdmInstallation();
|
||||
|
||||
Assert.Equal(NotificationPlatform.Adm, installation.Platform);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CanCreateAdmInstallationWithRegistrationId()
|
||||
{
|
||||
const string AdmRegistrationId = "00fc13adff785122b4ad28809a3420982341241421348097878e577c991de8f0";
|
||||
|
||||
var installation = new AdmInstallation(InstallationId, AdmRegistrationId);
|
||||
|
||||
Assert.Equal(InstallationId, installation.InstallationId);
|
||||
Assert.Equal(AdmRegistrationId, installation.PushChannel);
|
||||
Assert.Equal(NotificationPlatform.Adm, installation.Platform);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CanCreateBaiduInstallation()
|
||||
{
|
||||
var installation = new BaiduInstallation();
|
||||
|
||||
Assert.Equal(NotificationPlatform.Baidu, installation.Platform);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CanCreateBaiduInstallationWithUserIdAndChannelId()
|
||||
{
|
||||
const string UserId = "baiduuser";
|
||||
const string ChannelId = "baiduchannel";
|
||||
|
||||
var installation = new BaiduInstallation(InstallationId, UserId, ChannelId);
|
||||
|
||||
Assert.Equal(InstallationId, installation.InstallationId);
|
||||
Assert.Equal($"{UserId}-{ChannelId}", installation.PushChannel);
|
||||
Assert.Equal(NotificationPlatform.Baidu, installation.Platform);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CanCreateFcmInstallation()
|
||||
{
|
||||
var installation = new FcmInstallation();
|
||||
|
||||
Assert.Equal(NotificationPlatform.Fcm, installation.Platform);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CanCreateFcmInstallationWithRegistrationId()
|
||||
{
|
||||
const string FcmRegistrationId = "00fc13adff785122b4ad28809a3420982341241421348097878e577c991de8f0";
|
||||
|
||||
var installation = new FcmInstallation(InstallationId, FcmRegistrationId);
|
||||
|
||||
Assert.Equal(InstallationId, installation.InstallationId);
|
||||
Assert.Equal(FcmRegistrationId, installation.PushChannel);
|
||||
Assert.Equal(NotificationPlatform.Fcm, installation.Platform);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CanCreateWindowsInstallation()
|
||||
{
|
||||
var installation = new WindowsInstallation();
|
||||
|
||||
Assert.Equal(NotificationPlatform.Wns, installation.Platform);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CanCreateWindowsInstallationWithChannelUri()
|
||||
{
|
||||
const string ChannelUri = "https://notify.windows.net";
|
||||
|
||||
var installation = new WindowsInstallation(InstallationId, ChannelUri);
|
||||
|
||||
Assert.Equal(InstallationId, installation.InstallationId);
|
||||
Assert.Equal(ChannelUri, installation.PushChannel);
|
||||
Assert.Equal(NotificationPlatform.Wns, installation.Platform);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CanCreateWindowsPhoneInstallation()
|
||||
{
|
||||
var installation = new WindowsPhoneInstallation();
|
||||
|
||||
Assert.Equal(NotificationPlatform.Mpns, installation.Platform);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CanCreateWindowsPhoneInstallationWithChannelUri()
|
||||
{
|
||||
const string ChannelUri = "https://notify.windows.net";
|
||||
|
||||
var installation = new WindowsPhoneInstallation(InstallationId, ChannelUri);
|
||||
|
||||
Assert.Equal(ChannelUri, installation.PushChannel);
|
||||
Assert.Equal(NotificationPlatform.Mpns, installation.Platform);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
//------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See License.txt in the project root for
|
||||
// license information.
|
||||
//------------------------------------------------------------
|
||||
|
||||
using System;
|
||||
|
||||
namespace Microsoft.Azure.NotificationHubs
|
||||
{
|
||||
/// <summary>
|
||||
/// This class represents an Amazon Device Messaging (ADM) installation.
|
||||
/// </summary>
|
||||
public class AdmInstallation : Installation
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new instance of the AdmInstallation class.
|
||||
/// </summary>
|
||||
public AdmInstallation()
|
||||
{
|
||||
Platform = NotificationPlatform.Adm;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the AdmInstallation class.
|
||||
/// </summary>
|
||||
/// <param name="installationId">The unique identifier for the installation.</param>
|
||||
/// <param name="admRegistrationId">The ADM registration ID to use for the PushChannel.</param>
|
||||
public AdmInstallation(string installationId, string admRegistrationId) : this()
|
||||
{
|
||||
InstallationId = installationId ?? throw new ArgumentNullException(nameof(installationId));
|
||||
PushChannel = admRegistrationId ?? throw new ArgumentNullException(nameof(admRegistrationId));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
//------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See License.txt in the project root for
|
||||
// license information.
|
||||
//------------------------------------------------------------
|
||||
|
||||
using System;
|
||||
|
||||
namespace Microsoft.Azure.NotificationHubs
|
||||
{
|
||||
/// <summary>
|
||||
/// This class represents an Apple Push Notification service (APNs) installation.
|
||||
/// </summary>
|
||||
public class AppleInstallation : Installation
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new instance of the AppleInstallation class.
|
||||
/// </summary>
|
||||
public AppleInstallation()
|
||||
{
|
||||
Platform = NotificationPlatform.Apns;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the AppleInstallation class.
|
||||
/// </summary>
|
||||
/// <param name="installationId">The unique identifier for the installation.</param>
|
||||
/// <param name="deviceToken">The APNs device token to use for the PushChannel.</param>
|
||||
public AppleInstallation(string installationId, string deviceToken) : this()
|
||||
{
|
||||
InstallationId = installationId ?? throw new ArgumentNullException(nameof(installationId));
|
||||
PushChannel = deviceToken ?? throw new ArgumentNullException(nameof(deviceToken));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
//------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See License.txt in the project root for
|
||||
// license information.
|
||||
//------------------------------------------------------------
|
||||
|
||||
using System;
|
||||
|
||||
namespace Microsoft.Azure.NotificationHubs
|
||||
{
|
||||
/// <summary>
|
||||
/// This class represents an Baidu installation.
|
||||
/// </summary>
|
||||
public class BaiduInstallation : Installation
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new instance of the BaiduInstallation class.
|
||||
/// </summary>
|
||||
public BaiduInstallation()
|
||||
{
|
||||
Platform = NotificationPlatform.Baidu;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the BaiduInstallation class with the Baidu User ID and Channel ID
|
||||
/// to set on the PushChannel.
|
||||
/// </summary>
|
||||
/// <param name="installationId">The unique identifier for the installation.</param>
|
||||
/// <param name="baiduUserId">The Baidu User ID.</param>
|
||||
/// <param name="baiduChannelId">The Baidu Channel ID.</param>
|
||||
public BaiduInstallation(string installationId, string baiduUserId, string baiduChannelId) : this()
|
||||
{
|
||||
InstallationId = installationId ?? throw new ArgumentNullException(nameof(installationId));
|
||||
if (string.IsNullOrWhiteSpace(baiduUserId))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(baiduUserId));
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(baiduChannelId))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(baiduChannelId));
|
||||
}
|
||||
|
||||
PushChannel = $"{baiduUserId}-{baiduChannelId}";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -28,8 +28,8 @@ namespace Microsoft.Azure.NotificationHubs
|
|||
: base(string.Empty)
|
||||
{
|
||||
int index = pnsHandle.IndexOf('-');
|
||||
this.BaiduUserId = pnsHandle.Substring(0, index);
|
||||
this.BaiduChannelId = pnsHandle.Substring(index + 1, pnsHandle.Length - index - 1);
|
||||
BaiduUserId = pnsHandle.Substring(0, index);
|
||||
BaiduChannelId = pnsHandle.Substring(index + 1, pnsHandle.Length - index - 1);
|
||||
if (string.IsNullOrWhiteSpace(BaiduUserId))
|
||||
{
|
||||
throw new ArgumentNullException("baiduRegistrationId");
|
||||
|
@ -43,8 +43,8 @@ namespace Microsoft.Azure.NotificationHubs
|
|||
public BaiduRegistrationDescription(BaiduRegistrationDescription sourceRegistration)
|
||||
: base(sourceRegistration)
|
||||
{
|
||||
this.BaiduUserId = sourceRegistration.BaiduUserId;
|
||||
this.BaiduChannelId = sourceRegistration.BaiduChannelId;
|
||||
BaiduUserId = sourceRegistration.BaiduUserId;
|
||||
BaiduChannelId = sourceRegistration.BaiduChannelId;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -2,11 +2,9 @@
|
|||
// Licensed under the MIT License.
|
||||
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Net.Sockets;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Transactions;
|
||||
using Microsoft.Azure.NotificationHubs.Messaging;
|
||||
|
||||
namespace Microsoft.Azure.NotificationHubs
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
//------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See License.txt in the project root for
|
||||
// license information.
|
||||
//------------------------------------------------------------
|
||||
|
||||
using System;
|
||||
|
||||
namespace Microsoft.Azure.NotificationHubs
|
||||
{
|
||||
/// <summary>
|
||||
/// This class represents a Firebase Cloud Messaging (FCM) installation.
|
||||
/// </summary>
|
||||
public class FcmInstallation : Installation
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new instance of the FcmInstallation class.
|
||||
/// </summary>
|
||||
public FcmInstallation()
|
||||
{
|
||||
Platform = NotificationPlatform.Fcm;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the FcmInstallation class.
|
||||
/// </summary>
|
||||
/// <param name="installationId">The unique identifier for the installation.</param>
|
||||
/// <param name="registrationId">The Firebase registration ID to use for the PushChannel.</param>
|
||||
public FcmInstallation(string installationId, string registrationId) : this()
|
||||
{
|
||||
InstallationId = installationId ?? throw new ArgumentNullException(nameof(installationId));
|
||||
PushChannel = registrationId ?? throw new ArgumentNullException(nameof(registrationId));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -4,13 +4,13 @@
|
|||
// license information.
|
||||
//------------------------------------------------------------
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
|
||||
namespace Microsoft.Azure.NotificationHubs
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
|
||||
/// <summary>
|
||||
/// Represents device in Azure Notification Hub
|
||||
/// </summary>
|
||||
|
|
|
@ -4,13 +4,12 @@
|
|||
// license information.
|
||||
//------------------------------------------------------------
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Microsoft.Azure.NotificationHubs
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
/// <summary>
|
||||
/// Represents template which may belong to an instance of <see cref="T:Microsoft.Azure.NotificationHubs.Installation"/> class
|
||||
/// </summary>
|
||||
|
@ -47,4 +46,4 @@ namespace Microsoft.Azure.NotificationHubs
|
|||
return JsonConvert.SerializeObject(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
//------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See License.txt in the project root for
|
||||
// license information.
|
||||
//------------------------------------------------------------
|
||||
|
||||
using System;
|
||||
|
||||
namespace Microsoft.Azure.NotificationHubs
|
||||
{
|
||||
/// <summary>
|
||||
/// This class represents an Windows Notification Services (WNS) installation.
|
||||
/// </summary>
|
||||
public class WindowsInstallation : Installation
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new instance of the WnsInstallation class.
|
||||
/// </summary>
|
||||
public WindowsInstallation()
|
||||
{
|
||||
Platform = NotificationPlatform.Wns;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the WnsInstallation class.
|
||||
/// </summary>
|
||||
/// <param name="installationId">The unique identifier for the installation.</param>
|
||||
/// <param name="channelUri">The WNS Channel URI to use for the PushChannel.</param>
|
||||
public WindowsInstallation(string installationId, string channelUri) : this()
|
||||
{
|
||||
InstallationId = installationId ?? throw new ArgumentNullException(nameof(installationId));
|
||||
PushChannel = channelUri ?? throw new ArgumentNullException(nameof(channelUri));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
//------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See License.txt in the project root for
|
||||
// license information.
|
||||
//------------------------------------------------------------
|
||||
|
||||
using System;
|
||||
|
||||
namespace Microsoft.Azure.NotificationHubs
|
||||
{
|
||||
/// <summary>
|
||||
/// This class represents an Windows Phone (MPNS) installation.
|
||||
/// </summary>
|
||||
public class WindowsPhoneInstallation : Installation
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new instance of the WindowsPhoneInstallation class.
|
||||
/// </summary>
|
||||
public WindowsPhoneInstallation()
|
||||
{
|
||||
Platform = NotificationPlatform.Mpns;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the WindowsPhoneInstallation class.
|
||||
/// </summary>
|
||||
/// <param name="installationId">The unique identifier for the installation.</param>
|
||||
/// <param name="channelUri">The MPNS Channel URI to use for the PushChannel.</param>
|
||||
public WindowsPhoneInstallation(string installationId, string channelUri) : this()
|
||||
{
|
||||
InstallationId = installationId ?? throw new ArgumentNullException(nameof(installationId));
|
||||
PushChannel = channelUri ?? throw new ArgumentNullException(nameof(channelUri));
|
||||
}
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче