Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ public DictionaryRenderer(LanguageTemplateDictionary templates)
/// <param name="templateId">The template to render.</param>
/// <param name="data">The data object to use to render.</param>
/// <returns>Task.</returns>
#pragma warning disable UseAsyncSuffix // Use Async suffix (we can't change this without breaking compat)
public Task<object> RenderTemplate(ITurnContext turnContext, string language, string templateId, object data)
#pragma warning restore UseAsyncSuffix // Use Async suffix
{
if (_languages.TryGetValue(language, out var templates))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public interface ITemplateRenderer
/// <param name="templateId">template to render.</param>
/// <param name="data">data object to use to render.</param>
/// <returns>Task.</returns>
#pragma warning disable UseAsyncSuffix // Use Async suffix (we can't change this without breaking compat)
Task<object> RenderTemplate(ITurnContext turnContext, string language, string templateId, object data);
#pragma warning restore UseAsyncSuffix // Use Async suffix
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AsyncUsageAnalyzers" Version="1.0.0-alpha003">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Bot.Builder" Condition=" '$(IsBuildServer)' == '' " Version="$(LocalPackageVersion)" />
<PackageReference Include="Microsoft.Bot.Builder" Condition=" '$(IsBuildServer)' != '' " Version="$(ReleasePackageVersion)" />
<PackageReference Include="Microsoft.CSharp" Version="4.5.0" />
Expand Down
14 changes: 12 additions & 2 deletions libraries/Microsoft.Bot.Builder.TemplateManager/TemplateManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ namespace Microsoft.Bot.Builder.TemplateManager
/// <remarks>
/// ITemplateRenderer implements.
/// </remarks>
#pragma warning disable CA1724 // Type names should not match namespaces (by design and we can't change this without breaking binary compat)
public class TemplateManager
#pragma warning restore CA1724 // Type names should not match namespaces
{
/// <summary>
/// Initializes a new instance of the <see cref="TemplateManager"/> class.
Expand All @@ -28,15 +30,19 @@ public TemplateManager()
/// <value>
/// Template renderers.
/// </value>
#pragma warning disable CA2227 // Collection properties should be read only (we can't change this without breaking compat)
public List<ITemplateRenderer> Renderers { get; set; } = new List<ITemplateRenderer>();
#pragma warning restore CA2227 // Collection properties should be read only

/// <summary>
/// Gets or sets language fall-back policy.
/// </summary>
/// <value>
/// Language fall-back policy.
/// </value>
#pragma warning disable CA2227 // Collection properties should be read only (we can't change this without breaking compat)
public List<string> LanguageFallback { get; set; } = new List<string>();
#pragma warning restore CA2227 // Collection properties should be read only

/// <summary>
/// Creates an Activity object of type equal to "Template" and value equal to a new TemplateOptions object.
Expand Down Expand Up @@ -106,15 +112,17 @@ public IEnumerable<string> GetLanguagePolicy()
/// <param name="templateId">Id of the template.</param>
/// <param name="data">Data to render the template.</param>
/// <returns>Task.</returns>
#pragma warning disable UseAsyncSuffix // Use Async suffix (we can't change this without breaking compat)
public async Task ReplyWith(ITurnContext turnContext, string templateId, object data = null)
#pragma warning restore UseAsyncSuffix // Use Async suffix
{
BotAssert.ContextNotNull(turnContext);

// apply template
Activity boundActivity = await RenderTemplate(turnContext, turnContext.Activity?.AsMessageActivity()?.Locale, templateId, data).ConfigureAwait(false);
if (boundActivity != null)
{
await turnContext.SendActivityAsync(boundActivity);
await turnContext.SendActivityAsync(boundActivity).ConfigureAwait(false);
return;
}

Expand All @@ -129,7 +137,9 @@ public async Task ReplyWith(ITurnContext turnContext, string templateId, object
/// <param name="templateId">The id of the template.</param>
/// <param name="data">Data to render the template with.</param>
/// <returns>Task.</returns>
#pragma warning disable UseAsyncSuffix // Use Async suffix (we can't change this without breaking compat)
public async Task<Activity> RenderTemplate(ITurnContext turnContext, string language, string templateId, object data = null)
#pragma warning restore UseAsyncSuffix // Use Async suffix
{
var fallbackLocales = new List<string>(LanguageFallback);

Expand All @@ -145,7 +155,7 @@ public async Task<Activity> RenderTemplate(ITurnContext turnContext, string lang
{
foreach (var renderer in this.Renderers)
{
object templateOutput = await renderer.RenderTemplate(turnContext, locale, templateId, data);
object templateOutput = await renderer.RenderTemplate(turnContext, locale, templateId, data).ConfigureAwait(false);
if (templateOutput != null)
{
if (templateOutput is string)
Expand Down