Skip to content

Commit 3d2e32d

Browse files
committed
[NotificationHub]Add support to send native notifications
1 parent 3c9abe2 commit 3d2e32d

File tree

9 files changed

+73
-1
lines changed

9 files changed

+73
-1
lines changed

src/WebJobs.Script/Binding/NotificationHubBinding.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Reflection;
88
using System.Reflection.Emit;
99
using System.Threading.Tasks;
10+
using Microsoft.Azure.NotificationHubs;
1011
using Microsoft.Azure.WebJobs.Host.Bindings.Runtime;
1112
using Microsoft.Azure.WebJobs.Script.Description;
1213

@@ -20,14 +21,16 @@ public NotificationHubBinding(ScriptHostConfiguration config, NotificationHubBin
2021
base(config, metadata, access)
2122
{
2223
TagExpression = metadata.TagExpression;
24+
Platform = metadata.Platform;
2325
ConnectionString = metadata.Connection;
2426
HubName = metadata.HubName;
25-
2627
_bindingDirection = metadata.Direction;
2728
}
2829

2930
public string TagExpression { get; private set; }
3031

32+
public NotificationPlatform Platform { get; private set; }
33+
3134
public string ConnectionString { get; private set; }
3235

3336
public string HubName { get; private set; }
@@ -38,13 +41,15 @@ public override Collection<CustomAttributeBuilder> GetCustomAttributes(Type para
3841
PropertyInfo[] props = new[]
3942
{
4043
attributeType.GetProperty("TagExpression"),
44+
attributeType.GetProperty("Platform"),
4145
attributeType.GetProperty("ConnectionString"),
4246
attributeType.GetProperty("HubName")
4347
};
4448

4549
object[] propValues = new object[]
4650
{
4751
TagExpression,
52+
Platform,
4853
ConnectionString,
4954
HubName
5055
};
@@ -64,6 +69,7 @@ public override async Task BindAsync(BindingContext context)
6469
NotificationHubAttribute attribute = new NotificationHubAttribute
6570
{
6671
TagExpression = TagExpression,
72+
Platform = Platform,
6773
ConnectionString = ConnectionString,
6874
HubName = HubName
6975
};
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the MIT License. See License.txt in the project root for license information.
33

4+
using Microsoft.Azure.NotificationHubs;
5+
46
namespace Microsoft.Azure.WebJobs.Script.Description
57
{
68
internal class NotificationHubBindingMetadata : BindingMetadata
79
{
810
public string TagExpression { get; set; }
911

12+
public NotificationPlatform Platform { get; set; }
13+
1014
public string HubName { get; set; }
1115
}
1216
}

test/WebJobs.Script.Tests/CSharpEndToEndTests.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ public async Task NotificationHub_Out_Notification()
5151
await NotificationHubTest("NotificationHubOutNotification");
5252
}
5353

54+
[Fact]
55+
public async Task NotificationHubNative()
56+
{
57+
await NotificationHubTest("NotificationHubNative");
58+
}
59+
5460
[Fact]
5561
public async Task MobileTablesTable()
5662
{

test/WebJobs.Script.Tests/NodeEndToEndTests.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,12 @@ public async Task NotificationHub()
149149
await NotificationHubTest("NotificationHubOut");
150150
}
151151

152+
[Fact]
153+
public async Task NotificationHubNative()
154+
{
155+
await NotificationHubTest("NotificationHubNative");
156+
}
157+
152158
[Fact]
153159
public async Task MobileTables()
154160
{
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"bindings": [
3+
{
4+
"type": "manualTrigger",
5+
"direction": "in"
6+
},
7+
{
8+
"type": "notificationHub",
9+
"direction": "out",
10+
"name": "wnsToastPayload",
11+
"platform": "wns"
12+
}
13+
]
14+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
using System;
2+
public static void Run(string input, out string wnsToastPayload)
3+
{
4+
wnsToastPayload = "<toast><visual><binding template=\"ToastText01\"><text id=\"1\">Test message from C#</text></binding></visual></toast>";
5+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"bindings": [
3+
{
4+
"type": "manualTrigger",
5+
"direction": "in"
6+
},
7+
{
8+
"type": "notificationHub",
9+
"direction": "out",
10+
"name": "wnsToastPayload",
11+
"platform": "wns"
12+
}
13+
]
14+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = function (context, input) {
2+
context.log('Sending native windows toast notification...');
3+
context.bindings.wnsToastPayload = "<toast><visual><binding template=\"ToastText01\"><text id=\"1\">Test message from Node!</text></binding></visual></toast>";
4+
context.done();
5+
}

test/WebJobs.Script.Tests/WebJobs.Script.Tests.csproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,12 @@
366366
<None Include="TestScripts\CSharp\LoadScriptReference\run.csx">
367367
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
368368
</None>
369+
<None Include="TestScripts\CSharp\NotificationHubNative\function.json">
370+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
371+
</None>
372+
<None Include="TestScripts\CSharp\NotificationHubNative\run.csx">
373+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
374+
</None>
369375
<None Include="TestScripts\CSharp\NotificationHubOutNotification\function.json">
370376
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
371377
</None>
@@ -459,6 +465,9 @@
459465
<None Include="TestScripts\Node\MobileTableIn\function.json">
460466
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
461467
</None>
468+
<None Include="TestScripts\Node\NotificationHubNative\function.json">
469+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
470+
</None>
462471
<None Include="TestScripts\Node\NotificationHubOut\function.json">
463472
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
464473
</None>
@@ -498,6 +507,9 @@
498507
<Content Include="TestScripts\Node\HttpTriggerByteArray\index.js">
499508
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
500509
</Content>
510+
<Content Include="TestScripts\Node\NotificationHubNative\index.js">
511+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
512+
</Content>
501513
<Content Include="TestScripts\Node\QueueTriggerByteArray\index.js">
502514
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
503515
</Content>

0 commit comments

Comments
 (0)