-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #261 from Azure/addXiaomiNotification
Add xiaomi notification
- Loading branch information
Showing
4 changed files
with
108 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
src/Microsoft.Azure.NotificationHubs/XiaomiNotification.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
//---------------------------------------------------------------- | ||
// 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.Text; | ||
|
||
namespace Microsoft.Azure.NotificationHubs | ||
{ | ||
/// <summary> | ||
/// Represents a Xiaomi notification. | ||
/// </summary> | ||
public sealed class XiaomiNotification : Notification, INativeNotification | ||
{ | ||
static string contentType = $"application/json;charset={Encoding.UTF8.WebName}"; | ||
static string targetPipeline = "X-Target-Pipeline"; | ||
static string serviceBusNotificationFormat = "ServiceBusNotification-Format"; | ||
static string newPipeline = "New"; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="T:Microsoft.Azure.NotificationHubs.XiaomiNotification"/> class. | ||
/// </summary> | ||
/// <param name="jsonPayload">The JSON payload.</param> | ||
public XiaomiNotification(string jsonPayload) | ||
: base(null, null, contentType) | ||
{ | ||
if (string.IsNullOrWhiteSpace(jsonPayload)) | ||
{ | ||
throw new ArgumentNullException("jsonPayload"); | ||
} | ||
|
||
this.Body = jsonPayload; | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="T:Microsoft.Azure.NotificationHubs.FcmNotification"/> class. | ||
/// </summary> | ||
/// <param name="jsonPayload">The JSON payload.</param><param name="tag">The notification tag.</param> | ||
[Obsolete("This method is obsolete.")] | ||
public XiaomiNotification(string jsonPayload, string tag) | ||
: base(null, tag, contentType) | ||
{ | ||
if (string.IsNullOrWhiteSpace(jsonPayload)) | ||
{ | ||
throw new ArgumentNullException("jsonPayload"); | ||
} | ||
|
||
this.Body = jsonPayload; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the type of the platform. | ||
/// </summary> | ||
/// <value> | ||
/// The type of the platform. | ||
/// </value> | ||
protected override string PlatformType | ||
{ | ||
// This will be changed into XiaomiCredential.AppPlatformName when we add the XiaomiCredential class in a following PR | ||
get { return "xiaomi"; } | ||
} | ||
|
||
/// <summary> | ||
/// Validate and populates the headers. | ||
/// </summary> | ||
protected override void OnValidateAndPopulateHeaders() | ||
{ | ||
this.AddOrUpdateHeader(serviceBusNotificationFormat, PlatformType); | ||
this.AddOrUpdateHeader(targetPipeline, newPipeline); | ||
} | ||
} | ||
} | ||
|