|
1 | | -// Copyright (C) 2003-2010 Xtensive LLC. |
| 1 | +// Copyright (C) 2009-2021 Xtensive LLC. |
2 | 2 | // All rights reserved. |
3 | 3 | // For conditions of distribution and use, see license. |
4 | 4 | // Created by: Denis Krjuchkov |
@@ -433,5 +433,75 @@ public static NotSupportedException NotSupported(ServerFeatures feature) |
433 | 433 | { |
434 | 434 | return NotSupported(feature.ToString()); |
435 | 435 | } |
| 436 | + |
| 437 | + #region Notifications |
| 438 | + |
| 439 | + /// <summary> |
| 440 | + /// Notifies all the <paramref name="connectionHandlers"/> that |
| 441 | + /// <paramref name="connection"/> is about to be opened. |
| 442 | + /// </summary> |
| 443 | + /// <param name="connectionHandlers">The handlers that should be notified.</param> |
| 444 | + /// <param name="connection">The connection that is opening.</param> |
| 445 | + /// <param name="reconnect"><see langword="true"/> if event happened on attemp to restore connection, otherwise <see langword="false"/>.</param> |
| 446 | + [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| 447 | + public static void NotifyConnectionOpening( |
| 448 | + IEnumerable<IConnectionHandler> connectionHandlers, DbConnection connection, bool reconnect = false) |
| 449 | + { |
| 450 | + foreach (var handler in connectionHandlers) { |
| 451 | + handler.ConnectionOpening(new ConnectionEventData(connection, reconnect)); |
| 452 | + } |
| 453 | + } |
| 454 | + |
| 455 | + /// <summary> |
| 456 | + /// Notifies all the <paramref name="connectionHandlers"/> that |
| 457 | + /// opened connection is about to be initialized with <paramref name="initializationScript"/>. |
| 458 | + /// </summary> |
| 459 | + /// <param name="connectionHandlers">The handlers that should be notified.</param> |
| 460 | + /// <param name="connection">Opened but not initialized connection</param> |
| 461 | + /// <param name="initializationScript">The script that will run to initialize connection</param> |
| 462 | + /// <param name="reconnect"><see langword="true"/> if event happened on attemp to restore connection, otherwise <see langword="false"/>.</param> |
| 463 | + [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| 464 | + public static void NotifyConnectionInitializing( |
| 465 | + IEnumerable<IConnectionHandler> connectionHandlers, DbConnection connection, string initializationScript, bool reconnect = false) |
| 466 | + { |
| 467 | + foreach (var handler in connectionHandlers) { |
| 468 | + handler.ConnectionInitialization(new ConnectionInitEventData(initializationScript, connection, reconnect)); |
| 469 | + } |
| 470 | + } |
| 471 | + |
| 472 | + /// <summary> |
| 473 | + /// Notifies all the <paramref name="connectionHandlers"/> about |
| 474 | + /// successful connection opening. |
| 475 | + /// </summary> |
| 476 | + /// <param name="connectionHandlers">The handlers that should be notified.</param> |
| 477 | + /// <param name="connection">The connection that is completely opened and initialized.</param> |
| 478 | + /// <param name="reconnect"><see langword="true"/> if event happened on attemp to restore connection, otherwise <see langword="false"/>.</param> |
| 479 | + [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| 480 | + public static void NotifyConnectionOpened( |
| 481 | + IEnumerable<IConnectionHandler> connectionHandlers, DbConnection connection, bool reconnect = false) |
| 482 | + { |
| 483 | + foreach (var handler in connectionHandlers) { |
| 484 | + handler.ConnectionOpened(new ConnectionEventData(connection, reconnect)); |
| 485 | + } |
| 486 | + } |
| 487 | + |
| 488 | + /// <summary> |
| 489 | + /// Notifies all the <paramref name="connectionHandlers"/> about |
| 490 | + /// connection opening failure. |
| 491 | + /// </summary> |
| 492 | + /// <param name="connectionHandlers">The handlers that should be notified.</param> |
| 493 | + /// <param name="connection">Connection that failed to be opened or properly initialized.</param> |
| 494 | + /// <param name="exception">The exception which appeared.</param> |
| 495 | + /// <param name="reconnect"><see langword="true"/> if event happened on attemp to restore connection, otherwise <see langword="false"/>.</param> |
| 496 | + [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| 497 | + public static void NotifyConnectionOpeningFailed( |
| 498 | + IEnumerable<IConnectionHandler> connectionHandlers, DbConnection connection, Exception exception, bool reconnect = false) |
| 499 | + { |
| 500 | + foreach (var handler in connectionHandlers) { |
| 501 | + handler.ConnectionOpeningFailed(new ConnectionErrorEventData(exception, connection, reconnect)); |
| 502 | + } |
| 503 | + } |
| 504 | + |
| 505 | + #endregion |
436 | 506 | } |
437 | 507 | } |
0 commit comments