mirror of
https://github.com/JKorf/CryptoExchange.Net
synced 2025-06-08 00:16:27 +00:00
Added state getter for socket
This commit is contained in:
parent
43df283761
commit
9e8ccd6a0f
@ -39,6 +39,16 @@ namespace CryptoExchange.Net.Implementation
|
|||||||
set => socket.AutoSendPingInterval = (int) Math.Round(value.TotalSeconds);
|
set => socket.AutoSendPingInterval = (int) Math.Round(value.TotalSeconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public WebSocketState SocketState
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (socket == null)
|
||||||
|
return WebSocketState.None;
|
||||||
|
return socket.State;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public BaseSocket(Log log, string url):this(log, url, new Dictionary<string, string>(), new Dictionary<string, string>())
|
public BaseSocket(Log log, string url):this(log, url, new Dictionary<string, string>(), new Dictionary<string, string>())
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -1,86 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Security.Authentication;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using CryptoExchange.Net.Interfaces;
|
|
||||||
|
|
||||||
namespace CryptoExchange.Net.Implementation
|
|
||||||
{
|
|
||||||
public class TestWebsocket: IWebsocket
|
|
||||||
{
|
|
||||||
public List<string> MessagesSend = new List<string>();
|
|
||||||
|
|
||||||
public void Dispose()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SetEnabledSslProtocols(SslProtocols protocols)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SetProxy(string host, int port)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public event Action OnClose;
|
|
||||||
public event Action<string> OnMessage;
|
|
||||||
public event Action<Exception> OnError;
|
|
||||||
public event Action OnOpen;
|
|
||||||
|
|
||||||
public bool IsClosed { get; private set; } = true;
|
|
||||||
public bool IsOpen { get; private set; }
|
|
||||||
public bool PingConnection { get; set; }
|
|
||||||
public TimeSpan PingInterval { get; set; }
|
|
||||||
|
|
||||||
public bool HasConnection = true;
|
|
||||||
|
|
||||||
public Task<bool> Connect()
|
|
||||||
{
|
|
||||||
if (!HasConnection)
|
|
||||||
{
|
|
||||||
OnError?.Invoke(new Exception("No connection"));
|
|
||||||
return Task.FromResult(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
IsClosed = false;
|
|
||||||
IsOpen = true;
|
|
||||||
OnOpen?.Invoke();
|
|
||||||
|
|
||||||
return Task.FromResult(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Send(string data)
|
|
||||||
{
|
|
||||||
if (!HasConnection)
|
|
||||||
{
|
|
||||||
OnError?.Invoke(new Exception("No connection"));
|
|
||||||
Close();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
MessagesSend.Add(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task EnqueueMessage(string data, int wait)
|
|
||||||
{
|
|
||||||
await Task.Delay(wait);
|
|
||||||
OnMessage?.Invoke(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task InvokeError(Exception ex, bool closeConnection)
|
|
||||||
{
|
|
||||||
await Task.Delay(10);
|
|
||||||
OnError?.Invoke(ex);
|
|
||||||
if (closeConnection)
|
|
||||||
await Close();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task Close()
|
|
||||||
{
|
|
||||||
IsClosed = true;
|
|
||||||
IsOpen = false;
|
|
||||||
OnClose?.Invoke();
|
|
||||||
return Task.FromResult(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,13 +0,0 @@
|
|||||||
using CryptoExchange.Net.Interfaces;
|
|
||||||
using CryptoExchange.Net.Logging;
|
|
||||||
|
|
||||||
namespace CryptoExchange.Net.Implementation
|
|
||||||
{
|
|
||||||
public class TestWebsocketFactory : IWebsocketFactory
|
|
||||||
{
|
|
||||||
public IWebsocket CreateWebsocket(Log log, string url)
|
|
||||||
{
|
|
||||||
return new TestWebsocket();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Security.Authentication;
|
using System.Security.Authentication;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using WebSocket4Net;
|
||||||
|
|
||||||
namespace CryptoExchange.Net.Interfaces
|
namespace CryptoExchange.Net.Interfaces
|
||||||
{
|
{
|
||||||
@ -13,6 +14,7 @@ namespace CryptoExchange.Net.Interfaces
|
|||||||
event Action<Exception> OnError;
|
event Action<Exception> OnError;
|
||||||
event Action OnOpen;
|
event Action OnOpen;
|
||||||
|
|
||||||
|
WebSocketState SocketState { get; }
|
||||||
bool IsClosed { get; }
|
bool IsClosed { get; }
|
||||||
bool IsOpen { get; }
|
bool IsOpen { get; }
|
||||||
bool PingConnection { get; set; }
|
bool PingConnection { get; set; }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user