Skip to content

Commit

Permalink
Merge branch 'dev/develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
gmf520 committed Aug 27, 2020
2 parents 1199004 + df8a96a commit 08b80a2
Show file tree
Hide file tree
Showing 20 changed files with 157 additions and 59 deletions.
1 change: 1 addition & 0 deletions build/nuget-build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ dotnet pack ../src/OSharp.EntityFrameworkCore.Oracle/OSharp.EntityFrameworkCore.
dotnet pack ../src/OSharp.EntityFrameworkCore.PostgreSql/OSharp.EntityFrameworkCore.PostgreSql.csproj -c Release --output nupkgs
dotnet pack ../src/OSharp.EntityFrameworkCore.Sqlite/OSharp.EntityFrameworkCore.Sqlite.csproj -c Release --output nupkgs
dotnet pack ../src/OSharp.EntityFrameworkCore.SqlServer/OSharp.EntityFrameworkCore.SqlServer.csproj -c Release --output nupkgs
dotnet pack ../src/OSharp.Exceptionless/OSharp.Exceptionless.csproj -c Release --output nupkgs
dotnet pack ../src/OSharp.Hangfire/OSharp.Hangfire.csproj -c Release --output nupkgs
dotnet pack ../src/OSharp.Hosting.Apis/OSharp.Hosting.Apis.csproj -c Release --output nupkgs
dotnet pack ../src/OSharp.Hosting.Core/OSharp.Hosting.Core.csproj -c Release --output nupkgs
Expand Down
4 changes: 2 additions & 2 deletions build/nuget-delete.bat
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
:: 此命令将删除nuget官网上的osharp指定版本的包
:: 此命令将删除nuget官网上的osharp指定版本的包
@echo off
set /p version=请输入要删除的版本号:
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
Expand Down
21 changes: 15 additions & 6 deletions build/public.props
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
<Project>
<Project>
<PropertyGroup>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<Authors>LiuliuSoft</Authors>
<Company>柳柳软件(66soft.net)</Company>
<Copyright>Copyright @ 66SOFT 2014-2020</Copyright>
<Company>柳柳软件(liuliusoft)</Company>
<Copyright>Copyright (c) 2014-2020 LIULIUSOFT. All rights reserved.</Copyright>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/i66soft/osharp</PackageProjectUrl>
<PackageIconUrl>https://en.gravatar.com/userimage/140788132/0ff3b1e68fa0154337b1528c4276e276.png?size=80</PackageIconUrl>
<RepositoryUrl>https://github.com/i66soft/osharp.git</RepositoryUrl>
<PackageProjectUrl>https://github.com/dotnetcore/osharp</PackageProjectUrl>
<PackageReleaseNotes>https://github.com/dotnetcore/osharp/releases</PackageReleaseNotes>
<PackageIconUrl>https://en.gravatar.com/userimage/140788132/0ff3b1e68fa0154337b1528c4276e276.png?size=128</PackageIconUrl>
<RepositoryUrl>https://github.com/dotnetcore/osharp</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageTags>osharp osharpns</PackageTags>
<NeutralLanguage>zh-CHS</NeutralLanguage>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)OSharp.Keys.snk</AssemblyOriginatorKeyFile>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All"/>
</ItemGroup>
</Project>
4 changes: 2 additions & 2 deletions build/version.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<VersionPrefix>7</VersionPrefix>
<VersionSuffix>-preview</VersionSuffix>
<VersionSuffixVersion>0826</VersionSuffixVersion>
<Version>$(VersionMain).$(VersionPrefix)$(VersionSuffix)$(VersionSuffixVersion)</Version>
<!--<Version>$(VersionMain).$(VersionPrefix)</Version>-->
<!--<Version>$(VersionMain).$(VersionPrefix)$(VersionSuffix)$(VersionSuffixVersion)</Version>-->
<Version>$(VersionMain).$(VersionPrefix)</Version>
<AssemblyVersion>$(VersionMain).$(VersionPrefix)</AssemblyVersion>
<FileVersion>$(VersionMain).$(VersionPrefix).$(VersionSuffixVersion)</FileVersion>
</PropertyGroup>
Expand Down
7 changes: 7 additions & 0 deletions osharp.sln
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OSharp.Hosting.Apis", "src\
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OSharp.EntityFrameworkCore.Oracle", "src\OSharp.EntityFrameworkCore.Oracle\OSharp.EntityFrameworkCore.Oracle.csproj", "{4E26B25A-11F4-445E-AE75-BCE02FA3CA29}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OSharp.Exceptionless", "src\OSharp.Exceptionless\OSharp.Exceptionless.csproj", "{DF42EE5B-627F-408D-8E7F-675FACD5A318}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -234,6 +236,10 @@ Global
{4E26B25A-11F4-445E-AE75-BCE02FA3CA29}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4E26B25A-11F4-445E-AE75-BCE02FA3CA29}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4E26B25A-11F4-445E-AE75-BCE02FA3CA29}.Release|Any CPU.Build.0 = Release|Any CPU
{DF42EE5B-627F-408D-8E7F-675FACD5A318}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DF42EE5B-627F-408D-8E7F-675FACD5A318}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DF42EE5B-627F-408D-8E7F-675FACD5A318}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DF42EE5B-627F-408D-8E7F-675FACD5A318}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -275,6 +281,7 @@ Global
{FD428746-CA60-4F80-BC53-BA1A69CF739F} = {611006C4-BCE9-4EDC-8473-A85530C7FADE}
{3C2FF651-1C3F-4A8B-AB77-89E26DA260D0} = {611006C4-BCE9-4EDC-8473-A85530C7FADE}
{4E26B25A-11F4-445E-AE75-BCE02FA3CA29} = {611006C4-BCE9-4EDC-8473-A85530C7FADE}
{DF42EE5B-627F-408D-8E7F-675FACD5A318} = {611006C4-BCE9-4EDC-8473-A85530C7FADE}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {F1A8840B-B7DE-410D-9FA7-BA36515D2E11}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BootstrapBlazor" Version="3.1.16" />
<PackageReference Include="BootstrapBlazor" Version="3.1.17" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="3.2.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Build" Version="3.2.1" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="3.2.1" PrivateAssets="all" />
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 10 additions & 9 deletions samples/web/Liuliu.Demo.Mvc/appsettings.Development.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@
},
"OSharp": {
"DbContexts": {
"SqlServer": {
"DbContextTypeName": "OSharp.Entity.DefaultDbContext,OSharp.EntityFrameworkCore",
//"ConnectionString": "Server=(localdb)\\MSSQLLocalDB;Database=osharp-mvc-dev02;Trusted_Connection=True;MultipleActiveResultSets=true",
"ConnectionString": "Data Source=osharp-mvc-dev.db",
"DatabaseType": "Sqlite",
"LazyLoadingProxiesEnabled": true,
"AuditEntityEnabled": true,
"AutoMigrationEnabled": true
}
"SqlServer": {
"DbContextTypeName": "OSharp.Entity.DefaultDbContext,OSharp.EntityFrameworkCore",
//"ConnectionString": "Server=(localdb)\\MSSQLLocalDB;Database=osharp-mvc-dev02;Trusted_Connection=True;MultipleActiveResultSets=true",
"ConnectionString": "Data Source=osharp-mvc-dev.db",
"DatabaseType": "Sqlite",
"LazyLoadingProxiesEnabled": true,
"DateTimeUtcFormatEnabled": true,
"AuditEntityEnabled": true,
"AutoMigrationEnabled": true
}
},
"Jwt": {
"Issuer": "osharp identity",
Expand Down
30 changes: 18 additions & 12 deletions src/OSharp.EntityFrameworkCore/DbContextBase.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
// <copyright file="DbContextBase.cs" company="OSharp开源团队">
// Copyright (c) 2014-2019 OSharp. All rights reserved.
// </copyright>
Expand Down Expand Up @@ -45,7 +45,7 @@ protected DbContextBase(DbContextOptions options, IServiceProvider serviceProvid
_serviceProvider = serviceProvider;
_entityManager = serviceProvider.GetService<IEntityManager>();
_osharpDbOptions = serviceProvider?.GetOSharpOptions()?.DbContexts?.Values.FirstOrDefault(m => m.DbContextType == GetType());
Logger = serviceProvider?.GetLogger(this);
Logger = serviceProvider.GetLogger(this);
}

/// <summary>
Expand Down Expand Up @@ -80,10 +80,10 @@ protected DbContextBase(DbContextOptions options, IServiceProvider serviceProvid
public override int SaveChanges()
{
IList<AuditEntityEntry> auditEntities = new List<AuditEntityEntry>();
if (_osharpDbOptions?.AuditEntityEnabled == true)
if (_osharpDbOptions.AuditEntityEnabled == true)
{
IAuditEntityProvider auditEntityProvider = _serviceProvider.GetService<IAuditEntityProvider>();
auditEntities = auditEntityProvider?.GetAuditEntities(this)?.ToList();
auditEntities = auditEntityProvider?.GetAuditEntities(this).ToList();
}

//开启或使用现有事务
Expand All @@ -94,7 +94,7 @@ public override int SaveChanges()
{
AuditEntityEventData eventData = new AuditEntityEventData(auditEntities);
IEventBus eventBus = _serviceProvider.GetService<IEventBus>();
eventBus?.Publish(this, eventData);
eventBus.Publish(this, eventData);
}

return count;
Expand Down Expand Up @@ -128,10 +128,10 @@ public override int SaveChanges()
public override async Task<int> SaveChangesAsync(CancellationToken cancellationToken = new CancellationToken())
{
IList<AuditEntityEntry> auditEntities = new List<AuditEntityEntry>();
if (_osharpDbOptions?.AuditEntityEnabled == true)
if (_osharpDbOptions.AuditEntityEnabled == true)
{
IAuditEntityProvider auditEntityProvider = _serviceProvider.GetService<IAuditEntityProvider>();
auditEntities = auditEntityProvider?.GetAuditEntities(this)?.ToList();
auditEntities = auditEntityProvider?.GetAuditEntities(this).ToList();
}

//开启或使用现有事务
Expand Down Expand Up @@ -189,20 +189,26 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
foreach (IEntityRegister register in registers)
{
register.RegisterTo(modelBuilder);
Logger?.LogDebug($"将实体类 {register.EntityType} 注册到上下文 {contextType} 中");
Logger.LogDebug($"将实体类 {register.EntityType} 注册到上下文 {contextType} 中");
}
Logger?.LogInformation($"上下文 {contextType} 注册了{registers.Length}个实体类");
Logger.LogInformation($"上下文 {contextType} 注册了{registers.Length}个实体类");

//按预定前缀更改表名
var entityTypes = modelBuilder.Model.GetEntityTypes().ToList();
List<IMutableEntityType> entityTypes = modelBuilder.Model.GetEntityTypes().ToList();
foreach (IMutableEntityType entityType in entityTypes)
{
//启用时间属性UTC格式
if (_osharpDbOptions.DateTimeUtcFormatEnabled)
{
IEntityDateTimeUtcConversion utcConversion = _serviceProvider.GetService<IEntityDateTimeUtcConversion>();
utcConversion.Convert(entityType);
}

//按预定前缀更改表名
string prefix = GetTableNamePrefix(entityType.ClrType);
if (prefix.IsNullOrEmpty())
{
continue;
}

modelBuilder.Entity(entityType.ClrType).ToTable($"{prefix}_{entityType.GetTableName()}");
}
}
Expand Down
60 changes: 60 additions & 0 deletions src/OSharp.EntityFrameworkCore/EntityDateTimeUtcConversion.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// -----------------------------------------------------------------------
// <copyright file="EntityDateTimeUtcConversion.cs" company="OSharp开源团队">
// Copyright (c) 2014-2020 OSharp. All rights reserved.
// </copyright>
// <site>http://www.osharp.org</site>
// <last-editor>郭明锋</last-editor>
// <last-date>2020-08-26 23:44</last-date>
// -----------------------------------------------------------------------

using System;

using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;


namespace OSharp.Entity
{
/// <summary>
/// 实体时间属性UTC转换器
/// </summary>
/// <seealso cref="OSharp.Entity.IEntityDateTimeUtcConversion" />
public class EntityDateTimeUtcConversion : IEntityDateTimeUtcConversion
{
private readonly ValueConverter<DateTime, DateTime> _dateTimeConverter;
private readonly ValueConverter<DateTime?, DateTime?> _nullableDateTimeConverter;

/// <summary>
/// 初始化一个<see cref="EntityDateTimeUtcConversion"/>类型的新实例
/// </summary>
public EntityDateTimeUtcConversion()
{
_dateTimeConverter = new ValueConverter<DateTime, DateTime>(
local => local.ToUniversalTime(),
utc => utc.ToLocalTime());
_nullableDateTimeConverter = new ValueConverter<DateTime?, DateTime?>(
local => local.HasValue ? local.Value.ToUniversalTime() : local,
utc => utc.HasValue ? utc.Value.ToLocalTime() : utc);
}

/// <summary>
/// 转换指定的实体类型。
/// </summary>
/// <param name="entityType">实体类型</param>
public void Convert(IMutableEntityType entityType)
{
foreach (IMutableProperty property in entityType.GetProperties())
{
if (property.ClrType == typeof(DateTime))
{
property.SetValueConverter(_dateTimeConverter);
}
else if (property.ClrType == typeof(DateTime?))
{
property.SetValueConverter(_nullableDateTimeConverter);
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public override IServiceCollection AddServices(IServiceCollection services)
services.TryAddScoped<IUnitOfWorkManager, UnitOfWorkManager>();
services.TryAddSingleton<IEntityConfigurationTypeFinder, EntityConfigurationTypeFinder>();
services.TryAddSingleton<IEntityManager, EntityManager>();
services.TryAddSingleton<IEntityDateTimeUtcConversion, EntityDateTimeUtcConversion>();
services.AddSingleton<DbContextModelCache>();
services.AddOsharpDbContext<DefaultDbContext>();

Expand Down
26 changes: 26 additions & 0 deletions src/OSharp.EntityFrameworkCore/IEntityDateTimeUtcConversion.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// -----------------------------------------------------------------------
// <copyright file="IEntityUtcConverter.cs" company="OSharp开源团队">
// Copyright (c) 2014-2020 OSharp. All rights reserved.
// </copyright>
// <site>http://www.osharp.org</site>
// <last-editor>郭明锋</last-editor>
// <last-date>2020-08-26 23:37</last-date>
// -----------------------------------------------------------------------

using Microsoft.EntityFrameworkCore.Metadata;


namespace OSharp.Entity
{
/// <summary>
/// 实体时间属性UTC转换器
/// </summary>
public interface IEntityDateTimeUtcConversion
{
/// <summary>
/// 转换指定的实体类型。
/// </summary>
/// <param name="entityType">实体类型</param>
void Convert(IMutableEntityType entityType);
}
}
9 changes: 3 additions & 6 deletions src/OSharp.Exceptionless/OSharp.Exceptionless.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,20 @@
<Import Project="../../build/version.props" />

<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<PackageId>OSharpNS.Exceptionless</PackageId>
<Summary>OSharp Exceptionless 分布式日志组件</Summary>
<Description>OSharp Exceptionless 分布式日志组件,封装基于Exceptionless 分布式日志记录实现</Description>
<RootNamespace>OSharp.Exceptionless</RootNamespace>
<Version>2.2.6</Version>
<AssemblyVersion>2.2.6.0</AssemblyVersion>
<FileVersion>2.2.6.0</FileVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|AnyCPU'">
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<OutputPath>bin\Release\</OutputPath>
<DocumentationFile>bin\Release\OSharp.Exceptionless.xml</DocumentationFile>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Exceptionless.AspNetCore" Version="4.3.2027" />
<PackageReference Include="Exceptionless.AspNetCore" Version="4.4.1" />
</ItemGroup>

<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions src/OSharp.Hosting.Apis/OSharp.Hosting.Apis.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<OutputType>Library</OutputType>
<Summary>OSharp框架非业务WebAPI实现</Summary>
<Description>OSharp框架非业务WebAPI实现,封装框架非业务如认证,权限,系统,消息等模块的WebApi实现</Description>
<IsPackable>true</IsPackable>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/OSharp.Log4Net/OSharp.Log4Net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="log4net" Version="2.0.8" />
<PackageReference Include="log4net" Version="2.0.9" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/OSharp.NLog/OSharp.NLog.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="NLog" Version="4.7.3" />
<PackageReference Include="NLog" Version="4.7.4" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/OSharp.Wpf/OSharp.Wpf.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentValidation" Version="9.1.3" />
<PackageReference Include="FluentValidation" Version="9.2.0" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="3.1.7" />
<PackageReference Include="Microsoft.Win32.Registry" Version="4.7.0" />
<PackageReference Include="Stylet" Version="1.3.4" />
Expand Down
5 changes: 5 additions & 0 deletions src/OSharp/Core/Options/OSharpDbContextOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ public OsharpDbContextOptions()
/// </summary>
public bool LazyLoadingProxiesEnabled { get; set; }

/// <summary>
/// 获取或设置 是否启用时间UTC格式
/// </summary>
public bool DateTimeUtcFormatEnabled { get; set; }

/// <summary>
/// 获取或设置 是否允许审计实体
/// </summary>
Expand Down
Loading

0 comments on commit 08b80a2

Please sign in to comment.