From d3cd128ca899e651862f16a1b074131f2312ee10 Mon Sep 17 00:00:00 2001 From: Jan Korf Date: Fri, 1 Feb 2019 17:01:02 +0100 Subject: [PATCH] Added exception event on socket subscription --- CryptoExchange.Net/SocketClient.cs | 1 + CryptoExchange.Net/Sockets/SocketSubscription.cs | 6 ++++++ CryptoExchange.Net/Sockets/UpdateSubscription.cs | 9 +++++++++ 3 files changed, 16 insertions(+) diff --git a/CryptoExchange.Net/SocketClient.cs b/CryptoExchange.Net/SocketClient.cs index 642328e..f2bb669 100644 --- a/CryptoExchange.Net/SocketClient.cs +++ b/CryptoExchange.Net/SocketClient.cs @@ -158,6 +158,7 @@ namespace CryptoExchange.Net catch(Exception ex) { log.Write(LogVerbosity.Error, $"Socket {subscription.Socket.Id} Exception during message processing\r\nProcessor: {currentHandlerName}\r\nException: {ex}\r\nData: {data}"); + subscription.InvokeExceptionHandler(ex); } } diff --git a/CryptoExchange.Net/Sockets/SocketSubscription.cs b/CryptoExchange.Net/Sockets/SocketSubscription.cs index a5911c0..3031c83 100644 --- a/CryptoExchange.Net/Sockets/SocketSubscription.cs +++ b/CryptoExchange.Net/Sockets/SocketSubscription.cs @@ -12,6 +12,7 @@ namespace CryptoExchange.Net.Sockets { public event Action ConnectionLost; public event Action ConnectionRestored; + public event Action Exception; /// /// Message handlers for this subscription. Should return true if the message is handled and should not be distributed to the other handlers @@ -145,6 +146,11 @@ namespace CryptoExchange.Net.Sockets } } + public void InvokeExceptionHandler(Exception e) + { + Exception(e); + } + public async Task Close() { Socket.ShouldReconnect = false; diff --git a/CryptoExchange.Net/Sockets/UpdateSubscription.cs b/CryptoExchange.Net/Sockets/UpdateSubscription.cs index 7188679..ba872e9 100644 --- a/CryptoExchange.Net/Sockets/UpdateSubscription.cs +++ b/CryptoExchange.Net/Sockets/UpdateSubscription.cs @@ -25,6 +25,15 @@ namespace CryptoExchange.Net.Sockets remove => subscription.ConnectionRestored -= value; } + /// + /// Event when an exception happened + /// + public event Action Exception + { + add => subscription.Exception += value; + remove => subscription.Exception -= value; + } + /// /// The id of the socket ///