mirror of
https://github.com/JKorf/CryptoExchange.Net
synced 2025-06-11 18:06:27 +00:00
Added paused activity socket events
This commit is contained in:
parent
d459102323
commit
66c0b90016
@ -2689,6 +2689,16 @@
|
|||||||
Connecting restored event
|
Connecting restored event
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="E:CryptoExchange.Net.Sockets.SocketConnection.ActivityPaused">
|
||||||
|
<summary>
|
||||||
|
The connection is paused event
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="E:CryptoExchange.Net.Sockets.SocketConnection.ActivityUnpaused">
|
||||||
|
<summary>
|
||||||
|
The connection is unpaused event
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
<member name="E:CryptoExchange.Net.Sockets.SocketConnection.Closed">
|
<member name="E:CryptoExchange.Net.Sockets.SocketConnection.Closed">
|
||||||
<summary>
|
<summary>
|
||||||
Connecting closed event
|
Connecting closed event
|
||||||
@ -2858,6 +2868,16 @@
|
|||||||
Event when the connection is restored. Timespan parameter indicates the time the socket has been offline for before reconnecting
|
Event when the connection is restored. Timespan parameter indicates the time the socket has been offline for before reconnecting
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="E:CryptoExchange.Net.Sockets.UpdateSubscription.ActivityPaused">
|
||||||
|
<summary>
|
||||||
|
Event when the connection to the server is paused. No operations can be performed while paused
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="E:CryptoExchange.Net.Sockets.UpdateSubscription.ActivityUnpaused">
|
||||||
|
<summary>
|
||||||
|
Event when the connection to the server is unpaused
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
<member name="E:CryptoExchange.Net.Sockets.UpdateSubscription.Exception">
|
<member name="E:CryptoExchange.Net.Sockets.UpdateSubscription.Exception">
|
||||||
<summary>
|
<summary>
|
||||||
Event when an exception happened
|
Event when an exception happened
|
||||||
|
@ -161,6 +161,11 @@ namespace CryptoExchange.Net
|
|||||||
semaphoreSlim.Release();
|
semaphoreSlim.Release();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (socket.PausedActivity)
|
||||||
|
{
|
||||||
|
log.Write(LogVerbosity.Info, "Socket has been paused, can't subscribe at this moment");
|
||||||
|
return new CallResult<UpdateSubscription>(default, new ServerError("Socket is paused"));
|
||||||
|
}
|
||||||
|
|
||||||
if (request != null)
|
if (request != null)
|
||||||
{
|
{
|
||||||
|
@ -25,6 +25,14 @@ namespace CryptoExchange.Net.Sockets
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public event Action<TimeSpan>? ConnectionRestored;
|
public event Action<TimeSpan>? ConnectionRestored;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
/// The connection is paused event
|
||||||
|
/// </summary>
|
||||||
|
public event Action? ActivityPaused;
|
||||||
|
/// <summary>
|
||||||
|
/// The connection is unpaused event
|
||||||
|
/// </summary>
|
||||||
|
public event Action? ActivityUnpaused;
|
||||||
|
/// <summary>
|
||||||
/// Connecting closed event
|
/// Connecting closed event
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public event Action? Closed;
|
public event Action? Closed;
|
||||||
@ -60,11 +68,26 @@ namespace CryptoExchange.Net.Sockets
|
|||||||
/// Time of disconnecting
|
/// Time of disconnecting
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public DateTime? DisconnectTime { get; set; }
|
public DateTime? DisconnectTime { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// If activity is paused
|
/// If activity is paused
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool PausedActivity { get; set; }
|
public bool PausedActivity
|
||||||
|
{
|
||||||
|
get => pausedActivity;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (pausedActivity != value)
|
||||||
|
{
|
||||||
|
pausedActivity = value;
|
||||||
|
log.Write(LogVerbosity.Debug, "Paused activity: " + value);
|
||||||
|
if(pausedActivity) ActivityPaused?.Invoke();
|
||||||
|
else ActivityUnpaused?.Invoke();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool pausedActivity;
|
||||||
private readonly List<SocketSubscription> handlers;
|
private readonly List<SocketSubscription> handlers;
|
||||||
private readonly object handlersLock = new object();
|
private readonly object handlersLock = new object();
|
||||||
|
|
||||||
@ -155,7 +178,7 @@ namespace CryptoExchange.Net.Sockets
|
|||||||
var sw = Stopwatch.StartNew();
|
var sw = Stopwatch.StartNew();
|
||||||
lock (handlersLock)
|
lock (handlersLock)
|
||||||
{
|
{
|
||||||
foreach (var handler in handlers)
|
foreach (var handler in handlers.ToList())
|
||||||
{
|
{
|
||||||
currentSubscription = handler;
|
currentSubscription = handler;
|
||||||
if (handler.Request == null)
|
if (handler.Request == null)
|
||||||
|
@ -29,6 +29,24 @@ namespace CryptoExchange.Net.Sockets
|
|||||||
remove => connection.ConnectionRestored -= value;
|
remove => connection.ConnectionRestored -= value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Event when the connection to the server is paused. No operations can be performed while paused
|
||||||
|
/// </summary>
|
||||||
|
public event Action ActivityPaused
|
||||||
|
{
|
||||||
|
add => connection.ActivityPaused += value;
|
||||||
|
remove => connection.ActivityPaused -= value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Event when the connection to the server is unpaused
|
||||||
|
/// </summary>
|
||||||
|
public event Action ActivityUnpaused
|
||||||
|
{
|
||||||
|
add => connection.ActivityUnpaused += value;
|
||||||
|
remove => connection.ActivityUnpaused -= value;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Event when an exception happened
|
/// Event when an exception happened
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user