Skip to content

Commit

Permalink
Extending BindingTemplateExtensions by adding additional methods need…
Browse files Browse the repository at this point in the history
…ed by binding Extensions.
  • Loading branch information
mathewc committed Oct 22, 2015
1 parent 5ba3a16 commit c611a44
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 39 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Microsoft.Azure.WebJobs.Host.Bindings
/// <summary>
/// Class containing helper methods for path binding
/// </summary>
public static class BindingDataPathHelper
internal static class BindingDataPathHelper
{
/// <summary>
/// Converts all parameter values in the specified binding data to their path compatible string values.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// 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.Generic;
using System.Globalization;
using System.Linq;
using Microsoft.Azure.WebJobs.Host.Bindings.Path;

namespace Microsoft.Azure.WebJobs.Host.Bindings
{
/// <summary>
/// Class containing extension methods for <see cref="BindingTemplate"/> and other binding Types.
/// </summary>
public static class BindingTemplateExtensions
{
internal static void ValidateContractCompatibility<TPath>(this IBindablePath<TPath> path, IReadOnlyDictionary<string, Type> bindingDataContract)
{
if (path == null)
{
throw new ArgumentNullException("path");
}

ValidateContractCompatibility(path.ParameterNames, bindingDataContract);
}

/// <summary>
/// Verifies that the specified binding contract contains contract members for each of the
/// parameters in the specified <see cref="BindingTemplate"/>.
/// </summary>
/// <param name="bindingTemplate">The binding template to validate.</param>
/// <param name="bindingDataContract">The data contract to validate against.</param>
public static void ValidateContractCompatibility(this BindingTemplate bindingTemplate, IReadOnlyDictionary<string, Type> bindingDataContract)
{
if (bindingTemplate == null)
{
throw new ArgumentNullException("bindingTemplate");
}

ValidateContractCompatibility(bindingTemplate.ParameterNames, bindingDataContract);
}

/// <summary>
/// Bind the <see cref="BindingTemplate"/> using the specified binding data.
/// </summary>
/// <param name="bindingTemplate">The binding template to validate.</param>
/// <param name="bindingData">The binding data to apply to the template.</param>
/// <returns>The bound template string.</returns>
public static string Bind(this BindingTemplate bindingTemplate, IReadOnlyDictionary<string, object> bindingData)
{
if (bindingTemplate == null)
{
throw new ArgumentNullException("bindingTemplate");
}

if (bindingData == null ||
!bindingTemplate.ParameterNames.Any())
{
return bindingTemplate.Pattern;
}

IReadOnlyDictionary<string, string> parameters = BindingDataPathHelper.ConvertParameters(bindingData);
string path = bindingTemplate.Bind(parameters);

return path;
}

private static void ValidateContractCompatibility(IEnumerable<string> parameterNames, IReadOnlyDictionary<string, Type> bindingDataContract)
{
if (parameterNames != null && bindingDataContract != null)
{
foreach (string parameterName in parameterNames)
{
if (!bindingDataContract.ContainsKey(parameterName))
{
throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, "No binding parameter exists for '{0}'.", parameterName));
}
}
}
}
}
}
2 changes: 1 addition & 1 deletion src/Microsoft.Azure.WebJobs.Host/WebJobs.Host.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@
<Compile Include="Bindings\Data\StringToTArgumentBindingProvider.cs" />
<Compile Include="Bindings\Data\StructDataBinding.cs" />
<Compile Include="Bindings\Data\DataBindingProvider.cs" />
<Compile Include="Bindings\BindablePathExtensions.cs" />
<Compile Include="Bindings\BindingTemplateExtensions.cs" />
<Compile Include="Bindings\IBindablePath.cs" />
<Compile Include="Bindings\IFunctionBinding.cs" />
<Compile Include="Bindings\Invoke\ClassInvokeBinding.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ public string Bind(IReadOnlyDictionary<string, object> bindingData)
throw new ArgumentNullException("bindingData");
}

IReadOnlyDictionary<string, string> parameters = BindingDataPathHelper.ConvertParameters(bindingData);
string queueOrTopicName = _template.Bind(parameters);
string queueOrTopicName = _template.Bind(bindingData);
return queueOrTopicName;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ public void WebJobsHostPublicSurface_LimitedToSpecificTypes()
"INameResolver",
"WebJobsShutdownWatcher",
"BindingContext",
"BindingDataPathHelper",
"BindingProviderContext",
"BindingTemplate",
"BindStepOrder",
Expand Down Expand Up @@ -130,7 +129,8 @@ public void WebJobsHostPublicSurface_LimitedToSpecificTypes()
"BindingDataProvider",
"IBindingDataProvider",
"FunctionInvocationException",
"TraceEvent"
"TraceEvent",
"BindingTemplateExtensions"
};

AssertPublicTypes(expected, assembly);
Expand Down

0 comments on commit c611a44

Please sign in to comment.