From 39870408b5a0c63a5d4daf05d5422b55a0ea7800 Mon Sep 17 00:00:00 2001 From: MysticBoy Date: Sun, 3 Nov 2019 02:10:17 +0800 Subject: [PATCH] Upgrade to .Net Core 3.0 --- .../IoTSharp.Edge.ModBus.csproj | 21 ++++++------ IoTSharp.Edge.ModBus/Program.cs | 32 +++++++++++++++---- IoTSharp.Edge.ModBus/Startup.cs | 26 ++++++++------- IoTSharp.Edge.ModBus/reame.md | 5 ++- IoTSharp.Edges.sln | 23 +++++++++++++ 5 files changed, 76 insertions(+), 31 deletions(-) diff --git a/IoTSharp.Edge.ModBus/IoTSharp.Edge.ModBus.csproj b/IoTSharp.Edge.ModBus/IoTSharp.Edge.ModBus.csproj index fe9096d3..31662aae 100644 --- a/IoTSharp.Edge.ModBus/IoTSharp.Edge.ModBus.csproj +++ b/IoTSharp.Edge.ModBus/IoTSharp.Edge.ModBus.csproj @@ -1,7 +1,7 @@  - netcoreapp2.2 + netcoreapp3.0 InProcess @@ -20,24 +20,23 @@ + - - - + - - - - - - - + + + + + + + diff --git a/IoTSharp.Edge.ModBus/Program.cs b/IoTSharp.Edge.ModBus/Program.cs index 82011aff..319f1503 100644 --- a/IoTSharp.Edge.ModBus/Program.cs +++ b/IoTSharp.Edge.ModBus/Program.cs @@ -1,7 +1,12 @@ -using IoTSharp.Extensions; +using IoT.Things.ModBus.Services; +using IoTSharp.Extensions; +using IoTSharp.Extensions.AspNetCore; using Microsoft.AspNetCore; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using QuartzHostedService; namespace IoT.Things.ModBus { @@ -9,14 +14,27 @@ namespace IoT.Things.ModBus { public static void Main(string[] args) { - CreateWebHostBuilder(args).Build().RunAsEnv(); + CreateHostBuilder(args).Build().Run(); } - public static IWebHostBuilder CreateWebHostBuilder(string[] args) => - WebHost.CreateDefaultBuilder(args) - .UseContentRootAsEnv() - .UseStartup(); + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureWindowsServices() + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.ConfigureKestrel(serverOptions => + { + serverOptions.AllowSynchronousIO = true; + }); + webBuilder.UseStartup(); + }) + .ConfigureQuartzHost() + .ConfigureServices(services => + { + services.AddHostedService(); + + }); + - } } \ No newline at end of file diff --git a/IoTSharp.Edge.ModBus/Startup.cs b/IoTSharp.Edge.ModBus/Startup.cs index e08daee2..827c652c 100644 --- a/IoTSharp.Edge.ModBus/Startup.cs +++ b/IoTSharp.Edge.ModBus/Startup.cs @@ -1,15 +1,16 @@ -using IoT.Things.ModBus.Jobs; +using CrystalQuartz.AspNetCore; +using IoT.Things.ModBus.Jobs; using IoT.Things.ModBus.Services; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Quartz; using QuartzHostedService; -using Quartzmin; using System; using System.Linq; using System.Reflection; @@ -28,8 +29,7 @@ namespace IoT.Things.ModBus // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { - services.AddQuartzmin(); - services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); + services.AddControllersWithViews(); services.AddOptions(); services.Configure(Configuration); @@ -39,7 +39,7 @@ namespace IoT.Things.ModBus }); services.AddQuartzHostedService(); services.AddTransient(); - services.AddHostedService(); + services.AddSingleton(options => { var mqtt = new IoTSharp.EdgeSdk.MQTT.MQTTClient(); @@ -49,20 +49,22 @@ namespace IoT.Things.ModBus // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - public void Configure(IApplicationBuilder app, IHostingEnvironment env, IOptions options, ISchedulerFactory factory) + public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IOptions options, ISchedulerFactory factory) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } - app.UseQuartzmin(new QuartzminOptions() + + app.UseRouting(); + + + app.UseEndpoints(endpoints => { - Scheduler = factory.GetScheduler().Result, - ProductName = typeof(Startup).Assembly.GetName().Name, + endpoints.MapControllers(); }); - app.UseMvc(); - - + app.UseCrystalQuartz(() => factory.GetScheduler().Result); + } } } \ No newline at end of file diff --git a/IoTSharp.Edge.ModBus/reame.md b/IoTSharp.Edge.ModBus/reame.md index 8ee4e99f..3f96f3e6 100644 --- a/IoTSharp.Edge.ModBus/reame.md +++ b/IoTSharp.Edge.ModBus/reame.md @@ -4,4 +4,7 @@ 相关文章请参考 -https://www.cnblogs.com/MysticBoy/p/11110364.html \ No newline at end of file +https://www.cnblogs.com/MysticBoy/p/11110364.html + + +由于使用到的HSL组件已经闭源,本项目后期会从本项目中删除 \ No newline at end of file diff --git a/IoTSharp.Edges.sln b/IoTSharp.Edges.sln index 5bd35366..914261fb 100644 --- a/IoTSharp.Edges.sln +++ b/IoTSharp.Edges.sln @@ -6,6 +6,7 @@ MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{D5C97089-F896-436D-8E99-27B2E43BC65F}" ProjectSection(SolutionItems) = preProject appveyor.yml = appveyor.yml + GitVersion.yml = GitVersion.yml LICENSE = LICENSE README.md = README.md roadmap.md = roadmap.md @@ -23,6 +24,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IoTSharp.Edge.ModBus", "IoT EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IoTSharp.Extensions", "IoTSharp.Extensions\IoTSharp.Extensions.csproj", "{551E62E3-51DA-4C1D-8DBB-7346A29EE817}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IoTSharp.Extensions.AspNetCore", "IoTSharp.Extensions.AspNetCore\IoTSharp.Extensions.AspNetCore.csproj", "{AC80DA58-F40E-4B3C-8271-A25F65FEB0CB}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -163,6 +166,26 @@ Global {551E62E3-51DA-4C1D-8DBB-7346A29EE817}.Release|x64.Build.0 = Release|Any CPU {551E62E3-51DA-4C1D-8DBB-7346A29EE817}.Release|x86.ActiveCfg = Release|Any CPU {551E62E3-51DA-4C1D-8DBB-7346A29EE817}.Release|x86.Build.0 = Release|Any CPU + {AC80DA58-F40E-4B3C-8271-A25F65FEB0CB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AC80DA58-F40E-4B3C-8271-A25F65FEB0CB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AC80DA58-F40E-4B3C-8271-A25F65FEB0CB}.Debug|ARM.ActiveCfg = Debug|Any CPU + {AC80DA58-F40E-4B3C-8271-A25F65FEB0CB}.Debug|ARM.Build.0 = Debug|Any CPU + {AC80DA58-F40E-4B3C-8271-A25F65FEB0CB}.Debug|ARM64.ActiveCfg = Debug|Any CPU + {AC80DA58-F40E-4B3C-8271-A25F65FEB0CB}.Debug|ARM64.Build.0 = Debug|Any CPU + {AC80DA58-F40E-4B3C-8271-A25F65FEB0CB}.Debug|x64.ActiveCfg = Debug|Any CPU + {AC80DA58-F40E-4B3C-8271-A25F65FEB0CB}.Debug|x64.Build.0 = Debug|Any CPU + {AC80DA58-F40E-4B3C-8271-A25F65FEB0CB}.Debug|x86.ActiveCfg = Debug|Any CPU + {AC80DA58-F40E-4B3C-8271-A25F65FEB0CB}.Debug|x86.Build.0 = Debug|Any CPU + {AC80DA58-F40E-4B3C-8271-A25F65FEB0CB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AC80DA58-F40E-4B3C-8271-A25F65FEB0CB}.Release|Any CPU.Build.0 = Release|Any CPU + {AC80DA58-F40E-4B3C-8271-A25F65FEB0CB}.Release|ARM.ActiveCfg = Release|Any CPU + {AC80DA58-F40E-4B3C-8271-A25F65FEB0CB}.Release|ARM.Build.0 = Release|Any CPU + {AC80DA58-F40E-4B3C-8271-A25F65FEB0CB}.Release|ARM64.ActiveCfg = Release|Any CPU + {AC80DA58-F40E-4B3C-8271-A25F65FEB0CB}.Release|ARM64.Build.0 = Release|Any CPU + {AC80DA58-F40E-4B3C-8271-A25F65FEB0CB}.Release|x64.ActiveCfg = Release|Any CPU + {AC80DA58-F40E-4B3C-8271-A25F65FEB0CB}.Release|x64.Build.0 = Release|Any CPU + {AC80DA58-F40E-4B3C-8271-A25F65FEB0CB}.Release|x86.ActiveCfg = Release|Any CPU + {AC80DA58-F40E-4B3C-8271-A25F65FEB0CB}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE -- GitLab