1
0
mirror of https://github.com/JKorf/CryptoExchange.Net.git synced 2026-08-20 21:02:55 +00:00

Fixed various resharper warning

This commit is contained in:
JKorf
2018-11-30 16:19:01 +01:00
parent 4c6218c8e3
commit 64a66d4206
17 changed files with 91 additions and 97 deletions
+2 -9
View File
@@ -21,7 +21,6 @@ namespace CryptoExchange.Net.Sockets
protected WebSocket socket;
protected Log log;
protected object socketLock = new object();
protected DateTime? lostTime = null;
protected readonly List<Action<Exception>> errorHandlers = new List<Action<Exception>>();
protected readonly List<Action> openHandlers = new List<Action>();
@@ -214,16 +213,10 @@ namespace CryptoExchange.Net.Sockets
return connected;
}).ConfigureAwait(false);
}
public virtual void SetEnabledSslProtocols(SslProtocols protocols)
{
socket.Security.EnabledSslProtocols = protocols;
}
public virtual void SetProxy(string host, int port)
{
IPAddress address;
socket.Proxy = IPAddress.TryParse(host, out address)
socket.Proxy = IPAddress.TryParse(host, out var address)
? new HttpConnectProxy(new IPEndPoint(address, port))
: new HttpConnectProxy(new DnsEndPoint(host, port));
}
+3 -3
View File
@@ -6,7 +6,7 @@ namespace CryptoExchange.Net.Sockets
public class SocketEvent
{
public string Name { get; set; }
public int WaitingId { get; set; }
public string WaitingId { get; set; }
private CallResult<bool> result;
private ManualResetEvent setEvnt;
@@ -18,11 +18,11 @@ namespace CryptoExchange.Net.Sockets
result = new CallResult<bool>(false, new UnknownError("No response received"));
}
public void Set(bool result, Error error)
internal void Set(bool result, Error error)
{
this.result = new CallResult<bool>(result, error);
setEvnt.Set();
WaitingId = -1;
WaitingId = null;
}
public CallResult<bool> Wait(int timeout = 5000)
@@ -25,7 +25,7 @@ namespace CryptoExchange.Net.Sockets
public SocketType Type { get; set; }
private bool lostTriggered;
private List<SocketEvent> waitingForEvents;
private readonly List<SocketEvent> waitingForEvents;
public SocketSubscription(IWebsocket socket)
@@ -55,7 +55,7 @@ namespace CryptoExchange.Net.Sockets
if (lostTriggered)
{
lostTriggered = false;
ConnectionRestored?.Invoke(DateTime.UtcNow - Socket.DisconnectTime.Value);
ConnectionRestored?.Invoke(Socket.DisconnectTime.HasValue ? DateTime.UtcNow - Socket.DisconnectTime.Value: TimeSpan.FromSeconds(0));
}
};
}
@@ -65,7 +65,7 @@ namespace CryptoExchange.Net.Sockets
Events.Add(new SocketEvent(name));
}
public void SetEvent(string name, bool success, Error error)
public void SetEventByName(string name, bool success, Error error)
{
var waitingEvent = waitingForEvents.SingleOrDefault(e => e.Name == name);
if (waitingEvent != null)
@@ -75,7 +75,7 @@ namespace CryptoExchange.Net.Sockets
}
}
public void SetEvent(int id, bool success, Error error)
public void SetEventById(string id, bool success, Error error)
{
var waitingEvent = waitingForEvents.SingleOrDefault(e => e.WaitingId == id);
if (waitingEvent != null)
@@ -90,6 +90,13 @@ namespace CryptoExchange.Net.Sockets
return waitingForEvents.SingleOrDefault(w => w.Name == name);
}
public Task<CallResult<bool>> WaitForEvent(string name, TimeSpan timeout)
{
return WaitForEvent(name, (int)Math.Round(timeout.TotalMilliseconds, 0));
}
public Task<CallResult<bool>> WaitForEvent(string name, int timeout)
{
var evnt = Events.Single(e => e.Name == name);
@@ -97,7 +104,12 @@ namespace CryptoExchange.Net.Sockets
return Task.Run(() => evnt.Wait(timeout));
}
public Task<CallResult<bool>> WaitForEvent(string name, int id, int timeout)
public Task<CallResult<bool>> WaitForEvent(string name, string id, TimeSpan timeout)
{
return WaitForEvent(name, id, (int)Math.Round(timeout.TotalMilliseconds, 0));
}
public Task<CallResult<bool>> WaitForEvent(string name, string id, int timeout)
{
var evnt = Events.Single(e => e.Name == name);
evnt.WaitingId = id;
@@ -5,7 +5,7 @@ namespace CryptoExchange.Net.Sockets
{
public class UpdateSubscription
{
private SocketSubscription subscription;
private readonly SocketSubscription subscription;
/// <summary>
/// Event when the connection is lost
@@ -25,6 +25,9 @@ namespace CryptoExchange.Net.Sockets
remove => subscription.ConnectionRestored -= value;
}
/// <summary>
/// The id of the socket
/// </summary>
public int Id => subscription.Socket.Id;
public UpdateSubscription(SocketSubscription sub)