Skip to content

Commit

Permalink
Fixing Table input binding issue
Browse files Browse the repository at this point in the history
  • Loading branch information
mathewc committed Mar 28, 2016
1 parent 9e0f9fb commit 9f3104a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
7 changes: 6 additions & 1 deletion src/WebJobs.Script.WebHost/App_Start/WebApiConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ private static WebHostSettings GetDefaultSettings()
bool isLocal = string.IsNullOrEmpty(home);
if (isLocal)
{
settings.ScriptPath = Path.Combine(HostingEnvironment.ApplicationPhysicalPath, @"..\..\sample");
settings.ScriptPath = Environment.GetEnvironmentVariable("AzureWebJobsScriptRoot");
settings.LogPath = Path.Combine(Path.GetTempPath(), @"Functions");
settings.SecretsPath = HttpContext.Current.Server.MapPath("~/App_Data/Secrets");
}
Expand All @@ -129,6 +129,11 @@ private static WebHostSettings GetDefaultSettings()
settings.SecretsPath = Path.Combine(home, @"data\Functions\secrets");
}

if (string.IsNullOrEmpty(settings.ScriptPath))
{
throw new InvalidOperationException("Unable to determine function script root directory.");
}

return settings;
}
}
Expand Down
23 changes: 13 additions & 10 deletions src/WebJobs.Script/Binding/TableBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ public override async Task BindAsync(BindingContext context)
}
else
{
string json = null;

if (!string.IsNullOrEmpty(boundPartitionKey) &&
!string.IsNullOrEmpty(boundRowKey))
{
Expand All @@ -152,11 +154,7 @@ public override async Task BindAsync(BindingContext context)
DynamicTableEntity tableEntity = await context.Binder.BindAsync<DynamicTableEntity>(runtimeContext);
if (tableEntity != null)
{
string json = ConvertEntityToJObject(tableEntity).ToString();
using (StreamWriter sw = new StreamWriter(valueStream))
{
await sw.WriteAsync(json);
}
json = ConvertEntityToJObject(tableEntity).ToString();
}
}
else
Expand All @@ -172,11 +170,16 @@ public override async Task BindAsync(BindingContext context)
entityArray.Add(ConvertEntityToJObject(entity));
}

string json = entityArray.ToString(Formatting.None);
using (StreamWriter sw = new StreamWriter(valueStream))
{
await sw.WriteAsync(json);
}
json = entityArray.ToString(Formatting.None);
}

if (json != null)
{
// We're explicitly NOT disposing the StreamWriter because
// we don't want to close the underlying Stream
StreamWriter sw = new StreamWriter(valueStream);
await sw.WriteAsync(json);
sw.Flush();
}
}
}
Expand Down

0 comments on commit 9f3104a

Please sign in to comment.