Skip to content

Commit

Permalink
[NotificationHub]Add support to send native notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
pragnagopa committed May 25, 2016
1 parent 3c9abe2 commit 3d2e32d
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/WebJobs.Script/Binding/NotificationHubBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Reflection;
using System.Reflection.Emit;
using System.Threading.Tasks;
using Microsoft.Azure.NotificationHubs;
using Microsoft.Azure.WebJobs.Host.Bindings.Runtime;
using Microsoft.Azure.WebJobs.Script.Description;

Expand All @@ -20,14 +21,16 @@ public NotificationHubBinding(ScriptHostConfiguration config, NotificationHubBin
base(config, metadata, access)
{
TagExpression = metadata.TagExpression;
Platform = metadata.Platform;
ConnectionString = metadata.Connection;
HubName = metadata.HubName;

_bindingDirection = metadata.Direction;
}

public string TagExpression { get; private set; }

public NotificationPlatform Platform { get; private set; }

public string ConnectionString { get; private set; }

public string HubName { get; private set; }
Expand All @@ -38,13 +41,15 @@ public override Collection<CustomAttributeBuilder> GetCustomAttributes(Type para
PropertyInfo[] props = new[]
{
attributeType.GetProperty("TagExpression"),
attributeType.GetProperty("Platform"),
attributeType.GetProperty("ConnectionString"),
attributeType.GetProperty("HubName")
};

object[] propValues = new object[]
{
TagExpression,
Platform,
ConnectionString,
HubName
};
Expand All @@ -64,6 +69,7 @@ public override async Task BindAsync(BindingContext context)
NotificationHubAttribute attribute = new NotificationHubAttribute
{
TagExpression = TagExpression,
Platform = Platform,
ConnectionString = ConnectionString,
HubName = HubName
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using Microsoft.Azure.NotificationHubs;

namespace Microsoft.Azure.WebJobs.Script.Description
{
internal class NotificationHubBindingMetadata : BindingMetadata
{
public string TagExpression { get; set; }

public NotificationPlatform Platform { get; set; }

public string HubName { get; set; }
}
}
6 changes: 6 additions & 0 deletions test/WebJobs.Script.Tests/CSharpEndToEndTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ public async Task NotificationHub_Out_Notification()
await NotificationHubTest("NotificationHubOutNotification");
}

[Fact]
public async Task NotificationHubNative()
{
await NotificationHubTest("NotificationHubNative");
}

[Fact]
public async Task MobileTablesTable()
{
Expand Down
6 changes: 6 additions & 0 deletions test/WebJobs.Script.Tests/NodeEndToEndTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ public async Task NotificationHub()
await NotificationHubTest("NotificationHubOut");
}

[Fact]
public async Task NotificationHubNative()
{
await NotificationHubTest("NotificationHubNative");
}

[Fact]
public async Task MobileTables()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"bindings": [
{
"type": "manualTrigger",
"direction": "in"
},
{
"type": "notificationHub",
"direction": "out",
"name": "wnsToastPayload",
"platform": "wns"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
using System;
public static void Run(string input, out string wnsToastPayload)
{
wnsToastPayload = "<toast><visual><binding template=\"ToastText01\"><text id=\"1\">Test message from C#</text></binding></visual></toast>";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"bindings": [
{
"type": "manualTrigger",
"direction": "in"
},
{
"type": "notificationHub",
"direction": "out",
"name": "wnsToastPayload",
"platform": "wns"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = function (context, input) {
context.log('Sending native windows toast notification...');
context.bindings.wnsToastPayload = "<toast><visual><binding template=\"ToastText01\"><text id=\"1\">Test message from Node!</text></binding></visual></toast>";
context.done();
}
12 changes: 12 additions & 0 deletions test/WebJobs.Script.Tests/WebJobs.Script.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,12 @@
<None Include="TestScripts\CSharp\LoadScriptReference\run.csx">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="TestScripts\CSharp\NotificationHubNative\function.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="TestScripts\CSharp\NotificationHubNative\run.csx">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="TestScripts\CSharp\NotificationHubOutNotification\function.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down Expand Up @@ -459,6 +465,9 @@
<None Include="TestScripts\Node\MobileTableIn\function.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="TestScripts\Node\NotificationHubNative\function.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="TestScripts\Node\NotificationHubOut\function.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down Expand Up @@ -498,6 +507,9 @@
<Content Include="TestScripts\Node\HttpTriggerByteArray\index.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="TestScripts\Node\NotificationHubNative\index.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="TestScripts\Node\QueueTriggerByteArray\index.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
Expand Down

0 comments on commit 3d2e32d

Please sign in to comment.