From 9301ed3a0ebeaadc66a0748361e1d38be8ee311e Mon Sep 17 00:00:00 2001 From: John King Date: Mon, 7 Sep 2020 18:17:58 +0800 Subject: [PATCH 1/3] try-update- 3.1 --- .editorconfig | 11 ++++ .../BotSharp.Channel.FacebookMessenger.csproj | 8 +-- .../ModuleInjector.cs | 4 +- .../BotSharp.Channel.Weixin.csproj | 13 ++-- .../Controllers/WeixinAsyncController.cs | 7 +- .../Models/CustomMessageContext.cs | 11 +++- .../Models/CustomMessageHandler.cs | 12 ++-- BotSharp.Channel.Weixin/ModuleInjector.cs | 4 +- .../BotSharp.Core.UnitTest.csproj | 14 ++-- BotSharp.Core/BotSharp.Core.csproj | 40 +++++++----- BotSharp.Core/Modules/IModule.cs | 4 +- BotSharp.Core/Modules/ModulesStartup.cs | 4 +- .../BotSharp.Platform.Articulate.csproj | 6 +- .../ModuleInjector.cs | 4 +- .../BotSharp.Platform.Dialogflow.csproj | 6 +- .../ModuleInjector.cs | 4 +- .../BotSharp.Platform.Rasa.csproj | 6 +- BotSharp.WebHost/BotSharp.WebHost.csproj | 27 +++----- BotSharp.WebHost/Program.cs | 64 +++++++++++-------- BotSharp.WebHost/Startup.cs | 63 ++++++++++-------- .../SwaggerFileUploadOperation.cs | 43 +++++++------ BotSharp.sln | 6 ++ Directory.Build.props | 8 +++ 23 files changed, 209 insertions(+), 160 deletions(-) create mode 100644 .editorconfig create mode 100644 Directory.Build.props diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..e56cfa72 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,11 @@ + +# All files +[*] +indent_style = space +charset = utf-8 +# prevent linux/windows problem +end_of_line = lf + +# Xml files +[*.{xml,csproj}] +indent_size = 2 diff --git a/BotSharp.Channel.FacebookMessenger/BotSharp.Channel.FacebookMessenger.csproj b/BotSharp.Channel.FacebookMessenger/BotSharp.Channel.FacebookMessenger.csproj index d4eb4c0d..4c70e861 100644 --- a/BotSharp.Channel.FacebookMessenger/BotSharp.Channel.FacebookMessenger.csproj +++ b/BotSharp.Channel.FacebookMessenger/BotSharp.Channel.FacebookMessenger.csproj @@ -1,7 +1,7 @@ - + - netcoreapp2.2 + $(DefaultTargetFramework) @@ -9,8 +9,8 @@ - - + + diff --git a/BotSharp.Channel.FacebookMessenger/ModuleInjector.cs b/BotSharp.Channel.FacebookMessenger/ModuleInjector.cs index b0d23723..4a5f5218 100644 --- a/BotSharp.Channel.FacebookMessenger/ModuleInjector.cs +++ b/BotSharp.Channel.FacebookMessenger/ModuleInjector.cs @@ -1,4 +1,4 @@ -using BotSharp.Core.Modules; +using BotSharp.Core.Modules; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; @@ -14,7 +14,7 @@ namespace BotSharp.Channel.FacebookMessenger } - public void Configure(IApplicationBuilder app, IHostingEnvironment env/*, IOptions senparcSetting, IOptions senparcWeixinSetting*/) + public void Configure(IApplicationBuilder app, IWebHostEnvironment env/*, IOptions senparcSetting, IOptions senparcWeixinSetting*/) { } diff --git a/BotSharp.Channel.Weixin/BotSharp.Channel.Weixin.csproj b/BotSharp.Channel.Weixin/BotSharp.Channel.Weixin.csproj index be4faf1e..c5cf908a 100644 --- a/BotSharp.Channel.Weixin/BotSharp.Channel.Weixin.csproj +++ b/BotSharp.Channel.Weixin/BotSharp.Channel.Weixin.csproj @@ -1,16 +1,17 @@ - + - netcoreapp2.2 + $(DefaultTargetFramework) true + + + Haiping Chen https://github.com/Oceania2018/botsharp-channel-weixin git https://github.com/Oceania2018/botsharp-channel-weixin Apache 2.0 botsharp, wechat, wexin, chatbot - 0.1.1.0 - 0.1.1.0 0.1.1 @@ -19,8 +20,8 @@ - - + + diff --git a/BotSharp.Channel.Weixin/Controllers/WeixinAsyncController.cs b/BotSharp.Channel.Weixin/Controllers/WeixinAsyncController.cs index 65e8a44b..fa7ffa11 100644 --- a/BotSharp.Channel.Weixin/Controllers/WeixinAsyncController.cs +++ b/BotSharp.Channel.Weixin/Controllers/WeixinAsyncController.cs @@ -1,8 +1,9 @@ -using BotSharp.Channel.Weixin.Models; +using BotSharp.Channel.Weixin.Models; using BotSharp.Platform.Abstractions; using BotSharp.Platform.Dialogflow.Models; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Configuration; +using Senparc.CO2NET.AspNet.HttpUtility; using Senparc.CO2NET.HttpUtility; using Senparc.Weixin.MP; using Senparc.Weixin.MP.Entities.Request; @@ -93,7 +94,7 @@ namespace BotSharp.Channel.Weixin.Controllers messageHandler.RequestDocument.Save(Path.Combine(logPath, string.Format("{0}_Request_{1}_{2}.txt", _getRandomFileName(), messageHandler.RequestMessage.FromUserName, messageHandler.RequestMessage.MsgType))); - if (messageHandler.UsingEcryptMessage) + if (messageHandler.UsingEncryptMessage) { messageHandler.EcryptRequestDocument.Save(Path.Combine(logPath, string.Format("{0}_Request_Ecrypt_{1}_{2}.txt", _getRandomFileName(), messageHandler.RequestMessage.FromUserName, @@ -119,7 +120,7 @@ namespace BotSharp.Channel.Weixin.Controllers messageHandler.ResponseMessage.MsgType))); } - if (messageHandler.UsingEcryptMessage && messageHandler.FinalResponseDocument != null) + if (messageHandler.UsingEncryptMessage && messageHandler.FinalResponseDocument != null) { //记录加密后的响应信息 messageHandler.FinalResponseDocument.Save(Path.Combine(logPath, string.Format("{0}_Response_Final_{1}_{2}.txt", _getRandomFileName(), diff --git a/BotSharp.Channel.Weixin/Models/CustomMessageContext.cs b/BotSharp.Channel.Weixin/Models/CustomMessageContext.cs index 0dd6a67c..e5436b67 100644 --- a/BotSharp.Channel.Weixin/Models/CustomMessageContext.cs +++ b/BotSharp.Channel.Weixin/Models/CustomMessageContext.cs @@ -1,4 +1,4 @@ -/*---------------------------------------------------------------- +/*---------------------------------------------------------------- Copyright (C) 2018 Senparc 文件名:CustomMessageContext.cs @@ -12,18 +12,23 @@ using System; using System.Collections.Generic; using System.Linq; using System.Text; +using System.Xml.Linq; +using Senparc.NeuChar; using Senparc.NeuChar.Context; using Senparc.NeuChar.Entities; +using Senparc.Weixin.MP.MessageContexts; namespace BotSharp.Channel.Weixin.Models { - public class CustomMessageContext : MessageContext + public class CustomMessageContext : DefaultMpMessageContext { public CustomMessageContext() - { + { base.MessageContextRemoved += CustomMessageContext_MessageContextRemoved; } + + /// /// 当上下文过期,被移除时触发的时间 diff --git a/BotSharp.Channel.Weixin/Models/CustomMessageHandler.cs b/BotSharp.Channel.Weixin/Models/CustomMessageHandler.cs index cf28898a..6b5486ba 100644 --- a/BotSharp.Channel.Weixin/Models/CustomMessageHandler.cs +++ b/BotSharp.Channel.Weixin/Models/CustomMessageHandler.cs @@ -1,4 +1,4 @@ -/*---------------------------------------------------------------- +/*---------------------------------------------------------------- Copyright (C) 2018 Senparc 文件名:CustomMessageHandler.cs @@ -112,20 +112,22 @@ namespace BotSharp.Channel.Weixin.Models }; } - public override void OnExecuting() + public override async Task OnExecutingAsync(CancellationToken cancellationToken) { + var CurrentMessageContext = await GetCurrentMessageContext(); //测试MessageContext.StorageData if (CurrentMessageContext.StorageData == null) { CurrentMessageContext.StorageData = 0; } - base.OnExecuting(); + await base.OnExecutingAsync(cancellationToken); } - public override void OnExecuted() + public override async Task OnExecutedAsync(CancellationToken cancellationToken) { - base.OnExecuted(); + var CurrentMessageContext = await GetCurrentMessageContext(); CurrentMessageContext.StorageData = ((int)CurrentMessageContext.StorageData) + 1; + await base.OnExecutedAsync(cancellationToken); } /// diff --git a/BotSharp.Channel.Weixin/ModuleInjector.cs b/BotSharp.Channel.Weixin/ModuleInjector.cs index 28ddb27a..a26f41ba 100644 --- a/BotSharp.Channel.Weixin/ModuleInjector.cs +++ b/BotSharp.Channel.Weixin/ModuleInjector.cs @@ -1,4 +1,4 @@ -using BotSharp.Core.Modules; +using BotSharp.Core.Modules; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; @@ -17,7 +17,7 @@ namespace BotSharp.Channel.Weixin .AddSenparcWeixinServices(config); } - public void Configure(IApplicationBuilder app, IHostingEnvironment env/*, IOptions senparcSetting, IOptions senparcWeixinSetting*/) + public void Configure(IApplicationBuilder app, IWebHostEnvironment env/*, IOptions senparcSetting, IOptions senparcWeixinSetting*/) { //https://github.com/Senparc/Senparc.CO2NET/blob/master/Sample/Senparc.CO2NET.Sample.netcore/Startup.cs diff --git a/BotSharp.Core.UnitTest/BotSharp.Core.UnitTest.csproj b/BotSharp.Core.UnitTest/BotSharp.Core.UnitTest.csproj index 9af8eb99..5db15bbf 100644 --- a/BotSharp.Core.UnitTest/BotSharp.Core.UnitTest.csproj +++ b/BotSharp.Core.UnitTest/BotSharp.Core.UnitTest.csproj @@ -1,7 +1,7 @@ - + - netcoreapp2.2 + $(DefaultTargetFramework) false @@ -11,11 +11,11 @@ - - - - - + + + + + diff --git a/BotSharp.Core/BotSharp.Core.csproj b/BotSharp.Core/BotSharp.Core.csproj index f74d2942..22799830 100644 --- a/BotSharp.Core/BotSharp.Core.csproj +++ b/BotSharp.Core/BotSharp.Core.csproj @@ -1,5 +1,11 @@ - + + + $(DefaultTargetFramework) + true + 0.4.0 + + SAK SAK @@ -10,22 +16,20 @@ - netstandard2.0 - true Haiping Chen SciSharp STACK AI Bot Platform Builder - Open source AI Bot platform builder which is written in C# runs on .Net Core and is enterprise oriented. Integrated with multiple bot engines besides BotSharp bot engine. Modulized pipeline design make NLP tasks plugin easily. Abstract platform and NLP task, migrate existed chatbot from a platform into another platform perfectly through dump and restore. + + Open source AI Bot platform builder which is written in C# runs on .Net Core and is enterprise oriented. Integrated with multiple bot engines besides BotSharp bot engine. Modulized pipeline design make NLP tasks plugin easily. Abstract platform and NLP task, migrate existed chatbot from a platform into another platform perfectly through dump and restore. -If you feel that this project is helpful to you, please Star on the project, we will be very grateful. + If you feel that this project is helpful to you, please Star on the project, we will be very grateful. + git https://github.com/SciSharp/BotSharp NLU, Chatbot, Bot, AI Bot, Artificial Intelligence - 0.4.0 Support dialogue status tracking. Since 2018 Haiping Chen https://github.com/SciSharp/BotSharp - 0.4.0.0 https://raw.githubusercontent.com/SciSharp/BotSharp/master/docs/static/logos/BotSharp.png https://raw.githubusercontent.com/SciSharp/BotSharp/master/LICENSE @@ -61,17 +65,19 @@ If you feel that this project is helpful to you, please Star on the project, we - - - - + + + + + + + + - - - - - - + + + + diff --git a/BotSharp.Core/Modules/IModule.cs b/BotSharp.Core/Modules/IModule.cs index 2f8ed9f9..5202a0d3 100644 --- a/BotSharp.Core/Modules/IModule.cs +++ b/BotSharp.Core/Modules/IModule.cs @@ -1,4 +1,4 @@ -using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -28,6 +28,6 @@ namespace BotSharp.Core.Modules /// /// Instance of . /// - void Configure(IApplicationBuilder app, IHostingEnvironment env); + void Configure(IApplicationBuilder app, IWebHostEnvironment env); } } diff --git a/BotSharp.Core/Modules/ModulesStartup.cs b/BotSharp.Core/Modules/ModulesStartup.cs index 6e5cb2d2..3f18e4ac 100644 --- a/BotSharp.Core/Modules/ModulesStartup.cs +++ b/BotSharp.Core/Modules/ModulesStartup.cs @@ -1,4 +1,4 @@ -using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -93,7 +93,7 @@ namespace BotSharp.Core.Modules /// /// Instance of . /// - public void Configure(IApplicationBuilder app, IHostingEnvironment env) + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { foreach (IModule module in this._modules) { diff --git a/BotSharp.Platform.Articulate/BotSharp.Platform.Articulate.csproj b/BotSharp.Platform.Articulate/BotSharp.Platform.Articulate.csproj index 8235e9ed..9efdb2be 100644 --- a/BotSharp.Platform.Articulate/BotSharp.Platform.Articulate.csproj +++ b/BotSharp.Platform.Articulate/BotSharp.Platform.Articulate.csproj @@ -1,7 +1,7 @@ - + - netcoreapp2.2 + $(DefaultTargetFramework) @@ -9,7 +9,7 @@ - + diff --git a/BotSharp.Platform.Articulate/ModuleInjector.cs b/BotSharp.Platform.Articulate/ModuleInjector.cs index 61f78737..db9564b4 100644 --- a/BotSharp.Platform.Articulate/ModuleInjector.cs +++ b/BotSharp.Platform.Articulate/ModuleInjector.cs @@ -1,4 +1,4 @@ -using BotSharp.Core; +using BotSharp.Core; using BotSharp.Core.AgentStorage; using BotSharp.Core.Modules; using BotSharp.Platform.Articulate.Models; @@ -20,7 +20,7 @@ namespace BotSharp.Platform.Articulate PlatformConfigServiceRegister.Register("articulateAi", services, config); } - public void Configure(IApplicationBuilder app, IHostingEnvironment env) + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { } diff --git a/BotSharp.Platform.Dialogflow/BotSharp.Platform.Dialogflow.csproj b/BotSharp.Platform.Dialogflow/BotSharp.Platform.Dialogflow.csproj index c8bdaaae..54df0564 100644 --- a/BotSharp.Platform.Dialogflow/BotSharp.Platform.Dialogflow.csproj +++ b/BotSharp.Platform.Dialogflow/BotSharp.Platform.Dialogflow.csproj @@ -1,7 +1,7 @@ - + - netcoreapp2.2 + $(DefaultTargetFramework) true 0.2.2 Haiping Chen @@ -18,7 +18,7 @@ - + diff --git a/BotSharp.Platform.Dialogflow/ModuleInjector.cs b/BotSharp.Platform.Dialogflow/ModuleInjector.cs index cfa36689..5fb9c5d7 100644 --- a/BotSharp.Platform.Dialogflow/ModuleInjector.cs +++ b/BotSharp.Platform.Dialogflow/ModuleInjector.cs @@ -1,4 +1,4 @@ -using BotSharp.Core; +using BotSharp.Core; using BotSharp.Core.AgentStorage; using BotSharp.Core.ContextStorage; using BotSharp.Core.Modules; @@ -26,7 +26,7 @@ namespace BotSharp.Platform.Dialogflow ContextStorageServiceRegister.Register(services); } - public void Configure(IApplicationBuilder app, IHostingEnvironment env) + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { } diff --git a/BotSharp.Platform.Rasa/BotSharp.Platform.Rasa.csproj b/BotSharp.Platform.Rasa/BotSharp.Platform.Rasa.csproj index b326a68b..68ce76a9 100644 --- a/BotSharp.Platform.Rasa/BotSharp.Platform.Rasa.csproj +++ b/BotSharp.Platform.Rasa/BotSharp.Platform.Rasa.csproj @@ -1,11 +1,11 @@ - + - netcoreapp2.2 + $(DefaultTargetFramework) - + diff --git a/BotSharp.WebHost/BotSharp.WebHost.csproj b/BotSharp.WebHost/BotSharp.WebHost.csproj index b017b5e3..930dcd8d 100644 --- a/BotSharp.WebHost/BotSharp.WebHost.csproj +++ b/BotSharp.WebHost/BotSharp.WebHost.csproj @@ -1,30 +1,29 @@ - + - netcoreapp2.2 - Portable;win10-x64;centos.7-x64 + $(DefaultTargetFramework) AnyCPU;x64 Debug;Release; 4ee89154-9131-4e6b-8fd5-d4f04a8d77c4 - TRACE;DEBUG + $(DefineConstants);TRACE;DEBUG - DEBUG;TRACE;RASA + $(DefineConstants);RASA bin\RASA false - DEBUG;TRACE;NETCOREAPP;NETCOREAPP2_1 + $(DefineConstants); - TRACE;DEBUG + $(DefineConstants);TRACE;DEBUG false @@ -72,19 +71,11 @@ - - - - - - - - - - - + + + diff --git a/BotSharp.WebHost/Program.cs b/BotSharp.WebHost/Program.cs index 57d70b4a..306fe011 100644 --- a/BotSharp.WebHost/Program.cs +++ b/BotSharp.WebHost/Program.cs @@ -1,5 +1,6 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Hosting; using System; using System.IO; using System.Linq; @@ -10,42 +11,49 @@ namespace BotSharp.WebHost { public static void Main(string[] args) { - BuildWebHost(args).Run(); + CreateHostBuilder(args).Build().Run(); } - public static IWebHost BuildWebHost(string[] args) => - Microsoft.AspNetCore.WebHost.CreateDefaultBuilder(args) - .ConfigureAppConfiguration((hostingContext, config) => + + public static IHostBuilder CreateHostBuilder(string[] args) + { + return Host.CreateDefaultBuilder(args) + .ConfigureWebHostDefaults(webHost => { - var env = hostingContext.HostingEnvironment; - string dir = Path.GetFullPath(env.ContentRootPath); - string settingsFolder = Path.Combine(dir, "Settings"); - - // locate setting folder - if (!Directory.Exists(settingsFolder)) + webHost + .ConfigureAppConfiguration((hostingContext, config) => { - dir = Path.GetFullPath(env.ContentRootPath + "/.."); - } + var env = hostingContext.HostingEnvironment; + string dir = Path.GetFullPath(env.ContentRootPath); + string settingsFolder = Path.Combine(dir, "Settings"); - settingsFolder = Path.Combine(dir, "Settings"); + // locate setting folder + if (!Directory.Exists(settingsFolder)) + { + dir = Path.GetFullPath(env.ContentRootPath + "/.."); + } - if (!Directory.Exists(settingsFolder)) - { - dir = Path.GetFullPath(env.ContentRootPath + "/bin"); - } + settingsFolder = Path.Combine(dir, "Settings"); - settingsFolder = Path.Combine(dir, "Settings"); + if (!Directory.Exists(settingsFolder)) + { + dir = Path.GetFullPath(env.ContentRootPath + "/bin"); + } - Console.WriteLine($"Read settings from {settingsFolder}"); + settingsFolder = Path.Combine(dir, "Settings"); - var settings = Directory.GetFiles(settingsFolder, "*.json"); - settings.ToList().ForEach(setting => - { - config.AddJsonFile(setting, optional: false, reloadOnChange: true); - }); - }) - .UseUrls("http://0.0.0.0:3112") - .UseStartup() - .Build(); + Console.WriteLine($"Read settings from {settingsFolder}"); + + var settings = Directory.GetFiles(settingsFolder, "*.json"); + settings.ToList().ForEach(setting => + { + config.AddJsonFile(setting, optional: false, reloadOnChange: true); + }); + }) + .UseUrls("http://0.0.0.0:3112") + .UseStartup(); + + }); + } } } diff --git a/BotSharp.WebHost/Startup.cs b/BotSharp.WebHost/Startup.cs index 370fc526..c05f8078 100644 --- a/BotSharp.WebHost/Startup.cs +++ b/BotSharp.WebHost/Startup.cs @@ -1,9 +1,11 @@ -using BotSharp.Core.Modules; +using BotSharp.Core.Modules; using DotNetToolkit.JwtHelper; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Microsoft.OpenApi.Models; using Newtonsoft.Json.Serialization; using Swashbuckle.AspNetCore.Swagger; using Swashbuckle.AspNetCore.SwaggerUI; @@ -15,7 +17,7 @@ using System.Linq; namespace BotSharp.WebHost { - public partial class Startup + public class Startup { public Startup(IConfiguration configuration) { @@ -41,14 +43,15 @@ namespace BotSharp.WebHost }); services.AddJwtAuth(Configuration); - var mvcBuilder = services.AddMvc(options => - { - options.RespectBrowserAcceptHeader = true; - }).AddJsonOptions(options => - { - options.SerializerSettings.Converters.Add(new Newtonsoft.Json.Converters.StringEnumConverter()); - options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); - }); + services.AddMvc(options => + { + options.RespectBrowserAcceptHeader = true; + }) + .AddNewtonsoftJson(options => + { + options.SerializerSettings.Converters.Add(new Newtonsoft.Json.Converters.StringEnumConverter()); + options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); + }); //PlatformModuleAssembyLoader.LoadAssemblies(Configuration, assembly => mvcBuilder.AddApplicationPart(assembly)); @@ -56,26 +59,27 @@ namespace BotSharp.WebHost services.AddSwaggerGen(c => { - c.AddSecurityDefinition("Bearer", new ApiKeyScheme() + var scheme = new OpenApiSecurityScheme() { - In = "header", + In = ParameterLocation.Header, Description = "Please insert JWT with Bearer schema. Example: \"Authorization: Bearer {token}\"", Name = "Authorization", - Type = "apiKey" - }); + Type = SecuritySchemeType.ApiKey + }; + c.AddSecurityDefinition("Bearer", scheme); - c.AddSecurityRequirement(new Dictionary> { - { "Bearer", Enumerable.Empty() }, - }); - - var info = Configuration.GetSection("Swagger").Get(); + var info = Configuration.GetSection("Swagger").Get(); c.SwaggerDoc(info.Version, info); - //var filePath = Path.Combine(PlatformServices.Default.Application.ApplicationBasePath, "BotSharp.RestApi.xml"); - //c.IncludeXmlComments(filePath); + var filePath = Path.Combine(AppContext.BaseDirectory, "BotSharp.RestApi.xml"); + if (File.Exists(filePath)) + { + c.IncludeXmlComments(filePath); + } + - c.OperationFilter(); - }); + //c.OperationFilter(); + }).AddSwaggerGenNewtonsoftSupport(); // register platform dependency /*services.AddTransient((provider) => @@ -84,7 +88,7 @@ namespace BotSharp.WebHost });*/ } - public void Configure(IApplicationBuilder app, IHostingEnvironment env) + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { @@ -95,11 +99,11 @@ namespace BotSharp.WebHost app.UseDefaultFiles(); app.UseStaticFiles(); - + app.UseRouting(); app.UseSwagger(); app.UseSwaggerUI(c => { - var info = Configuration.GetSection("Swagger").Get(); + var info = Configuration.GetSection("Swagger").Get(); c.SupportedSubmitMethods(SubmitMethod.Get, SubmitMethod.Post, SubmitMethod.Put, SubmitMethod.Patch, SubmitMethod.Delete); c.ShowExtensions(); @@ -129,8 +133,11 @@ namespace BotSharp.WebHost await next.Invoke(); }); app.UseAuthentication(); - - app.UseMvc(); + app.UseAuthorization(); + app.UseEndpoints(routes=> + { + routes.MapControllers(); + }); this.modulesStartup.Configure(app, env); diff --git a/BotSharp.WebHost/SwaggerFileUploadOperation.cs b/BotSharp.WebHost/SwaggerFileUploadOperation.cs index 259faf34..9e71e80a 100644 --- a/BotSharp.WebHost/SwaggerFileUploadOperation.cs +++ b/BotSharp.WebHost/SwaggerFileUploadOperation.cs @@ -1,4 +1,5 @@ -using Swashbuckle.AspNetCore.Swagger; +using Microsoft.OpenApi.Models; +using Swashbuckle.AspNetCore.Swagger; using Swashbuckle.AspNetCore.SwaggerGen; using System; using System.Collections.Generic; @@ -7,24 +8,26 @@ using System.Text; namespace BotSharp.WebHost { - public class SwaggerFileUploadOperation : IOperationFilter - { - public void Apply(Operation operation, OperationFilterContext context) - { - if (operation.OperationId == "Import") - { - operation.Parameters.Clear(); + //public class SwaggerFileUploadOperation : IOperationFilter + //{ - operation.Parameters.Add(new NonBodyParameter - { - Name = "uploadedFile", - In = "formData", - Description = "Upload Zip File, meta.json is the extra data for customized function.", - Required = true, - Type = "file" - }); - operation.Consumes.Add("multipart/form-data"); - } - } - } + // public void Apply(OpenApiOperation operation, OperationFilterContext context) + // { + // if (operation.OperationId == "Import") + // { + // operation.Parameters.Clear(); + + // operation.Parameters.Add(new OpenApiParameter + // { + // Name = "uploadedFile", + // In = "formData", + // Description = "Upload Zip File, meta.json is the extra data for customized function.", + // Required = true, + // Type = "file" + // }); + // operation.Consumes.Add("multipart/form-data"); + // operation. + // } + // } + //} } diff --git a/BotSharp.sln b/BotSharp.sln index ec571647..db0c559c 100644 --- a/BotSharp.sln +++ b/BotSharp.sln @@ -19,6 +19,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.Platform.Rasa", "B EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.Platform.Articulate", "BotSharp.Platform.Articulate\BotSharp.Platform.Articulate.csproj", "{7290AC89-88DE-4CF8-946A-A1BB0E4C30EB}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "solution items", "solution items", "{44D9C8BF-FA7B-4FA1-AF2D-93BC223D11B6}" + ProjectSection(SolutionItems) = preProject + .editorconfig = .editorconfig + Directory.Build.props = Directory.Build.props + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU diff --git a/Directory.Build.props b/Directory.Build.props new file mode 100644 index 00000000..2ca8e7be --- /dev/null +++ b/Directory.Build.props @@ -0,0 +1,8 @@ + + + netcoreapp3.1 + 3.1.7 + 0.2.1 + + + \ No newline at end of file From b481b0b6bf245b599f860afc3965e24ed41c2e04 Mon Sep 17 00:00:00 2001 From: John King Date: Mon, 7 Sep 2020 18:33:04 +0800 Subject: [PATCH 2/3] fix compile --- BotSharp.Platform.Rasa/ModuleInjector.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/BotSharp.Platform.Rasa/ModuleInjector.cs b/BotSharp.Platform.Rasa/ModuleInjector.cs index c430792c..7f817e66 100644 --- a/BotSharp.Platform.Rasa/ModuleInjector.cs +++ b/BotSharp.Platform.Rasa/ModuleInjector.cs @@ -1,4 +1,4 @@ -using BotSharp.Core; +using BotSharp.Core; using BotSharp.Core.AgentStorage; using BotSharp.Core.Modules; using BotSharp.Platform.Rasa.Models; @@ -21,7 +21,7 @@ namespace BotSharp.Platform.Rasa PlatformConfigServiceRegister.Register("rasaAi", services, config); } - public void Configure(IApplicationBuilder app, IHostingEnvironment env) + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { } From aa746f92042a9cc371e226e921ec7168ec2fda88 Mon Sep 17 00:00:00 2001 From: John King Date: Tue, 8 Sep 2020 15:23:07 +0800 Subject: [PATCH 3/3] fix swagger issue, fix logging --- .../Abstractions/IInitializationLoader.cs | 5 +-- BotSharp.Core/Engines/BotEngineBase.cs | 9 +++-- BotSharp.Core/Engines/DbInitializer.cs | 4 +-- .../BotSharp.Platform.Dialogflow.csproj | 5 +++ .../Controllers/AgentController.cs | 4 +-- BotSharp.WebHost/Settings/logging.json | 28 ++++++++------- BotSharp.WebHost/Startup.cs | 24 +++++++++---- .../SwaggerFileUploadOperation.cs | 34 ++++++++----------- 8 files changed, 64 insertions(+), 49 deletions(-) diff --git a/BotSharp.Core/Abstractions/IInitializationLoader.cs b/BotSharp.Core/Abstractions/IInitializationLoader.cs index befa988a..e3d1638e 100644 --- a/BotSharp.Core/Abstractions/IInitializationLoader.cs +++ b/BotSharp.Core/Abstractions/IInitializationLoader.cs @@ -1,5 +1,6 @@ -using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Hosting; using System; using System.Collections.Generic; using System.Text; @@ -9,6 +10,6 @@ namespace BotSharp.Core.Abstractions public interface IInitializationLoader { int Priority { get; } - void Initialize(IConfiguration config, IHostingEnvironment env); + void Initialize(IConfiguration config, IWebHostEnvironment env); } } diff --git a/BotSharp.Core/Engines/BotEngineBase.cs b/BotSharp.Core/Engines/BotEngineBase.cs index 51c6aae6..240c430d 100644 --- a/BotSharp.Core/Engines/BotEngineBase.cs +++ b/BotSharp.Core/Engines/BotEngineBase.cs @@ -1,4 +1,4 @@ -using BotSharp.Platform.Models; +using BotSharp.Platform.Models; using BotSharp.Platform.Models.AiRequest; using BotSharp.Platform.Models.AiResponse; using BotSharp.Platform.Models.Entities; @@ -27,7 +27,7 @@ namespace BotSharp.Core.Engines Dc = new DefaultDataContextLoader().GetDefaultDc(); } - public async Task TextRequest(AiRequest request) + public Task TextRequest(AiRequest request) { var preditor = new BotPredictor(); var doc = preditor.Predict(Agent, new AiRequest @@ -44,8 +44,7 @@ namespace BotSharp.Core.Engines doc.Sentences[0].Entities = new List(); } doc.Sentences[0].Entities.ForEach(x => parameters[x.Entity] = x.Value); - - return new AiResponse + return Task.FromResult(new AiResponse { /*Lang = request.Language, Timestamp = DateTime.UtcNow, @@ -66,7 +65,7 @@ namespace BotSharp.Core.Engines IntentName = doc.Sentences[0].Intent?.Label } }*/ - }; + }); } /*public TrainingCorpus GetIntentExpressions(AgentBase agent) diff --git a/BotSharp.Core/Engines/DbInitializer.cs b/BotSharp.Core/Engines/DbInitializer.cs index d9d5c066..3a955d25 100644 --- a/BotSharp.Core/Engines/DbInitializer.cs +++ b/BotSharp.Core/Engines/DbInitializer.cs @@ -1,4 +1,4 @@ -using BotSharp.Core.Abstractions; +using BotSharp.Core.Abstractions; using DotNetToolkit; using EntityFrameworkCore.BootKit; using Microsoft.AspNetCore.Hosting; @@ -14,7 +14,7 @@ namespace BotSharp.Core.Engines { public int Priority => 1; - public void Initialize(IConfiguration config, IHostingEnvironment env) + public void Initialize(IConfiguration config, IWebHostEnvironment env) { var dc = new DefaultDataContextLoader().GetDefaultDc(); diff --git a/BotSharp.Platform.Dialogflow/BotSharp.Platform.Dialogflow.csproj b/BotSharp.Platform.Dialogflow/BotSharp.Platform.Dialogflow.csproj index 54df0564..e5f20416 100644 --- a/BotSharp.Platform.Dialogflow/BotSharp.Platform.Dialogflow.csproj +++ b/BotSharp.Platform.Dialogflow/BotSharp.Platform.Dialogflow.csproj @@ -4,6 +4,11 @@ $(DefaultTargetFramework) true 0.2.2 + true + $(NoWarn);1591 + + + Haiping Chen BotSharp platform emulator which is compatible with Google Dialogflow. https://github.com/Oceania2018/botsharp-dialogflow diff --git a/BotSharp.Platform.Dialogflow/Controllers/AgentController.cs b/BotSharp.Platform.Dialogflow/Controllers/AgentController.cs index c5623a7e..e36f95a5 100644 --- a/BotSharp.Platform.Dialogflow/Controllers/AgentController.cs +++ b/BotSharp.Platform.Dialogflow/Controllers/AgentController.cs @@ -1,4 +1,4 @@ -using BotSharp.Platform.Dialogflow.Models; +using BotSharp.Platform.Dialogflow.Models; using BotSharp.Platform.Dialogflow.ViewModels; using BotSharp.Platform.Models.Agents; using Microsoft.AspNetCore.Http; @@ -31,7 +31,7 @@ namespace BotSharp.Platform.Dialogflow.Controllers /// /// Import a agent from a uploaded zip file /// - /// + /// Upload Zip File, meta.json is the extra data for customized function. /// [HttpPost("import")] [ProducesResponseType(typeof(ImportedAgentViewModel), 200)] diff --git a/BotSharp.WebHost/Settings/logging.json b/BotSharp.WebHost/Settings/logging.json index 26bb0ac7..537f535e 100644 --- a/BotSharp.WebHost/Settings/logging.json +++ b/BotSharp.WebHost/Settings/logging.json @@ -1,15 +1,19 @@ -{ +{ "Logging": { - "IncludeScopes": false, - "Debug": { - "LogLevel": { - "Default": "Warning" - } - }, - "Console": { - "LogLevel": { - "Default": "Warning" - } - } + //"IncludeScopes": false, + "LogLevel": { + "Default": "Information", + "Microsoft.Hosting.Lifetime": "Information" + }//, + //"Debug": { + // "LogLevel": { + // "Default": "Warning" + // } + //}, + //"Console": { + // "LogLevel": { + // "Default": "Warning" + // } + //} } } diff --git a/BotSharp.WebHost/Startup.cs b/BotSharp.WebHost/Startup.cs index c05f8078..128678b4 100644 --- a/BotSharp.WebHost/Startup.cs +++ b/BotSharp.WebHost/Startup.cs @@ -11,6 +11,7 @@ using Swashbuckle.AspNetCore.Swagger; using Swashbuckle.AspNetCore.SwaggerUI; using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; using System.Drawing; using System.IO; using System.Linq; @@ -59,14 +60,20 @@ namespace BotSharp.WebHost services.AddSwaggerGen(c => { - var scheme = new OpenApiSecurityScheme() + c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme() { In = ParameterLocation.Header, Description = "Please insert JWT with Bearer schema. Example: \"Authorization: Bearer {token}\"", Name = "Authorization", - Type = SecuritySchemeType.ApiKey - }; - c.AddSecurityDefinition("Bearer", scheme); + Type = SecuritySchemeType.ApiKey, + Scheme = "Bearer" + }); + c.AddSecurityRequirement(new OpenApiSecurityRequirement + { + { new OpenApiSecurityScheme(){ + Reference = new OpenApiReference{Type = ReferenceType.SecurityScheme ,Id = "Bearer"} + }, new List(0) } + }); var info = Configuration.GetSection("Swagger").Get(); c.SwaggerDoc(info.Version, info); @@ -76,9 +83,14 @@ namespace BotSharp.WebHost { c.IncludeXmlComments(filePath); } - - //c.OperationFilter(); + var xmlPath = Path.Combine(AppContext.BaseDirectory, "BotSharp.Platform.Dialogflow.xml"); + if (File.Exists(xmlPath)) + { + c.IncludeXmlComments(xmlPath); + } + + c.OperationFilter(); }).AddSwaggerGenNewtonsoftSupport(); // register platform dependency diff --git a/BotSharp.WebHost/SwaggerFileUploadOperation.cs b/BotSharp.WebHost/SwaggerFileUploadOperation.cs index 9e71e80a..0d71c963 100644 --- a/BotSharp.WebHost/SwaggerFileUploadOperation.cs +++ b/BotSharp.WebHost/SwaggerFileUploadOperation.cs @@ -8,26 +8,20 @@ using System.Text; namespace BotSharp.WebHost { - //public class SwaggerFileUploadOperation : IOperationFilter - //{ + public class SwaggerFileUploadOperation : IOperationFilter + { - // public void Apply(OpenApiOperation operation, OperationFilterContext context) - // { - // if (operation.OperationId == "Import") - // { - // operation.Parameters.Clear(); + public void Apply(OpenApiOperation operation, OperationFilterContext context) + { + if(context.MethodInfo.Name == "Import") + { + if(operation.RequestBody.Content.FirstOrDefault().Value?.Schema?.Properties.ContainsKey("uploadedFile") == true) + { + var p = operation.RequestBody.Content.FirstOrDefault(); + p.Value.Schema.Properties["uploadedFile"].Description = "Upload Zip File, meta.json is the extra data for customized function."; + } + } - // operation.Parameters.Add(new OpenApiParameter - // { - // Name = "uploadedFile", - // In = "formData", - // Description = "Upload Zip File, meta.json is the extra data for customized function.", - // Required = true, - // Type = "file" - // }); - // operation.Consumes.Add("multipart/form-data"); - // operation. - // } - // } - //} + } + } }