@@ -25,6 +25,7 @@ public DocumentDBBinding(ScriptHostConfiguration config, DocumentDBBindingMetada
2525 CollectionName = metadata . CollectionName ;
2626 CreateIfNotExists = metadata . CreateIfNotExists ;
2727 ConnectionString = metadata . Connection ;
28+ Id = metadata . Id ;
2829 _bindingDirection = metadata . Direction ;
2930 }
3031
@@ -36,6 +37,8 @@ public DocumentDBBinding(ScriptHostConfiguration config, DocumentDBBindingMetada
3637
3738 public string ConnectionString { get ; private set ; }
3839
40+ public string Id { get ; private set ; }
41+
3942 public override bool HasBindingParameters
4043 {
4144 get
@@ -57,13 +60,15 @@ public override Collection<CustomAttributeBuilder> GetCustomAttributes()
5760 PropertyInfo [ ] props = new [ ]
5861 {
5962 attributeType . GetProperty ( "CreateIfNotExists" ) ,
60- attributeType . GetProperty ( "ConnectionString" )
63+ attributeType . GetProperty ( "ConnectionString" ) ,
64+ attributeType . GetProperty ( "Id" )
6165 } ;
6266
6367 object [ ] propValues = new object [ ]
6468 {
6569 CreateIfNotExists ,
66- ConnectionString
70+ ConnectionString ,
71+ Id
6772 } ;
6873
6974 ConstructorInfo constructor = attributeType . GetConstructor ( new [ ] { typeof ( string ) , typeof ( string ) } ) ;
@@ -75,16 +80,28 @@ public override Collection<CustomAttributeBuilder> GetCustomAttributes()
7580
7681 public override async Task BindAsync ( BindingContext context )
7782 {
78- // Only output bindings are supported.
79- if ( Access == FileAccess . Write && _bindingDirection == BindingDirection . Out )
83+ DocumentDBAttribute attribute = new DocumentDBAttribute ( DatabaseName , CollectionName )
8084 {
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 ) ;
8690
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+ {
88105 IAsyncCollector < JObject > collector = await context . Binder . BindAsync < IAsyncCollector < JObject > > ( runtimeContext ) ;
89106 byte [ ] bytes ;
90107 using ( MemoryStream ms = new MemoryStream ( ) )
0 commit comments