forked from Azure/azure-functions-host
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
464 additions
and
45 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"bindings": [ | ||
{ | ||
"type": "apiHubTrigger", | ||
"connection": "AzureWebJobsDropBox", | ||
"direction": "in", | ||
"path": "testin/{name}" | ||
}, | ||
{ | ||
"type": "apiHub", | ||
"name": "output", | ||
"connection": "AzureWebJobsDropBox", | ||
"direction": "out", | ||
"path": "testOutBatch/{name}" | ||
} | ||
] | ||
} |
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,4 @@ | ||
echo OFF | ||
SET /p input=<%input% | ||
echo Windows Batch script processed file | ||
echo %input% > %output% |
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,18 @@ | ||
{ | ||
"bindings": [ | ||
{ | ||
"type": "apiHubTrigger", | ||
"connection": "AzureWebJobsDropBox", | ||
"direction": "in", | ||
"path": "test/{name}", | ||
"name": "input" | ||
}, | ||
{ | ||
"name": "output", | ||
"type": "apiHub", | ||
"connection": "AzureWebJobsDropBox", | ||
"direction": "out", | ||
"path": "testOut/{name}" | ||
} | ||
] | ||
} |
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,14 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Net; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
using System.Diagnostics; | ||
using Microsoft.Azure.WebJobs.Host; | ||
|
||
public static void Run(string input, out string output, TraceWriter log) | ||
{ | ||
log.Verbose($"C# ApiHub trigger function processed a file..."); | ||
|
||
output = input; | ||
} |
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,17 @@ | ||
{ | ||
"bindings": [ | ||
{ | ||
"type": "apiHubTrigger", | ||
"connection": "AzureWebJobsDropBox", | ||
"direction": "in", | ||
"path": "testinnode/{name}" | ||
}, | ||
{ | ||
"type": "apiHub", | ||
"name": "output", | ||
"connection": "AzureWebJobsDropBox", | ||
"direction": "out", | ||
"path": "testoutnode/{name}" | ||
} | ||
] | ||
} |
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,6 @@ | ||
module.exports = function (context, input) { | ||
context.log('Node.js ApiHub trigger function processed ', input); | ||
context.done(null, { | ||
output: input | ||
}); | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Collections.ObjectModel; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Reflection.Emit; | ||
using System.Threading.Tasks; | ||
using Microsoft.Azure.WebJobs.Host.Bindings.Path; | ||
using Microsoft.Azure.WebJobs.Host.Bindings.Runtime; | ||
using Microsoft.Azure.WebJobs.Script.Description; | ||
|
||
namespace Microsoft.Azure.WebJobs.Script.Binding | ||
{ | ||
public class ApiHubBinding : FunctionBinding | ||
{ | ||
private readonly BindingTemplate _pathBindingTemplate; | ||
|
||
public ApiHubBinding(ScriptHostConfiguration config, ApiHubBindingMetadata apiHubBindingMetadata, FileAccess access) : base(config, apiHubBindingMetadata, access) | ||
{ | ||
if (apiHubBindingMetadata == null) | ||
{ | ||
throw new ArgumentNullException("apiHubBindingMetadata"); | ||
} | ||
|
||
if (string.IsNullOrEmpty(apiHubBindingMetadata.Path)) | ||
{ | ||
throw new ArgumentException("The ApiHub path cannot be null or empty."); | ||
} | ||
|
||
Key = apiHubBindingMetadata.Key; | ||
Path = apiHubBindingMetadata.Path; | ||
_pathBindingTemplate = BindingTemplate.FromString(Path); | ||
} | ||
|
||
public override bool HasBindingParameters | ||
{ | ||
get | ||
{ | ||
return _pathBindingTemplate.ParameterNames.Any(); | ||
} | ||
} | ||
|
||
public string Key { get; private set; } | ||
|
||
public string Path { get; private set; } | ||
|
||
public override Collection<CustomAttributeBuilder> GetCustomAttributes() | ||
{ | ||
Collection<CustomAttributeBuilder> attributes = new Collection<CustomAttributeBuilder>(); | ||
|
||
var constructorTypes = new Type[] { typeof(string), typeof(string), typeof(FileAccess) }; | ||
var constructorArguments = new object[] { Key, Path, FileAccess.Read }; | ||
|
||
var attribute = new CustomAttributeBuilder(typeof(ApiHubFileAttribute).GetConstructor(constructorTypes), constructorArguments); | ||
|
||
attributes.Add(attribute); | ||
|
||
return attributes; | ||
} | ||
|
||
public override async Task BindAsync(BindingContext context) | ||
{ | ||
string boundBlobPath = Path; | ||
if (context.BindingData != null) | ||
{ | ||
boundBlobPath = _pathBindingTemplate.Bind(context.BindingData); | ||
} | ||
|
||
boundBlobPath = Resolve(boundBlobPath); | ||
|
||
var attribute = new ApiHubFileAttribute(Key, boundBlobPath, Access); | ||
|
||
RuntimeBindingContext runtimeContext = new RuntimeBindingContext(attribute); | ||
Stream blobStream = await context.Binder.BindAsync<Stream>(runtimeContext); | ||
|
||
if (Access == FileAccess.Write) | ||
{ | ||
await context.Value.CopyToAsync(blobStream); | ||
} | ||
else | ||
{ | ||
await blobStream.CopyToAsync(context.Value); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.