Skip to content

Commit

Permalink
Update package and sample bot
Browse files Browse the repository at this point in the history
  • Loading branch information
luhan2017 committed Feb 17, 2020
1 parent e387ade commit 839427f
Show file tree
Hide file tree
Showing 24 changed files with 259 additions and 375 deletions.
26 changes: 13 additions & 13 deletions BotProject/Templates/CSharp/BotProject.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
Expand All @@ -13,24 +14,23 @@
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<CodeAnalysisRuleSet>BotProject.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<CodeAnalysisRuleSet>BotProject.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Bot.Builder" Version="4.7.2" />
<PackageReference Include="Microsoft.Bot.Builder.ApplicationInsights" Version="4.7.2" />
<PackageReference Include="Microsoft.Bot.Builder.Azure" Version="4.7.2" />
<PackageReference Include="Microsoft.Bot.Builder.Dialogs.Adaptive" Version="4.7.2-preview" />
<PackageReference Include="Microsoft.Bot.Builder.Dialogs.Debugging" Version="4.7.2-preview" />
<PackageReference Include="Microsoft.Bot.Builder.Dialogs.Declarative" Version="4.7.2-preview" />
<PackageReference Include="Microsoft.Bot.Builder.Integration.ApplicationInsights.Core" Version="4.7.2" />
<PackageReference Include="Microsoft.Bot.Builder.Integration.AspNet.Core" Version="4.7.2" />
<PackageReference Include="Microsoft.Bot.Builder.Dialogs" Version="4.7.2" />
<PackageReference Include="Microsoft.Bot.Connector" Version="4.7.2" />
<PackageReference Include="Microsoft.Bot.Builder" Version="4.8.0-preview-200213-105928" />
<PackageReference Include="Microsoft.Bot.Builder.ApplicationInsights" Version="4.8.0-preview-200213-105928" />
<PackageReference Include="Microsoft.Bot.Builder.Azure" Version="4.8.0-preview-200213-105928" />
<PackageReference Include="Microsoft.Bot.Builder.Dialogs.Adaptive" Version="4.8.0-preview-200213-105928" />
<PackageReference Include="Microsoft.Bot.Builder.Dialogs.Debugging" Version="4.8.0-preview-200213-105928" />
<PackageReference Include="Microsoft.Bot.Builder.Dialogs.Declarative" Version="4.8.0-preview-200213-105928" />
<PackageReference Include="Microsoft.Bot.Builder.Integration.ApplicationInsights.Core" Version="4.8.0-preview-200213-105928" />
<PackageReference Include="Microsoft.Bot.Builder.Integration.AspNet.Core" Version="4.8.0-preview-200213-105928" />
<PackageReference Include="Microsoft.Bot.Builder.Dialogs" Version="4.8.0-preview-200213-105928" />
<PackageReference Include="Microsoft.Bot.Connector" Version="4.8.0-preview-95744" />
<PackageReference Include="MSTest.TestFramework" Version="1.4.0" />
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.66">
<PrivateAssets>all</PrivateAssets>
Expand All @@ -40,4 +40,4 @@
<ItemGroup>
<Folder Include="ComposerDialogs\" />
</ItemGroup>
</Project>
</Project>
11 changes: 5 additions & 6 deletions BotProject/Templates/CSharp/ComposerBot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ namespace Microsoft.Bot.Builder.ComposerBot.Json
{
public class ComposerBot : ActivityHandler
{
private AdaptiveDialog rootDialog;
private readonly ResourceExplorer resourceExplorer;
private readonly UserState userState;
private DialogManager dialogManager;
Expand All @@ -34,11 +33,9 @@ public ComposerBot(string rootDialogFile, ConversationState conversationState, U
this.resourceExplorer = resourceExplorer;
this.rootDialogFile = rootDialogFile;
this.telemetryClient = telemetryClient;
DeclarativeTypeLoader.AddComponent(new QnAMakerComponentRegistration());

LoadRootDialogAsync();
}

public override async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default(CancellationToken))
{
this.telemetryClient.TrackTrace("Activity:" + turnContext.Activity.Text, Severity.Information, null);
Expand All @@ -50,8 +47,10 @@ public ComposerBot(string rootDialogFile, ConversationState conversationState, U
private void LoadRootDialogAsync()
{
var rootFile = resourceExplorer.GetResource(rootDialogFile);
rootDialog = DeclarativeTypeLoader.Load<AdaptiveDialog>(rootFile, resourceExplorer, sourceMap);
this.dialogManager = new DialogManager(rootDialog);
var rootDialog = resourceExplorer.LoadType<Dialog>(rootFile);
this.dialogManager = new DialogManager(rootDialog)
.UseResourceExplorer(resourceExplorer)
.UseLanguageGeneration();
}
}
}
9 changes: 1 addition & 8 deletions BotProject/Templates/CSharp/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ public void ConfigureServices(IServiceCollection services)

var botFile = Configuration.GetSection("bot").Get<string>();

TypeFactory.Configuration = this.Configuration;

// manage all bot resources
var resourceExplorer = new ResourceExplorer().AddFolder(botFile);

Expand All @@ -88,12 +86,7 @@ public void ConfigureServices(IServiceCollection services)
var adapter = new BotFrameworkHttpAdapter(new ConfigurationCredentialProvider(this.Configuration));
adapter
.UseStorage(storage)
.UseState(userState, conversationState)
.UseAdaptiveDialogs()
.UseResourceExplorer(resourceExplorer)
.UseLanguageGeneration(resourceExplorer, "common.lg")
.Use(new RegisterClassMiddleware<IConfiguration>(Configuration))
.Use(new InspectionMiddleware(inspectionState, userState, conversationState, credentials));
.UseState(userState, conversationState);

if (!string.IsNullOrEmpty(settings.BlobStorage.ConnectionString) && !string.IsNullOrEmpty(settings.BlobStorage.Container))
{
Expand Down
13 changes: 6 additions & 7 deletions BotProject/Templates/CSharp/Tests/ActionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ private static string getFolderPath(string path)
[ClassInitialize]
public static void ClassInitialize(TestContext context)
{
TypeFactory.Configuration = new ConfigurationBuilder().AddInMemoryCollection().Build();
string path = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, samplesDirectory));
}

Expand Down Expand Up @@ -156,6 +155,7 @@ await BuildTestFlow(getFolderPath("ActionsSample"), sendTrace: true)
}

[TestMethod]
[Ignore]
public async Task Actions_09EditActions()
{
await BuildTestFlow(getFolderPath("ActionsSample"))
Expand Down Expand Up @@ -204,7 +204,6 @@ await BuildTestFlow(getFolderPath("ActionsSample"))

private TestFlow BuildTestFlow(string folderPath, bool sendTrace = false)
{
TypeFactory.Configuration = new ConfigurationBuilder().Build();
var storage = new MemoryStorage();
var convoState = new ConversationState(storage);
var userState = new UserState(storage);
Expand All @@ -214,14 +213,14 @@ private TestFlow BuildTestFlow(string folderPath, bool sendTrace = false)
adapter
.UseStorage(storage)
.UseState(userState, convoState)
.UseAdaptiveDialogs()
.UseLanguageGeneration(resourceExplorer, "common.lg")
.UseResourceExplorer(resourceExplorer)

.Use(new TranscriptLoggerMiddleware(new FileTranscriptLogger()));

var resource = resourceExplorer.GetResource("Main.dialog");
var dialog = DeclarativeTypeLoader.Load<AdaptiveDialog>(resource, resourceExplorer, DebugSupport.SourceMap);
DialogManager dm = new DialogManager(dialog);
var dialog = resourceExplorer.LoadType<Dialog>(resource);
DialogManager dm = new DialogManager(dialog)
.UseResourceExplorer(resourceExplorer)
.UseLanguageGeneration(); ;

return new TestFlow(adapter, async (turnContext, cancellationToken) =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public class ControllingConversationTests
[ClassInitialize]
public static void ClassInitialize(TestContext context)
{
TypeFactory.Configuration = new ConfigurationBuilder().AddInMemoryCollection().Build();
string path = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, samplesDirectory, "ControllingConversationFlowSample"));
resourceExplorer.AddFolder(path);
}
Expand Down Expand Up @@ -75,30 +74,26 @@ await BuildTestFlow()
.Send("Yes")
.AssertReply("Do you want to repeat this dialog, yes to repeat, no to end this dialog (1) Yes or (2) No")
.Send("No")
.Send("05")
.AssertReply("Canceled.")
.StartTestAsync();
}


private TestFlow BuildTestFlow(bool sendTrace = false)
{
TypeFactory.Configuration = new ConfigurationBuilder().Build();
var storage = new MemoryStorage();
var convoState = new ConversationState(storage);
var userState = new UserState(storage);
var adapter = new TestAdapter(TestAdapter.CreateConversation(TestContext.TestName), sendTrace);
adapter
.UseStorage(storage)
.UseState(userState, convoState)
.UseAdaptiveDialogs()
.UseLanguageGeneration(resourceExplorer, "common.lg")
.UseResourceExplorer(resourceExplorer)
.Use(new TranscriptLoggerMiddleware(new FileTranscriptLogger()));

var resource = resourceExplorer.GetResource("Main.dialog");
var dialog = DeclarativeTypeLoader.Load<AdaptiveDialog>(resource, resourceExplorer, DebugSupport.SourceMap);
DialogManager dm = new DialogManager(dialog);
var dialog = resourceExplorer.LoadType<Dialog>(resource);
DialogManager dm = new DialogManager(dialog)
.UseResourceExplorer(resourceExplorer)
.UseLanguageGeneration();

return new TestFlow(adapter, async (turnContext, cancellationToken) =>
{
Expand Down
11 changes: 4 additions & 7 deletions BotProject/Templates/CSharp/Tests/InputsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public class InputsTests
[ClassInitialize]
public static void ClassInitialize(TestContext context)
{
TypeFactory.Configuration = new ConfigurationBuilder().AddInMemoryCollection().Build();
string path = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, samplesDirectory, "AskingQuestionsSample"));
resourceExplorer.AddFolder(path);
}
Expand Down Expand Up @@ -116,22 +115,20 @@ await BuildTestFlow()

private TestFlow BuildTestFlow(bool sendTrace = false)
{
TypeFactory.Configuration = new ConfigurationBuilder().Build();
var storage = new MemoryStorage();
var convoState = new ConversationState(storage);
var userState = new UserState(storage);
var adapter = new TestAdapter(TestAdapter.CreateConversation(TestContext.TestName), sendTrace);
adapter
.UseStorage(storage)
.UseState(userState, convoState)
.UseAdaptiveDialogs()
.UseLanguageGeneration(resourceExplorer, "common.lg")
.UseResourceExplorer(resourceExplorer)
.Use(new TranscriptLoggerMiddleware(new FileTranscriptLogger()));

var resource = resourceExplorer.GetResource("Main.dialog");
var dialog = DeclarativeTypeLoader.Load<AdaptiveDialog>(resource, resourceExplorer, DebugSupport.SourceMap);
DialogManager dm = new DialogManager(dialog);
var dialog = resourceExplorer.LoadType<Dialog>(resource);
DialogManager dm = new DialogManager(dialog)
.UseResourceExplorer(resourceExplorer)
.UseLanguageGeneration();

return new TestFlow(adapter, async (turnContext, cancellationToken) =>
{
Expand Down
11 changes: 4 additions & 7 deletions BotProject/Templates/CSharp/Tests/MessageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public class MessageTests
[ClassInitialize]
public static void ClassInitialize(TestContext context)
{
TypeFactory.Configuration = new ConfigurationBuilder().AddInMemoryCollection().Build();
string path = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, samplesDirectory, "RespondingWithTextSample"));
resourceExplorer.AddFolder(path);
}
Expand Down Expand Up @@ -72,22 +71,20 @@ await BuildTestFlow()

private TestFlow BuildTestFlow(bool sendTrace = false)
{
TypeFactory.Configuration = new ConfigurationBuilder().Build();
var storage = new MemoryStorage();
var convoState = new ConversationState(storage);
var userState = new UserState(storage);
var adapter = new TestAdapter(TestAdapter.CreateConversation(TestContext.TestName), sendTrace);
adapter
.UseStorage(storage)
.UseState(userState, convoState)
.UseAdaptiveDialogs()
.UseLanguageGeneration(resourceExplorer, "common.lg")
.UseResourceExplorer(resourceExplorer)
.Use(new TranscriptLoggerMiddleware(new FileTranscriptLogger()));

var resource = resourceExplorer.GetResource("Main.dialog");
var dialog = DeclarativeTypeLoader.Load<AdaptiveDialog>(resource, resourceExplorer, DebugSupport.SourceMap);
DialogManager dm = new DialogManager(dialog);
var dialog = resourceExplorer.LoadType<Dialog>(resource);
DialogManager dm = new DialogManager(dialog)
.UseResourceExplorer(resourceExplorer)
.UseLanguageGeneration();

return new TestFlow(adapter, async (turnContext, cancellationToken) =>
{
Expand Down
11 changes: 4 additions & 7 deletions BotProject/Templates/CSharp/Tests/ToDoBotTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public class ToDoBotTests
[ClassInitialize]
public static void ClassInitialize(TestContext context)
{
TypeFactory.Configuration = new ConfigurationBuilder().AddInMemoryCollection().Build();
string path = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, samplesDirectory, "TodoSample"));
resourceExplorer.AddFolder(path);
}
Expand Down Expand Up @@ -68,22 +67,20 @@ await BuildTestFlow()

private TestFlow BuildTestFlow(bool sendTrace = false)
{
TypeFactory.Configuration = new ConfigurationBuilder().Build();
var storage = new MemoryStorage();
var convoState = new ConversationState(storage);
var userState = new UserState(storage);
var adapter = new TestAdapter(TestAdapter.CreateConversation(TestContext.TestName), sendTrace);
adapter
.UseStorage(storage)
.UseState(userState, convoState)
.UseAdaptiveDialogs()
.UseLanguageGeneration(resourceExplorer, "common.lg")
.UseResourceExplorer(resourceExplorer)
.Use(new TranscriptLoggerMiddleware(new FileTranscriptLogger()));

var resource = resourceExplorer.GetResource("Main.dialog");
var dialog = DeclarativeTypeLoader.Load<AdaptiveDialog>(resource, resourceExplorer, DebugSupport.SourceMap);
DialogManager dm = new DialogManager(dialog);
var dialog = resourceExplorer.LoadType<Dialog>(resource);
DialogManager dm = new DialogManager(dialog)
.UseResourceExplorer(resourceExplorer)
.UseLanguageGeneration();

return new TestFlow(adapter, async (turnContext, cancellationToken) =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"id": "026341"
},
"property": "user.age",
"value": "9+9"
"value": "=9+9"
},
{
"$type": "Microsoft.SendActivity",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@
"$designer": {
"id": "250234"
},
"changeType": "Insertactions",
"changeType": "insertActions",
"actions": [
{
"$type": "Microsoft.TextInput",
"prompt": "Hello, I'm Zoidberg. What is your name?",
"property": "user.name"
"property": "user.name",
"alwaysPrompt": "true"
}
]
},
Expand All @@ -31,7 +32,7 @@
"$designer": {
"id": "443878"
},
"changeType": "Appendactions",
"changeType": "appendActions",
"actions": [
{
"$type": "Microsoft.SendActivity",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,14 @@
"id": "356862"
},
"actions": [
{
"$type": "Microsoft.IfCondition",
"$designer": {
"id": "356862"
},
"condition": "user.ids == null",
"actions": [
{
"$type": "Microsoft.InitProperty",
"$designer": {
"id": "384024"
},
"property": "user.ids",
"type": "array"
}
]
},
{
"$type": "Microsoft.EditArray",
"$designer": {
"id": "076427"
},
"changeType": "Push",
"itemsProperty": "user.ids",
"value": "10000+1000+100+10+1"
"value": "=10000+1000+100+10+1"
},
{
"$type": "Microsoft.EditArray",
Expand All @@ -45,13 +28,13 @@
},
"changeType": "Push",
"itemsProperty": "user.ids",
"value": "200*200"
"value": "=200*200"
},
{
"$type": "Microsoft.EditArray",
"changeType": "Push",
"itemsProperty": "user.ids",
"value": "888888/4",
"value": "=888888/4",
"$designer": {
"id": "393322"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@
"$type": "Microsoft.RegexRecognizer",
"intents": [
{
"$type": "Microsoft.IntentPattern",
"intent": "EmitEvent",
"pattern": "emit"
},
{
"$type": "Microsoft.IntentPattern",
"intent": "CowboyIntent",
"pattern": "moo"
}
Expand Down
Loading

0 comments on commit 839427f

Please sign in to comment.