@@ -25,6 +25,7 @@ public DocumentDBBinding(ScriptHostConfiguration config, DocumentDBBindingMetada
25
25
CollectionName = metadata . CollectionName ;
26
26
CreateIfNotExists = metadata . CreateIfNotExists ;
27
27
ConnectionString = metadata . Connection ;
28
+ Id = metadata . Id ;
28
29
_bindingDirection = metadata . Direction ;
29
30
}
30
31
@@ -36,6 +37,8 @@ public DocumentDBBinding(ScriptHostConfiguration config, DocumentDBBindingMetada
36
37
37
38
public string ConnectionString { get ; private set ; }
38
39
40
+ public string Id { get ; private set ; }
41
+
39
42
public override bool HasBindingParameters
40
43
{
41
44
get
@@ -57,13 +60,15 @@ public override Collection<CustomAttributeBuilder> GetCustomAttributes()
57
60
PropertyInfo [ ] props = new [ ]
58
61
{
59
62
attributeType . GetProperty ( "CreateIfNotExists" ) ,
60
- attributeType . GetProperty ( "ConnectionString" )
63
+ attributeType . GetProperty ( "ConnectionString" ) ,
64
+ attributeType . GetProperty ( "Id" )
61
65
} ;
62
66
63
67
object [ ] propValues = new object [ ]
64
68
{
65
69
CreateIfNotExists ,
66
- ConnectionString
70
+ ConnectionString ,
71
+ Id
67
72
} ;
68
73
69
74
ConstructorInfo constructor = attributeType . GetConstructor ( new [ ] { typeof ( string ) , typeof ( string ) } ) ;
@@ -75,16 +80,28 @@ public override Collection<CustomAttributeBuilder> GetCustomAttributes()
75
80
76
81
public override async Task BindAsync ( BindingContext context )
77
82
{
78
- // Only output bindings are supported.
79
- if ( Access == FileAccess . Write && _bindingDirection == BindingDirection . Out )
83
+ DocumentDBAttribute attribute = new DocumentDBAttribute ( DatabaseName , CollectionName )
80
84
{
81
- DocumentDBAttribute attribute = new DocumentDBAttribute ( DatabaseName , CollectionName )
82
- {
83
- CreateIfNotExists = CreateIfNotExists ,
84
- ConnectionString = ConnectionString
85
- } ;
85
+ CreateIfNotExists = CreateIfNotExists ,
86
+ ConnectionString = ConnectionString ,
87
+ Id = Id
88
+ } ;
89
+ RuntimeBindingContext runtimeContext = new RuntimeBindingContext ( attribute ) ;
86
90
87
- RuntimeBindingContext runtimeContext = new RuntimeBindingContext ( attribute ) ;
91
+ if ( Access == FileAccess . Read && _bindingDirection == BindingDirection . In )
92
+ {
93
+ JObject input = await context . Binder . BindAsync < JObject > ( runtimeContext ) ;
94
+ if ( input != null )
95
+ {
96
+ byte [ ] byteArray = Encoding . UTF8 . GetBytes ( input . ToString ( ) ) ;
97
+ using ( MemoryStream stream = new MemoryStream ( byteArray ) )
98
+ {
99
+ stream . CopyTo ( context . Value ) ;
100
+ }
101
+ }
102
+ }
103
+ else if ( Access == FileAccess . Write && _bindingDirection == BindingDirection . Out )
104
+ {
88
105
IAsyncCollector < JObject > collector = await context . Binder . BindAsync < IAsyncCollector < JObject > > ( runtimeContext ) ;
89
106
byte [ ] bytes ;
90
107
using ( MemoryStream ms = new MemoryStream ( ) )
0 commit comments