Skip to content

Commit

Permalink
[CSharp-ContosoFlowers] Update to Microsoft.Bot.Builder v3.5.0 and ad…
Browse files Browse the repository at this point in the history
…d of Bing Location control
  • Loading branch information
pcostantini authored and ejadib committed Jan 9, 2017
1 parent b45cf35 commit 53d7210
Show file tree
Hide file tree
Showing 29 changed files with 264 additions and 756 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,38 +31,42 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Autofac, Version=4.0.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da, processorArchitecture=MSIL">
<HintPath>..\packages\Autofac.4.0.0\lib\net451\Autofac.dll</HintPath>
<Reference Include="Autofac, Version=4.2.1.0, Culture=neutral, PublicKeyToken=17863af14b0044da, processorArchitecture=MSIL">
<HintPath>..\packages\Autofac.4.2.1\lib\net45\Autofac.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Chronic, Version=0.3.2.0, Culture=neutral, PublicKeyToken=3bd1f1ef638b0d3c, processorArchitecture=MSIL">
<HintPath>..\packages\Chronic.Signed.0.3.2\lib\net40\Chronic.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Bot.Builder, Version=3.2.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Bot.Builder.3.2.1\lib\net46\Microsoft.Bot.Builder.dll</HintPath>
<Reference Include="Microsoft.Bot.Builder, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Bot.Builder.3.5.0\lib\net46\Microsoft.Bot.Builder.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Bot.Connector, Version=3.2.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Bot.Builder.3.2.1\lib\net46\Microsoft.Bot.Connector.dll</HintPath>
<Reference Include="Microsoft.Bot.Builder.Location, Version=1.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Bot.Builder.Location.1.1.0\lib\net46\Microsoft.Bot.Builder.Location.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.IdentityModel.Protocol.Extensions, Version=1.0.2.33, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.IdentityModel.Protocol.Extensions.1.0.2.206221351\lib\net45\Microsoft.IdentityModel.Protocol.Extensions.dll</HintPath>
<Reference Include="Microsoft.Bot.Connector, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Bot.Builder.3.5.0\lib\net46\Microsoft.Bot.Connector.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.IdentityModel.Protocol.Extensions, Version=1.0.3.42, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.IdentityModel.Protocol.Extensions.1.0.3.308261200\lib\net45\Microsoft.IdentityModel.Protocol.Extensions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Rest.ClientRuntime, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Rest.ClientRuntime.2.3.2\lib\net45\Microsoft.Rest.ClientRuntime.dll</HintPath>
<HintPath>..\packages\Microsoft.Rest.ClientRuntime.2.3.4\lib\net45\Microsoft.Rest.ClientRuntime.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.IdentityModel.Tokens.Jwt, Version=4.0.20622.1351, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\System.IdentityModel.Tokens.Jwt.4.0.2.206221351\lib\net45\System.IdentityModel.Tokens.Jwt.dll</HintPath>
<Reference Include="System.IdentityModel.Tokens.Jwt, Version=4.0.30826.1200, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\System.IdentityModel.Tokens.Jwt.4.0.3.308261200\lib\net45\System.IdentityModel.Tokens.Jwt.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Net" />
Expand All @@ -84,7 +88,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Dialogs\AddressDialog.cs" />
<Compile Include="ContosoLocationResourceManager.cs" />
<Compile Include="Dialogs\CancelablePromptChoice.cs" />
<Compile Include="Dialogs\DialogFactory.cs" />
<Compile Include="Dialogs\IDialogFactory.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace ContosoFlowers.BotAssets
{
using System;
using Microsoft.Bot.Builder.Location;
using Properties;

[Serializable]
public class ContosoLocationResourceManager : LocationResourceManager
{
public override string ConfirmationAsk => Resources.Location_ConfirmationAsk;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class CancelablePromptChoice<T> : PromptDialog.PromptChoice<T>
{
private static IEnumerable<string> cancelTerms = new[] { "Cancel", "Back", "B", "Abort" };

protected new readonly CancelablePromptOptions<T> promptOptions;
private new readonly CancelablePromptOptions<T> promptOptions;

public CancelablePromptChoice(CancelablePromptOptions<T> promptOptions)
: base(promptOptions)
Expand Down Expand Up @@ -52,17 +52,17 @@ protected override bool TryParse(IMessageActivity message, out T result)
return base.TryParse(message, out result);
}

protected override IMessageActivity MakePrompt(IDialogContext context, string prompt, IList<T> options = null)
protected override IMessageActivity MakePrompt(IDialogContext context, string prompt, IReadOnlyList<T> options = null, IReadOnlyList<string> descriptions = null)
{
prompt += Environment.NewLine + (promptOptions.CancelPrompt ?? promptOptions.DefaultCancelPrompt);
prompt += Environment.NewLine + (this.promptOptions.CancelPrompt ?? this.promptOptions.DefaultCancelPrompt);
return base.MakePrompt(context, prompt, options);
}
}

[Serializable]
public class CancelablePromptOptions<T> : PromptOptions<T>
{
public CancelablePromptOptions(string prompt, string cancelPrompt = null, string retry = null, string tooManyAttempts = null, IList<T> options = null, int attempts = 3, PromptStyler promptStyler = null)
public CancelablePromptOptions(string prompt, string cancelPrompt = null, string retry = null, string tooManyAttempts = null, IReadOnlyList<T> options = null, int attempts = 3, PromptStyler promptStyler = null)
: base(prompt, retry, tooManyAttempts, options, attempts, promptStyler)
{
this.DefaultCancelPrompt = Resources.CancelablePromptChoice_CancelText;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
namespace ContosoFlowers.BotAssets
{
using System.Collections.Generic;
using System.Linq;
using Autofac;
using Microsoft.Bot.Builder.Internals.Fibers;

Expand All @@ -21,5 +23,10 @@ public T Create<T, U>(U parameter)
{
return this.Scope.Resolve<T>(TypedParameter.From(parameter));
}

public T Create<T>(IDictionary<string, object> parameters)
{
return this.Scope.Resolve<T>(parameters.Select(kv => new NamedParameter(kv.Key, kv.Value)));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
namespace ContosoFlowers.BotAssets
{
using System.Collections.Generic;

public interface IDialogFactory
{
T Create<T>();

T Create<T, U>(U parameter);

T Create<T>(IDictionary<string, object> parameters);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Builder.Location;
using Microsoft.Bot.Connector;
using Properties;
using Services;

[Serializable]
public class SavedAddressDialog : IDialog<SavedAddressDialog.SavedAddressResult>
Expand All @@ -16,26 +17,23 @@ public class SavedAddressDialog : IDialog<SavedAddressDialog.SavedAddressResult>
private readonly string prompt;
private readonly string useSavedAddressPrompt;
private readonly string saveAddressPrompt;
private readonly ILocationService locationService;
private readonly IDialogFactory dialogFactory;

private string currentAddress;

public SavedAddressDialog(
string prompt,
string useSavedAddressPrompt,
string saveAddressPrompt,
IDictionary<string, string> savedAddresses,
string prompt,
string useSavedAddressPrompt,
string saveAddressPrompt,
IDictionary<string, string> savedAddresses,
IEnumerable<string> saveOptionNames,
ILocationService locationService,
IDialogFactory dialogFactory)
{
this.savedAddresses = savedAddresses ?? new Dictionary<string, string>();
this.saveOptionNames = saveOptionNames;
this.prompt = prompt;
this.useSavedAddressPrompt = useSavedAddressPrompt;
this.saveAddressPrompt = saveAddressPrompt;
this.locationService = locationService;
this.dialogFactory = dialogFactory;
}

Expand All @@ -53,13 +51,22 @@ public async Task StartAsync(IDialogContext context)

private void AddressPrompt(IDialogContext context)
{
var addressDialog = this.dialogFactory.Create<AddressDialog, string>(this.prompt);
context.Call(addressDialog, this.AfterAddressPrompt);
// BotBuilder's LocationDialog
// Leverage DI to inject other parameters
var locationDialog = this.dialogFactory.Create<LocationDialog>(
new Dictionary<string, object>()
{
{ "prompt", this.prompt },
{ "channelId", context.Activity.ChannelId }
});

context.Call(locationDialog, this.AfterAddressPrompt);
}

private async Task AfterAddressPrompt(IDialogContext context, IAwaitable<string> result)
private async Task AfterAddressPrompt(IDialogContext context, IAwaitable<Place> result)
{
this.currentAddress = await result;
var place = await result;
this.currentAddress = place.GetPostalAddress().FormattedAddress;
PromptDialog.Choice(context, this.AfterSelectToSaveAddress, this.saveOptionNames.Concat(new[] { Resources.SavedAddressDialog_NotThisTime }), this.saveAddressPrompt);
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,7 @@
<data name="SavedAddressDialog_NotThisTime" xml:space="preserve">
<value>No, thanks!</value>
</data>
<data name="Location_ConfirmationAsk" xml:space="preserve">
<value>OK, you want to use {0}. Is that correct? Enter 'yes' or 'no'.</value>
</data>
</root>
20 changes: 18 additions & 2 deletions CSharp/demo-ContosoFlowers/ContosoFlowers.BotAssets/app.config
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,27 @@
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0" />
<bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Autofac" publicKeyToken="17863af14b0044da" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
<bindingRedirect oldVersion="0.0.0.0-4.2.1.0" newVersion="4.2.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Bot.Connector" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.5.0.0" newVersion="3.5.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Bot.Builder" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.5.0.0" newVersion="3.5.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.IdentityModel.Tokens.Jwt" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.30826.1200" newVersion="4.0.30826.1200" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.IdentityModel.Protocol.Extensions" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.0.3.42" newVersion="1.0.3.42" />
</dependentAssembly>
</assemblyBinding>
</runtime>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Autofac" version="4.0.0" targetFramework="net46" />
<package id="Autofac" version="4.2.1" targetFramework="net46" />
<package id="Chronic.Signed" version="0.3.2" targetFramework="net46" />
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net46" />
<package id="Microsoft.AspNet.WebApi.Core" version="5.2.3" targetFramework="net46" />
<package id="Microsoft.Bot.Builder" version="3.2.1" targetFramework="net46" />
<package id="Microsoft.IdentityModel.Protocol.Extensions" version="1.0.2.206221351" targetFramework="net46" />
<package id="Microsoft.Rest.ClientRuntime" version="2.3.2" targetFramework="net46" />
<package id="Newtonsoft.Json" version="8.0.3" targetFramework="net46" />
<package id="System.IdentityModel.Tokens.Jwt" version="4.0.2.206221351" targetFramework="net46" />
<package id="Microsoft.Bot.Builder" version="3.5.0" targetFramework="net46" />
<package id="Microsoft.Bot.Builder.Location" version="1.1.0" targetFramework="net46" />
<package id="Microsoft.IdentityModel.Protocol.Extensions" version="1.0.3.308261200" targetFramework="net46" />
<package id="Microsoft.Rest.ClientRuntime" version="2.3.4" targetFramework="net46" />
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net46" />
<package id="System.IdentityModel.Tokens.Jwt" version="4.0.3.308261200" targetFramework="net46" />
</packages>

This file was deleted.

Loading

0 comments on commit 53d7210

Please sign in to comment.