Skip to content

Commit

Permalink
Move Rules folder => Events folder
Browse files Browse the repository at this point in the history
Move Steps Folder => Actions Folder
Switch to OnXXX naming pattern for events
  • Loading branch information
Tom Laird-McConnell committed Jul 17, 2019
1 parent c21e7c6 commit 0879e8b
Show file tree
Hide file tree
Showing 170 changed files with 2,328 additions and 2,204 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"$schema": "../../app.schema",
"$type": "Microsoft.AdaptiveDialog",
"generator": "showimage.lg",
"rules": [
"events": [
{
"$type": "Microsoft.BeginDialogRule",
"$type": "Microsoft.OnBeginDialog",
"actions": [
{
"$type": "Microsoft.AttachmentInput",
Expand Down
Binary file added bot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bot_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Microsoft.Bot.Builder.Dialogs.Adaptive.Actions
/// <summary>
/// Write log activity to console log
/// </summary>
public class LogStep : DialogAction
public class LogAction : DialogAction
{
/// <summary>
/// LG expression to log
Expand All @@ -28,7 +28,7 @@ public class LogStep : DialogAction
public bool TraceActivity { get; set; } = false;

[JsonConstructor]
public LogStep(string text = null, [CallerFilePath] string callerPath = "", [CallerLineNumber] int callerLine = 0)
public LogAction(string text = null, [CallerFilePath] string callerPath = "", [CallerLineNumber] int callerLine = 0)
{
this.RegisterSourceLocation(callerPath, callerLine);
if (text != null)
Expand Down
40 changes: 20 additions & 20 deletions libraries/Microsoft.Bot.Builder.Dialogs.Adaptive/AdaptiveDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Bot.Builder.Dialogs.Adaptive.Rules;
using Microsoft.Bot.Builder.Dialogs.Adaptive.Events;
using Microsoft.Bot.Builder.Dialogs.Adaptive.Selectors;
using Microsoft.Bot.Builder.Dialogs.Debugging;
using Microsoft.Bot.Builder.Expressions;
Expand All @@ -20,7 +20,7 @@ namespace Microsoft.Bot.Builder.Dialogs.Adaptive
{

/// <summary>
/// The Adaptive Dialog models conversation using events and rules to adapt dynamicaly to changing conversation flow
/// The Adaptive Dialog models conversation using events and events to adapt dynamicaly to changing conversation flow
/// </summary>
public class AdaptiveDialog : DialogContainer
{
Expand All @@ -47,7 +47,7 @@ public class AdaptiveDialog : DialogContainer
/// <summary>
/// Rules for handling events to dynamic modifying the executing plan
/// </summary>
public virtual List<IRule> Rules { get; set; } = new List<IRule>();
public virtual List<IOnEvent> Events { get; set; } = new List<IOnEvent>();

/// <summary>
/// Gets or sets the policty to Automatically end the dialog when there are no actions to execute
Expand All @@ -59,9 +59,9 @@ public class AdaptiveDialog : DialogContainer
public bool AutoEndDialog { get; set; } = true;

/// <summary>
/// Gets or sets the selector for picking the possible rules to execute.
/// Gets or sets the selector for picking the possible events to execute.
/// </summary>
public IRuleSelector Selector { get; set; }
public IEventSelector Selector { get; set; }

/// <summary>
/// Gets or sets the property to return as the result when the dialog ends when there are no more Actions and AutoEndDialog = true.
Expand Down Expand Up @@ -110,7 +110,7 @@ public AdaptiveDialog(string dialogId = null, [CallerFilePath] string callerPath
state.Result = state.Options["value"];
}

// Evaluate rules and queue up step changes
// Evaluate events and queue up step changes
var dialogEvent = new DialogEvent()
{
Name = AdaptiveEvents.BeginDialog,
Expand Down Expand Up @@ -153,7 +153,7 @@ public AdaptiveDialog(string dialogId = null, [CallerFilePath] string callerPath
// Save into turn
sequenceContext.State.SetValue(DialogContextState.TURN_DIALOGEVENT, dialogEvent);

// Look for triggered rule
// Look for triggered evt
var handled = await this.QueueFirstMatchAsync(sequenceContext, dialogEvent, preBubble, cancellationToken).ConfigureAwait(false);

if (handled)
Expand Down Expand Up @@ -265,17 +265,17 @@ public AdaptiveDialog(string dialogId = null, [CallerFilePath] string callerPath
}
}

public void AddRule(IRule rule)
public void AddEvent(IOnEvent evt)
{
rule.Actions.ForEach(s => _dialogs.Add(s));
this.Rules.Add(rule);
evt.Actions.ForEach(s => _dialogs.Add(s));
this.Events.Add(evt);
}

public void AddRules(IEnumerable<IRule> rules)
public void AddEvents(IEnumerable<IOnEvent> events)
{
foreach (var rule in rules)
foreach (var evt in events)
{
this.AddRule(rule);
this.AddEvent(evt);
}
}

Expand Down Expand Up @@ -452,10 +452,10 @@ private async Task<bool> QueueFirstMatchAsync(SequenceContext sequenceContext, D
var selection = await Selector.Select(sequenceContext, cancellationToken).ConfigureAwait(false);
if (selection.Any())
{
var rule = Rules[selection.First()];
await sequenceContext.DebuggerStepAsync(rule, dialogEvent, cancellationToken).ConfigureAwait(false);
System.Diagnostics.Trace.TraceInformation($"Executing Dialog: {this.Id} Rule[{selection}]: {rule.GetType().Name}: {rule.GetExpression(null)}");
var changes = await rule.ExecuteAsync(sequenceContext).ConfigureAwait(false);
var evt = Events[selection.First()];
await sequenceContext.DebuggerStepAsync(evt, dialogEvent, cancellationToken).ConfigureAwait(false);
System.Diagnostics.Trace.TraceInformation($"Executing Dialog: {this.Id} Rule[{selection}]: {evt.GetType().Name}: {evt.GetExpression(null)}");
var changes = await evt.ExecuteAsync(sequenceContext).ConfigureAwait(false);

if (changes != null && changes.Count > 0)
{
Expand All @@ -474,9 +474,9 @@ private void EnsureDependenciesInstalled()
{
installedDependencies = true;

foreach (var rule in this.Rules)
foreach (var evt in this.Events)
{
AddDialog(rule.Actions.ToArray());
AddDialog(evt.Actions.ToArray());
}

// Wire up selector
Expand All @@ -488,7 +488,7 @@ private void EnsureDependenciesInstalled()
Selector = new FirstSelector()
};
}
this.Selector.Initialize(this.Rules, true);
this.Selector.Initialize(this.Events, true);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
using System.Threading.Tasks;
using Microsoft.Bot.Builder.Dialogs.Debugging;

namespace Microsoft.Bot.Builder.Dialogs.Adaptive.Rules
namespace Microsoft.Bot.Builder.Dialogs.Adaptive.Events
{
public static partial class Extensions
{
public static async Task DebuggerStepAsync(this DialogContext context, IRule rule, DialogEvent dialogEvent, CancellationToken cancellationToken)
public static async Task DebuggerStepAsync(this DialogContext context, IOnEvent rule, DialogEvent dialogEvent, CancellationToken cancellationToken)
{
var more = dialogEvent.Name;
await context.GetDebugger().StepAsync(context, rule, more, cancellationToken).ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Licensed under the MIT License.
// Copyright (c) Microsoft Corporation. All rights reserved.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using Microsoft.Bot.Builder.Expressions;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace Microsoft.Bot.Builder.Dialogs.Adaptive.Events
{

/// <summary>
/// Event triggered when a Activity of a given type is received
/// </summary>
public class OnActivity : OnDialogEvent
{
[JsonConstructor]
public OnActivity(string type=null, List<IDialog> actions = null, string constraint = null, [CallerFilePath] string callerPath = "", [CallerLineNumber] int callerLine = 0)
: base(events: new List<string>()
{
AdaptiveEvents.ActivityReceived
},
actions: actions,
constraint: constraint,
callerPath: callerPath, callerLine: callerLine)
{
Type = type;
}

/// <summary>
/// ActivityType
/// </summary>
[JsonProperty("type")]
public string Type { get; set; }

protected override Expression BuildExpression(IExpressionParser factory)
{

// add constraints for activity type
return Expression.AndExpression(factory.Parse($"turn.dialogEvent.value.type == '{this.Type}'"),
base.BuildExpression(factory));
}

protected override ActionChangeList OnCreateChangeList(SequenceContext planning, object dialogOptions = null)
{
return new ActionChangeList()
{
Actions = Actions.Select(s => new ActionState()
{
DialogStack = new List<DialogInstance>(),
DialogId = s.Id,
Options = dialogOptions
}).ToList()
};
}

public override string GetIdentity()
{
return $"{this.GetType().Name}({this.Type})[{this.Constraint}]";
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
using Microsoft.Bot.Builder.Expressions;
using Newtonsoft.Json;

namespace Microsoft.Bot.Builder.Dialogs.Adaptive.Rules
namespace Microsoft.Bot.Builder.Dialogs.Adaptive.Events
{
/// <summary>
/// Rule triggered when a dialog is started via BeginDialog()
/// </summary>
public class BeginDialogRule : EventRule
public class OnBeginDialog : OnDialogEvent
{
[JsonConstructor]
public BeginDialogRule(List<IDialog> actions = null, string constraint = null, [CallerFilePath] string callerPath = "", [CallerLineNumber] int callerLine = 0)
public OnBeginDialog(List<IDialog> actions = null, string constraint = null, [CallerFilePath] string callerPath = "", [CallerLineNumber] int callerLine = 0)
: base(events: new List<string>()
{
AdaptiveEvents.BeginDialog
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Licensed under the MIT License.
// Copyright (c) Microsoft Corporation. All rights reserved.

using System.Collections.Generic;
using System.Runtime.CompilerServices;
using Microsoft.Bot.Schema;
using Newtonsoft.Json;

namespace Microsoft.Bot.Builder.Dialogs.Adaptive.Events
{
/// <summary>
/// Event for ConversationUpdate Activity
/// </summary>
public class OnConversationUpdateActivity : OnActivity
{
[JsonConstructor]
public OnConversationUpdateActivity(List<IDialog> actions = null, string constraint= null, [CallerFilePath] string callerPath = "", [CallerLineNumber] int callerLine = 0)
: base(type: ActivityTypes.ConversationUpdate, actions: actions, constraint: constraint, callerPath: callerPath, callerLine: callerLine) { }
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@
using Microsoft.Bot.Builder.Expressions;
using Newtonsoft.Json;

namespace Microsoft.Bot.Builder.Dialogs.Adaptive.Rules
namespace Microsoft.Bot.Builder.Dialogs.Adaptive.Events
{
/// <summary>
/// Rule triggered when a dialog event matching a list of event names is emitted.
/// Event triggered when a dialog event matching a list of event names is emitted.
/// </summary>
public class EventRule : Rule
public class OnDialogEvent : OnEvent
{
/// <summary>
/// List of events to filter
/// </summary>
public List<string> Events { get; set; }

[JsonConstructor]
public EventRule(List<string> events = null, List<IDialog> actions = null, string constraint = null, [CallerFilePath] string callerPath = "", [CallerLineNumber] int callerLine = 0)
public OnDialogEvent(List<string> events = null, List<IDialog> actions = null, string constraint = null, [CallerFilePath] string callerPath = "", [CallerLineNumber] int callerLine = 0)
: base(constraint: constraint, actions: actions, callerPath: callerPath, callerLine: callerLine)
{
this.Events = events ?? new List<string>();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Licensed under the MIT License.
// Copyright (c) Microsoft Corporation. All rights reserved.

using System.Collections.Generic;
using System.Runtime.CompilerServices;
using Microsoft.Bot.Schema;
using Newtonsoft.Json;

namespace Microsoft.Bot.Builder.Dialogs.Adaptive.Events
{
/// <summary>
/// Event for EndOfConversation Activity
/// </summary>
public class OnEndOfConversationActivity : OnActivity
{
[JsonConstructor]
public OnEndOfConversationActivity(List<IDialog> actions = null, string constraint= null, [CallerFilePath] string callerPath = "", [CallerLineNumber] int callerLine = 0)
: base(type: ActivityTypes.EndOfConversation, actions: actions, constraint: constraint, callerPath: callerPath, callerLine: callerLine) { }
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
using Microsoft.Bot.Builder.Expressions.Parser;
using Newtonsoft.Json;

namespace Microsoft.Bot.Builder.Dialogs.Adaptive.Rules
namespace Microsoft.Bot.Builder.Dialogs.Adaptive.Events
{
/// <summary>
/// Defines basic Rule contract
/// Defines basic OnEvent handler
/// </summary>
[DebuggerDisplay("{GetIdentity()}")]
public abstract class Rule : IRule, IItemIdentity
public abstract class OnEvent : IOnEvent, IItemIdentity
{
// constraints from Rule.AddConstraint()
private List<Expression> extraConstraints = new List<Expression>();
Expand All @@ -29,7 +29,7 @@ public abstract class Rule : IRule, IItemIdentity
private Expression fullConstraint = null;

[JsonConstructor]
public Rule(string constraint = null, List<IDialog> actions = null, [CallerFilePath] string callerPath = "", [CallerLineNumber] int callerLine = 0)
public OnEvent(string constraint = null, List<IDialog> actions = null, [CallerFilePath] string callerPath = "", [CallerLineNumber] int callerLine = 0)
{
this.RegisterSourceLocation(callerPath, callerLine);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Licensed under the MIT License.
// Copyright (c) Microsoft Corporation. All rights reserved.

using System.Collections.Generic;
using System.Runtime.CompilerServices;
using Microsoft.Bot.Schema;
using Newtonsoft.Json;

namespace Microsoft.Bot.Builder.Dialogs.Adaptive.Events
{
/// <summary>
/// Event for Event Activity
/// </summary>
public class OnEventActivity : OnActivity
{
[JsonConstructor]
public OnEventActivity(List<IDialog> actions = null, string constraint= null, [CallerFilePath] string callerPath = "", [CallerLineNumber] int callerLine = 0)
: base(type: ActivityTypes.Event, actions: actions, constraint: constraint, callerPath: callerPath, callerLine: callerLine) { }
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Licensed under the MIT License.
// Copyright (c) Microsoft Corporation. All rights reserved.

using System.Collections.Generic;
using System.Runtime.CompilerServices;
using Microsoft.Bot.Schema;
using Newtonsoft.Json;

namespace Microsoft.Bot.Builder.Dialogs.Adaptive.Events
{
/// <summary>
/// Event for Handoff Activity
/// </summary>
public class OnHandoffActivity : OnActivity
{
[JsonConstructor]
public OnHandoffActivity(List<IDialog> actions = null, string constraint= null, [CallerFilePath] string callerPath = "", [CallerLineNumber] int callerLine = 0)
: base(type: ActivityTypes.Handoff, actions: actions, constraint: constraint, callerPath: callerPath, callerLine: callerLine) { }
}

}
Loading

0 comments on commit 0879e8b

Please sign in to comment.