-
Notifications
You must be signed in to change notification settings - Fork 478
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Register
missingProperties
custom function to get all variables the…
… template contains (#5518) * Register missingProperties custom function * add test * fix comments * update * add test * fix case * add functions * add * add tests * fix * init * remove some restrict * do not export LG in TemplateEngineGenerator * fix issue * refine code * remove unused using * fix test
- Loading branch information
Showing
16 changed files
with
472 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
libraries/Microsoft.Bot.Builder.Dialogs.Adaptive/Functions/MissingPropertiesFunction.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Licensed under the MIT License. | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
|
||
using System.Collections.Generic; | ||
using AdaptiveExpressions; | ||
using AdaptiveExpressions.Memory; | ||
using Microsoft.Bot.Builder.Dialogs.Adaptive; | ||
|
||
namespace Microsoft.Bot.Builder.Dialogs.Functions | ||
{ | ||
/// <summary> | ||
/// Defines missingProperties(template) expression function. | ||
/// </summary> | ||
/// <remarks> | ||
/// This expression will get all variables the template contains. | ||
/// </remarks> | ||
public class MissingPropertiesFunction : ExpressionEvaluator | ||
{ | ||
/// <summary> | ||
/// Function identifier name. | ||
/// </summary> | ||
public const string Name = "missingProperties"; | ||
|
||
private const string GeneratorPath = "dialogclass.generator"; | ||
|
||
private static DialogContext dialogContext; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="MissingPropertiesFunction"/> class. | ||
/// </summary> | ||
/// <param name="context">Dialog context.</param> | ||
public MissingPropertiesFunction(DialogContext context) | ||
: base(Name, Function, ReturnType.Array, FunctionUtils.ValidateUnaryString) | ||
{ | ||
dialogContext = context; | ||
} | ||
|
||
private static (object value, string error) Function(Expression expression, IMemory state, Options options) | ||
{ | ||
var (args, error) = FunctionUtils.EvaluateChildren(expression, state, options); | ||
if (error != null) | ||
{ | ||
return (null, error); | ||
} | ||
|
||
var templateBody = args[0]?.ToString(); | ||
|
||
if (state.TryGetValue(GeneratorPath, out var lgGenerator)) | ||
{ | ||
var generator = lgGenerator as LanguageGenerator; | ||
return (generator.MissingProperties(dialogContext, templateBody, state, options), null); | ||
} | ||
|
||
return (new List<string>(), null); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.