diff --git a/build/OSharpNS.nuspec b/build/OSharpNS.nuspec index 348f33e3a..459e5c95f 100644 --- a/build/OSharpNS.nuspec +++ b/build/OSharpNS.nuspec @@ -2,39 +2,32 @@ OSharpNS - 6.0.5-preview.505 - OSharpFramework(.NET6.0/.NET5.0/.NETCoreApp3.1) + 6.0.6-preview.816 + OSharpFramework(.NET6.0/.NETCoreApp3.1) 柳柳软件(66soft.net) LiuliuSoft nnc false Apache-2.0 icon.png https://github.com/dotnetcore/osharp - OSharp Framework with .NETCoreApp3.0,此Package包含了OSharp的所有常用组件 + OSharp Framework with .NET,此Package包含了OSharp的所有常用组件 https://github.com/dotnetcore/osharp/releases Copyright (c) 2014-2021 LIULIUSOFT. All rights reserved. osharp - - - - - - - - - - - - + + + + + - - - - - + + + + + diff --git a/build/nuget-build.ps1 b/build/nuget-build.ps1 index 67aad5647..c3017a010 100644 --- a/build/nuget-build.ps1 +++ b/build/nuget-build.ps1 @@ -1,6 +1,16 @@ -function GetVersion() +#Requires -Version 6 + +function WriteXml([System.Xml.XmlDocument]$xml, [string]$file) { - $file = "version.props" + $encoding = New-Object System.Text.UTF8Encoding($true) + $writer = New-Object System.IO.StreamWriter($file, $false, $encoding) + $xml.Save($writer) + $writer.Close() +} + +function GetVersion() +{ + $file = "$($rootPath)\build\version.props" $xml = New-Object -TypeName XML $xml.Load($file) $version = $xml.Project.PropertyGroup.Version @@ -17,54 +27,106 @@ function SetOsharpNSVersion() { - $file = "OSharpNS.nuspec" + $file = "$($rootPath)\build\OSharpNS.nuspec" + Write-Host ("正在更新文件 $($file) 的版本号:$($version)") $xml = New-Object -TypeName XML $xml.Load($file) $xml.package.metadata.version = $version - #$nodes = $xml.SelectNodes("/package/metadata/dependencies/group") $nodes = $xml.package.metadata.dependencies.group.dependency foreach($node in $nodes) { $node.version = $version } - # Utf-8 with BOM 保存 - $encoding = New-Object System.Text.UTF8Encoding($true) - $writer = New-Object System.IO.StreamWriter($file, $false, $encoding) - $xml.Save($writer) - $writer.Close() - Write-Host ("{0} 更新成功,新版本:{1}`n" -f $file,$version) + WriteXml $xml $file + Write-Host "OSharp.nuspec 版本号更新成功" } -$rootPath = Split-Path -Parent $MyInvocation.MyCommand.Definition -Write-Host ("当前目录:{0}" -f $rootPath) -$version = GetVersion -Write-Host ("当前版本:{0}" -f $version) -SetOsharpNSVersion - - -$output = ".\output" -if(Test-Path $output) +function BuildNugetPackages() { - Remove-Item ("{0}\*.*" -f $output) - Write-Host ("清空 {0} 文件夹" -f $output) -} -else -{ - New-Item -Path . -Name $output -ItemType "directory" -Force - Write-Host ("创建 {0} 文件夹" -f $output) -} -$props = @("OSharp", "OSharp.AspNetCore", "OSharp.Authorization.Datas", "OSharp.Authorization.Functions", + $output = "$($rootPath)\build\output" + if(Test-Path $output) + { + Remove-Item ("$($output)\*.*") + Write-Host ("清空文件夹:$($output)") + } + else + { + New-Item -ItemType directory -Path $output + Write-Host "创建文件夹:$($output)" + } + + $projs = @("OSharp", "OSharp.AspNetCore", "OSharp.Authorization.Datas", "OSharp.Authorization.Functions", "OSharp.AutoMapper", "OSharp.EntityFrameworkCore","OSharp.EntityFrameworkCore.MySql", "OSharp.EntityFrameworkCore.Oracle", "OSharp.EntityFrameworkCore.PostgreSql", "OSharp.EntityFrameworkCore.Sqlite","OSharp.EntityFrameworkCore.SqlServer", "OSharp.Exceptionless", "OSharp.Hangfire", "OSharp.Hosting.Apis", "OSharp.Hosting.Core", "OSharp.Hosting.EntityConfiguration", "OSharp.Identity", "OSharp.Log4Net", "OSharp.MiniProfiler", "OSharp.Redis", "OSharp.Swagger", "OSharp.Wpf") -foreach($prop in $props) + foreach($proj in $projs) + { + $path = "$($rootPath)/src/$($proj)/$($proj).csproj" + dotnet build $path -c Release + dotnet pack $path -c Release --output $output + } + + $file = "$($rootPath)\build\OSharpNS.nuspec" + $nuget = "D:\GreenSoft\Envs\nuget\nuget.exe" + & $nuget pack $file -OutputDirectory $output + if($ENV:WORKSPACE -eq $null) + { + Invoke-Item $output + } +} + +function PushNugetPackages() { - $path = ("../src/{0}/{0}.csproj" -f $prop) - dotnet build $path -c Release - dotnet pack $path -c Release --output $output + $output = "$($rootPath)\build\output" + if(!(Test-Path $output)) + { + Write-Host "输出文件夹 $($output) 不存在" + exit + } + Write-Host "正在查找 nupkg 发布包" + $files = [System.IO.Directory]::GetFiles($output, "*.$($version)*nupkg") + Write-Host "共找到 $($files.Length) 个版本号为 $($version) 的nuget文件" + if($files.Length -eq 0) + { + exit + } + + $key = "D:\GreenSoft\Envs\nuget\nuget.org-apikey.txt" + $key = [System.IO.File]::ReadAllText($key) + $server = "https://api.nuget.org/v3/index.json" + Write-Host "nuget服务器:$($server),密钥:$($key)" + $items=@() + foreach($file in $files) + { + $obj = New-Object PSObject -Property @{ + Server = $server + File = $file + Key = $key + } + $items += @($obj) + } + + $items | ForEach-Object -Parallel { + $nuget = "D:\GreenSoft\Envs\nuget\nuget.exe" + $item = $_ + $name = [System.IO.Path]::GetFileName($item.File) + Write-Host ("正在 {0} 向发布{1}" -f $item.Server, $name) + $server = @("push", $item.File, "-Source", $item.Server, "-ApiKey", $item.Key, "-SkipDuplicate") + & $nuget $server + } -ThrottleLimit 5 } -nuget pack .\OSharp.nuspec -OutputDirectory $output -Invoke-Item $output -pause \ No newline at end of file +$now = [DateTime]::Now +$rootPath = ($ENV:WORKSPACE) +if($rootPath -eq $null) +{ + $rootPath = Split-Path -Parent $MyInvocation.MyCommand.Definition + $rootPath = Split-Path -Parent $rootPath +} +Write-Host ("当前目录:$($rootPath)") +$version = GetVersion +Write-Host ("当前版本:$($version)") +SetOsharpNSVersion +BuildNugetPackages +#PushNugetPackages diff --git a/build/nuget-delete.bat b/build/nuget-delete.bat deleted file mode 100644 index 1b7ae9502..000000000 --- a/build/nuget-delete.bat +++ /dev/null @@ -1,27 +0,0 @@ -:: ɾnugetϵosharpָ汾İ -@echo off -set /p version=Ҫɾİ汾ţ -nuget delete OSharpNS.Core %version% -src https://www.nuget.org -NonInteractive -nuget delete OSharpNS.AspNetCore %version% -src https://www.nuget.org -NonInteractive -nuget delete OSharpNS.Authorization.Datas %version% -src https://www.nuget.org -NonInteractive -nuget delete OSharpNS.Authorization.Functions %version% -src https://www.nuget.org -NonInteractive -nuget delete OSharpNS.AutoMapper %version% -src https://www.nuget.org -NonInteractive -nuget delete OSharpNS.EntityFrameworkCore %version% -src https://www.nuget.org -NonInteractive -nuget delete OSharpNS.EntityFrameworkCore.MySql %version% -src https://www.nuget.org -NonInteractive -nuget delete OSharpNS.EntityFrameworkCore.Oracle %version% -src https://www.nuget.org -NonInteractive -nuget delete OSharpNS.EntityFrameworkCore.PostgreSql %version% -src https://www.nuget.org -NonInteractive -nuget delete OSharpNS.EntityFrameworkCore.Sqlite %version% -src https://www.nuget.org -NonInteractive -nuget delete OSharpNS.EntityFrameworkCore.SqlServer %version% -src https://www.nuget.org -NonInteractive -nuget delete OSharpNS.Exceptionless %version% -src https://www.nuget.org -NonInteractive -nuget delete OSharpNS.Hangfire %version% -src https://www.nuget.org -NonInteractive -nuget delete OSharpNS.Hosting.Apis %version% -src https://www.nuget.org -NonInteractive -nuget delete OSharpNS.Hosting.Core %version% -src https://www.nuget.org -NonInteractive -nuget delete OSharpNS.Hosting.EntityConfiguration %version% -src https://www.nuget.org -NonInteractive -nuget delete OSharpNS.Identity %version% -src https://www.nuget.org -NonInteractive -nuget delete OSharpNS.Log4Net %version% -src https://www.nuget.org -NonInteractive -nuget delete OSharpNS.MiniProfiler %version% -src https://www.nuget.org -NonInteractive -nuget delete OSharpNS.Redis %version% -src https://www.nuget.org -NonInteractive -nuget delete OSharpNS.Swagger %version% -src https://www.nuget.org -NonInteractive -nuget delete OSharpNS %version% -src https://www.nuget.org -NonInteractive -nuget delete OSharpNS.Template.Mvc_Angular %version% -src https://www.nuget.org -NonInteractive -nuget delete OSharpNS.CodeGeneration %version% -src https://www.nuget.org -NonInteractive \ No newline at end of file diff --git a/build/nuget.build.ps1 b/build/nuget.build.ps1 deleted file mode 100644 index c3017a010..000000000 --- a/build/nuget.build.ps1 +++ /dev/null @@ -1,132 +0,0 @@ -#Requires -Version 6 - -function WriteXml([System.Xml.XmlDocument]$xml, [string]$file) -{ - $encoding = New-Object System.Text.UTF8Encoding($true) - $writer = New-Object System.IO.StreamWriter($file, $false, $encoding) - $xml.Save($writer) - $writer.Close() -} - -function GetVersion() -{ - $file = "$($rootPath)\build\version.props" - $xml = New-Object -TypeName XML - $xml.Load($file) - $version = $xml.Project.PropertyGroup.Version - if($version.contains("VersionSuffixVersion")) - { - $version = "{0}.{1}{2}{3}" -f $xml.Project.PropertyGroup.VersionMain,$xml.Project.PropertyGroup.VersionPrefix,$xml.Project.PropertyGroup.VersionSuffix,$xml.Project.PropertyGroup.VersionSuffixVersion - } - else - { - $version = "{0}.{1}" -f $xml.Project.PropertyGroup.VersionMain,$xml.Project.PropertyGroup.VersionPrefix - } - return $version -} - -function SetOsharpNSVersion() -{ - $file = "$($rootPath)\build\OSharpNS.nuspec" - Write-Host ("正在更新文件 $($file) 的版本号:$($version)") - $xml = New-Object -TypeName XML - $xml.Load($file) - $xml.package.metadata.version = $version - $nodes = $xml.package.metadata.dependencies.group.dependency - foreach($node in $nodes) - { - $node.version = $version - } - WriteXml $xml $file - Write-Host "OSharp.nuspec 版本号更新成功" -} - -function BuildNugetPackages() -{ - $output = "$($rootPath)\build\output" - if(Test-Path $output) - { - Remove-Item ("$($output)\*.*") - Write-Host ("清空文件夹:$($output)") - } - else - { - New-Item -ItemType directory -Path $output - Write-Host "创建文件夹:$($output)" - } - - $projs = @("OSharp", "OSharp.AspNetCore", "OSharp.Authorization.Datas", "OSharp.Authorization.Functions", -"OSharp.AutoMapper", "OSharp.EntityFrameworkCore","OSharp.EntityFrameworkCore.MySql", "OSharp.EntityFrameworkCore.Oracle", -"OSharp.EntityFrameworkCore.PostgreSql", "OSharp.EntityFrameworkCore.Sqlite","OSharp.EntityFrameworkCore.SqlServer", -"OSharp.Exceptionless", "OSharp.Hangfire", "OSharp.Hosting.Apis", "OSharp.Hosting.Core", "OSharp.Hosting.EntityConfiguration", -"OSharp.Identity", "OSharp.Log4Net", "OSharp.MiniProfiler", "OSharp.Redis", "OSharp.Swagger", "OSharp.Wpf") - foreach($proj in $projs) - { - $path = "$($rootPath)/src/$($proj)/$($proj).csproj" - dotnet build $path -c Release - dotnet pack $path -c Release --output $output - } - - $file = "$($rootPath)\build\OSharpNS.nuspec" - $nuget = "D:\GreenSoft\Envs\nuget\nuget.exe" - & $nuget pack $file -OutputDirectory $output - if($ENV:WORKSPACE -eq $null) - { - Invoke-Item $output - } -} - -function PushNugetPackages() -{ - $output = "$($rootPath)\build\output" - if(!(Test-Path $output)) - { - Write-Host "输出文件夹 $($output) 不存在" - exit - } - Write-Host "正在查找 nupkg 发布包" - $files = [System.IO.Directory]::GetFiles($output, "*.$($version)*nupkg") - Write-Host "共找到 $($files.Length) 个版本号为 $($version) 的nuget文件" - if($files.Length -eq 0) - { - exit - } - - $key = "D:\GreenSoft\Envs\nuget\nuget.org-apikey.txt" - $key = [System.IO.File]::ReadAllText($key) - $server = "https://api.nuget.org/v3/index.json" - Write-Host "nuget服务器:$($server),密钥:$($key)" - $items=@() - foreach($file in $files) - { - $obj = New-Object PSObject -Property @{ - Server = $server - File = $file - Key = $key - } - $items += @($obj) - } - - $items | ForEach-Object -Parallel { - $nuget = "D:\GreenSoft\Envs\nuget\nuget.exe" - $item = $_ - $name = [System.IO.Path]::GetFileName($item.File) - Write-Host ("正在 {0} 向发布{1}" -f $item.Server, $name) - $server = @("push", $item.File, "-Source", $item.Server, "-ApiKey", $item.Key, "-SkipDuplicate") - & $nuget $server - } -ThrottleLimit 5 -} - -$now = [DateTime]::Now -$rootPath = ($ENV:WORKSPACE) -if($rootPath -eq $null) -{ - $rootPath = Split-Path -Parent $MyInvocation.MyCommand.Definition - $rootPath = Split-Path -Parent $rootPath -} -Write-Host ("当前目录:$($rootPath)") -$version = GetVersion -Write-Host ("当前版本:$($version)") -SetOsharpNSVersion -BuildNugetPackages -#PushNugetPackages diff --git a/build/version.props b/build/version.props index 1d541a9be..8ef241695 100644 --- a/build/version.props +++ b/build/version.props @@ -1,9 +1,9 @@ 6.0 - 5 + 6 -preview. - 505 + 816 $(VersionMain).$(VersionPrefix)$(VersionSuffix)$(VersionSuffixVersion) $(VersionMain).$(VersionPrefix).$(VersionSuffixVersion) @@ -18,7 +18,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/samples/wpf/OSharp.CodeGenerator/build/osharp-code-generator.db.bak b/samples/wpf/OSharp.CodeGenerator/build/osharp-code-generator.db.bak new file mode 100644 index 000000000..9efcfcbf1 Binary files /dev/null and b/samples/wpf/OSharp.CodeGenerator/build/osharp-code-generator.db.bak differ diff --git a/src/OSharp.AspNetCore/JsonExceptionHandlerMiddleware.cs b/src/OSharp.AspNetCore/JsonExceptionHandlerMiddleware.cs index 0610d8032..963052660 100644 --- a/src/OSharp.AspNetCore/JsonExceptionHandlerMiddleware.cs +++ b/src/OSharp.AspNetCore/JsonExceptionHandlerMiddleware.cs @@ -1,4 +1,4 @@ -// ----------------------------------------------------------------------- +// ----------------------------------------------------------------------- // // Copyright (c) 2014-2018 OSharp. All rights reserved. // @@ -8,6 +8,8 @@ // ----------------------------------------------------------------------- using System; +using System.IO; +using System.Net.Http; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; @@ -67,4 +69,4 @@ public async Task InvokeAsync(HttpContext context) } } } -} \ No newline at end of file +} diff --git a/src/OSharp.AspNetCore/OSharp.AspNetCore.csproj b/src/OSharp.AspNetCore/OSharp.AspNetCore.csproj index 689693ad5..dacb06fd4 100644 --- a/src/OSharp.AspNetCore/OSharp.AspNetCore.csproj +++ b/src/OSharp.AspNetCore/OSharp.AspNetCore.csproj @@ -4,7 +4,7 @@ - netcoreapp3.1;net5.0;net6.0 + netcoreapp3.1;net6.0 OSharp.AspNetCore OSharp AspNetCore组件 OSharp AspNetCore组件,提供AspNetCore的服务端功能的封装 @@ -16,19 +16,14 @@ - - - - - - - - + + + - - - + + + diff --git a/src/OSharp.Authorization.Datas/OSharp.Authorization.Datas.csproj b/src/OSharp.Authorization.Datas/OSharp.Authorization.Datas.csproj index 89c5f36a3..fa0e24568 100644 --- a/src/OSharp.Authorization.Datas/OSharp.Authorization.Datas.csproj +++ b/src/OSharp.Authorization.Datas/OSharp.Authorization.Datas.csproj @@ -4,7 +4,7 @@ - netcoreapp3.1;net5.0;net6.0 + netcoreapp3.1;net6.0 OSharp.Authorization.Datas OSharp 数据权限组件 OSharp 数据权限组件,对应用中数据权限进行授权的设计实现 diff --git a/src/OSharp.Authorization.Functions/Events/FunctionAuthCacheRefreshEvent.cs b/src/OSharp.Authorization.Functions/Events/FunctionAuthCacheRefreshEvent.cs index 38c6b6878..f75926db6 100644 --- a/src/OSharp.Authorization.Functions/Events/FunctionAuthCacheRefreshEvent.cs +++ b/src/OSharp.Authorization.Functions/Events/FunctionAuthCacheRefreshEvent.cs @@ -27,8 +27,8 @@ public class FunctionAuthCacheRefreshEventData : EventDataBase /// public FunctionAuthCacheRefreshEventData() { - FunctionIds = new Guid[0]; - UserNames = new string[0]; + FunctionIds = Array.Empty(); + UserNames = Array.Empty(); } /// @@ -70,6 +70,10 @@ public override void Handle(FunctionAuthCacheRefreshEventData eventData) } IFunctionAuthCache cache = _provider.GetService(); + if (cache == null) + { + return; + } if (eventData.FunctionIds.Length > 0) { cache.RemoveFunctionCaches(eventData.FunctionIds); @@ -88,4 +92,4 @@ public override void Handle(FunctionAuthCacheRefreshEventData eventData) } } } -} \ No newline at end of file +} diff --git a/src/OSharp.Authorization.Functions/Events/FunctionCacheRefreshEvent.cs b/src/OSharp.Authorization.Functions/Events/FunctionCacheRefreshEvent.cs index 59df21a61..9e186207e 100644 --- a/src/OSharp.Authorization.Functions/Events/FunctionCacheRefreshEvent.cs +++ b/src/OSharp.Authorization.Functions/Events/FunctionCacheRefreshEvent.cs @@ -51,7 +51,7 @@ public override void Handle(FunctionCacheRefreshEventData eventData) return; } IFunctionHandler functionHandler = _provider.GetService(); - functionHandler.RefreshCache(); + functionHandler?.RefreshCache(); } } -} \ No newline at end of file +} diff --git a/src/OSharp.Authorization.Functions/FunctionAuthCacheBase.cs b/src/OSharp.Authorization.Functions/FunctionAuthCacheBase.cs index efa6d9f96..d605ef0f6 100644 --- a/src/OSharp.Authorization.Functions/FunctionAuthCacheBase.cs +++ b/src/OSharp.Authorization.Functions/FunctionAuthCacheBase.cs @@ -63,7 +63,7 @@ public virtual void BuildRoleCaches() //只创建 功能-角色集合 的映射,用户-功能 的映射,遇到才即时创建并缓存 _serviceProvider.ExecuteScopedWork(provider => { - IRepository functionRepository = provider.GetService>(); + IRepository functionRepository = provider.GetRequiredService>(); Guid[] functionIds = functionRepository.QueryAsNoTracking(null, false).Select(m => m.Id).ToArray(); foreach (Guid functionId in functionIds) @@ -131,21 +131,21 @@ public string[] GetFunctionRoles(Guid functionId, IServiceProvider scopeProvider provider = serviceScope.ServiceProvider; } - IRepository moduleFunctionRepository = provider.GetService>(); + IRepository moduleFunctionRepository = provider.GetRequiredService>(); TModuleKey[] moduleIds = moduleFunctionRepository.QueryAsNoTracking(m => m.FunctionId.Equals(functionId)).Select(m => m.ModuleId).Distinct() .ToArray(); if (moduleIds.Length == 0) { serviceScope?.Dispose(); - return new string[0]; + return Array.Empty(); } - roleNames = new string[0]; - IRepository moduleRoleRepository = provider.GetService>(); + roleNames = Array.Empty(); + IRepository moduleRoleRepository = provider.GetRequiredService>(); TRoleKey[] roleIds = moduleRoleRepository.QueryAsNoTracking(m => moduleIds.Contains(m.ModuleId)).Select(m => m.RoleId).Distinct().ToArray(); if (roleIds.Length > 0) { - IRepository roleRepository = provider.GetService>(); + IRepository roleRepository = provider.GetRequiredService>(); roleNames = roleRepository.QueryAsNoTracking(m => roleIds.Contains(m.Id)).Select(m => m.Name).Distinct().ToArray(); } @@ -174,18 +174,18 @@ public virtual Guid[] GetUserFunctions(string userName) } functionIds = _serviceProvider.ExecuteScopedWork(provider => { - IRepository userRepository = provider.GetService>(); + IRepository userRepository = provider.GetRequiredService>(); TUserKey userId = userRepository.QueryAsNoTracking(m => m.UserName == userName).Select(m => m.Id).FirstOrDefault(); if (Equals(userId, default(TUserKey))) { - return new Guid[0]; + return Array.Empty(); } - IRepository moduleUserRepository = provider.GetService>(); + IRepository moduleUserRepository = provider.GetRequiredService>(); TModuleKey[] moduleIds = moduleUserRepository.QueryAsNoTracking(m => m.UserId.Equals(userId)).Select(m => m.ModuleId).Distinct().ToArray(); - IRepository moduleRepository = provider.GetService>(); + IRepository moduleRepository = provider.GetRequiredService>(); moduleIds = moduleIds.Select(m => moduleRepository.QueryAsNoTracking(n => n.TreePathString.Contains("$" + m + "$")) .Select(n => n.Id)).SelectMany(m => m).Distinct().ToArray(); - IRepository moduleFunctionRepository = provider.GetService>(); + IRepository moduleFunctionRepository = provider.GetRequiredService>(); return moduleFunctionRepository.QueryAsNoTracking(m => moduleIds.Contains(m.ModuleId)).Select(m => m.FunctionId).Distinct().ToArray(); }); @@ -207,4 +207,4 @@ private static string GetUserFunctionsKey(string userName) return $"Auth:Function:UserFunctions:{userName}"; } } -} \ No newline at end of file +} diff --git a/src/OSharp.Authorization.Functions/FunctionAuthorizationManagerBase.cs b/src/OSharp.Authorization.Functions/FunctionAuthorizationManagerBase.cs index 5bda2e0a1..afd4e162d 100644 --- a/src/OSharp.Authorization.Functions/FunctionAuthorizationManagerBase.cs +++ b/src/OSharp.Authorization.Functions/FunctionAuthorizationManagerBase.cs @@ -361,7 +361,7 @@ public virtual async Task DeleteModule(TModuleKey id) if (result.Succeeded) { //功能权限缓存刷新事件 - Guid[] functionIds = ModuleFunctionRepository.QueryAsNoTracking(m => m.Id.Equals(id)).Select(m => m.FunctionId).ToArray(); + Guid[] functionIds = ModuleFunctionRepository.QueryAsNoTracking(m => m.ModuleId.Equals(id)).Select(m => m.FunctionId).ToArray(); FunctionAuthCacheRefreshEventData removeEventData = new FunctionAuthCacheRefreshEventData() { FunctionIds = functionIds }; await EventBus.PublishAsync(removeEventData); } @@ -686,4 +686,4 @@ public virtual TModuleKey[] GetUserWithRoleModuleIds(TUserKey userId) #endregion Implementation of IModuleUserStore } -} \ No newline at end of file +} diff --git a/src/OSharp.Authorization.Functions/ModuleHandlerBase.cs b/src/OSharp.Authorization.Functions/ModuleHandlerBase.cs index 3577772e3..2b8ad60e6 100644 --- a/src/OSharp.Authorization.Functions/ModuleHandlerBase.cs +++ b/src/OSharp.Authorization.Functions/ModuleHandlerBase.cs @@ -241,4 +241,4 @@ private static string GetModulePosition(TModule[] source, TModule module) return codes.ExpandAndToString("."); } } -} \ No newline at end of file +} diff --git a/src/OSharp.Authorization.Functions/OSharp.Authorization.Functions.csproj b/src/OSharp.Authorization.Functions/OSharp.Authorization.Functions.csproj index 0fdf88063..13e05c831 100644 --- a/src/OSharp.Authorization.Functions/OSharp.Authorization.Functions.csproj +++ b/src/OSharp.Authorization.Functions/OSharp.Authorization.Functions.csproj @@ -4,7 +4,7 @@ - netcoreapp3.1;net5.0;net6.0 + netcoreapp3.1;net6.0 OSharp.Authorization.Functions OSharp 功能权限组件 OSharp 功能权限组件,API功能权限授权的设计实现 diff --git a/src/OSharp.Authorization.Functions/ServiceCollectionExtensions.cs b/src/OSharp.Authorization.Functions/ServiceCollectionExtensions.cs index a013079a9..4513d5c6c 100644 --- a/src/OSharp.Authorization.Functions/ServiceCollectionExtensions.cs +++ b/src/OSharp.Authorization.Functions/ServiceCollectionExtensions.cs @@ -30,7 +30,7 @@ public static class ServiceCollectionExtensions /// public static IServiceCollection AddFunctionAuthorizationHandler(this IServiceCollection services) { - OsharpOptions options = services.GetOsharpOptions(); + //OsharpOptions options = services.GetOsharpOptions(); //services.AddAuthorization(); services.AddAuthorization(opts => @@ -56,16 +56,16 @@ public static IApplicationBuilder UseFunctionAuthorization(this IApplicationBuil IServiceProvider provider = app.ApplicationServices; - IModuleHandler moduleHandler = provider.GetService(); + IModuleHandler moduleHandler = provider.GetRequiredService(); moduleHandler.Initialize(); - IFunctionHandler functionHandler = provider.GetService(); + IFunctionHandler functionHandler = provider.GetRequiredService(); functionHandler.RefreshCache(); - IFunctionAuthCache functionAuthCache = provider.GetService(); + IFunctionAuthCache functionAuthCache = provider.GetRequiredService(); functionAuthCache.BuildRoleCaches(); return app; } } -} \ No newline at end of file +} diff --git a/src/OSharp.AutoMapper/AutoMapperPack.cs b/src/OSharp.AutoMapper/AutoMapperPack.cs index a987e8d0b..48b3081a1 100644 --- a/src/OSharp.AutoMapper/AutoMapperPack.cs +++ b/src/OSharp.AutoMapper/AutoMapperPack.cs @@ -1,4 +1,4 @@ -// ----------------------------------------------------------------------- +// ----------------------------------------------------------------------- // // Copyright (c) 2014-2018 OSharp. All rights reserved. // @@ -57,7 +57,7 @@ public override IServiceCollection AddServices(IServiceCollection services) public override void UsePack(IServiceProvider provider) { ILogger logger = provider.GetLogger(); - MapperConfigurationExpression cfg = provider.GetService(); + MapperConfigurationExpression cfg = provider.GetRequiredService(); //获取已注册到IoC的所有Profile IMapTuple[] tuples = provider.GetServices().OrderBy(m => m.Order).ToArray(); @@ -76,4 +76,4 @@ public override void UsePack(IServiceProvider provider) IsEnabled = true; } } -} \ No newline at end of file +} diff --git a/src/OSharp.AutoMapper/OSharp.AutoMapper.csproj b/src/OSharp.AutoMapper/OSharp.AutoMapper.csproj index 6ec1d49e1..c3537f24c 100644 --- a/src/OSharp.AutoMapper/OSharp.AutoMapper.csproj +++ b/src/OSharp.AutoMapper/OSharp.AutoMapper.csproj @@ -4,7 +4,7 @@ - netstandard2.0;net5.0;net6.0 + netstandard2.0;net6.0 OSharp.AutoMapper OSharp AutoMapper 对象映射组件 OSharp AutoMapper 对象映射组件,封装基于AutoMapper的对象映射实现 diff --git a/src/OSharp.EntityFrameworkCore.MySql/OSharp.EntityFrameworkCore.MySql.csproj b/src/OSharp.EntityFrameworkCore.MySql/OSharp.EntityFrameworkCore.MySql.csproj index 57e98511e..159613fa3 100644 --- a/src/OSharp.EntityFrameworkCore.MySql/OSharp.EntityFrameworkCore.MySql.csproj +++ b/src/OSharp.EntityFrameworkCore.MySql/OSharp.EntityFrameworkCore.MySql.csproj @@ -4,7 +4,7 @@ - netstandard2.0;net5.0;net6.0 + netstandard2.0;net6.0 OSharp.EntityFrameworkCore.MySql OSharp 数据访问组件,封装EntityFrameworkCore的MySql数据访问功能的实现 OSharp 数据访问组件MySql @@ -14,11 +14,8 @@ - - - - + diff --git a/src/OSharp.EntityFrameworkCore.Oracle/OSharp.EntityFrameworkCore.Oracle.csproj b/src/OSharp.EntityFrameworkCore.Oracle/OSharp.EntityFrameworkCore.Oracle.csproj index b90615aba..22157a7ee 100644 --- a/src/OSharp.EntityFrameworkCore.Oracle/OSharp.EntityFrameworkCore.Oracle.csproj +++ b/src/OSharp.EntityFrameworkCore.Oracle/OSharp.EntityFrameworkCore.Oracle.csproj @@ -4,7 +4,7 @@ - netstandard2.0;net5.0;net6.0 + netstandard2.0;net6.0 OSharp.EntityFrameworkCore.Oracle OSharp 数据访问组件,封装EntityFrameworkCore的Oracle数据访问功能的实现 OSharp 数据访问组件Oracle @@ -14,11 +14,8 @@ - - - - + diff --git a/src/OSharp.EntityFrameworkCore.PostgreSql/OSharp.EntityFrameworkCore.PostgreSql.csproj b/src/OSharp.EntityFrameworkCore.PostgreSql/OSharp.EntityFrameworkCore.PostgreSql.csproj index f98c5ab04..737e95fda 100644 --- a/src/OSharp.EntityFrameworkCore.PostgreSql/OSharp.EntityFrameworkCore.PostgreSql.csproj +++ b/src/OSharp.EntityFrameworkCore.PostgreSql/OSharp.EntityFrameworkCore.PostgreSql.csproj @@ -4,7 +4,7 @@ - netstandard2.0;net5.0;net6.0 + netstandard2.0;net6.0 OSharp.EntityFrameworkCore.PostgreSql OSharp 数据访问组件,封装EntityFrameworkCore的PostgreSql数据访问功能的实现 OSharp 数据访问组件PostgreSql @@ -14,11 +14,8 @@ - - - - + diff --git a/src/OSharp.EntityFrameworkCore.SqlServer/OSharp.EntityFrameworkCore.SqlServer.csproj b/src/OSharp.EntityFrameworkCore.SqlServer/OSharp.EntityFrameworkCore.SqlServer.csproj index 27b534592..3931385f4 100644 --- a/src/OSharp.EntityFrameworkCore.SqlServer/OSharp.EntityFrameworkCore.SqlServer.csproj +++ b/src/OSharp.EntityFrameworkCore.SqlServer/OSharp.EntityFrameworkCore.SqlServer.csproj @@ -4,7 +4,7 @@ - netstandard2.0;net5.0;net6.0 + netstandard2.0;net6.0 OSharp.EntityFrameworkCore.SqlServer OSharp 数据访问组件,封装EntityFrameworkCore的SqlServer数据访问功能的实现 OSharp 数据访问组件SqlServer @@ -12,13 +12,10 @@ - - - - + - + diff --git a/src/OSharp.EntityFrameworkCore.Sqlite/OSharp.EntityFrameworkCore.Sqlite.csproj b/src/OSharp.EntityFrameworkCore.Sqlite/OSharp.EntityFrameworkCore.Sqlite.csproj index 0a3d86157..2009d76cb 100644 --- a/src/OSharp.EntityFrameworkCore.Sqlite/OSharp.EntityFrameworkCore.Sqlite.csproj +++ b/src/OSharp.EntityFrameworkCore.Sqlite/OSharp.EntityFrameworkCore.Sqlite.csproj @@ -4,7 +4,7 @@ - netstandard2.0;net5.0;net6.0 + netstandard2.0;net6.0 OSharp.EntityFrameworkCore.Sqlite OSharp 数据访问组件,封装EntityFrameworkCore的Sqlite数据访问功能的实现 OSharp 数据访问组件Sqlite @@ -12,13 +12,10 @@ - - - - + - + diff --git a/src/OSharp.EntityFrameworkCore/OSharp.EntityFrameworkCore.csproj b/src/OSharp.EntityFrameworkCore/OSharp.EntityFrameworkCore.csproj index c423c4171..2e10e91e3 100644 --- a/src/OSharp.EntityFrameworkCore/OSharp.EntityFrameworkCore.csproj +++ b/src/OSharp.EntityFrameworkCore/OSharp.EntityFrameworkCore.csproj @@ -4,7 +4,7 @@ - netstandard2.0;net5.0;net6.0 + netstandard2.0;net6.0 OSharp.EntityFrameworkCore OSharp数据访问组件,封装EntityFrameworkCore数据访问功能的实现 OSharp数据访问组件 @@ -16,19 +16,14 @@ - - - - - - - - + + + - - - + + + diff --git a/src/OSharp.Exceptionless/OSharp.Exceptionless.csproj b/src/OSharp.Exceptionless/OSharp.Exceptionless.csproj index 3255a9d28..421d86ef9 100644 --- a/src/OSharp.Exceptionless/OSharp.Exceptionless.csproj +++ b/src/OSharp.Exceptionless/OSharp.Exceptionless.csproj @@ -12,7 +12,7 @@ - + diff --git a/src/OSharp.Hangfire/OSharp.Hangfire.csproj b/src/OSharp.Hangfire/OSharp.Hangfire.csproj index 5bf5a5e5b..b1ea729ec 100644 --- a/src/OSharp.Hangfire/OSharp.Hangfire.csproj +++ b/src/OSharp.Hangfire/OSharp.Hangfire.csproj @@ -11,7 +11,7 @@ - + diff --git a/src/OSharp.Hosting.Apis/Areas/Admin/Controllers/Auth/ModuleController.cs b/src/OSharp.Hosting.Apis/Areas/Admin/Controllers/Auth/ModuleController.cs index c7b99aeae..890d06d83 100644 --- a/src/OSharp.Hosting.Apis/Areas/Admin/Controllers/Auth/ModuleController.cs +++ b/src/OSharp.Hosting.Apis/Areas/Admin/Controllers/Auth/ModuleController.cs @@ -1,4 +1,4 @@ -// ----------------------------------------------------------------------- +// ----------------------------------------------------------------------- // // Copyright (c) 2014-2018 OSharp. All rights reserved. // @@ -25,6 +25,7 @@ using OSharp.Hosting.Authorization; using OSharp.Hosting.Authorization.Dtos; using OSharp.Hosting.Authorization.Entities; +using OSharp.Linq; namespace OSharp.Hosting.Apis.Areas.Admin.Controllers @@ -141,28 +142,32 @@ private bool IsRoleLimit(int moduleId) [ModuleInfo] [DependOnFunction(nameof(Read))] [Description("读取模块功能")] - public AjaxResult ReadFunctions(PageRequest request) + public AjaxResult ReadFunctions(int moduleId, [FromBody] PageRequest request) { - var emptyPage = new PageData(); - if (request.FilterGroup.Rules.Count == 0) + var empty = new PageData(); + if (moduleId == 0) { - return new AjaxResult(emptyPage); + return new AjaxResult(empty); } - Expression> moduleExp = FilterService.GetExpression(request.FilterGroup); + + string token = $"${moduleId}$"; + Expression> moduleExp = m => m.TreePathString != null && m.TreePathString.Contains(token); int[] moduleIds = _functionAuthManager.Modules.Where(moduleExp).Select(m => m.Id).ToArray(); Guid[] functionIds = _functionAuthManager.ModuleFunctions.Where(m => moduleIds.Contains(m.ModuleId)) .Select(m => m.FunctionId).Distinct().ToArray(); if (functionIds.Length == 0) { - return new AjaxResult(emptyPage); + return new AjaxResult(empty); } + + Expression> funcExp = FilterService.GetExpression(request.FilterGroup); + funcExp = funcExp.And(m => functionIds.Contains(m.Id)); if (request.PageCondition.SortConditions.Length == 0) { request.PageCondition.SortConditions = new[] { new SortCondition("Area"), new SortCondition("Controller") }; } - var page = _functionAuthManager.Functions.ToPage(m => functionIds.Contains(m.Id), - request.PageCondition, - m => new FunctionOutputDto2() { Id = m.Id, Name = m.Name, AccessType = m.AccessType, Area = m.Area, Controller = m.Controller }); + + var page = _functionAuthManager.Functions.ToPage(funcExp, request.PageCondition); return new AjaxResult(page.ToPageData()); } diff --git a/src/OSharp.Hosting.Apis/Areas/Admin/Controllers/Auth/RoleFunctionController.cs b/src/OSharp.Hosting.Apis/Areas/Admin/Controllers/Auth/RoleFunctionController.cs index e3e2631d3..9b07d6da0 100644 --- a/src/OSharp.Hosting.Apis/Areas/Admin/Controllers/Auth/RoleFunctionController.cs +++ b/src/OSharp.Hosting.Apis/Areas/Admin/Controllers/Auth/RoleFunctionController.cs @@ -76,8 +76,8 @@ public AjaxResult ReadFunctions(int roleId, [FromBody] PageRequest request) FunctionAuthManager functionAuthManager = _provider.GetRequiredService(); int[] moduleIds = functionAuthManager.GetRoleModuleIds(roleId); - Guid[] functionIds = functionAuthManager.ModuleFunctions.Where(m => moduleIds.Contains(m.ModuleId)).Select(m => m.FunctionId).Distinct() - .ToArray(); + Guid[] functionIds = functionAuthManager.ModuleFunctions.Where(m => moduleIds.Contains(m.ModuleId)) + .Select(m => m.FunctionId).Distinct().ToArray(); if (functionIds.Length == 0) { return new AjaxResult(empty); diff --git a/src/OSharp.Hosting.Apis/Areas/Admin/Controllers/Auth/UserFunctionController.cs b/src/OSharp.Hosting.Apis/Areas/Admin/Controllers/Auth/UserFunctionController.cs index 49a4d5323..01c8be1ec 100644 --- a/src/OSharp.Hosting.Apis/Areas/Admin/Controllers/Auth/UserFunctionController.cs +++ b/src/OSharp.Hosting.Apis/Areas/Admin/Controllers/Auth/UserFunctionController.cs @@ -75,8 +75,8 @@ public AjaxResult ReadFunctions(int userId, [FromBody] PageRequest request) FunctionAuthManager functionAuthManager = _provider.GetRequiredService(); int[] moduleIds = functionAuthManager.GetUserWithRoleModuleIds(userId); - Guid[] functionIds = functionAuthManager.ModuleFunctions.Where(m => moduleIds.Contains(m.ModuleId)).Select(m => m.FunctionId).Distinct() - .ToArray(); + Guid[] functionIds = functionAuthManager.ModuleFunctions.Where(m => moduleIds.Contains(m.ModuleId)) + .Select(m => m.FunctionId).Distinct().ToArray(); if (functionIds.Length == 0) { return new AjaxResult(empty); diff --git a/src/OSharp.Hosting.Apis/Areas/Admin/Controllers/Identity/RoleController.cs b/src/OSharp.Hosting.Apis/Areas/Admin/Controllers/Identity/RoleController.cs index 70b33423d..2fa1eaefa 100644 --- a/src/OSharp.Hosting.Apis/Areas/Admin/Controllers/Identity/RoleController.cs +++ b/src/OSharp.Hosting.Apis/Areas/Admin/Controllers/Identity/RoleController.cs @@ -1,4 +1,4 @@ -// ----------------------------------------------------------------------- +// ----------------------------------------------------------------------- // // Copyright (c) 2014-2018 OSharp. All rights reserved. // @@ -23,7 +23,6 @@ using OSharp.AspNetCore.UI; using OSharp.Authorization.Functions; using OSharp.Authorization.Modules; -using OSharp.Caching; using OSharp.Collections; using OSharp.Data; using OSharp.Entity; diff --git a/src/OSharp.Hosting.Apis/Controllers/AuthController.cs b/src/OSharp.Hosting.Apis/Controllers/AuthController.cs index f8e9283bf..8ec0bb8c6 100644 --- a/src/OSharp.Hosting.Apis/Controllers/AuthController.cs +++ b/src/OSharp.Hosting.Apis/Controllers/AuthController.cs @@ -67,7 +67,7 @@ public bool CheckUrlAuth(string url) public string[] GetAuthInfo() { IModuleHandler moduleHandler = _provider.GetRequiredService(); - IFunctionAuthorization functionAuthorization = _provider.GetService(); + IFunctionAuthorization functionAuthorization = _provider.GetRequiredService(); ModuleInfo[] moduleInfos = moduleHandler.ModuleInfos; //先查找出所有有权限的模块 diff --git a/src/OSharp.Hosting.Apis/Controllers/CommonController.cs b/src/OSharp.Hosting.Apis/Controllers/CommonController.cs index e01befd6c..9ed888adc 100644 --- a/src/OSharp.Hosting.Apis/Controllers/CommonController.cs +++ b/src/OSharp.Hosting.Apis/Controllers/CommonController.cs @@ -101,7 +101,7 @@ public object SystemInfo() { Message = "WebApi 数据服务已启动", CliVersion = cliVersion, - OSharpVersion = osharpVersion + OsharpVersion = osharpVersion }; return info; diff --git a/src/OSharp.Hosting.Apis/Controllers/IdentityController.cs b/src/OSharp.Hosting.Apis/Controllers/IdentityController.cs index 12e15f380..10bfed8ba 100644 --- a/src/OSharp.Hosting.Apis/Controllers/IdentityController.cs +++ b/src/OSharp.Hosting.Apis/Controllers/IdentityController.cs @@ -1,4 +1,4 @@ -// ----------------------------------------------------------------------- +// ----------------------------------------------------------------------- // // Copyright (c) 2014-2020 OSharp. All rights reserved. // @@ -183,6 +183,11 @@ public async Task Token(TokenDto dto) OperationResult result = await IdentityContract.Login(loginDto); if (!result.Succeeded) { +#if NET5_0_OR_GREATER + await unitOfWork.CommitAsync(); +#else + unitOfWork.Commit(); +#endif return result.ToAjaxResult(); } @@ -267,20 +272,19 @@ public async Task Logout() /// /// [HttpGet] - [LoggedIn] [ModuleInfo] [Description("用户信息")] public async Task Profile() { if (User.Identity?.IsAuthenticated != true) { - return null; + return new OnlineUser(); } IOnlineUserProvider onlineUserProvider = HttpContext.RequestServices.GetService(); if (onlineUserProvider == null) { - return null; + return new OnlineUser(); } OnlineUser onlineUser = await onlineUserProvider.GetOrCreate(User.Identity.Name); diff --git a/src/OSharp.Hosting.Apis/Controllers/TestController.cs b/src/OSharp.Hosting.Apis/Controllers/TestController.cs index 45f22be97..21057c478 100644 --- a/src/OSharp.Hosting.Apis/Controllers/TestController.cs +++ b/src/OSharp.Hosting.Apis/Controllers/TestController.cs @@ -23,6 +23,7 @@ using OSharp.AspNetCore; using OSharp.AspNetCore.Mvc.Filters; +using OSharp.Authorization; using OSharp.Collections; using OSharp.Data; using OSharp.Entity; @@ -105,6 +106,7 @@ public async Task Test01() [HttpPost] [Description("测试2")] + [RoleLimit] public async Task Test02() { IServiceProvider provider = HttpContext.RequestServices; diff --git a/src/OSharp.Hosting.Apis/OSharp.Hosting.Apis.csproj b/src/OSharp.Hosting.Apis/OSharp.Hosting.Apis.csproj index 4cb1d9651..ba1bb5a92 100644 --- a/src/OSharp.Hosting.Apis/OSharp.Hosting.Apis.csproj +++ b/src/OSharp.Hosting.Apis/OSharp.Hosting.Apis.csproj @@ -4,7 +4,7 @@ - netcoreapp3.1;net5.0;net6.0 + netcoreapp3.1;net6.0 OSharp.Hosting.Apis Library OSharp框架非业务WebAPI实现 @@ -22,11 +22,8 @@ - - - - + diff --git a/src/OSharp.Hosting.Core/OSharp.Hosting.Core.csproj b/src/OSharp.Hosting.Core/OSharp.Hosting.Core.csproj index 5a970aa72..725313569 100644 --- a/src/OSharp.Hosting.Core/OSharp.Hosting.Core.csproj +++ b/src/OSharp.Hosting.Core/OSharp.Hosting.Core.csproj @@ -1,4 +1,4 @@ - + @@ -12,7 +12,7 @@ - + diff --git a/src/OSharp.Hosting.EntityConfiguration/OSharp.Hosting.EntityConfiguration.csproj b/src/OSharp.Hosting.EntityConfiguration/OSharp.Hosting.EntityConfiguration.csproj index b6b2b3caa..58db70bc3 100644 --- a/src/OSharp.Hosting.EntityConfiguration/OSharp.Hosting.EntityConfiguration.csproj +++ b/src/OSharp.Hosting.EntityConfiguration/OSharp.Hosting.EntityConfiguration.csproj @@ -1,10 +1,10 @@ - + - netcoreapp3.1;net5.0;net6.0 + netcoreapp3.1;net6.0 OSharp.Hosting.EntityConfiguration OSharp框架非业务实体映射 OSharp框架非业务实体映射,封装框架非业务如认证,权限,系统,消息等模块的EFCore实体映射 diff --git a/src/OSharp.Identity/OSharp.Identity.csproj b/src/OSharp.Identity/OSharp.Identity.csproj index 2728e0e29..21c250c55 100644 --- a/src/OSharp.Identity/OSharp.Identity.csproj +++ b/src/OSharp.Identity/OSharp.Identity.csproj @@ -4,7 +4,7 @@ - netcoreapp3.1;net5.0;net6.0 + netcoreapp3.1;net6.0 OSharp.Identity OSharp 身份认证组件 OSharp 身份认证组件,基于AspNetCore.Identity和Osharp仓储系统的身份认证实现 @@ -21,16 +21,12 @@ - - - - - - + + - - + + diff --git a/src/OSharp.Log4Net/OSharp.Log4Net.csproj b/src/OSharp.Log4Net/OSharp.Log4Net.csproj index 0d927c5e5..e447f8b22 100644 --- a/src/OSharp.Log4Net/OSharp.Log4Net.csproj +++ b/src/OSharp.Log4Net/OSharp.Log4Net.csproj @@ -4,14 +4,14 @@ - netstandard2.0 + netstandard2.0;net6.0 OSharp.Log4Net OSharp Log4Net组件 OSharp Log4Net组件,封装使用log4net组件来实现框架的日志输出功能 - + diff --git a/src/OSharp.NLog/OSharp.NLog.csproj b/src/OSharp.NLog/OSharp.NLog.csproj index 4172f7c54..448cded13 100644 --- a/src/OSharp.NLog/OSharp.NLog.csproj +++ b/src/OSharp.NLog/OSharp.NLog.csproj @@ -4,7 +4,7 @@ - netstandard2.0;net5.0;net6.0 + netstandard2.0;net6.0 OSharp.NLog OSharp NLog组件,封装使用nlog组件来实现框架的日志输出功能 OSharp NLog组件 @@ -12,7 +12,7 @@ - + diff --git a/src/OSharp.Redis/OSharp.Redis.csproj b/src/OSharp.Redis/OSharp.Redis.csproj index df00aaee8..c634148f7 100644 --- a/src/OSharp.Redis/OSharp.Redis.csproj +++ b/src/OSharp.Redis/OSharp.Redis.csproj @@ -4,20 +4,17 @@ - netstandard2.0;net5.0;net6.0 + netstandard2.0;net6.0 OSharp.Redis OSharp Redis 缓存组件 OSharp Redis 缓存组件,封装基于Redis客户端的缓存实现 - - - - + - + diff --git a/src/OSharp.Swagger/OSharp.Swagger.csproj b/src/OSharp.Swagger/OSharp.Swagger.csproj index 8975181e7..73e3405cd 100644 --- a/src/OSharp.Swagger/OSharp.Swagger.csproj +++ b/src/OSharp.Swagger/OSharp.Swagger.csproj @@ -1,4 +1,4 @@ - + @@ -19,7 +19,7 @@ - + diff --git a/src/OSharp.Wpf/OSharp.Wpf.csproj b/src/OSharp.Wpf/OSharp.Wpf.csproj index 364c3bdae..a7ca5de15 100644 --- a/src/OSharp.Wpf/OSharp.Wpf.csproj +++ b/src/OSharp.Wpf/OSharp.Wpf.csproj @@ -17,18 +17,18 @@ - + - + - + - + diff --git a/src/OSharp/Authorization/EntityInfos/EntityInfoBase.cs b/src/OSharp/Authorization/EntityInfos/EntityInfoBase.cs index e950d3597..60e29563d 100644 --- a/src/OSharp/Authorization/EntityInfos/EntityInfoBase.cs +++ b/src/OSharp/Authorization/EntityInfos/EntityInfoBase.cs @@ -64,7 +64,7 @@ public EntityProperty[] Properties { if (string.IsNullOrEmpty(PropertyJson) || !PropertyJson.StartsWith("[")) { - return new EntityProperty[0]; + return Array.Empty(); } return PropertyJson.FromJsonString(); @@ -128,4 +128,4 @@ public override string ToString() #endregion } -} \ No newline at end of file +} diff --git a/src/OSharp/Authorization/EntityInfos/EntityInfoHandlerBase.cs b/src/OSharp/Authorization/EntityInfos/EntityInfoHandlerBase.cs index 83d82fcc9..f7dd7934d 100644 --- a/src/OSharp/Authorization/EntityInfos/EntityInfoHandlerBase.cs +++ b/src/OSharp/Authorization/EntityInfos/EntityInfoHandlerBase.cs @@ -235,11 +235,11 @@ protected virtual TEntityInfo[] GetFromDatabase(IServiceProvider scopedProvider) IRepository repository = scopedProvider.GetService>(); if (repository == null) { - return new TEntityInfo[0]; + return Array.Empty(); } TEntityInfo[] entityInfos = repository.QueryAsNoTracking(null, false).ToArray(); return entityInfos; } } -} \ No newline at end of file +} diff --git a/src/OSharp/Authorization/FunctionAuthorizationBase.cs b/src/OSharp/Authorization/FunctionAuthorizationBase.cs index 1a0b313b5..5b267f026 100644 --- a/src/OSharp/Authorization/FunctionAuthorizationBase.cs +++ b/src/OSharp/Authorization/FunctionAuthorizationBase.cs @@ -64,7 +64,7 @@ public virtual string[] GetOkRoles(IFunction function, IPrincipal principal) { if (!principal.Identity.IsAuthenticated) { - return new string[0]; + return Array.Empty(); } string[] userRoles = principal.Identity.GetRoles(); @@ -182,4 +182,4 @@ protected virtual AuthorizationResult AuthorizeUserName(IFunction function, stri return new AuthorizationResult(AuthorizationStatus.Forbidden); } } -} \ No newline at end of file +} diff --git a/src/OSharp/Authorization/Functions/FunctionHandlerBase.cs b/src/OSharp/Authorization/Functions/FunctionHandlerBase.cs index 4870f1aa2..9b0bdd449 100644 --- a/src/OSharp/Authorization/Functions/FunctionHandlerBase.cs +++ b/src/OSharp/Authorization/Functions/FunctionHandlerBase.cs @@ -371,11 +371,11 @@ protected virtual TFunction[] GetFromDatabase(IServiceProvider scopedProvider) IRepository repository = scopedProvider.GetService>(); if (repository == null) { - return new TFunction[0]; + return Array.Empty(); } TFunction[] functions = repository.QueryAsNoTracking(null, false).ToArray(); return functions; } } -} \ No newline at end of file +} diff --git a/src/OSharp/Caching/CacheService.cs b/src/OSharp/Caching/CacheService.cs index 9de85f0f4..ddf2a71ae 100644 --- a/src/OSharp/Caching/CacheService.cs +++ b/src/OSharp/Caching/CacheService.cs @@ -1,4 +1,4 @@ -// ----------------------------------------------------------------------- +// ----------------------------------------------------------------------- // // Copyright (c) 2014-2018 OSharp. All rights reserved. // @@ -41,7 +41,7 @@ public class CacheService : ICacheService /// public CacheService(IServiceProvider provider) { - _cache = provider.GetService(); + _cache = provider.GetRequiredService(); _logger = provider.GetLogger(); } @@ -619,4 +619,4 @@ private string GetKey(Expression expression, params object[] keyParams) #endregion } -} \ No newline at end of file +} diff --git a/src/OSharp/Caching/DistributedCacheExtensions.cs b/src/OSharp/Caching/DistributedCacheExtensions.cs index 4ae1205a2..dd8685896 100644 --- a/src/OSharp/Caching/DistributedCacheExtensions.cs +++ b/src/OSharp/Caching/DistributedCacheExtensions.cs @@ -8,24 +8,14 @@ // ----------------------------------------------------------------------- using System; -using System.Collections.Generic; -using System.Linq; -using System.Linq.Expressions; -using System.Reflection; using System.Threading.Tasks; using Microsoft.Extensions.Caching.Distributed; using OSharp.Authorization.Functions; -using OSharp.Collections; using OSharp.Data; -using OSharp.Dependency; -using OSharp.Entity; -using OSharp.Exceptions; using OSharp.Extensions; -using OSharp.Filter; using OSharp.Json; -using OSharp.Reflection; namespace OSharp.Caching @@ -296,4 +286,4 @@ public static DistributedCacheEntryOptions ToCacheOptions(this IFunction functio } } -} \ No newline at end of file +} diff --git a/src/OSharp/CodeGenerator/TypeMetadataHandler.cs b/src/OSharp/CodeGenerator/TypeMetadataHandler.cs index 218fc780c..35e75204d 100644 --- a/src/OSharp/CodeGenerator/TypeMetadataHandler.cs +++ b/src/OSharp/CodeGenerator/TypeMetadataHandler.cs @@ -1,9 +1,9 @@ // ----------------------------------------------------------------------- -// +// // Copyright (c) 2014-2018 OSharp. All rights reserved. // // http://www.osharp.org -// +// 郭明锋 // 2018-08-06 13:44 // ----------------------------------------------------------------------- @@ -17,14 +17,14 @@ namespace OSharp.CodeGenerator { /// - /// Ԫݴ + /// 类型元数据处理器 /// public class TypeMetadataHandler : ITypeMetadataHandler { /// - /// ȡʵԪ + /// 获取实体类的元数据 /// - /// Ԫݼ + /// 元数据集合 public TypeMetadata[] GetEntityTypeMetadatas() { Type[] entityTypes = AssemblyManager.FindTypesByBase(typeof(IEntity<>)).Where(m => !m.HasAttribute()).ToArray(); @@ -32,9 +32,9 @@ public TypeMetadata[] GetEntityTypeMetadatas() } /// - /// ȡDTO͵Ԫ + /// 获取输入DTO类型的元数据 /// - /// Ԫݼ + /// 元数据集合 public TypeMetadata[] GetInputDtoMetadatas() { Type[] inputDtoTypes = AssemblyManager.FindTypesByBase(typeof(IInputDto<>)).Where(m => !m.HasAttribute()) @@ -43,9 +43,9 @@ public TypeMetadata[] GetInputDtoMetadatas() } /// - /// ȡDTO͵Ԫ + /// 获取输出DTO类型的元数据 /// - /// Ԫݼ + /// 元数据集合 public TypeMetadata[] GetOutputDtoMetadata() { Type[] outDtoTypes = AssemblyManager.FindTypesByBase(typeof(IOutputDto)).Where(m => !m.HasAttribute()).ToArray(); @@ -53,10 +53,10 @@ public TypeMetadata[] GetOutputDtoMetadata() } /// - /// ȡָ͵Ԫ + /// 获取指定类型的元数据 /// - /// - /// Ԫ + /// 类型 + /// 元数据 public TypeMetadata GetTypeMetadata(Type type) { if (type == null) @@ -66,4 +66,4 @@ public TypeMetadata GetTypeMetadata(Type type) return new TypeMetadata(type); } } -} \ No newline at end of file +} diff --git a/src/OSharp/Core/Options/OSharpOptionsSetup.cs b/src/OSharp/Core/Options/OSharpOptionsSetup.cs index c0bead6ab..1bd195293 100644 --- a/src/OSharp/Core/Options/OSharpOptionsSetup.cs +++ b/src/OSharp/Core/Options/OSharpOptionsSetup.cs @@ -7,6 +7,7 @@ // 2017-09-03 12:32 // ----------------------------------------------------------------------- +using System; using System.Collections.Generic; using System.Linq; @@ -162,7 +163,7 @@ private void SetDbContextOptions(OsharpOptions options) DbContextTypeName = "OSharp.Entity.DefaultDbContext,OSharp.EntityFrameworkCore", ConnectionString = connectionString, DatabaseType = DatabaseType.SqlServer, - Slaves = new SlaveDatabaseOptions[0] + Slaves = Array.Empty() }; options.DbContexts.Add("DefaultDbContext", dbContextOptions); return; diff --git a/src/OSharp/Dependency/ScopedDictionary.cs b/src/OSharp/Dependency/ScopedDictionary.cs index 6bc68a24c..55de2b6ce 100644 --- a/src/OSharp/Dependency/ScopedDictionary.cs +++ b/src/OSharp/Dependency/ScopedDictionary.cs @@ -31,7 +31,7 @@ public sealed class ScopedDictionary : ConcurrentDictionary, IDi /// /// 获取或设置 对于当前功能有效的角色集合,用于数据权限判断 /// - public string[] DataAuthValidRoleNames { get; set; } = new string[0]; + public string[] DataAuthValidRoleNames { get; set; } = Array.Empty(); /// /// 获取或设置 当前操作审计 @@ -52,4 +52,4 @@ public void Dispose() this.Clear(); } } -} \ No newline at end of file +} diff --git a/src/OSharp/Filter/CollectionPropertySorter.cs b/src/OSharp/Filter/CollectionPropertySorter.cs index 96102e47e..b2f56b456 100644 --- a/src/OSharp/Filter/CollectionPropertySorter.cs +++ b/src/OSharp/Filter/CollectionPropertySorter.cs @@ -38,7 +38,7 @@ public static class CollectionPropertySorter /// 排序方向 public static IOrderedEnumerable OrderBy(IEnumerable source, string propertyName, ListSortDirection sortDirection) { - propertyName.CheckNotNullOrEmpty("propertyName" ); + propertyName.CheckNotNullOrEmpty("propertyName"); dynamic expression = GetKeySelector(propertyName); dynamic keySelector = expression.Compile(); return sortDirection == ListSortDirection.Ascending @@ -54,7 +54,7 @@ public static IOrderedEnumerable OrderBy(IEnumerable source, string proper /// 排序方向 public static IOrderedEnumerable ThenBy(IOrderedEnumerable source, string propertyName, ListSortDirection sortDirection) { - propertyName.CheckNotNullOrEmpty("propertyName" ); + propertyName.CheckNotNullOrEmpty("propertyName"); dynamic expression = GetKeySelector(propertyName); dynamic keySelector = expression.Compile(); return sortDirection == ListSortDirection.Ascending @@ -71,7 +71,7 @@ public static IOrderedEnumerable ThenBy(IOrderedEnumerable source, string /// public static IOrderedQueryable OrderBy(IQueryable source, string propertyName, ListSortDirection sortDirection) { - propertyName.CheckNotNullOrEmpty("propertyName" ); + propertyName.CheckNotNullOrEmpty("propertyName"); dynamic keySelector = GetKeySelector(propertyName); return sortDirection == ListSortDirection.Ascending ? Queryable.OrderBy(source, keySelector) @@ -87,7 +87,7 @@ public static IOrderedQueryable OrderBy(IQueryable source, string property /// public static IOrderedQueryable ThenBy(IOrderedQueryable source, string propertyName, ListSortDirection sortDirection) { - propertyName.CheckNotNullOrEmpty("propertyName" ); + propertyName.CheckNotNullOrEmpty("propertyName"); dynamic keySelector = GetKeySelector(propertyName); return sortDirection == ListSortDirection.Ascending ? Queryable.ThenBy(source, keySelector) @@ -110,7 +110,12 @@ private static LambdaExpression GetKeySelector(string keyName) PropertyInfo property = type.GetProperty(propertyName); if (property == null) { - throw new OsharpException(string.Format(Resources.ObjectExtensions_PropertyNameNotExistsInType, propertyName)); + string propertyName2 = propertyName.ToUpperCase(); + property = type.GetProperty(propertyName2); + if (property == null) + { + throw new OsharpException(string.Format(Resources.ObjectExtensions_PropertyNameNotExistsInType, propertyName)); + } } type = property.PropertyType; propertyAccess = Expression.MakeMemberAccess(propertyAccess, property); @@ -120,4 +125,4 @@ private static LambdaExpression GetKeySelector(string keyName) return keySelector; } } -} \ No newline at end of file +} diff --git a/src/OSharp/Filter/PageResult.cs b/src/OSharp/Filter/PageResult.cs index 54b8d00b6..a078a3bb0 100644 --- a/src/OSharp/Filter/PageResult.cs +++ b/src/OSharp/Filter/PageResult.cs @@ -21,7 +21,7 @@ public class PageResult /// 初始化一个类型的新实例 /// public PageResult() - : this(new T[0], 0) + : this(Array.Empty(), 0) { } /// @@ -62,4 +62,4 @@ public PageResult ToPageResult(Func func) return new PageResult(func(Data), Total); } } -} \ No newline at end of file +} diff --git a/src/OSharp/Identity/ClaimsIdentityExtensions.cs b/src/OSharp/Identity/ClaimsIdentityExtensions.cs index 5ca76def1..758c5c0eb 100644 --- a/src/OSharp/Identity/ClaimsIdentityExtensions.cs +++ b/src/OSharp/Identity/ClaimsIdentityExtensions.cs @@ -145,7 +145,7 @@ public static string[] GetRoles(this IIdentity identity) Check.NotNull(identity, nameof(identity)); if (!(identity is ClaimsIdentity claimsIdentity)) { - return new string[0]; + return Array.Empty(); } return claimsIdentity.FindAll(ClaimTypes.Role).SelectMany(m => { @@ -154,4 +154,4 @@ public static string[] GetRoles(this IIdentity identity) }).ToArray(); } } -} \ No newline at end of file +} diff --git a/src/OSharp/Identity/OnlineUser.cs b/src/OSharp/Identity/OnlineUser.cs index aa525321e..470dc189a 100644 --- a/src/OSharp/Identity/OnlineUser.cs +++ b/src/OSharp/Identity/OnlineUser.cs @@ -7,6 +7,7 @@ // 2019-06-02 0:01 // ----------------------------------------------------------------------- +using System; using System.Collections.Generic; using OSharp.Identity.JwtBearer; @@ -57,7 +58,7 @@ public class OnlineUser /// /// 获取或设置 用户角色 /// - public string[] Roles { get; set; } = new string[0]; + public string[] Roles { get; set; } = Array.Empty(); /// /// 获取或设置 客户端刷新Token @@ -69,4 +70,4 @@ public class OnlineUser /// public IDictionary ExtendData { get; } = new Dictionary(); } -} \ No newline at end of file +} diff --git a/src/OSharp/OSharp.csproj b/src/OSharp/OSharp.csproj index 62eb9efee..f3aa7bc60 100644 --- a/src/OSharp/OSharp.csproj +++ b/src/OSharp/OSharp.csproj @@ -4,7 +4,7 @@ - netstandard2.0;net5.0;net6.0 + netstandard2.0;net6.0 OSharp.Core OSharp核心组件,封装着框架核心及数据存储,缓存,辅助操作等功能 OSharp核心组件 @@ -16,7 +16,7 @@ - + diff --git a/tests/Liuliu.Demo.Core.Tests/Liuliu.Demo.Core.Tests.csproj b/tests/Liuliu.Demo.Core.Tests/Liuliu.Demo.Core.Tests.csproj index 2429ec62f..e56adc0c5 100644 --- a/tests/Liuliu.Demo.Core.Tests/Liuliu.Demo.Core.Tests.csproj +++ b/tests/Liuliu.Demo.Core.Tests/Liuliu.Demo.Core.Tests.csproj @@ -7,8 +7,8 @@ - - + + diff --git a/tests/OSharp.AspNetCore.Tests/OSharp.AspNetCore.Tests.csproj b/tests/OSharp.AspNetCore.Tests/OSharp.AspNetCore.Tests.csproj index 2bc3f34bb..167522b9b 100644 --- a/tests/OSharp.AspNetCore.Tests/OSharp.AspNetCore.Tests.csproj +++ b/tests/OSharp.AspNetCore.Tests/OSharp.AspNetCore.Tests.csproj @@ -12,7 +12,7 @@ - + diff --git a/tests/OSharp.AutoMapper.Tests/OSharp.AutoMapper.Tests.csproj b/tests/OSharp.AutoMapper.Tests/OSharp.AutoMapper.Tests.csproj index 6e3bc4569..0c2664757 100644 --- a/tests/OSharp.AutoMapper.Tests/OSharp.AutoMapper.Tests.csproj +++ b/tests/OSharp.AutoMapper.Tests/OSharp.AutoMapper.Tests.csproj @@ -7,7 +7,7 @@ - + diff --git a/tests/OSharp.Tests/OSharp.Tests.csproj b/tests/OSharp.Tests/OSharp.Tests.csproj index a96a1a706..92d8ecd28 100644 --- a/tests/OSharp.Tests/OSharp.Tests.csproj +++ b/tests/OSharp.Tests/OSharp.Tests.csproj @@ -6,7 +6,7 @@ - + diff --git a/tests/OSharp.UnitTest.Infrastructure/OSharp.UnitTest.Infrastructure.csproj b/tests/OSharp.UnitTest.Infrastructure/OSharp.UnitTest.Infrastructure.csproj index 8bd84afa4..73df3a6a6 100644 --- a/tests/OSharp.UnitTest.Infrastructure/OSharp.UnitTest.Infrastructure.csproj +++ b/tests/OSharp.UnitTest.Infrastructure/OSharp.UnitTest.Infrastructure.csproj @@ -1,7 +1,7 @@ - net5.0;net6.0 + net6.0 false @@ -12,19 +12,16 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive - + - - - - +