Skip to content

Commit

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

* disable fragile test
  • Loading branch information
johnataylor authored and EricDahlvang committed Nov 6, 2021
1 parent d33c8d5 commit 84bb65e
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 @@ -605,11 +605,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 (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 @@ -542,11 +542,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 (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 @@ -77,6 +77,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 @@ -1832,6 +1832,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 84bb65e

Please sign in to comment.