1
1
懒得勤快 6 жил өмнө
parent
commit
b0059d609b

+ 5 - 3
Masuit.Tools.AspNetCore.ResumeFileResults.WebTest/Masuit.Tools.AspNetCore.ResumeFileResults.WebTest.csproj

@@ -1,8 +1,10 @@
 <Project Sdk="Microsoft.NET.Sdk.Web">
 
   <PropertyGroup>
-    <TargetFramework>netcoreapp2.2</TargetFramework>
+    <TargetFramework>netcoreapp3.0</TargetFramework>
     <AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
+    <RunAnalyzersDuringBuild>false</RunAnalyzersDuringBuild>
+    <RunAnalyzersDuringLiveAnalysis>false</RunAnalyzersDuringLiveAnalysis>
   </PropertyGroup>
 
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
@@ -18,8 +20,8 @@
   </ItemGroup>
 
   <ItemGroup>
-    <PackageReference Include="Microsoft.AspNetCore.App" />
-    <PackageReference Include="Swashbuckle.AspNetCore" Version="4.0.1" />
+    <PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.0.0" />
+    <PackageReference Include="Swashbuckle.AspNetCore" Version="5.0.0-rc4" />
   </ItemGroup>
 
   <ItemGroup>

+ 3 - 12
Masuit.Tools.AspNetCore.ResumeFileResults.WebTest/Program.cs

@@ -1,12 +1,5 @@
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using System.Threading.Tasks;
-using Microsoft.AspNetCore;
-using Microsoft.AspNetCore.Hosting;
-using Microsoft.Extensions.Configuration;
-using Microsoft.Extensions.Logging;
+using Microsoft.AspNetCore.Hosting;
+using Microsoft.Extensions.Hosting;
 
 namespace Masuit.Tools.AspNetCore.ResumeFileResults.WebTest
 {
@@ -17,8 +10,6 @@ namespace Masuit.Tools.AspNetCore.ResumeFileResults.WebTest
             CreateWebHostBuilder(args).Build().Run();
         }
 
-        public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
-            WebHost.CreateDefaultBuilder(args)
-                .UseStartup<Startup>();
+        public static IHostBuilder CreateWebHostBuilder(string[] args) => Host.CreateDefaultBuilder(args).ConfigureWebHostDefaults(builder => builder.UseStartup<Startup>());
     }
 }

+ 25 - 23
Masuit.Tools.AspNetCore.ResumeFileResults.WebTest/Startup.cs

@@ -1,12 +1,13 @@
 using Masuit.Tools.Core.AspNetCore;
 using Microsoft.AspNetCore.Builder;
 using Microsoft.AspNetCore.Hosting;
-using Microsoft.AspNetCore.Mvc;
 using Microsoft.Extensions.Configuration;
 using Microsoft.Extensions.DependencyInjection;
-using Microsoft.Extensions.PlatformAbstractions;
-using Swashbuckle.AspNetCore.Swagger;
-using System.IO;
+using Microsoft.Extensions.WebEncoders;
+using Microsoft.OpenApi.Models;
+using System;
+using System.Text.Encodings.Web;
+using System.Text.Unicode;
 
 namespace Masuit.Tools.AspNetCore.ResumeFileResults.WebTest
 {
@@ -24,29 +25,25 @@ namespace Masuit.Tools.AspNetCore.ResumeFileResults.WebTest
             services.AddResumeFileResult();
             services.AddSwaggerGen(c =>
             {
-                c.SwaggerDoc("v1", new Info
+                c.SwaggerDoc("v1", new OpenApiInfo
                 {
-                    Title = "API文档",
                     Version = "v1",
-                    Contact = new Contact()
-                    {
-                        Email = "[email protected]",
-                        Name = "懒得勤快",
-                        Url = "https://masuit.com"
-                    },
-                    Description = "断点续传和多线程下载测试站点",
-                    License = new License()
-                    {
-                        Name = "懒得勤快",
-                        Url = "https://masuit.com"
-                    }
+                    Title = $"接口文档",
+                    Description = $"HTTP API ",
+                    Contact = new OpenApiContact { Name = "懒得勤快", Email = "[email protected]", Url = new Uri("https://masuit.coom") },
+                    License = new OpenApiLicense { Name = "懒得勤快", Url = new Uri("https://masuit.com") }
                 });
-                c.DescribeAllEnumsAsStrings();
-                var basePath = PlatformServices.Default.Application.ApplicationBasePath;
-                var xmlPath = Path.Combine(basePath, "Masuit.Tools.AspNetCore.ResumeFileResults.WebTest.xml");
+                var xmlPath = AppContext.BaseDirectory + "Masuit.Tools.AspNetCore.ResumeFileResults.WebTest.xml";
                 c.IncludeXmlComments(xmlPath);
             });
-            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
+            services.AddControllers().AddControllersAsServices(); // WebAPI
+            services.AddControllersWithViews().AddControllersAsServices().AddViewComponentsAsServices().AddTagHelpersAsServices(); // MVC
+            services.AddRazorPages().AddViewComponentsAsServices().AddTagHelpersAsServices(); // RazorPage
+
+            services.Configure<WebEncoderOptions>(options =>
+            {
+                options.TextEncoderSettings = new TextEncoderSettings(UnicodeRanges.All);
+            }); //解决razor视图中中文被编码的问题
         }
 
         public void Configure(IApplicationBuilder app, IHostingEnvironment env)
@@ -59,7 +56,12 @@ namespace Masuit.Tools.AspNetCore.ResumeFileResults.WebTest
             {
                 c.SwaggerEndpoint($"{Configuration["Swagger:VirtualPath"]}/swagger/v1/swagger.json", "断点续传和多线程下载测试站点");
             });
-            app.UseMvcWithDefaultRoute();
+            app.UseRouting(); // 放在 UseStaticFiles 之后
+            app.UseEndpoints(endpoints =>
+           {
+               endpoints.MapControllers(); // 属性路由
+               endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}"); // 默认路由
+           });
         }
     }
 }

+ 7 - 3
Masuit.Tools.Core.UnitTest/AspNetCore/TestBase.cs

@@ -17,16 +17,20 @@ namespace Masuit.Tools.Core.UnitTest.AspNetCore
             var di = new DirectoryInfo(path).Parent.Parent.Parent;
 
             // Arrange
-            Server = new TestServer(new WebHostBuilder().UseStartup<Startup>().UseContentRoot(di.FullName));
+            //var hostBuilder = Host.CreateDefaultBuilder().ConfigureWebHostDefaults(configurationBuilder => configurationBuilder.UseStartup<Startup>().UseContentRoot(di.FullName));
+            //var host = hostBuilder.Build();
+            //host.Run();
+            //todo:.NET Core3.0创建测试服务器
+            Server = new TestServer(new WebHostBuilder().UseStartup<Startup>());
             Client = Server.CreateClient();
         }
 
-        public HttpClient Client { get; }
+        public HttpClient Client { get; private set; }
 
         public EntityTagHeaderValue EntityTag { get; } = new EntityTagHeaderValue("\"TestFile\"");
 
         public DateTimeOffset LastModified { get; } = new DateTimeOffset(2016, 1, 1, 0, 0, 0, TimeSpan.Zero);
 
-        public TestServer Server { get; }
+        public TestServer Server { get; private set; }
     }
 }

+ 3 - 2
Masuit.Tools.Core.UnitTest/Masuit.Tools.Core.UnitTest.csproj

@@ -1,13 +1,14 @@
 <Project Sdk="Microsoft.NET.Sdk">
 
   <PropertyGroup>
-    <TargetFramework>netcoreapp2.2</TargetFramework>
+    <TargetFramework>netcoreapp3.0</TargetFramework>
 
     <IsPackable>false</IsPackable>
   </PropertyGroup>
 
   <ItemGroup>
-    <PackageReference Include="Microsoft.AspNetCore.TestHost" Version="2.2.0" />
+    <PackageReference Include="Microsoft.AspNetCore.TestHost" Version="3.0.0" />
+    <PackageReference Include="Microsoft.Extensions.Hosting" Version="3.0.0" />
     <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.3.0" />
     <PackageReference Include="xunit" Version="2.4.1" />
     <PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">

+ 1 - 2
Masuit.Tools.Core/Config/CoreConfig.cs

@@ -1,5 +1,4 @@
 using Microsoft.Extensions.Configuration;
-using Microsoft.Extensions.DependencyInjection;
 using System;
 
 namespace Masuit.Tools.Core.Config
@@ -12,6 +11,6 @@ namespace Masuit.Tools.Core.Config
         /// <summary>
         /// 配置对象
         /// </summary>
-        internal static IConfiguration Configuration => new ConfigurationBuilder().SetBasePath(AppContext.BaseDirectory).AddJsonFile("appsettings.json", true, true).AddInMemoryCollection().AddEnvironmentVariables().AddApplicationInsightsSettings().Build();
+        internal static IConfiguration Configuration => new ConfigurationBuilder().SetBasePath(AppContext.BaseDirectory).AddJsonFile("appsettings.json", true, true).AddInMemoryCollection().AddEnvironmentVariables().Build();
     }
 }

+ 0 - 20
Masuit.Tools.Core/Database/DataExt.cs

@@ -1,6 +1,5 @@
 using System;
 using System.Data;
-using System.Data.SqlClient;
 using System.Reflection;
 
 namespace Masuit.Tools.Database
@@ -10,25 +9,6 @@ namespace Masuit.Tools.Database
     /// </summary>
     public static class DataExt
     {
-        /// <summary>
-        /// 根据SqlDataReader映射到实体模型
-        /// </summary>
-        /// <typeparam name="T">实体模型</typeparam>
-        /// <param name="reader">SqlDataReader</param>
-        /// <returns>映射后的实体模型</returns>
-        public static T MapEntity<T>(this SqlDataReader reader) where T : class
-        {
-            T obj = Assembly.GetAssembly(typeof(T)).CreateInstance(typeof(T).FullName) as T;
-            Type type = typeof(T);
-            PropertyInfo[] properties = type.GetProperties();
-            foreach (PropertyInfo p in properties)
-            {
-                p.SetValue(obj, reader[p.Name]);
-            }
-
-            return obj;
-        }
-
         /// <summary>
         /// 根据DataRow映射到实体模型
         /// </summary>

+ 40 - 50
Masuit.Tools.Core/Files/SevenZipCompressor.cs

@@ -40,19 +40,17 @@ namespace Masuit.Tools.Files
         /// <returns>文件流</returns>
         public MemoryStream ZipStream(List<string> files, string rootdir = "")
         {
-            using (var archive = CreateZipArchive(files, rootdir))
+            using var archive = CreateZipArchive(files, rootdir);
+            var ms = new MemoryStream();
+            archive.SaveTo(ms, new WriterOptions(CompressionType.Deflate)
             {
-                var ms = new MemoryStream();
-                archive.SaveTo(ms, new WriterOptions(CompressionType.Deflate)
+                LeaveStreamOpen = true,
+                ArchiveEncoding = new ArchiveEncoding()
                 {
-                    LeaveStreamOpen = true,
-                    ArchiveEncoding = new ArchiveEncoding()
-                    {
-                        Default = Encoding.UTF8
-                    }
-                });
-                return ms;
-            }
+                    Default = Encoding.UTF8
+                }
+            });
+            return ms;
         }
 
         /// <summary>
@@ -63,17 +61,15 @@ namespace Masuit.Tools.Files
         /// <param name="rootdir">压缩包内部根文件夹</param>
         public void Zip(List<string> files, string zipFile, string rootdir = "")
         {
-            using (var archive = CreateZipArchive(files, rootdir))
+            using var archive = CreateZipArchive(files, rootdir);
+            archive.SaveTo(zipFile, new WriterOptions(CompressionType.Deflate)
             {
-                archive.SaveTo(zipFile, new WriterOptions(CompressionType.Deflate)
+                LeaveStreamOpen = true,
+                ArchiveEncoding = new ArchiveEncoding()
                 {
-                    LeaveStreamOpen = true,
-                    ArchiveEncoding = new ArchiveEncoding()
-                    {
-                        Default = Encoding.UTF8
-                    }
-                });
-            }
+                    Default = Encoding.UTF8
+                }
+            });
         }
 
         /// <summary>
@@ -89,17 +85,15 @@ namespace Masuit.Tools.Files
                 dir = Path.GetDirectoryName(rar);
             }
 
-            using (var archive = RarArchive.Open(rar))
+            using var archive = RarArchive.Open(rar);
+            var entries = ignoreEmptyDir ? archive.Entries.Where(entry => !entry.IsDirectory) : archive.Entries;
+            foreach (var entry in entries)
             {
-                var entries = ignoreEmptyDir ? archive.Entries.Where(entry => !entry.IsDirectory) : archive.Entries;
-                foreach (var entry in entries)
+                entry.WriteToDirectory(dir, new ExtractionOptions()
                 {
-                    entry.WriteToDirectory(dir, new ExtractionOptions()
-                    {
-                        ExtractFullPath = true,
-                        Overwrite = true
-                    });
-                }
+                    ExtractFullPath = true,
+                    Overwrite = true
+                });
             }
         }
 
@@ -124,31 +118,27 @@ namespace Masuit.Tools.Files
                 dir = Path.GetDirectoryName(compressedFile);
             }
 
-            using (Stream stream = File.OpenRead(compressedFile))
+            using Stream stream = File.OpenRead(compressedFile);
+            using var reader = ReaderFactory.Open(stream);
+            while (reader.MoveToNextEntry())
             {
-                using (var reader = ReaderFactory.Open(stream))
+                if (ignoreEmptyDir)
                 {
-                    while (reader.MoveToNextEntry())
+                    reader.WriteEntryToDirectory(dir, new ExtractionOptions()
                     {
-                        if (ignoreEmptyDir)
-                        {
-                            reader.WriteEntryToDirectory(dir, new ExtractionOptions()
-                            {
-                                ExtractFullPath = true,
-                                Overwrite = true
-                            });
-                        }
-                        else
+                        ExtractFullPath = true,
+                        Overwrite = true
+                    });
+                }
+                else
+                {
+                    if (!reader.Entry.IsDirectory)
+                    {
+                        reader.WriteEntryToDirectory(dir, new ExtractionOptions()
                         {
-                            if (!reader.Entry.IsDirectory)
-                            {
-                                reader.WriteEntryToDirectory(dir, new ExtractionOptions()
-                                {
-                                    ExtractFullPath = true,
-                                    Overwrite = true
-                                });
-                            }
-                        }
+                            ExtractFullPath = true,
+                            Overwrite = true
+                        });
                     }
                 }
             }

+ 7 - 3
Masuit.Tools.Core/Masuit.Tools.Core.csproj

@@ -1,8 +1,8 @@
 <Project Sdk="Microsoft.NET.Sdk">
 
   <PropertyGroup>
-    <TargetFramework>netcoreapp2.2</TargetFramework>
-    <Version>2.2.6.4</Version>
+    <TargetFramework>netcoreapp3.0</TargetFramework>
+    <Version>2.2.7</Version>
     <Authors>懒得勤快</Authors>
     <Company>masuit.com</Company>
     <Description>包含一些常用的操作类,大都是静态类,加密解密,反射操作,硬件信息,字符串扩展方法,日期时间扩展操作,大文件拷贝,图像裁剪,html处理,验证码、NoSql等常用封装。
@@ -33,7 +33,11 @@ github:https://github.com/ldqk/Masuit.Tools</Description>
   <ItemGroup>
     <PackageReference Include="HtmlAgilityPack" Version="1.11.16" />
     <PackageReference Include="HtmlSanitizer" Version="4.0.217" />
-    <PackageReference Include="Microsoft.AspNetCore.All" Version="2.2.7" />
+    <PackageReference Include="Microsoft.AspNetCore.Hosting" Version="2.2.7" />
+    <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
+    <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.0.0" />
+    <PackageReference Include="Microsoft.Extensions.Http" Version="3.0.0" />
+    <PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
     <PackageReference Include="SharpCompress" Version="0.24.0" />
     <PackageReference Include="System.Diagnostics.PerformanceCounter" Version="4.6.0" />
     <PackageReference Include="System.Drawing.Common" Version="4.6.0" />

+ 0 - 8
Masuit.Tools.Core/Masuit.Tools.Core.xml

@@ -772,14 +772,6 @@
             SqlDataReader扩展类
             </summary>
         </member>
-        <member name="M:Masuit.Tools.Database.DataExt.MapEntity``1(System.Data.SqlClient.SqlDataReader)">
-            <summary>
-            根据SqlDataReader映射到实体模型
-            </summary>
-            <typeparam name="T">实体模型</typeparam>
-            <param name="reader">SqlDataReader</param>
-            <returns>映射后的实体模型</returns>
-        </member>
         <member name="M:Masuit.Tools.Database.DataExt.MapEntity``1(System.Data.DataRow)">
             <summary>
             根据DataRow映射到实体模型

+ 1 - 1
Masuit.Tools.ExpressionMapperBenchmark/Masuit.Tools.ExpressionMapperBenchmark.csproj

@@ -2,7 +2,7 @@
 
   <PropertyGroup>
     <OutputType>Exe</OutputType>
-    <TargetFramework>netcoreapp2.2</TargetFramework>
+    <TargetFramework>netcoreapp3.0</TargetFramework>
   </PropertyGroup>
 
   <ItemGroup>

+ 1 - 1
Masuit.Tools.NoSQL.MongoDBClient/Masuit.Tools.NoSQL.MongoDBClient.csproj

@@ -1,7 +1,7 @@
 <Project Sdk="Microsoft.NET.Sdk">
 
   <PropertyGroup>
-    <TargetFramework>netstandard2.0</TargetFramework>
+    <TargetFramework>netstandard2.1</TargetFramework>
     <Version>1.8.6</Version>
     <Authors>懒得勤快</Authors>
     <Company>masuit.com</Company>

+ 1 - 1
Masuit.Tools.UnitTest/Masuit.Tools.UnitTest.csproj

@@ -55,7 +55,7 @@
       <HintPath>..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll</HintPath>
     </Reference>
     <Reference Include="Moq, Version=4.13.0.0, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
-      <HintPath>..\packages\Moq.4.13.0\lib\net45\Moq.dll</HintPath>
+      <HintPath>..\packages\Moq.4.13.1\lib\net45\Moq.dll</HintPath>
     </Reference>
     <Reference Include="nunit.framework, Version=3.12.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
       <HintPath>..\packages\NUnit.3.12.0\lib\net45\nunit.framework.dll</HintPath>

+ 1 - 1
Masuit.Tools.UnitTest/packages.config

@@ -5,7 +5,7 @@
   <package id="Microsoft.AspNet.Razor" version="3.2.7" targetFramework="net461" />
   <package id="Microsoft.AspNet.WebPages" version="3.2.7" targetFramework="net461" />
   <package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net461" />
-  <package id="Moq" version="4.13.0" targetFramework="net461" />
+  <package id="Moq" version="4.13.1" targetFramework="net461" />
   <package id="MSTest.TestAdapter" version="2.0.0" targetFramework="net461" />
   <package id="MSTest.TestFramework" version="2.0.0" targetFramework="net461" />
   <package id="NUnit" version="3.12.0" targetFramework="net461" />

+ 1 - 1
Masuit.Tools/Masuit.Tools.csproj

@@ -9,7 +9,7 @@
     <AppDesignerFolder>Properties</AppDesignerFolder>
     <RootNamespace>Masuit.Tools</RootNamespace>
     <AssemblyName>Masuit.Tools</AssemblyName>
-    <TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
+    <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
     <FileAlignment>512</FileAlignment>
     <NuGetPackageImportStamp>
     </NuGetPackageImportStamp>

+ 6 - 6
Masuit.Tools/app.config

@@ -1,15 +1,15 @@
-<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8"?>
 <configuration>
   <runtime>
     <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
       <dependentAssembly>
-        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30AD4FE6B2A6AEED" culture="neutral" />
-        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
+        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30AD4FE6B2A6AEED" culture="neutral"/>
+        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0"/>
       </dependentAssembly>
       <dependentAssembly>
-        <assemblyIdentity name="AngleSharp" publicKeyToken="e83494dcdc6d31ea" culture="neutral" />
-        <bindingRedirect oldVersion="0.0.0.0-0.13.0.0" newVersion="0.13.0.0" />
+        <assemblyIdentity name="AngleSharp" publicKeyToken="e83494dcdc6d31ea" culture="neutral"/>
+        <bindingRedirect oldVersion="0.0.0.0-0.13.0.0" newVersion="0.13.0.0"/>
       </dependentAssembly>
     </assemblyBinding>
   </runtime>
-<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6" /></startup></configuration>
+<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/></startup></configuration>

+ 3 - 5
NetCoreTest/NetCoreTest.csproj

@@ -1,7 +1,9 @@
 <Project Sdk="Microsoft.NET.Sdk.Web">
 
   <PropertyGroup>
-    <TargetFramework>netcoreapp2.2</TargetFramework>
+    <TargetFramework>netcoreapp3.0</TargetFramework>
+    <RunAnalyzersDuringBuild>false</RunAnalyzersDuringBuild>
+    <RunAnalyzersDuringLiveAnalysis>false</RunAnalyzersDuringLiveAnalysis>
   </PropertyGroup>
 
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
@@ -16,10 +18,6 @@
     <Folder Include="wwwroot\" />
   </ItemGroup>
 
-  <ItemGroup>
-    <PackageReference Include="Microsoft.AspNetCore.App" />
-  </ItemGroup>
-
   <ItemGroup>
     <ProjectReference Include="..\Masuit.Tools.Core\Masuit.Tools.Core.csproj" />
   </ItemGroup>

+ 1 - 1
Test/App.config

@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
 <configuration>
     <startup> 
-        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6"/>
+        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/>
     </startup>
   <runtime>
     <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">

+ 1 - 1
Test/Test.csproj

@@ -9,7 +9,7 @@
     <AppDesignerFolder>Properties</AppDesignerFolder>
     <RootNamespace>Test</RootNamespace>
     <AssemblyName>Test</AssemblyName>
-    <TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
+    <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
     <FileAlignment>512</FileAlignment>
     <TargetFrameworkProfile />
   </PropertyGroup>