Skip to content

Commit

Permalink
Tomlm/fix deadlock regression when talking to emulator (#4569)
Browse files Browse the repository at this point in the history
* fix deadlock

* update echobot to use dialog for response.
  • Loading branch information
Tom Laird-McConnell authored May 6, 2018
1 parent 0fe9fd2 commit 35e6058
Show file tree
Hide file tree
Showing 20 changed files with 81 additions and 38 deletions.
14 changes: 13 additions & 1 deletion CSharp/EchoBot/App_Start/WebApiConfig.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Http;
Expand All @@ -10,6 +12,16 @@ public static class WebApiConfig
public static void Register(HttpConfiguration config)
{
// Web API configuration and services
// Json settings
config.Formatters.JsonFormatter.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;
config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
config.Formatters.JsonFormatter.SerializerSettings.Formatting = Formatting.Indented;
JsonConvert.DefaultSettings = () => new JsonSerializerSettings()
{
ContractResolver = new CamelCasePropertyNamesContractResolver(),
Formatting = Newtonsoft.Json.Formatting.Indented,
NullValueHandling = NullValueHandling.Ignore,
};

// Web API routes
config.MapHttpAttributeRoutes();
Expand Down
37 changes: 30 additions & 7 deletions CSharp/EchoBot/Controllers/MessagesController.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,36 @@
using Microsoft.Bot.Connector;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Connector;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using System.Web.Http;

namespace EchoBot.Controllers
{
[Serializable]
public class RootDialog : IDialog<object>
{
public Task StartAsync(IDialogContext context)
{
context.Wait(MessageReceivedAsync);

return Task.CompletedTask;
}

private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<object> result)
{
var activity = await result as Activity;

// calculate something for us to return
int length = (activity.Text ?? string.Empty).Length;

// return our reply to the user
await context.PostAsync($"You sent {activity.Text} which was {length} characters");

context.Wait(MessageReceivedAsync);
}
}

[BotAuthentication]
public class MessagesController : ApiController
{
Expand All @@ -17,10 +39,11 @@ public async Task Post([FromBody]Activity activity)
{
if (activity.Type == ActivityTypes.Message)
{
MicrosoftAppCredentials.AutoTokenRefreshTimeSpan = TimeSpan.FromSeconds(30);
await Conversation.SendAsync(activity, () => new RootDialog());
//MicrosoftAppCredentials.AutoTokenRefreshTimeSpan = TimeSpan.FromSeconds(30);

ConnectorClient client = new ConnectorClient(new Uri(activity.ServiceUrl), new MicrosoftAppCredentials());
await client.Conversations.ReplyToActivityAsync(activity.CreateReply(activity.Text));
//ConnectorClient client = new ConnectorClient(new Uri(activity.ServiceUrl), new MicrosoftAppCredentials());
//await client.Conversations.ReplyToActivityAsync(activity.CreateReply(activity.Text));
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions CSharp/EchoBot/EchoBot.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@
<Folder Include="Models\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Library\Microsoft.Bot.Builder.Autofac\Microsoft.Bot.Builder.Autofac.csproj">
<Project>{2c145824-38dd-409c-ab52-b3538997726c}</Project>
<Name>Microsoft.Bot.Builder.Autofac</Name>
</ProjectReference>
<ProjectReference Include="..\Library\Microsoft.Bot.Builder\Microsoft.Bot.Builder.csproj">
<Project>{cdfec7d6-847e-4c13-956b-0a960ae3eb60}</Project>
<Name>Microsoft.Bot.Builder</Name>
</ProjectReference>
<ProjectReference Include="..\Library\Microsoft.Bot.Connector.NetFramework\Microsoft.Bot.Connector.NetFramework.csproj">
<Project>{df397efc-91db-4911-9971-c509926fc288}</Project>
<Name>Microsoft.Bot.Connector.NetFramework</Name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("3.15.2.0")]
[assembly: AssemblyFileVersion("3.15.2.0")]
[assembly: AssemblyVersion("3.15.2.1")]
[assembly: AssemblyFileVersion("3.15.2.1")]

[assembly: InternalsVisibleTo("Microsoft.Bot.Builder.Tests")]
[assembly: InternalsVisibleTo("Microsoft.Bot.Sample.Tests")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("3.15.2.0")]
[assembly: AssemblyFileVersion("3.15.2.0")]
[assembly: AssemblyVersion("3.15.2.1")]
[assembly: AssemblyFileVersion("3.15.2.1")]

//[assembly: AssemblyKeyFileAttribute(@"..\\..\\buildtools\\35MSSharedLib1024.snk")]
//[assembly: AssemblyDelaySignAttribute(true)]
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("3.15.2.0")]
[assembly: AssemblyFileVersion("3.15.2.0")]
[assembly: AssemblyVersion("3.15.2.1")]
[assembly: AssemblyFileVersion("3.15.2.1")]

[assembly: InternalsVisibleTo("Microsoft.Bot.Builder.Tests")]
[assembly: InternalsVisibleTo("Microsoft.Bot.Sample.Tests")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("3.15.2.0")]
[assembly: AssemblyFileVersion("3.15.2.0")]
[assembly: AssemblyVersion("3.15.2.1")]
[assembly: AssemblyFileVersion("3.15.2.1")]

//[assembly: AssemblyKeyFileAttribute(@"..\\..\\buildtools\\35MSSharedLib1024.snk")]
//[assembly: AssemblyDelaySignAttribute(true)]
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public ConnectorClientFactory(IAddress address, MicrosoftAppCredentials credenti
if (IsEmulator(this.address))
{
// Send the mode notification (emulated OAuthCards or not) to the emulator
Task.WaitAll(oauthClient.OAuthApi.SendEmulateOAuthCardsAsync(emulateOAuthCards.Value));
Task.Run(async () => await oauthClient.OAuthApi.SendEmulateOAuthCardsAsync(emulateOAuthCards.Value).ConfigureAwait(false)).Wait();
}

oauthClients[key] = oauthClient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<dependency id="Autofac" version="3.5.2"/>
<dependency id="Chronic.Signed" version="0.3.2" />
<dependency id="Microsoft.AspNet.WebAPI.Core" version="5.2.3" />
<dependency id="Microsoft.Bot.Connector" version="3.15.2.0" />
<dependency id="Microsoft.Bot.Connector" version="3.15.2.1" />
<dependency id="Microsoft.Rest.ClientRuntime" version="2.3.2" />
<dependency id="Newtonsoft.Json" version="9.0.1" />
<dependency id="System.IdentityModel.Tokens.Jwt" version="5.1.4" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("3.15.2.0")]
[assembly: AssemblyFileVersion("3.15.2.0")]
[assembly: AssemblyVersion("3.15.2.1")]
[assembly: AssemblyFileVersion("3.15.2.1")]


[assembly: InternalsVisibleTo("Microsoft.Bot.Builder.Tests")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<metadata xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<id>Microsoft.Bot.Connector.AspNetCore</id>
<version>1.1.3.13</version>
<version>1.1.3.14</version>
<authors>Microsoft</authors>
<owners>microsoft, BotFramework, nugetbotbuilder </owners>
<iconUrl>https://bots.botframework.com/Client/Images/bot-framework-default-7.png</iconUrl>
Expand All @@ -22,7 +22,7 @@
<dependency id="Newtonsoft.Json" version="9.0.1" />
<dependency id="System.IdentityModel.Tokens.Jwt" version="5.1.4" />
<dependency id="Microsoft.AspNetCore.Mvc.Core" version="1.1.4" />
<dependency id="Microsoft.Bot.Connector" version="3.15.2.0" />
<dependency id="Microsoft.Bot.Connector" version="3.15.2.1" />
</group>
</dependencies>
</metadata>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
[assembly: AssemblyCulture("")]


[assembly: AssemblyVersion("1.1.3.13")]
[assembly: AssemblyFileVersion("1.1.3.13")]
[assembly: AssemblyVersion("1.1.3.14")]
[assembly: AssemblyFileVersion("1.1.3.14")]

//[assembly: AssemblyKeyFileAttribute(@"..\\..\\buildtools\\35MSSharedLib1024.snk")]
//[assembly: AssemblyDelaySignAttribute(true)]
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
[assembly: AssemblyCulture("")]


[assembly: AssemblyVersion("2.0.1.5")]
[assembly: AssemblyFileVersion("2.0.1.5")]
[assembly: AssemblyVersion("2.0.1.6")]
[assembly: AssemblyFileVersion("2.0.1.6")]

//[assembly: AssemblyKeyFileAttribute(@"..\\..\\buildtools\\35MSSharedLib1024.snk")]
//[assembly: AssemblyDelaySignAttribute(true)]
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<metadata xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<id>Microsoft.Bot.Connector.AspNetCore</id>
<version>2.0.1.5</version>
<version>2.0.1.6</version>
<authors>Microsoft</authors>
<owners>microsoft, BotFramework, nugetbotbuilder </owners>
<iconUrl>https://bots.botframework.com/Client/Images/bot-framework-default-7.png</iconUrl>
Expand All @@ -19,7 +19,7 @@
<dependency id="Microsoft.AspNetCore.Authentication.JwtBearer" version="2.0.0" />
<dependency id="Microsoft.AspNetCore.Mvc" version="2.0.0" />
<dependency id="Microsoft.Rest.ClientRuntime" version="2.3.10" />
<dependency id="Microsoft.Bot.Connector" version="3.15.2.0" />
<dependency id="Microsoft.Bot.Connector" version="3.15.2.1" />
</group>
</dependencies>
</metadata>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<metadata xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<id>Microsoft.Bot.Connector</id>
<version>3.15.2.0</version>
<version>3.15.2.1</version>
<authors>Microsoft</authors>
<owners>microsoft, BotFramework, nugetbotbuilder </owners>
<iconUrl>https://bots.botframework.com/Client/Images/bot-framework-default-7.png</iconUrl>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

[assembly: AssemblyVersion("3.15.2.0")]
[assembly: AssemblyFileVersion("3.15.2.0")]
[assembly: AssemblyVersion("3.15.2.1")]
[assembly: AssemblyFileVersion("3.15.2.1")]

//[assembly: AssemblyKeyFileAttribute(@"..\\..\\buildtools\\35MSSharedLib1024.snk")]
//[assembly: AssemblyDelaySignAttribute(true)]
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System.Reflection;
using System.Resources;

[assembly: AssemblyVersion("3.15.2.0")]
[assembly: AssemblyFileVersion("3.15.2.0")]
[assembly: AssemblyVersion("3.15.2.1")]
[assembly: AssemblyFileVersion("3.15.2.1")]

//[assembly: AssemblyKeyFileAttribute(@"..\\..\\buildtools\\35MSSharedLib1024.snk")]
//[assembly: AssemblyDelaySignAttribute(true)]
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<metadata xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<id>Microsoft.Bot.Connector</id>
<version>3.15.2.0</version>
<version>3.15.2.1</version>
<authors>Microsoft</authors>
<owners>microsoft, BotFramework, nugetbotbuilder </owners>
<iconUrl>https://bots.botframework.com/Client/Images/bot-framework-default-7.png</iconUrl>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

[assembly: AssemblyVersion("3.15.2.0")]
[assembly: AssemblyFileVersion("3.15.2.0")]
[assembly: AssemblyVersion("3.15.2.1")]
[assembly: AssemblyFileVersion("3.15.2.1")]

//[assembly: AssemblyKeyFileAttribute(@"..\\..\\buildtools\\35MSSharedLib1024.snk")]
//[assembly: AssemblyDelaySignAttribute(true)]
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System.Reflection;
using System.Runtime.InteropServices;

[assembly: AssemblyVersion("3.15.2.0")]
[assembly: AssemblyFileVersion("3.15.2.0")]
[assembly: AssemblyVersion("3.15.2.1")]
[assembly: AssemblyFileVersion("3.15.2.1")]

//[assembly: AssemblyKeyFileAttribute(@"..\\..\\buildtools\\35MSSharedLib1024.snk")]
//[assembly: AssemblyDelaySignAttribute(true)]

0 comments on commit 35e6058

Please sign in to comment.