Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DCR] Normalize all expression and add '=' to force expression. #3253

Merged
merged 23 commits into from
Jan 18, 2020

Conversation

tomlm
Copy link
Contributor

@tomlm tomlm commented Jan 11, 2020

  • Added StringExpression,ValueExpression, etc. for expression or value access
  • added a ton of unit tests for the expression stuff
  • For ambigious expressions (StringExpression and ValueExpression) it will treat as string interpolation unless it starts with =. "Hello @{world}" ==> "hello world", "=user.foo" => Expression("user.foo")
  • Added assignment operators so you can assign string expressions to expression properties.
  • cleaned up dialogs files
  • Exposed Dialogset to DialogManager so you can register external external dialogs
  • Added DialogId to BeginDialog to allow you to invoke external dialogs

It basically boils down to how to deal with strings as input:

  • StringExpression always assumes string interpolation unless prefixed with =, producing a string
  • ValueExpression always assumes string interpolation unless prefixed with =, producing an object which MAY be a string
  • ExpressionProperty<T> always assumes strings represent something to be interpreted as the type of T, so always producing object of T.

StringExpression

Interpretation of string is as a string interpolation result unless =.

| Input                         | Result        |
|-------------------------------|---------------|
| "13"                          | "13"          |
| "=13"                         | "13"          |
| "user.age"                    | "user.age"    |
| "=user.age"                   | "13"          |
| "Hello world"                 | "Hello World" |
| "='Hello world'"              | "Hello World" |
| "Hello @{user.name}"          | "Hello Joe"   |
| "=concat('Hello ', user.name) | "Hello Joe"   |

BoolExpression

Interpretation of string is as a bool expression

| Input           | Result        |
|-----------------|---------------|
| true            | true          |
| "true"          | true          |
| "=true"         | true          |
| "user.age > 3"  | true          |
| "=user.age > 3" | true          |
| "bad"           | default(bool) |
| "bad @{bad}"    | default(bool) |

IntExpression

Interpretation of string is as a int expression

| Input                | Result       |
|----------------------|--------------|
| 13                   | 13           |
| "13"                 | 13           |
| "=13"                | 13           |
| "x.y.z"              | 13           |
| "=x.y.z"             | 13           |
| "Hello world"        | default(int) |
| "Hello @{user.name}" | default(int) |

FloatExpression

Interpretation of string is as a float expression

| Input        | Result         |
|--------------|----------------|
| 3.14F        | 3.14           |
| "3.14"       | 3.14           |
| "=3.14"      | 3.14           |
| "x.y.z"      | 3.14           |
| "=x.y.z"     | 3.14           |
| "bad"        | default(float) |
| "bad @{bad}" | default(float) |

ExpressionProperty

Interpretation of string is as a T expression

| Input        | Result     |
|--------------|------------|
| T            | T          |
| "x.y.z"      | T          |
| "=x.y.z"     | T          |
| "bad"        | default(T) |
| "bad @{bad}" | default(T) |

ValueExpression (T == object)

Interpretation of string is as a string interpolation result unless =.

| Input                         | Result      |
|-------------------------------|-------------|
| object                        | object      |
| "13"                          | "13"        |
| "=13"                         | 13          |
| "x.y.z"                       | "x.y.z"     |
| "=x.y.z"                      | object      |
| "='x.y.z'"                    | "x.y.z"     |
| "Hello @{user.name}"          | "Hello Joe" |
| "=concat('Hello ', user.name) | "Hello Joe" |

Also Fixes Bugs
#3166 Luis settings not parsed correctly
#3236 Use dialogId as an expression
#3219 HttpRequest body not parsed correctly

@tomlm tomlm added DCR R8 Release 8 - March 16th, 2020 labels Jan 11, 2020
@coveralls
Copy link
Collaborator

coveralls commented Jan 13, 2020

@fuselabs
Copy link
Collaborator

✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.AI.Luis.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.AI.QnA.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.ApplicationInsights.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.Azure.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.Dialogs.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.Integration.ApplicationInsights.Core.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.Integration.AspNet.Core.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.TemplateManager.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.Testing.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Configuration.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Connector.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Schema.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Streaming.dll compared against version 4.6.3

Tom Laird-McConnell added 2 commits January 14, 2020 08:41
rename FloatExpression to NumberExpression to better align with javascript (int, number) and json schema (int, number)
Remove LongExpression
changed to dcState pattern
@tomlm tomlm removed the WIP label Jan 15, 2020
@tomlm tomlm marked this pull request as ready for review January 15, 2020 19:36
@fuselabs
Copy link
Collaborator

✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.AI.Luis.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.AI.QnA.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.ApplicationInsights.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.Azure.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.Dialogs.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.Integration.ApplicationInsights.Core.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.Integration.AspNet.Core.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.TemplateManager.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.Testing.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Configuration.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Connector.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Schema.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Streaming.dll compared against version 4.6.3

@fuselabs
Copy link
Collaborator

✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.AI.Luis.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.AI.QnA.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.ApplicationInsights.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.Azure.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.Dialogs.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.Integration.ApplicationInsights.Core.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.Integration.AspNet.Core.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.TemplateManager.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.Testing.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Configuration.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Connector.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Schema.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Streaming.dll compared against version 4.6.3


if (activity.LocalTimestamp == null || activity.LocalTimestamp == default(DateTimeOffset))
{
activity.LocalTimestamp = DateTimeOffset.Now;
Copy link
Contributor

@chrimc62 chrimc62 Jan 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was this fixing? #ByDesign

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

time recognizer tests would fail when run in the morning because it was executing in UTC, so tommorrow gives you a different date. TestAdapter should have been setting this.


In reply to: 367263801 [](ancestors = 367263801)


if (this.disabled != null && (bool?)this.disabled.TryEvaluate(dc.GetState()).value == true)
if (this.Disabled != null && this.Disabled.GetValue(dcState) == true)
Copy link
Contributor

@chrimc62 chrimc62 Jan 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.Disabled != null [](start = 16, length = 21)

This is testing to see if there is an expression assigned, right? #ByDesign

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes


In reply to: 367266589 [](ancestors = 367266589)

[JsonConstructor]
public EmitEvent(string eventName = null, string eventValue = null, bool bubble = false, [CallerFilePath] string callerPath = "", [CallerLineNumber] int callerLine = 0)
public EmitEvent(string eventName = null, object eventValue = null, bool bubble = false, [CallerFilePath] string callerPath = "", [CallerLineNumber] int callerLine = 0)
Copy link
Contributor

@chrimc62 chrimc62 Jan 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

object [](start = 50, length = 6)

This seems like a good chsnge. #ByDesign

@@ -167,13 +165,22 @@ public override async Task<DialogTurnResult> BeginDialogAsync(DialogContext dc,
JToken instanceBody = null;
if (this.Body != null)
{
instanceBody = (JToken)this.Body.DeepClone();
Copy link
Contributor

@chrimc62 chrimc62 Jan 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DeepClone [](start = 49, length = 9)

Is FromObject better than DeepClone? #Resolved

@@ -3,6 +3,7 @@

using System;
using System.Collections.Generic;
using System.ComponentModel;
Copy link
Contributor

@chrimc62 chrimc62 Jan 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need this? #Resolved

using Newtonsoft.Json;
//using System;
//using Microsoft.Bot.Expressions;
//using Newtonsoft.Json;
Copy link
Contributor

@chrimc62 chrimc62 Jan 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete whole file? #Resolved

@@ -1338,10 +1330,6 @@ private static (object value, string error) Substring(Expression expression, IMe
}
}
}
else
{
error = $"{expression.Children[0]} is not a string.";
Copy link
Contributor

@chrimc62 chrimc62 Jan 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

error = $"{expression.Children[0]} is not a string."; [](start = 20, length = 53)

Why did you drop this? At runtime you can up with a non-string. #ByDesign

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was checking to see if the object returned was not a string. The TryEvaluate() will coerce the result to a string, aka, the number 31 => "31".


In reply to: 367282705 [](ancestors = 367282705)

@@ -34,8 +34,6 @@
"description": "Extra information for the Bot Framework Designer."
},
"expression": {
Copy link
Contributor

@chrimc62 chrimc62 Jan 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should delete this. #Resolved

@@ -12,7 +12,7 @@
{
"$kind": "Microsoft.SetProperty",
"property": "$Bread",
"value": "@BreadEntity"
"value": "=@BreadEntity"
Copy link
Contributor

@chrimc62 chrimc62 Jan 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

=@BreadEntity [](start = 22, length = 13)

Once this is checked-in, I'll need to update the generator. #ByDesign

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes you will :)


In reply to: 367284059 [](ancestors = 367284059)

Copy link
Contributor

@chrimc62 chrimc62 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🕐

@tomlm
Copy link
Contributor Author

tomlm commented Jan 16, 2020

        "title": "Options",

decided to make it an expression.


In reply to: 575033823 [](ancestors = 575033823)


Refers to: libraries/Microsoft.Bot.Builder.Dialogs.Adaptive/Schemas/Actions/Microsoft.ReplaceDialog.schema:32 in 3ad16f3. [](commit_id = 3ad16f3, deletion_comment = False)

}

public ObjectExpression(string expressionOrString)
: base(expressionOrString)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still missing comments.

{
}

public static implicit operator ValueExpression(string valueOrExpression) => new ValueExpression(valueOrExpression);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public static [](start = 8, length = 13)

Do we not have to document public statics? Missing here and a couple of other places.

Copy link
Contributor

@chrimc62 chrimc62 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@fuselabs
Copy link
Collaborator

✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.AI.Luis.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.AI.QnA.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.ApplicationInsights.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.Azure.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.Dialogs.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.Integration.ApplicationInsights.Core.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.Integration.AspNet.Core.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.TemplateManager.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.Testing.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Configuration.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Connector.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Schema.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Streaming.dll compared against version 4.6.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
composer Impacts composer R8 Release 8 - March 16th, 2020
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants