-
Notifications
You must be signed in to change notification settings - Fork 933
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replaced TransactionCompletion delegates with interface implementations
- Loading branch information
Showing
18 changed files
with
393 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/NHibernate/Action/AfterTransactionCompletionProcess.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace NHibernate.Action | ||
{ | ||
public partial class AfterTransactionCompletionProcess : IAfterTransactionCompletionProcess | ||
{ | ||
private readonly Action<bool> _syncAction; | ||
private readonly Func<bool, CancellationToken, Task> _asyncAction; | ||
|
||
public AfterTransactionCompletionProcess(Action<bool> syncAction, Func<bool, CancellationToken, Task> asyncAction) | ||
{ | ||
|
||
_syncAction = syncAction; | ||
_asyncAction = asyncAction; | ||
} | ||
|
||
public AfterTransactionCompletionProcess(Action<bool> syncAction) | ||
{ | ||
_syncAction = syncAction; | ||
_asyncAction = (success, cancellationToken) => | ||
{ | ||
if (cancellationToken.IsCancellationRequested) | ||
{ | ||
return Task.FromCanceled<object>(cancellationToken); | ||
} | ||
try | ||
{ | ||
_syncAction(success); | ||
return Task.CompletedTask; | ||
} | ||
catch (Exception ex) | ||
{ | ||
return Task.FromException<object>(ex); | ||
} | ||
}; | ||
} | ||
|
||
public void Execute(bool success) | ||
{ | ||
_syncAction(success); | ||
} | ||
|
||
public Task ExecuteAsync(bool success, CancellationToken cancellationToken) | ||
{ | ||
return _asyncAction(success, cancellationToken); | ||
} | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
src/NHibernate/Action/BeforeTransactionCompletionProcess.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace NHibernate.Action | ||
{ | ||
public class BeforeTransactionCompletionProcess : IBeforeTransactionCompletionProcess | ||
{ | ||
private readonly System.Action _syncAction; | ||
private readonly Func<CancellationToken, Task> _asyncAction; | ||
|
||
public BeforeTransactionCompletionProcess(System.Action syncAction, Func<CancellationToken, Task> asyncAction) | ||
{ | ||
_syncAction = syncAction; | ||
_asyncAction = asyncAction; | ||
} | ||
|
||
public BeforeTransactionCompletionProcess(System.Action syncAction) | ||
{ | ||
_syncAction = syncAction; | ||
_asyncAction = (cancellationToken) => | ||
{ | ||
if (cancellationToken.IsCancellationRequested) | ||
{ | ||
return Task.FromCanceled<object>(cancellationToken); | ||
} | ||
try | ||
{ | ||
_syncAction(); | ||
return Task.CompletedTask; | ||
} | ||
catch (Exception ex) | ||
{ | ||
return Task.FromException<object>(ex); | ||
} | ||
}; | ||
} | ||
|
||
public void Execute() | ||
{ | ||
_syncAction(); | ||
} | ||
|
||
public Task ExecuteAsync(CancellationToken cancellationToken) | ||
{ | ||
return _asyncAction(cancellationToken); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/NHibernate/Action/IAfterTransactionCompletionProcess.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
namespace NHibernate.Action | ||
{ | ||
public partial interface IAfterTransactionCompletionProcess | ||
{ | ||
/// <summary> | ||
/// Perform whatever processing is encapsulated here after completion of the transaction. | ||
/// </summary> | ||
/// <param name="success">Did the transaction complete successfully? True means it did.</param> | ||
void Execute(bool success); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace NHibernate.Action | ||
{ | ||
public partial interface IBeforeTransactionCompletionProcess | ||
{ | ||
void Execute(); | ||
} | ||
} |
Oops, something went wrong.