Skip to content

Commit 58ca0bb

Browse files
authored
Add Session DbCommandCanceled event (#128)
1 parent a12db3e commit 58ca0bb

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

Orm/Xtensive.Orm.Tests/Storage/SessionEventsTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ public class EventInfo : SessionBound, IDisposable
5555
public EntityFieldValueEventArgs EntityFieldValueSettingArgs;
5656
public EntityFieldValueSetEventArgs EntityFieldValueSetArgs;
5757

58-
public QueryEventArgs QueryExecuting;
59-
public QueryEventArgs QueryExecuted;
58+
public QueryEventArgs? QueryExecuting;
59+
public QueryEventArgs? QueryExecuted;
6060

6161
public DbCommandEventArgs? DbCommandExecuting;
6262
public DbCommandEventArgs? DbCommandExecuted;

Orm/Xtensive.Orm/Orm/Providers/StorageDriver.Operations.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,7 @@ private async Task<TResult> ExecuteCommandAsync<TResult>(Session session,
469469
result = await action(command, commandBehavior, cancellationToken).ConfigureAwait(false);
470470
}
471471
catch (OperationCanceledException) {
472+
session?.Events.NotifyDbCommandCanceled(command);
472473
throw;
473474
}
474475
catch (Exception exception) {

Orm/Xtensive.Orm/Orm/QueryEventArgs.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ namespace Xtensive.Orm
1212
/// Event args for <see cref="SessionEventAccessor.QueryExecuting"/>
1313
/// and <see cref="SessionEventAccessor.QueryExecuted"/>.
1414
/// </summary>
15-
public class QueryEventArgs : EventArgs
15+
public readonly struct QueryEventArgs
1616
{
1717
/// <summary>
1818
/// Gets executed expression.
1919
/// </summary>
20-
public Expression Expression { get; set; }
20+
public Expression Expression { get; }
2121

2222
/// <summary>
2323
/// Gets exception, thrown during expression execution. <see langword="null" /> if expression executed successfully.

Orm/Xtensive.Orm/Orm/SessionEventAccessor.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ public sealed class SessionEventAccessor
4242
/// </summary>
4343
public event EventHandler<DbCommandEventArgs> DbCommandExecuted;
4444

45+
/// <summary>
46+
/// Occurs when <see cref="DbCommand"/> is canceled.
47+
/// </summary>
48+
public event EventHandler<DbCommandEventArgs> DbCommandCanceled;
49+
4550
/// <summary>
4651
/// Occurs when LINQ query is about to execute.
4752
/// </summary>
@@ -253,6 +258,9 @@ internal void NotifyDbCommandExecuted(DbCommand command, Exception exception = n
253258
DbCommandExecuted?.Invoke(this, new DbCommandEventArgs(command, exception));
254259
}
255260

261+
internal void NotifyDbCommandCanceled(DbCommand command) =>
262+
DbCommandCanceled?.Invoke(this, new DbCommandEventArgs(command));
263+
256264
internal Expression NotifyQueryExecuting(Expression expression)
257265
{
258266
var args = new QueryEventArgs(expression);

0 commit comments

Comments
 (0)