Skip to content

Commit

Permalink
add control property (#5943) (#5944)
Browse files Browse the repository at this point in the history
* add control property

* disable fragile test

Co-authored-by: johnataylor <johtaylo@microsoft.com>
  • Loading branch information
EricDahlvang and johnataylor authored Oct 29, 2021
1 parent 0286c05 commit aa95898
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 8 deletions.
11 changes: 7 additions & 4 deletions libraries/Microsoft.Bot.Builder.LanguageGeneration/Evaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -593,11 +593,14 @@ private EvaluatorLookup CustomizedEvaluatorLookup(EvaluatorLookup baseLookup)
return new ExpressionEvaluator(template, FunctionUtils.Apply(this.TemplateFunction()), ReturnType.Object, this.ValidateTemplateFunction);
}
const string fromFile = "fromFile";
if (name.Equals(fromFile, StringComparison.Ordinal))
if (LanguageGeneration.Templates.EnableFromFile)
{
return new ExpressionEvaluator(fromFile, FunctionUtils.Apply(FromFile()), ReturnType.String, ValidateFromFile);
const string fromFile = "fromFile";
if (name.Equals(fromFile, StringComparison.Ordinal))
{
return new ExpressionEvaluator(fromFile, FunctionUtils.Apply(FromFile()), ReturnType.String, ValidateFromFile);
}
}
const string activityAttachment = "ActivityAttachment";
Expand Down
11 changes: 7 additions & 4 deletions libraries/Microsoft.Bot.Builder.LanguageGeneration/Expander.cs
Original file line number Diff line number Diff line change
Expand Up @@ -533,11 +533,14 @@ private EvaluatorLookup CustomizedEvaluatorLookup(EvaluatorLookup baseLookup, bo
return new ExpressionEvaluator(template, FunctionUtils.Apply(this.TemplateFunction()), ReturnType.Object, this.ValidateTemplateFunction);
}
const string fromFile = "fromFile";
if (name.Equals(fromFile, StringComparison.Ordinal))
if (LanguageGeneration.Templates.EnableFromFile)
{
return new ExpressionEvaluator(fromFile, FunctionUtils.Apply(this.FromFile()), ReturnType.String, ValidateFromFile);
const string fromFile = "fromFile";
if (name.Equals(fromFile, StringComparison.Ordinal))
{
return new ExpressionEvaluator(fromFile, FunctionUtils.Apply(this.FromFile()), ReturnType.String, ValidateFromFile);
}
}
const string activityAttachment = "ActivityAttachment";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ public Templates(
InjectToExpressionFunction();
}

/// <summary>
/// Gets or sets a value indicating whether fromFile is allowed in LG templates.
/// </summary>
/// <value>
/// Boolean where true indicates fromFile is allowed.
/// </value>
public static bool EnableFromFile { get; set; } = true;

/// <summary>
/// Gets get all templates from current lg file and reference lg files.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1743,6 +1743,18 @@ public void TestFileOperation()
Assert.Equal("hi ${name}", evaluated);
}

[Fact]
public void TestFileOperationDisabled()
{
Templates.EnableFromFile = false;

Assert.Throws<InvalidOperationException>(() =>
{
var templates = Templates.ParseFile(GetExampleFilePath("FileOperation.lg"));
var evaluated = templates.Evaluate("FromFileWithoutEvaluation");
});
}

public class LoopClass
{
public string Name { get; set; }
Expand Down

0 comments on commit aa95898

Please sign in to comment.