-
Notifications
You must be signed in to change notification settings - Fork 450
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
27 changed files
with
395 additions
and
28 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": "queueTrigger", | ||
"direction": "in", | ||
"queueName": "samples-documentdb-csharp" | ||
}, | ||
{ | ||
"type": "documentdb", | ||
"direction": "out", | ||
"name": "newItem", | ||
"databaseName": "ItemDb", | ||
"collectionName": "ItemCollection", | ||
"createIfNotExists": false | ||
} | ||
] | ||
} |
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,9 @@ | ||
using System; | ||
|
||
public static void Run(string input, out object newItem) | ||
{ | ||
newItem = new | ||
{ | ||
text = "Hello from C#! " + 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": "queueTrigger", | ||
"direction": "in", | ||
"queueName": "samples-documentdb-node" | ||
}, | ||
{ | ||
"type": "documentdb", | ||
"direction": "out", | ||
"name": "item", | ||
"databaseName": "ItemDb", | ||
"collectionName": "ItemCollection", | ||
"createIfNotExists": false | ||
} | ||
] | ||
} |
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,9 @@ | ||
module.exports = function (context, input) { | ||
context.log('Node.js queue-triggered DocumentDB function called with input ' + input); | ||
|
||
context.bindings.item = { | ||
text: "Hello from Node! " + input | ||
}; | ||
|
||
context.done(); | ||
} |
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.IO; | ||
using System.Reflection; | ||
using System.Reflection.Emit; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Microsoft.Azure.WebJobs.Script.Description; | ||
using Newtonsoft.Json.Linq; | ||
|
||
namespace Microsoft.Azure.WebJobs.Script.Binding | ||
{ | ||
internal class DocumentDBBinding : FunctionBinding | ||
{ | ||
private BindingDirection _bindingDirection; | ||
|
||
public DocumentDBBinding(ScriptHostConfiguration config, string name, string databaseName, string collectionName, bool createIfNotExists, FileAccess access, BindingDirection direction) : | ||
base(config, name, BindingType.DocumentDB, access, false) | ||
{ | ||
DatabaseName = databaseName; | ||
CollectionName = collectionName; | ||
CreateIfNotExists = createIfNotExists; | ||
_bindingDirection = direction; | ||
} | ||
|
||
public string DatabaseName { get; private set; } | ||
|
||
public string CollectionName { get; private set; } | ||
|
||
public bool CreateIfNotExists { get; private set; } | ||
|
||
public override bool HasBindingParameters | ||
{ | ||
get | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
public override CustomAttributeBuilder GetCustomAttribute() | ||
{ | ||
Type attributeType = typeof(DocumentDBAttribute); | ||
PropertyInfo[] props = new[] | ||
{ | ||
attributeType.GetProperty("DatabaseName"), | ||
attributeType.GetProperty("CollectionName"), | ||
attributeType.GetProperty("CreateIfNotExists") | ||
}; | ||
|
||
object[] propValues = new object[] | ||
{ | ||
DatabaseName, | ||
CollectionName, | ||
CreateIfNotExists | ||
}; | ||
|
||
ConstructorInfo constructor = attributeType.GetConstructor(System.Type.EmptyTypes); | ||
|
||
return new CustomAttributeBuilder(constructor, new object[] { }, props, propValues); | ||
} | ||
|
||
public override async Task BindAsync(BindingContext context) | ||
{ | ||
DocumentDBAttribute attribute = new DocumentDBAttribute | ||
{ | ||
DatabaseName = DatabaseName, | ||
CollectionName = CollectionName, | ||
CreateIfNotExists = CreateIfNotExists | ||
}; | ||
|
||
// Only output bindings are supported. | ||
if (Access == FileAccess.Write && _bindingDirection == BindingDirection.Out) | ||
{ | ||
IAsyncCollector<JObject> collector = context.Binder.Bind<IAsyncCollector<JObject>>(attribute); | ||
byte[] bytes; | ||
using (MemoryStream ms = new MemoryStream()) | ||
{ | ||
context.Value.CopyTo(ms); | ||
bytes = ms.ToArray(); | ||
} | ||
JObject entity = JObject.Parse(Encoding.UTF8.GetString(bytes)); | ||
await collector.AddAsync(entity); | ||
} | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -18,6 +18,7 @@ public enum BindingType | |
Table, | ||
ManualTrigger, | ||
TimerTrigger, | ||
EasyTable | ||
EasyTable, | ||
DocumentDB | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/WebJobs.Script/Description/DocumentDBBindingMetadata.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,36 @@ | ||
// 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 Microsoft.Azure.WebJobs.Extensions.DocumentDB; | ||
|
||
namespace Microsoft.Azure.WebJobs.Script.Description | ||
{ | ||
internal class DocumentDBBindingMetadata : BindingMetadata | ||
{ | ||
public string DatabaseName { get; set; } | ||
|
||
public string CollectionName { get; set; } | ||
|
||
public bool CreateIfNotExists { get; set; } | ||
|
||
[AllowNameResolution] | ||
public string ConnectionString { get; set; } | ||
|
||
public override void ApplyToConfig(JobHostConfigurationBuilder configBuilder) | ||
{ | ||
if (configBuilder == null) | ||
{ | ||
throw new ArgumentNullException("configBuilder"); | ||
} | ||
|
||
DocumentDBConfiguration config = new DocumentDBConfiguration(); | ||
if (!string.IsNullOrEmpty(ConnectionString)) | ||
{ | ||
config.ConnectionString = ConnectionString; | ||
} | ||
|
||
configBuilder.Config.UseDocumentDB(config); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.