Skip to content

Commit

Permalink
Revert the change on RootDialog while still allowing LG functions. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
chrimc62 authored Nov 4, 2020
1 parent 26260a2 commit 39a2fd6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,12 @@ await adapter.ProcessActivityAsync(
DialogManager dm;
if (callback == null)
{
dm = new DialogManager(Dialog)
dm = new DialogManager()
.UseResourceExplorer(resourceExplorer)
.UseLanguageGeneration();

dm.RootDialog = Dialog;

if (LanguagePolicy != null)
{
dm.UseLanguagePolicy(LanguagePolicy);
Expand Down
45 changes: 28 additions & 17 deletions libraries/Microsoft.Bot.Builder.Dialogs/DialogManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public class DialogManager
private const string LastAccess = "_lastAccess";
private string _rootDialogId;
private readonly string _dialogStateProperty;
private readonly object _lock = new object();

/// <summary>
/// Initializes a new instance of the <see cref="DialogManager"/> class.
Expand Down Expand Up @@ -70,7 +69,34 @@ public DialogManager(Dialog rootDialog = null, string dialogStateProperty = null
/// <value>
/// Root dialog to use to start conversation.
/// </value>
public Dialog RootDialog { get; set; }
public Dialog RootDialog
{
get
{
if (_rootDialogId != null)
{
return Dialogs.Find(_rootDialogId);
}

return null;
}

set
{
Dialogs = new DialogSet();
if (value != null)
{
_rootDialogId = value.Id;
Dialogs.TelemetryClient = value.TelemetryClient;
Dialogs.Add(value);
RegisterContainerDialogs(RootDialog, registerRoot: false);
}
else
{
_rootDialogId = null;
}
}
}

/// <summary>
/// Gets or sets global dialogs that you want to have be callable.
Expand Down Expand Up @@ -103,21 +129,6 @@ public DialogManager(Dialog rootDialog = null, string dialogStateProperty = null
/// <returns>result of the running the logic against the activity.</returns>
public async Task<DialogManagerResult> OnTurnAsync(ITurnContext context, CancellationToken cancellationToken = default)
{
// Lazy initialize rootdialog so it can refer to assets like LG function templates
if (_rootDialogId == null)
{
lock (_lock)
{
if (_rootDialogId == null)
{
_rootDialogId = RootDialog.Id;
Dialogs.TelemetryClient = RootDialog.TelemetryClient;
Dialogs.Add(RootDialog);
RegisterContainerDialogs(RootDialog, registerRoot: false);
}
}
}

var botStateSet = new BotStateSet();

// Preload TurnState with DM TurnState.
Expand Down

0 comments on commit 39a2fd6

Please sign in to comment.