1- // Copyright (C) 2009-2020 Xtensive LLC.
1+ // Copyright (C) 2009-2021 Xtensive LLC.
22// This code is distributed under MIT license terms.
33// See the License.txt file in the project root for more information.
44// Created by: Denis Krjuchkov
88using System . Collections . Generic ;
99using System . Data ;
1010using System . Data . Common ;
11- using System . Data . SqlClient ;
12- using System . Linq ;
1311using System . Runtime . CompilerServices ;
14- using System . Text ;
1512using System . Threading ;
1613using System . Threading . Tasks ;
17- using JetBrains . Annotations ;
18- using Xtensive . Collections ;
1914using Xtensive . Core ;
2015using Xtensive . Orm ;
2116using Xtensive . Sql . Dml ;
@@ -491,6 +486,8 @@ public static NotSupportedException NotSupported(ServerFeatures feature)
491486 return NotSupported ( feature . ToString ( ) ) ;
492487 }
493488
489+ #region Notifications
490+
494491 /// <summary>
495492 /// Notifies all the <paramref name="connectionHandlers"/> that
496493 /// <paramref name="connection"/> is about to be opened.
@@ -502,8 +499,29 @@ public static NotSupportedException NotSupported(ServerFeatures feature)
502499 public static void NotifyConnectionOpening (
503500 IEnumerable < IConnectionHandler > connectionHandlers , DbConnection connection , bool reconnect = false )
504501 {
505- foreach ( var handler in connectionHandlers )
502+ foreach ( var handler in connectionHandlers ) {
506503 handler . ConnectionOpening ( new ConnectionEventData ( connection , reconnect ) ) ;
504+ }
505+ }
506+
507+ /// <summary>
508+ /// Notifies all the <paramref name="connectionHandlers"/> that
509+ /// <paramref name="connection"/> is about to be opened.
510+ /// </summary>
511+ /// <param name="connectionHandlers">The handlers that should be notified.</param>
512+ /// <param name="connection">The connection that is opening.</param>
513+ /// <param name="reconnect"><see langword="true"/> if event happened on attemp to restore connection, otherwise <see langword="false"/>.</param>
514+ /// <param name="token">Cancellation token.</param>
515+ /// <returns>Task performing operation.</returns>
516+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
517+ public static async Task NotifyConnectionOpeningAsync (
518+ IEnumerable < IConnectionHandler > connectionHandlers , DbConnection connection , bool reconnect = false , CancellationToken token = default )
519+ {
520+ foreach ( var handler in connectionHandlers ) {
521+ await handler . ConnectionOpeningAsync (
522+ new ConnectionEventData ( connection , reconnect ) , token )
523+ . ConfigureAwait ( false ) ;
524+ }
507525 }
508526
509527 /// <summary>
@@ -518,8 +536,33 @@ public static void NotifyConnectionOpening(
518536 public static void NotifyConnectionInitializing (
519537 IEnumerable < IConnectionHandler > connectionHandlers , DbConnection connection , string initializationScript , bool reconnect = false )
520538 {
521- foreach ( var handler in connectionHandlers )
539+ foreach ( var handler in connectionHandlers ) {
522540 handler . ConnectionInitialization ( new ConnectionInitEventData ( initializationScript , connection , reconnect ) ) ;
541+ }
542+ }
543+
544+ /// <summary>
545+ /// Notifies all the <paramref name="connectionHandlers"/> that
546+ /// opened connection is about to be initialized with <paramref name="initializationScript"/>.
547+ /// </summary>
548+ /// <param name="connectionHandlers">The handlers that should be notified.</param>
549+ /// <param name="connection">Opened but not initialized connection</param>
550+ /// <param name="initializationScript">The script that will run to initialize connection</param>
551+ /// <param name="reconnect"><see langword="true"/> if event happened on attemp to restore connection, otherwise <see langword="false"/>.</param>
552+ /// <param name="token">Cancellation token.</param>
553+ /// <returns>Task performing operation.</returns>
554+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
555+ public static async Task NotifyConnectionInitializingAsync ( IEnumerable < IConnectionHandler > connectionHandlers ,
556+ DbConnection connection ,
557+ string initializationScript ,
558+ bool reconnect = false ,
559+ CancellationToken token = default )
560+ {
561+ foreach ( var handler in connectionHandlers ) {
562+ await handler . ConnectionInitializationAsync (
563+ new ConnectionInitEventData ( initializationScript , connection , reconnect ) , token )
564+ . ConfigureAwait ( false ) ;
565+ }
523566 }
524567
525568 /// <summary>
@@ -533,8 +576,29 @@ public static void NotifyConnectionInitializing(
533576 public static void NotifyConnectionOpened (
534577 IEnumerable < IConnectionHandler > connectionHandlers , DbConnection connection , bool reconnect = false )
535578 {
536- foreach ( var handler in connectionHandlers )
579+ foreach ( var handler in connectionHandlers ) {
537580 handler . ConnectionOpened ( new ConnectionEventData ( connection , reconnect ) ) ;
581+ }
582+ }
583+
584+ /// <summary>
585+ /// Notifies all the <paramref name="connectionHandlers"/> about
586+ /// successful connection opening.
587+ /// </summary>
588+ /// <param name="connectionHandlers">The handlers that should be notified.</param>
589+ /// <param name="connection">The connection that is completely opened and initialized.</param>
590+ /// <param name="reconnect"><see langword="true"/> if event happened on attemp to restore connection, otherwise <see langword="false"/>.</param>
591+ /// <param name="token">Cancellation token.</param>
592+ /// <returns>Task performing operation.</returns>
593+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
594+ public static async Task NotifyConnectionOpenedAsync (
595+ IEnumerable < IConnectionHandler > connectionHandlers , DbConnection connection , bool reconnect = false , CancellationToken token = default )
596+ {
597+ foreach ( var handler in connectionHandlers ) {
598+ await handler . ConnectionOpenedAsync (
599+ new ConnectionEventData ( connection , reconnect ) , token )
600+ . ConfigureAwait ( false ) ;
601+ }
538602 }
539603
540604 /// <summary>
@@ -549,8 +613,35 @@ public static void NotifyConnectionOpened(
549613 public static void NotifyConnectionOpeningFailed (
550614 IEnumerable < IConnectionHandler > connectionHandlers , DbConnection connection , Exception exception , bool reconnect = false )
551615 {
552- foreach ( var handler in connectionHandlers )
616+ foreach ( var handler in connectionHandlers ) {
553617 handler . ConnectionOpeningFailed ( new ConnectionErrorEventData ( exception , connection , reconnect ) ) ;
618+ }
554619 }
620+
621+ /// <summary>
622+ /// Notifies all the <paramref name="connectionHandlers"/> about
623+ /// connection opening failure.
624+ /// </summary>
625+ /// <param name="connectionHandlers">The handlers that should be notified.</param>
626+ /// <param name="connection">Connection that failed to be opened or properly initialized.</param>
627+ /// <param name="exception">The exception which appeared.</param>
628+ /// <param name="reconnect"><see langword="true"/> if event happened on attemp to restore connection, otherwise <see langword="false"/>.</param>
629+ /// <param name="token">Cancellation token.</param>
630+ /// <returns>Task performing operation.</returns>
631+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
632+ public static async Task NotifyConnectionOpeningFailedAsync ( IEnumerable < IConnectionHandler > connectionHandlers ,
633+ DbConnection connection ,
634+ Exception exception ,
635+ bool reconnect = false ,
636+ CancellationToken token = default )
637+ {
638+ foreach ( var handler in connectionHandlers ) {
639+ await handler . ConnectionOpeningFailedAsync (
640+ new ConnectionErrorEventData ( exception , connection , reconnect ) , token )
641+ . ConfigureAwait ( false ) ;
642+ }
643+ }
644+
645+ #endregion
555646 }
556647}
0 commit comments