Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,38 @@

namespace Microsoft.Bot.Builder.Dialogs.Adaptive
{
/// <summary>
/// Defines the action state change list.
/// </summary>
[DebuggerDisplay("{ChangeType}:{Desire}")]
public class ActionChangeList
{
/// <summary>
/// Gets or sets the action change type value.
/// </summary>
/// <value>
/// Action change type value.
/// </value>
[JsonProperty(PropertyName = "changeType")]
public ActionChangeType ChangeType { get; set; } = ActionChangeType.InsertActions;

/// <summary>
/// Gets or sets the <see cref="ActionState"/> list.
/// </summary>
/// <value>
/// <see cref="ActionState"/> list.
/// </value>
[JsonProperty(PropertyName = "actions")]
#pragma warning disable CA2227 // Collection properties should be read only (we can't change this without breaking binary compat)
public List<ActionState> Actions { get; set; } = new List<ActionState>();
#pragma warning restore CA2227 // Collection properties should be read only

/// <summary>
/// Gets or sets the tag list.
/// </summary>
/// <value>
/// Tag list.
/// </value>
[JsonProperty(PropertyName = "tags")]
#pragma warning disable CA2227 // Collection properties should be read only (we can't change this without breaking binary compat)
public List<string> Tags { get; set; } = new List<string>();
Expand Down
23 changes: 23 additions & 0 deletions libraries/Microsoft.Bot.Builder.Dialogs.Adaptive/ActionState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,45 @@

namespace Microsoft.Bot.Builder.Dialogs.Adaptive
{
/// <summary>
/// Contains state information about the action.
/// </summary>
[DebuggerDisplay("{DialogId}")]
public class ActionState : DialogState
{
/// <summary>
/// Initializes a new instance of the <see cref="ActionState"/> class.
/// </summary>
public ActionState()
{
}

/// <summary>
/// Initializes a new instance of the <see cref="ActionState"/> class.
/// </summary>
/// <param name="dialogId">Optional, dialog identifier value.</param>
/// <param name="options">Optional, dialog options.</param>
public ActionState(string dialogId = null, object options = null)
{
DialogId = dialogId;
Options = options;
}

/// <summary>
/// Gets or sets DialogId value.
/// </summary>
/// <value>
/// DialogId value.
/// </value>
[JsonProperty(PropertyName = "dialogId")]
public string DialogId { get; set; }

/// <summary>
/// Gets or sets options value.
/// </summary>
/// <value>
/// Options value.
/// </value>
[JsonProperty(PropertyName = "options")]
public object Options { get; set; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,14 @@

namespace Microsoft.Bot.Builder.Dialogs.Adaptive
{
/// <summary>
/// <see cref="ComponentRegistration"/> implementation for adaptive components.
/// </summary>
public class AdaptiveComponentRegistration : ComponentRegistration, IComponentDeclarativeTypes
{
/// <summary>
/// Initializes a new instance of the <see cref="AdaptiveComponentRegistration"/> class.
/// </summary>
public AdaptiveComponentRegistration()
{
// adaptive dialog functions
Expand All @@ -34,6 +40,11 @@ public AdaptiveComponentRegistration()
Expression.Functions.Add(HasPendingActionsFunction.Name, new HasPendingActionsFunction());
}

/// <summary>
/// Gets adaptive <see cref="DeclarativeType"/> resources.
/// </summary>
/// <param name="resourceExplorer"><see cref="ResourceExplorer"/> with expected path to get all schema resources.</param>
/// <returns>Adaptive <see cref="DeclarativeType"/> resources.</returns>
public virtual IEnumerable<DeclarativeType> GetDeclarativeTypes(ResourceExplorer resourceExplorer)
{
// Conditionals
Expand Down Expand Up @@ -173,6 +184,12 @@ public virtual IEnumerable<DeclarativeType> GetDeclarativeTypes(ResourceExplorer
}
}

/// <summary>
/// Gets adaptive <see cref="JsonConverter"/> resources.
/// </summary>
/// <param name="resourceExplorer">ResourceExplorer to use to resolve references.</param>
/// <param name="sourceContext">SourceContext to build debugger source map.</param>
/// <returns>Adaptive <see cref="JsonConverter"/> resources.</returns>
public virtual IEnumerable<JsonConverter> GetConverters(ResourceExplorer resourceExplorer, SourceContext sourceContext)
{
yield return new InterfaceConverter<OnCondition>(resourceExplorer, sourceContext);
Expand Down
108 changes: 108 additions & 0 deletions libraries/Microsoft.Bot.Builder.Dialogs.Adaptive/AdaptiveDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ namespace Microsoft.Bot.Builder.Dialogs.Adaptive
/// </summary>
public class AdaptiveDialog : DialogContainer, IDialogDependencies
{
/// <summary>
/// Class identifier.
/// </summary>
[JsonProperty("$kind")]
public const string Kind = "Microsoft.AdaptiveDialog";

Expand All @@ -53,6 +56,12 @@ public class AdaptiveDialog : DialogContainer, IDialogDependencies

private SchemaHelper dialogSchema;

/// <summary>
/// Initializes a new instance of the <see cref="AdaptiveDialog"/> class.
/// </summary>
/// <param name="dialogId">Optional, dialog identifier.</param>
/// <param name="callerPath">Optional, source file full path.</param>
/// <param name="callerLine">Optional, line number in source file.</param>
public AdaptiveDialog(string dialogId = null, [CallerFilePath] string callerPath = "", [CallerLineNumber] int callerLine = 0)
: base(dialogId)
{
Expand Down Expand Up @@ -136,6 +145,14 @@ public JObject Schema
}
}

/// <summary>
/// Called when the dialog is started and pushed onto the dialog stack.
/// </summary>
/// <param name="dc">The <see cref="DialogContext"/> for the current turn of conversation.</param>
/// <param name="options">Optional, initial information to pass to the dialog.</param>
/// <param name="cancellationToken">Optional, a <see cref="CancellationToken"/> that can be used by other objects
/// or threads to receive notice of cancellation.</param>
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
public override async Task<DialogTurnResult> BeginDialogAsync(DialogContext dc, object options = null, CancellationToken cancellationToken = default)
{
if (options is CancellationToken)
Expand Down Expand Up @@ -207,6 +224,14 @@ public override async Task<DialogTurnResult> BeginDialogAsync(DialogContext dc,
return await ContinueActionsAsync(dc, options, cancellationToken: cancellationToken).ConfigureAwait(false);
}

/// <summary>
/// Called when the dialog is _continued_, where it is the active dialog and the
/// user replies with a new activity.
/// </summary>
/// <param name="dc">The <see cref="DialogContext"/> for the current turn of conversation.</param>
/// <param name="cancellationToken">Optional, a <see cref="CancellationToken"/> that can be used by other objects
/// or threads to receive notice of cancellation.</param>
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
public override async Task<DialogTurnResult> ContinueDialogAsync(DialogContext dc, CancellationToken cancellationToken = default)
{
EnsureDependenciesInstalled();
Expand All @@ -217,6 +242,16 @@ public override async Task<DialogTurnResult> ContinueDialogAsync(DialogContext d
return await ContinueActionsAsync(dc, options: null, cancellationToken).ConfigureAwait(false);
}

/// <summary>
/// Called when a child dialog completed its turn, returning control to this dialog.
/// </summary>
/// <param name="dc">The dialog context for the current turn of the conversation.</param>
/// <param name="reason">Reason why the dialog resumed.</param>
/// <param name="result">Optional, value returned from the dialog that was called. The type
/// of the value returned is dependent on the child dialog.</param>
/// <param name="cancellationToken">Optional, A <see cref="CancellationToken"/> that can be used by other objects
/// or threads to receive notice of cancellation.</param>
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
public override async Task<DialogTurnResult> ResumeDialogAsync(DialogContext dc, DialogReason reason, object result = null, CancellationToken cancellationToken = default)
{
if (result is CancellationToken)
Expand All @@ -236,6 +271,15 @@ public override async Task<DialogTurnResult> ResumeDialogAsync(DialogContext dc,
return EndOfTurn;
}

/// <summary>
/// Called when the dialog is ending.
/// </summary>
/// <param name="turnContext">The context object for this turn.</param>
/// <param name="instance">State information associated with the instance of this dialog on the dialog stack.</param>
/// <param name="reason">Reason why the dialog ended.</param>
/// <param name="cancellationToken">Optional, a <see cref="CancellationToken"/> that can be used by other objects
/// or threads to receive notice of cancellation.</param>
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
public override Task EndDialogAsync(ITurnContext turnContext, DialogInstance instance, DialogReason reason, CancellationToken cancellationToken = default)
{
var properties = new Dictionary<string, string>()
Expand Down Expand Up @@ -278,6 +322,11 @@ public virtual async Task RepromptDialogAsync(DialogContext dc, DialogInstance i
}
}

/// <summary>
/// Creates a child <see cref="DialogContext"/> for the given context.
/// </summary>
/// <param name="dc">The <see cref="DialogContext"/> for the current turn of conversation.</param>
/// <returns>The child <see cref="DialogContext"/> or null if no <see cref="AdaptiveDialogState.Actions"/> are found for the given context.</returns>
public override DialogContext CreateChildContext(DialogContext dc)
{
var activeDialogState = dc.ActiveDialog.State as Dictionary<string, object>;
Expand All @@ -304,13 +353,21 @@ public override DialogContext CreateChildContext(DialogContext dc)
return null;
}

/// <summary>
/// Gets <see cref="Dialog"/> enumerated dependencies.
/// </summary>
/// <returns><see cref="Dialog"/> enumerated dependencies.</returns>
public IEnumerable<Dialog> GetDependencies()
{
EnsureDependenciesInstalled();

yield break;
}

/// <summary>
/// Gets the internal version string.
/// </summary>
/// <returns>Internal version string.</returns>
protected override string GetInternalVersion()
{
StringBuilder sb = new StringBuilder();
Expand All @@ -333,6 +390,13 @@ protected override string GetInternalVersion()
return StringUtils.Hash(sb.ToString());
}

/// <summary>
/// Called before an event is bubbled to its parent.
/// </summary>
/// <param name="dc">The <see cref="DialogContext"/> for the current turn of conversation.</param>
/// <param name="dialogEvent">The <see cref="DialogEvent"/> being raised.</param>
/// <param name="cancellationToken">Optional, the <see cref="CancellationToken"/> that can be used by other objects or threads to receive notice of cancellation.</param>
/// <returns> Whether the event is handled by the current dialog and further processing should stop.</returns>
protected override async Task<bool> OnPreBubbleEventAsync(DialogContext dc, DialogEvent dialogEvent, CancellationToken cancellationToken = default)
{
var actionContext = ToActionContext(dc);
Expand All @@ -341,6 +405,13 @@ protected override async Task<bool> OnPreBubbleEventAsync(DialogContext dc, Dial
return await ProcessEventAsync(actionContext, dialogEvent, preBubble: true, cancellationToken: cancellationToken).ConfigureAwait(false);
}

/// <summary>
/// Called after an event was bubbled to all parents and wasn't handled.
/// </summary>
/// <param name="dc">The <see cref="DialogContext"/> for the current turn of conversation.</param>
/// <param name="dialogEvent">The <see cref="DialogEvent"/> being raised.</param>
/// <param name="cancellationToken">Optional, the <see cref="CancellationToken"/> that can be used by other objects or threads to receive notice of cancellation.</param>
/// <returns> Whether the event is handled by the current dialog and further processing should stop.</returns>
protected override async Task<bool> OnPostBubbleEventAsync(DialogContext dc, DialogEvent dialogEvent, CancellationToken cancellationToken = default)
{
var actionContext = ToActionContext(dc);
Expand All @@ -349,6 +420,14 @@ protected override async Task<bool> OnPostBubbleEventAsync(DialogContext dc, Dia
return await ProcessEventAsync(actionContext, dialogEvent, preBubble: false, cancellationToken: cancellationToken).ConfigureAwait(false);
}

/// <summary>
/// Event processing implementation.
/// </summary>
/// <param name="actionContext">The <see cref="ActionContext"/> for the current turn of conversation.</param>
/// <param name="dialogEvent">The <see cref="DialogEvent"/> being raised.</param>
/// <param name="preBubble">A flag indicator for preBubble processing.</param>
/// <param name="cancellationToken">Optional, a <see cref="CancellationToken"/> used to signal this operation should be cancelled.</param>
/// <returns>A <see cref="Task"/> representation of a boolean indicator or the result.</returns>
protected virtual async Task<bool> ProcessEventAsync(ActionContext actionContext, DialogEvent dialogEvent, bool preBubble, CancellationToken cancellationToken = default(CancellationToken))
{
// Save into turn
Expand Down Expand Up @@ -550,6 +629,13 @@ protected override async Task<bool> OnPostBubbleEventAsync(DialogContext dc, Dia
return handled;
}

/// <summary>
/// Waits for pending actions to complete and moves on to <see cref="OnEndOfActions"/>.
/// </summary>
/// <param name="dc">The <see cref="DialogContext"/> for the current turn of conversation.</param>
/// <param name="options">Options used in evaluation. </param>
/// <param name="cancellationToken">Optional, the <see cref="CancellationToken"/> that can be used by other objects or threads to receive notice of cancellation.</param>
/// <returns>A <see cref="Task"/> representation of <see cref="DialogTurnResult"/>.</returns>
protected async Task<DialogTurnResult> ContinueActionsAsync(DialogContext dc, object options, CancellationToken cancellationToken)
{
if (options is CancellationToken)
Expand Down Expand Up @@ -645,6 +731,12 @@ protected virtual void OnSetScopedServices(DialogContext dialogContext)
}
}

/// <summary>
/// Removes the current most action from the given <see cref="ActionContext"/> if there are any.
/// </summary>
/// <param name="actionContext">The <see cref="ActionContext"/> for the current turn of conversation.</param>
/// <param name="cancellationToken">Optional, a <see cref="CancellationToken"/> that can be used by other objects.</param>
/// <returns>A <see cref="Task"/> representing a boolean indicator for the result.</returns>
#pragma warning disable CA1801 // Review unused parameters (we can't remove the cancellationToken parameter withoutt breaking binary compat).
protected Task<bool> EndCurrentActionAsync(ActionContext actionContext, CancellationToken cancellationToken = default)
#pragma warning restore CA1801 // Review unused parameters
Expand All @@ -657,6 +749,12 @@ protected Task<bool> EndCurrentActionAsync(ActionContext actionContext, Cancella
return Task.FromResult(false);
}

/// <summary>
/// Awaits for completed actions to finish processing entity assignments and finishes turn.
/// </summary>
/// <param name="actionContext">The <see cref="ActionContext"/> for the current turn of conversation.</param>
/// <param name="cancellationToken">Optional, a <see cref="CancellationToken"/> that can be used by other objects.</param>
/// <returns>A <see cref="Task"/> representation of <see cref="DialogTurnResult"/>.</returns>
protected async Task<DialogTurnResult> OnEndOfActionsAsync(ActionContext actionContext, CancellationToken cancellationToken = default)
{
// Is the current dialog still on the stack?
Expand All @@ -682,6 +780,13 @@ protected async Task<DialogTurnResult> OnEndOfActionsAsync(ActionContext actionC
return new DialogTurnResult(DialogTurnStatus.Cancelled);
}

/// <summary>
/// Recognizes intent for current activity given the class recognizer set, if set is null no intent will be recognized.
/// </summary>
/// <param name="actionContext">The <see cref="ActionContext"/> for the current turn of conversation.</param>
/// <param name="activity"><see cref="Activity"/> to recognize.</param>
/// <param name="cancellationToken">Optional, a <see cref="CancellationToken"/> that can be used by other objects or threads to receive notice of cancellation.</param>
/// <returns>A <see cref="Task"/> representing a <see cref="RecognizerResult"/>.</returns>
protected async Task<RecognizerResult> OnRecognizeAsync(ActionContext actionContext, Activity activity, CancellationToken cancellationToken = default)
{
if (Recognizer != null)
Expand Down Expand Up @@ -730,6 +835,9 @@ protected async Task<RecognizerResult> OnRecognizeAsync(ActionContext actionCont
};
}

/// <summary>
/// Ensures all dependencies for the class are installed.
/// </summary>
protected virtual void EnsureDependenciesInstalled()
{
if (!installedDependencies)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,24 @@

namespace Microsoft.Bot.Builder.Dialogs.Adaptive
{
/// <summary>
/// Defines adaptive dialog <see cref="ActionState"/> list.
/// </summary>
public class AdaptiveDialogState
{
/// <summary>
/// Initializes a new instance of the <see cref="AdaptiveDialogState"/> class.
/// </summary>
public AdaptiveDialogState()
{
}

/// <summary>
/// Gets or sets <see cref="ActionState"/> list.
/// </summary>
/// <value>
/// <see cref="ActionState"/> list.
/// </value>
[JsonProperty(PropertyName = "actions")]
#pragma warning disable CA2227 // Collection properties should be read only (we can't change this without breaking binary compat)
public List<ActionState> Actions { get; set; } = new List<ActionState>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

namespace Microsoft.Bot.Builder.Dialogs.Adaptive
{
/// <summary>
/// Adaptive event identifier definition list.
/// </summary>
public class AdaptiveEvents : DialogEvents
{
/// <summary>
Expand Down
Loading