Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes made to run project on .netcore 3.1 #60

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
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
6 changes: 0 additions & 6 deletions IntermediatorBotSample.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ VisualStudioVersion = 15.0.27428.2037
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IntermediatorBotSample", "IntermediatorBotSample\IntermediatorBotSample.csproj", "{C5442A0C-E1AB-4237-B069-097A470AF818}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotMessageRouting", "bot-message-routing\BotMessageRouting\BotMessageRouting.csproj", "{E2A695B5-29F9-450A-8809-CB57B40619F6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -17,10 +15,6 @@ Global
{C5442A0C-E1AB-4237-B069-097A470AF818}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C5442A0C-E1AB-4237-B069-097A470AF818}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C5442A0C-E1AB-4237-B069-097A470AF818}.Release|Any CPU.Build.0 = Release|Any CPU
{E2A695B5-29F9-450A-8809-CB57B40619F6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E2A695B5-29F9-450A-8809-CB57B40619F6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E2A695B5-29F9-450A-8809-CB57B40619F6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E2A695B5-29F9-450A-8809-CB57B40619F6}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
12 changes: 12 additions & 0 deletions IntermediatorBotSample/.config/dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": 1,
"isRoot": true,
"tools": {
"dotnet-ef": {
"version": "5.0.11",
"commands": [
"dotnet-ef"
]
}
}
}
5 changes: 3 additions & 2 deletions IntermediatorBotSample/Bot/IntermediatorBot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Microsoft.Bot.Builder;
using Microsoft.Bot.Schema;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;

namespace IntermediatorBotSample.Bot
Expand All @@ -11,7 +12,7 @@ public class IntermediatorBot : IBot
{
private const string SampleUrl = "https://github.com/tompaana/intermediator-bot-sample";

public async Task OnTurn(ITurnContext context)
public async Task OnTurnAsync(ITurnContext context, CancellationToken ct)
{
Command showOptionsCommand = new Command(Commands.ShowOptions);

Expand All @@ -33,7 +34,7 @@ public async Task OnTurn(ITurnContext context)

Activity replyActivity = context.Activity.CreateReply();
replyActivity.Attachments = new List<Attachment>() { heroCard.ToAttachment() };
await context.SendActivity(replyActivity);
await context.SendActivityAsync(replyActivity);
}
}
}
2 changes: 1 addition & 1 deletion IntermediatorBotSample/CommandHandling/CommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ await _connectionRequestHandler.AcceptOrRejectRequestAsync(

if (replyActivity != null)
{
await context.SendActivity(replyActivity);
await context.SendActivityAsync(replyActivity);
}

return wasHandled;
Expand Down
2 changes: 1 addition & 1 deletion IntermediatorBotSample/ConversationHistory/MessageLogs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public MessageLogs(string connectionString)
{
System.Diagnostics.Debug.WriteLine("Using Azure Table Storage for storing message logs");
_messageLogsTable = AzureStorageHelper.GetTable(connectionString, MessageLogsTableName);
MakeSureConversationHistoryTableExistsAsync().RunSynchronously();
MakeSureConversationHistoryTableExistsAsync().Wait();
}
}

Expand Down
32 changes: 16 additions & 16 deletions IntermediatorBotSample/IntermediatorBotSample.csproj
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<Compile Remove="Mw\**" />
<Content Remove="Mw\**" />
<EmbeddedResource Remove="Mw\**" />
<None Remove="Mw\**" />
</ItemGroup>
<PackageReference Include="BotMessageRouting" Version="2.0.2-alpha" />

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.6" />
<PackageReference Include="Microsoft.Bot.Builder.Core" Version="4.0.1-preview" />
<PackageReference Include="Microsoft.Bot.Builder.Core.Extensions" Version="4.0.1-preview" />
<PackageReference Include="Microsoft.Bot.Builder.Integration.AspNet.Core" Version="4.0.1-preview" />
</ItemGroup>
<PackageReference Include="Microsoft.Bot.Builder" Version="4.2.2" />


<PackageReference Include="Microsoft.Bot.Builder.Integration.AspNet.Core" Version="4.2.2" />
<PackageReference Include="Microsoft.Bot.Configuration" Version="4.2.2" />
<PackageReference Include="Microsoft.Bot.Connector" Version="4.2.2" />

<ItemGroup>
<ProjectReference Include="..\bot-message-routing\BotMessageRouting\BotMessageRouting.csproj" />
</ItemGroup>


<PackageReference Include="Microsoft.Bot.Schema" Version="4.2.2" />
<PackageReference Include="Microsoft.Extensions.Logging.AzureAppServices" Version="5.0.11" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />

</ItemGroup>

<ItemGroup>
<Compile Update="Resources\Strings.Designer.cs">
<DesignTime>True</DesignTime>
Expand Down
44 changes: 44 additions & 0 deletions IntermediatorBotSample/Middleware/CatchExceptionMiddleware.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;
using System.Threading;
using System.Threading.Tasks;

namespace Microsoft.Bot.Builder.Core.Extensions
{
/// <summary>
/// This piece of middleware can be added to allow you to handle exceptions when they are thrown
/// within your bot's code or middleware further down the pipeline. Using this handler you might
/// send an appropriate message to the user to let them know that something has gone wrong.
/// You can specify the type of exception the middleware should catch and this middleware can be added
/// multiple times to allow you to handle different exception types in different ways.
/// </summary>
/// <typeparam name="T">
/// The type of the exception that you want to catch. This can be 'Exception' to
/// catch all or a specific type of exception
/// </typeparam>
public class CatchExceptionMiddleware<T> : IMiddleware where T : Exception
{
private readonly Func<ITurnContext, T, Task> _handler;

public CatchExceptionMiddleware(Func<ITurnContext, T, Task> callOnException)
{
_handler = callOnException;
}

public async Task OnTurnAsync(ITurnContext context, NextDelegate next, CancellationToken cancellationToken = default(CancellationToken))
{
try
{
// Continue to route the activity through the pipeline
// any errors further down the pipeline will be caught by
// this try / catch
await next(cancellationToken).ConfigureAwait(false);
}
catch (T ex)
{
// If an error is thrown and the exception is of type T then invoke the handler
await _handler.Invoke(context, ex).ConfigureAwait(false);
}
}

}
}
10 changes: 8 additions & 2 deletions IntermediatorBotSample/Middleware/HandoffMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Microsoft.Bot.Schema;
using Microsoft.Extensions.Configuration;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Underscore.Bot.MessageRouting;
using Underscore.Bot.MessageRouting.DataStore;
Expand Down Expand Up @@ -89,7 +90,7 @@ public HandoffMiddleware(IConfiguration configuration)
MessageLogs = new MessageLogs(connectionString);
}

public async Task OnTurn(ITurnContext context, MiddlewareSet.NextDelegate next)
public async Task OnTurnAsync(ITurnContext context, NextDelegate next, CancellationToken ct)
{
Activity activity = context.Activity;

Expand Down Expand Up @@ -134,7 +135,7 @@ public async Task OnTurn(ITurnContext context, MiddlewareSet.NextDelegate next)
else
{
// No action taken - this middleware did not consume the activity so let it propagate
await next().ConfigureAwait(false);
await next(ct).ConfigureAwait(false);
}
}
}
Expand All @@ -148,6 +149,11 @@ public async Task OnTurn(ITurnContext context, MiddlewareSet.NextDelegate next)
// Handle the result, if necessary
await MessageRouterResultHandler.HandleResultAsync(messageRouterResult);
}
else
{
// No action taken - this middleware did not consume the activity so let it propagate
await next(ct).ConfigureAwait(false);
}
}

/// <summary>
Expand Down
12 changes: 11 additions & 1 deletion IntermediatorBotSample/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "http://localhost:29211/"
},
"WSL": {
"commandName": "WSL2",
"launchBrowser": true,
"launchUrl": "http://localhost:29211/",
"environmentVariables": {
"ASPNETCORE_URLS": "http://localhost:29211/",
"ASPNETCORE_ENVIRONMENT": "Development"
},
"distributionName": ""
}
}
}
}
39 changes: 25 additions & 14 deletions IntermediatorBotSample/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
using IntermediatorBotSample.Middleware;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Bot.Builder.BotFramework;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Core.Extensions;
using Microsoft.Bot.Builder.BotFramework;
using Microsoft.Bot.Builder.Integration;
using Microsoft.Bot.Builder.Integration.AspNet.Core;
using Microsoft.Bot.Builder.TraceExtensions;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Server.Kestrel.Core;

namespace IntermediatorBotSample
{
Expand Down Expand Up @@ -36,9 +40,18 @@ public Startup(IHostingEnvironment env)
/// <param name="services"></param>
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().AddControllersAsServices();

services.AddSingleton(_ => Configuration);

// If using Kestrel:
services.Configure<KestrelServerOptions>(options =>
{
options.AllowSynchronousIO = true;
});
// If using IIS:
services.Configure<IISServerOptions>(options =>
{
options.AllowSynchronousIO = true;
});
services.AddBot<IntermediatorBot>(options =>
{
options.CredentialProvider = new ConfigurationCredentialProvider(Configuration);
Expand All @@ -50,8 +63,8 @@ public void ConfigureServices(IServiceCollection services)
// an "Ooops" message is sent.
options.Middleware.Add(new CatchExceptionMiddleware<Exception>(async (context, exception) =>
{
await context.TraceActivity("Bot Exception", exception);
await context.SendActivity($"Sorry, it looks like something went wrong: {exception.Message}");
await context.TraceActivityAsync("Bot Exception", exception);
await context.SendActivityAsync($"Sorry, it looks like something went wrong: {exception.Message}");
}));

// The Memory Storage used here is for local bot debugging only. When the bot
Expand All @@ -73,9 +86,12 @@ public void ConfigureServices(IServiceCollection services)

// Handoff middleware
options.Middleware.Add(new HandoffMiddleware(Configuration));


});

services.AddMvc(); // Required Razor pages
//services.AddMvc(); // Required Razor pages
services.AddRazorPages();
}

/// <summary>
Expand All @@ -93,14 +109,9 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env)

app.UseDefaultFiles()
.UseStaticFiles()
.UseMvc() // Required Razor pages
.UseBotFramework(bot =>
{
// This is how you can define a custom endpoint in case you're unhappy with
// the default "/api/messages":
bot.BasePath = Configuration["BotBasePath"];
bot.MessagesPath = Configuration["BotMessagesPath"];
});
.UseRouting()
.UseBotFramework();

}
}
}
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2016-2018 Microsoft
Copyright (c) 2016-2019 Microsoft

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down