From 13294fafeb246b48fb50e737a4a8236eedb13a98 Mon Sep 17 00:00:00 2001 From: chuanzhang Date: Wed, 7 Jun 2017 15:10:21 +0800 Subject: [PATCH 1/6] trigger transaction-commited-event when dbcontextcollection savechanges --- .../Implementations/DbContextCollection.cs | 16 ++++++++++++++++ .../Interfaces/IDbContextCollection.cs | 5 +++++ 2 files changed, 21 insertions(+) diff --git a/Mehdime.Entity/Implementations/DbContextCollection.cs b/Mehdime.Entity/Implementations/DbContextCollection.cs index 578790e..f55e461 100644 --- a/Mehdime.Entity/Implementations/DbContextCollection.cs +++ b/Mehdime.Entity/Implementations/DbContextCollection.cs @@ -84,6 +84,11 @@ public TDbContext Get() where TDbContext : DbContext return _initializedDbContexts[requestedType] as TDbContext; } + /// + /// When Transaction Commited + /// + public event EventHandler TransactionCommited; + public int Commit() { if (_disposed) @@ -140,6 +145,8 @@ public int Commit() if (lastError != null) lastError.Throw(); // Re-throw while maintaining the exception's original stack track + OnTransactionCommited(new EventArgs()); + return c; } @@ -192,6 +199,8 @@ public async Task CommitAsync(CancellationToken cancelToken) if (lastError != null) lastError.Throw(); // Re-throw while maintaining the exception's original stack track + OnTransactionCommited(new EventArgs()); + return c; } @@ -281,5 +290,12 @@ private static TValue GetValueOrDefault(IDictionary TValue value; return dictionary.TryGetValue(key, out value) ? value : default(TValue); } + + protected void OnTransactionCommited(EventArgs e) + { + var temp = Volatile.Read(ref TransactionCommited); + + temp?.Invoke(this, e); + } } } \ No newline at end of file diff --git a/Mehdime.Entity/Interfaces/IDbContextCollection.cs b/Mehdime.Entity/Interfaces/IDbContextCollection.cs index 5476c6c..ff66ed7 100644 --- a/Mehdime.Entity/Interfaces/IDbContextCollection.cs +++ b/Mehdime.Entity/Interfaces/IDbContextCollection.cs @@ -19,5 +19,10 @@ public interface IDbContextCollection : IDisposable /// Get or create a DbContext instance of the specified type. /// TDbContext Get() where TDbContext : DbContext; + + /// + /// When Transaction Commited + /// + event EventHandler TransactionCommited; } } \ No newline at end of file From 6a56719561530a49318ada6f915a0ec025a4c626 Mon Sep 17 00:00:00 2001 From: chuanzhang Date: Wed, 7 Jun 2017 15:18:37 +0800 Subject: [PATCH 2/6] change version --- Mehdime.Entity/Properties/AssemblyInfo.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Mehdime.Entity/Properties/AssemblyInfo.cs b/Mehdime.Entity/Properties/AssemblyInfo.cs index 6a67ff1..2dee2a4 100644 --- a/Mehdime.Entity/Properties/AssemblyInfo.cs +++ b/Mehdime.Entity/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: AssemblyVersion("1.0.0.1")] +[assembly: AssemblyFileVersion("1.0.0.1")] From 851100ebca99912a8fbddf8c6402fa96afd144d6 Mon Sep 17 00:00:00 2001 From: chuanzhang Date: Thu, 7 Sep 2017 10:57:30 +0800 Subject: [PATCH 3/6] rename --- ConsoleApplication1/App.config | 6 ++ .../ConsoleApplication1.csproj | 60 +++++++++++++++++++ ConsoleApplication1/Program.cs | 15 +++++ .../Properties/AssemblyInfo.cs | 36 +++++++++++ ConsoleApplication1/packages.config | 4 ++ 5 files changed, 121 insertions(+) create mode 100644 ConsoleApplication1/App.config create mode 100644 ConsoleApplication1/ConsoleApplication1.csproj create mode 100644 ConsoleApplication1/Program.cs create mode 100644 ConsoleApplication1/Properties/AssemblyInfo.cs create mode 100644 ConsoleApplication1/packages.config diff --git a/ConsoleApplication1/App.config b/ConsoleApplication1/App.config new file mode 100644 index 0000000..88fa402 --- /dev/null +++ b/ConsoleApplication1/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/ConsoleApplication1/ConsoleApplication1.csproj b/ConsoleApplication1/ConsoleApplication1.csproj new file mode 100644 index 0000000..dd8a534 --- /dev/null +++ b/ConsoleApplication1/ConsoleApplication1.csproj @@ -0,0 +1,60 @@ + + + + + Debug + AnyCPU + {E3795473-F7F0-4B61-A589-6EBC601A90AA} + Exe + Properties + ConsoleApplication1 + ConsoleApplication1 + v4.5.2 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ConsoleApplication1/Program.cs b/ConsoleApplication1/Program.cs new file mode 100644 index 0000000..99abfb2 --- /dev/null +++ b/ConsoleApplication1/Program.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApplication1 +{ + class Program + { + static void Main(string[] args) + { + } + } +} diff --git a/ConsoleApplication1/Properties/AssemblyInfo.cs b/ConsoleApplication1/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..30dd501 --- /dev/null +++ b/ConsoleApplication1/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的一般信息由以下 +// 控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("ConsoleApplication1")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("ConsoleApplication1")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +//将 ComVisible 设置为 false 将使此程序集中的类型 +//对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, +//请将此类型的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("e3795473-f7f0-4b61-a589-6ebc601a90aa")] + +// 程序集的版本信息由下列四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, +// 方法是按如下所示使用“*”: : +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/ConsoleApplication1/packages.config b/ConsoleApplication1/packages.config new file mode 100644 index 0000000..d814976 --- /dev/null +++ b/ConsoleApplication1/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file From 332b0430bba9f61eb26c3828742c71f015c6a34a Mon Sep 17 00:00:00 2001 From: chuanzhang Date: Thu, 7 Sep 2017 10:59:52 +0800 Subject: [PATCH 4/6] ~ --- ConsoleApplication1/App.config | 6 -- .../ConsoleApplication1.csproj | 60 ------------------- ConsoleApplication1/Program.cs | 15 ----- .../Properties/AssemblyInfo.cs | 36 ----------- ConsoleApplication1/packages.config | 4 -- 5 files changed, 121 deletions(-) delete mode 100644 ConsoleApplication1/App.config delete mode 100644 ConsoleApplication1/ConsoleApplication1.csproj delete mode 100644 ConsoleApplication1/Program.cs delete mode 100644 ConsoleApplication1/Properties/AssemblyInfo.cs delete mode 100644 ConsoleApplication1/packages.config diff --git a/ConsoleApplication1/App.config b/ConsoleApplication1/App.config deleted file mode 100644 index 88fa402..0000000 --- a/ConsoleApplication1/App.config +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/ConsoleApplication1/ConsoleApplication1.csproj b/ConsoleApplication1/ConsoleApplication1.csproj deleted file mode 100644 index dd8a534..0000000 --- a/ConsoleApplication1/ConsoleApplication1.csproj +++ /dev/null @@ -1,60 +0,0 @@ - - - - - Debug - AnyCPU - {E3795473-F7F0-4B61-A589-6EBC601A90AA} - Exe - Properties - ConsoleApplication1 - ConsoleApplication1 - v4.5.2 - 512 - true - - - AnyCPU - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - AnyCPU - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/ConsoleApplication1/Program.cs b/ConsoleApplication1/Program.cs deleted file mode 100644 index 99abfb2..0000000 --- a/ConsoleApplication1/Program.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ConsoleApplication1 -{ - class Program - { - static void Main(string[] args) - { - } - } -} diff --git a/ConsoleApplication1/Properties/AssemblyInfo.cs b/ConsoleApplication1/Properties/AssemblyInfo.cs deleted file mode 100644 index 30dd501..0000000 --- a/ConsoleApplication1/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// 有关程序集的一般信息由以下 -// 控制。更改这些特性值可修改 -// 与程序集关联的信息。 -[assembly: AssemblyTitle("ConsoleApplication1")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("ConsoleApplication1")] -[assembly: AssemblyCopyright("Copyright © 2017")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -//将 ComVisible 设置为 false 将使此程序集中的类型 -//对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, -//请将此类型的 ComVisible 特性设置为 true。 -[assembly: ComVisible(false)] - -// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID -[assembly: Guid("e3795473-f7f0-4b61-a589-6ebc601a90aa")] - -// 程序集的版本信息由下列四个值组成: -// -// 主版本 -// 次版本 -// 生成号 -// 修订号 -// -//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, -// 方法是按如下所示使用“*”: : -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/ConsoleApplication1/packages.config b/ConsoleApplication1/packages.config deleted file mode 100644 index d814976..0000000 --- a/ConsoleApplication1/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file From 929aa87844cd1980fdcad671d61108dc55d43d8d Mon Sep 17 00:00:00 2001 From: chuanzhang Date: Thu, 7 Sep 2017 11:01:06 +0800 Subject: [PATCH 5/6] rename --- DbContextScope.sln | 4 ++-- .../Implementations/DbContextCollection.cs | 12 ++++++------ Mehdime.Entity/Interfaces/IDbContextCollection.cs | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/DbContextScope.sln b/DbContextScope.sln index f93c8fd..a8f91a3 100644 --- a/DbContextScope.sln +++ b/DbContextScope.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2013 -VisualStudioVersion = 12.0.31101.0 +# Visual Studio 14 +VisualStudioVersion = 14.0.25420.1 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Demo Application", "DemoApplication\Demo Application.csproj", "{977FC0C6-4FDF-4DD9-AAC0-456D4D79C96C}" EndProject diff --git a/Mehdime.Entity/Implementations/DbContextCollection.cs b/Mehdime.Entity/Implementations/DbContextCollection.cs index f55e461..f4410ba 100644 --- a/Mehdime.Entity/Implementations/DbContextCollection.cs +++ b/Mehdime.Entity/Implementations/DbContextCollection.cs @@ -85,9 +85,9 @@ public TDbContext Get() where TDbContext : DbContext } /// - /// When Transaction Commited + /// When Transaction Committed /// - public event EventHandler TransactionCommited; + public event EventHandler TransactionCommitted; public int Commit() { @@ -145,7 +145,7 @@ public int Commit() if (lastError != null) lastError.Throw(); // Re-throw while maintaining the exception's original stack track - OnTransactionCommited(new EventArgs()); + OnTransactionCommitted(new EventArgs()); return c; } @@ -199,7 +199,7 @@ public async Task CommitAsync(CancellationToken cancelToken) if (lastError != null) lastError.Throw(); // Re-throw while maintaining the exception's original stack track - OnTransactionCommited(new EventArgs()); + OnTransactionCommitted(new EventArgs()); return c; } @@ -291,9 +291,9 @@ private static TValue GetValueOrDefault(IDictionary return dictionary.TryGetValue(key, out value) ? value : default(TValue); } - protected void OnTransactionCommited(EventArgs e) + protected void OnTransactionCommitted(EventArgs e) { - var temp = Volatile.Read(ref TransactionCommited); + var temp = Volatile.Read(ref TransactionCommitted); temp?.Invoke(this, e); } diff --git a/Mehdime.Entity/Interfaces/IDbContextCollection.cs b/Mehdime.Entity/Interfaces/IDbContextCollection.cs index ff66ed7..5463073 100644 --- a/Mehdime.Entity/Interfaces/IDbContextCollection.cs +++ b/Mehdime.Entity/Interfaces/IDbContextCollection.cs @@ -21,8 +21,8 @@ public interface IDbContextCollection : IDisposable TDbContext Get() where TDbContext : DbContext; /// - /// When Transaction Commited + /// When Transaction Committed /// - event EventHandler TransactionCommited; + event EventHandler TransactionCommitted; } } \ No newline at end of file From 7a984fb25fa9b04395c9c15fae5fbd90c4d7e3e1 Mon Sep 17 00:00:00 2001 From: chuanzhang Date: Thu, 7 Sep 2017 11:02:09 +0800 Subject: [PATCH 6/6] change version --- Mehdime.Entity/Properties/AssemblyInfo.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Mehdime.Entity/Properties/AssemblyInfo.cs b/Mehdime.Entity/Properties/AssemblyInfo.cs index 2dee2a4..0fc1dcd 100644 --- a/Mehdime.Entity/Properties/AssemblyInfo.cs +++ b/Mehdime.Entity/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.1")] -[assembly: AssemblyFileVersion("1.0.0.1")] +[assembly: AssemblyVersion("1.0.0.2")] +[assembly: AssemblyFileVersion("1.0.0.2")]