Skip to content

Commit

Permalink
Merge pull request #55 from DarkXoro/master
Browse files Browse the repository at this point in the history
Updated to 5.0
  • Loading branch information
rigofunc authored Mar 10, 2021
2 parents bf69d3c + 32ecac3 commit fcf462b
Show file tree
Hide file tree
Showing 66 changed files with 60 additions and 108 deletions.
18 changes: 9 additions & 9 deletions AutoHistory.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26228.4
# Visual Studio Version 16
VisualStudioVersion = 16.0.30907.101
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{EEF95A1B-E224-4488-91ED-4CC4EC3CEEE3}"
EndProject
Expand All @@ -18,9 +18,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
README.md = README.md
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{DAEF4300-2306-4680-A609-86F2F9E4513A}"
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{1C12ACF7-CF58-460C-8EF3-2349D8E62AC1}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AspNetCore2.2.MVC.EF.Blogs", "samples\AspNetCore2.2.MVC.EF.Blogs\AspNetCore2.2.MVC.EF.Blogs.csproj", "{AB1074C0-4529-44F0-B837-07E34AB9B321}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AspNetCore5.0.MVC.EF.Blogs", "samples\AspNetCore5.0.MVC.EF.Blogs\AspNetCore5.0.MVC.EF.Blogs.csproj", "{01180CD5-4F4E-4C51-9478-00090C03FE73}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -36,18 +36,18 @@ Global
{2F6C239E-9F05-4654-936B-CFBB00412E4B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2F6C239E-9F05-4654-936B-CFBB00412E4B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2F6C239E-9F05-4654-936B-CFBB00412E4B}.Release|Any CPU.Build.0 = Release|Any CPU
{AB1074C0-4529-44F0-B837-07E34AB9B321}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AB1074C0-4529-44F0-B837-07E34AB9B321}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AB1074C0-4529-44F0-B837-07E34AB9B321}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AB1074C0-4529-44F0-B837-07E34AB9B321}.Release|Any CPU.Build.0 = Release|Any CPU
{01180CD5-4F4E-4C51-9478-00090C03FE73}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{01180CD5-4F4E-4C51-9478-00090C03FE73}.Debug|Any CPU.Build.0 = Debug|Any CPU
{01180CD5-4F4E-4C51-9478-00090C03FE73}.Release|Any CPU.ActiveCfg = Release|Any CPU
{01180CD5-4F4E-4C51-9478-00090C03FE73}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{5927DE0F-FA62-4B71-8AAF-2B3DDC405E34} = {EEF95A1B-E224-4488-91ED-4CC4EC3CEEE3}
{2F6C239E-9F05-4654-936B-CFBB00412E4B} = {504C6707-0D9C-4FA7-861D-B1A97AF39E32}
{AB1074C0-4529-44F0-B837-07E34AB9B321} = {DAEF4300-2306-4680-A609-86F2F9E4513A}
{01180CD5-4F4E-4C51-9478-00090C03FE73} = {1C12ACF7-CF58-460C-8EF3-2349D8E62AC1}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {ED8B7FB1-308D-49C1-8124-E03D7D6E6D85}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
<TargetFramework>netcoreapp5.0</TargetFramework>
<!--<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>-->
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}

public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.ConfigureKestrel(serverOptions =>
{
// Set properties and call methods on options
})
.UseStartup<Startup>();
webBuilder.UseStartup<Startup>();
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ public void ConfigureServices(IServiceCollection services)
options.MinimumSameSitePolicy = SameSiteMode.None;
});

services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_3_0);
services.AddControllersWithViews();

var connection = @"Server=(local);Database=AutoHistoryTest;Trusted_Connection=True;ConnectRetryCount=0";
var connection = @"Server=.;Database=AutoHistoryTest;Trusted_Connection=True;ConnectRetryCount=0";
services.AddDbContext<BloggingContext>(options =>
{
options.UseSqlServer(connection);
Expand All @@ -53,10 +53,18 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
app.UseStaticFiles();
app.UseCookiePolicy();

app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapDefaultControllerRoute();
});

// only runs once at system startup
using (var scope = app.ApplicationServices.CreateScope())
{
var db = scope.ServiceProvider.GetRequiredService<BloggingContext>();
db.Database.Migrate();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System;
using System.Collections.Generic;
using System.Text;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;

namespace Microsoft.EntityFrameworkCore.Internal
{
Expand Down Expand Up @@ -45,21 +43,5 @@ private AutoHistoryOptions()
/// The max length for the table column. Default: 128.
/// </summary>
public int TableMaxLength { get; set; } = 128;

/// <summary>
/// The JsonSerializerSettings for the changed column.
/// </summary>
public JsonSerializerSettings JsonSerializerSettings { get; set; } = new JsonSerializerSettings()
{
ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
ContractResolver = new CamelCasePropertyNamesContractResolver(),
Formatting = Formatting.None,
NullValueHandling = NullValueHandling.Ignore
};

/// <summary>
/// The json serializer to use when writing changes. Created internally.
/// </summary>
internal JsonSerializer JsonSerializer { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
using System;
using System.Collections.Generic;
using System.Linq;

using System.Text.Json;
using Microsoft.EntityFrameworkCore.ChangeTracking;
using Microsoft.EntityFrameworkCore.Internal;

using Newtonsoft.Json.Linq;

namespace Microsoft.EntityFrameworkCore
{
/// <summary>
Expand Down Expand Up @@ -47,9 +45,7 @@ internal static TAutoHistory AutoHistory<TAutoHistory>(this EntityEntry entry, F
// (include shadow properties, not include navigations & references)
var properties = entry.Properties;

var formatting = AutoHistoryOptions.Instance.JsonSerializerSettings.Formatting;
var jsonSerializer = AutoHistoryOptions.Instance.JsonSerializer;
var json = new JObject();
dynamic json = new System.Dynamic.ExpandoObject();
switch (entry.State)
{
case EntityState.Added:
Expand All @@ -59,19 +55,19 @@ internal static TAutoHistory AutoHistory<TAutoHistory>(this EntityEntry entry, F
{
continue;
}
json[prop.Metadata.Name] = prop.CurrentValue != null
? JToken.FromObject(prop.CurrentValue, jsonSerializer)
: JValue.CreateNull();
((IDictionary<String, Object>)json)[prop.Metadata.Name] = prop.CurrentValue != null
? prop.CurrentValue
: null;
}

// REVIEW: what's the best way to set the RowId?
history.RowId = "0";
history.Kind = EntityState.Added;
history.Changed = json.ToString(formatting);
history.Changed = JsonSerializer.Serialize(json);
break;
case EntityState.Modified:
var bef = new JObject();
var aft = new JObject();
dynamic bef = new System.Dynamic.ExpandoObject();
dynamic aft = new System.Dynamic.ExpandoObject();

PropertyValues databaseValues = null;
foreach (var prop in properties)
Expand All @@ -82,45 +78,45 @@ internal static TAutoHistory AutoHistory<TAutoHistory>(this EntityEntry entry, F
{
if (!prop.OriginalValue.Equals(prop.CurrentValue))
{
bef[prop.Metadata.Name] = JToken.FromObject(prop.OriginalValue, jsonSerializer);
((IDictionary<String, Object>)bef)[prop.Metadata.Name] = prop.OriginalValue;
}
else
{
databaseValues = databaseValues ?? entry.GetDatabaseValues();
var originalValue = databaseValues.GetValue<object>(prop.Metadata.Name);
bef[prop.Metadata.Name] = originalValue != null
? JToken.FromObject(originalValue, jsonSerializer)
: JValue.CreateNull();
((IDictionary<String, Object>)bef)[prop.Metadata.Name] = originalValue != null
? originalValue
: null;
}
}
else
{
bef[prop.Metadata.Name] = JValue.CreateNull();
((IDictionary<String, Object>)bef)[prop.Metadata.Name] = null;
}

aft[prop.Metadata.Name] = prop.CurrentValue != null
? JToken.FromObject(prop.CurrentValue, jsonSerializer)
: JValue.CreateNull();
((IDictionary<String, Object>)aft)[prop.Metadata.Name] = prop.CurrentValue != null
? prop.CurrentValue
: null;
}
}

json["before"] = bef;
json["after"] = aft;
((IDictionary<String, Object>)json)["before"] = bef;
((IDictionary<String, Object>)json)["after"] = aft;

history.RowId = entry.PrimaryKey();
history.Kind = EntityState.Modified;
history.Changed = json.ToString(formatting);
history.Changed = JsonSerializer.Serialize(json);
break;
case EntityState.Deleted:
foreach (var prop in properties)
{
json[prop.Metadata.Name] = prop.OriginalValue != null
? JToken.FromObject(prop.OriginalValue, jsonSerializer)
: JValue.CreateNull();
((IDictionary<String, Object>)json)[prop.Metadata.Name] = prop.OriginalValue != null
? prop.OriginalValue
: null;
}
history.RowId = entry.PrimaryKey();
history.Kind = EntityState.Deleted;
history.Changed = json.ToString(formatting);
history.Changed = JsonSerializer.Serialize(json);
break;
case EntityState.Detached:
case EntityState.Unchanged:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

using System;
using Microsoft.EntityFrameworkCore.Internal;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;

namespace Microsoft.EntityFrameworkCore
{
Expand Down Expand Up @@ -34,7 +32,6 @@ public static ModelBuilder EnableAutoHistory<TAutoHistory>(this ModelBuilder mod
{
var options = AutoHistoryOptions.Instance;
configure?.Invoke(options);
options.JsonSerializer = JsonSerializer.Create(options.JsonSerializerSettings);

modelBuilder.Entity<TAutoHistory>(b =>
{
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Description>A plugin for Microsoft.EntityFrameworkCore to support automatically recording data changes history.</Description>
<VersionPrefix>3.1.3</VersionPrefix>
<VersionPrefix>5.0.0</VersionPrefix>
<Authors>rigofunc;[email protected]</Authors>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
<NoWarn>$(NoWarn);CS1591</NoWarn>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
Expand All @@ -16,7 +16,6 @@
<RepositoryUrl>https://github.com/arch/AutoHistory.git</RepositoryUrl>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="3.1.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="5.0.0" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>netcoreapp5.0</TargetFramework>
<NoWarn>$(NoWarn);CS1591</NoWarn>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<AssemblyName>Microsoft.EntityFrameworkCore.AutoHistory.Test</AssemblyName>
<PackageId>Microsoft.EntityFrameworkCore.AutoHistory.Test</PackageId>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="3.1.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="5.0.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="xunit" Version="2.4.1" />
</ItemGroup>
<ItemGroup>
Expand Down

0 comments on commit fcf462b

Please sign in to comment.