mirror of
https://github.com/JKorf/CryptoExchange.Net
synced 2025-06-10 09:26:22 +00:00
Fixed some resharper warnings
This commit is contained in:
parent
bb227b4b12
commit
b5833e5230
@ -10,6 +10,7 @@ using System.Threading.Tasks;
|
||||
using CryptoExchange.Net.Authentication;
|
||||
using CryptoExchange.Net.Interfaces;
|
||||
using CryptoExchange.Net.Logging;
|
||||
using CryptoExchange.Net.Objects;
|
||||
using CryptoExchange.Net.RateLimiter;
|
||||
using Moq;
|
||||
using Newtonsoft.Json;
|
||||
|
@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using CryptoExchange.Net.Authentication;
|
||||
using CryptoExchange.Net.Interfaces;
|
||||
using CryptoExchange.Net.Objects;
|
||||
|
||||
namespace CryptoExchange.Net.UnitTests
|
||||
{
|
||||
|
@ -1,11 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace CryptoExchange.Net.Attributes
|
||||
{
|
||||
public class JsonOptionalPropertyAttribute : Attribute
|
||||
{
|
||||
public JsonOptionalPropertyAttribute() { }
|
||||
}
|
||||
}
|
||||
|
@ -57,9 +57,10 @@ namespace CryptoExchange.Net.Authentication
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create Api credentials providing a private key for authenication
|
||||
/// Create Api credentials providing a api key and secret for authenciation
|
||||
/// </summary>
|
||||
/// <param name="privateKey">The private key used for signing</param>
|
||||
/// <param name="key">The api key used for identification</param>
|
||||
/// <param name="secret">The api secret used for signing</param>
|
||||
public ApiCredentials(string key, string secret)
|
||||
{
|
||||
if (string.IsNullOrEmpty(key) || string.IsNullOrEmpty(secret))
|
||||
|
@ -31,7 +31,7 @@ namespace CryptoExchange.Net
|
||||
protected AuthenticationProvider authProvider;
|
||||
private List<IRateLimiter> rateLimiters;
|
||||
|
||||
private static JsonSerializer defaultSerializer = JsonSerializer.Create(new JsonSerializerSettings()
|
||||
private static readonly JsonSerializer defaultSerializer = JsonSerializer.Create(new JsonSerializerSettings()
|
||||
{
|
||||
DateTimeZoneHandling = DateTimeZoneHandling.Utc
|
||||
});
|
||||
@ -104,7 +104,7 @@ namespace CryptoExchange.Net
|
||||
{
|
||||
var ping = new Ping();
|
||||
var uri = new Uri(baseAddress);
|
||||
PingReply reply = null;
|
||||
PingReply reply;
|
||||
try
|
||||
{
|
||||
reply = await ping.SendPingAsync(uri.Host);
|
||||
@ -115,8 +115,7 @@ namespace CryptoExchange.Net
|
||||
{
|
||||
if (e.InnerException is SocketException)
|
||||
return new CallResult<long>(0, new CantConnectError() { Message = "Ping failed: " + ((SocketException)e.InnerException).SocketErrorCode });
|
||||
else
|
||||
return new CallResult<long>(0, new CantConnectError() { Message = "Ping failed: " + e.InnerException.Message });
|
||||
return new CallResult<long>(0, new CantConnectError() { Message = "Ping failed: " + e.InnerException.Message });
|
||||
}
|
||||
return new CallResult<long>(0, new CantConnectError() { Message = "Ping failed: " + e.Message });
|
||||
}
|
||||
@ -150,7 +149,8 @@ namespace CryptoExchange.Net
|
||||
log.Write(LogVerbosity.Debug, $"Request {uri.AbsolutePath} failed because of rate limit");
|
||||
return new CallResult<T>(null, limitResult.Error);
|
||||
}
|
||||
else if (limitResult.Data > 0)
|
||||
|
||||
if (limitResult.Data > 0)
|
||||
log.Write(LogVerbosity.Debug, $"Request {uri.AbsolutePath} was limited by {limitResult.Data}ms by {limiter.GetType().Name}");
|
||||
}
|
||||
|
||||
@ -359,7 +359,7 @@ namespace CryptoExchange.Net
|
||||
|
||||
foreach (var prop in properties)
|
||||
{
|
||||
var propInfo = props.FirstOrDefault(p => p.Name == prop ||
|
||||
var propInfo = props.First(p => p.Name == prop ||
|
||||
((JsonPropertyAttribute)p.GetCustomAttributes(typeof(JsonPropertyAttribute), false).FirstOrDefault())?.PropertyName == prop);
|
||||
var optional = propInfo.GetCustomAttributes(typeof(JsonOptionalPropertyAttribute), false).FirstOrDefault();
|
||||
if (optional != null)
|
||||
|
@ -33,7 +33,7 @@ namespace CryptoExchange.Net
|
||||
{
|
||||
lock (source)
|
||||
{
|
||||
string result = null;
|
||||
string result;
|
||||
int length = source.Length;
|
||||
IntPtr pointer = IntPtr.Zero;
|
||||
char[] chars = new char[length];
|
||||
|
@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Security.Authentication;
|
||||
@ -47,9 +46,11 @@ namespace CryptoExchange.Net.Implementation
|
||||
public BaseSocket(Log log, string url, IDictionary<string, string> cookies, IDictionary<string, string> headers)
|
||||
{
|
||||
this.log = log;
|
||||
socket = new WebSocket(url, cookies: cookies.ToList(), customHeaderItems: headers.ToList());
|
||||
socket.EnableAutoSendPing = true;
|
||||
socket.AutoSendPingInterval = 10;
|
||||
socket = new WebSocket(url, cookies: cookies.ToList(), customHeaderItems: headers.ToList())
|
||||
{
|
||||
EnableAutoSendPing = true,
|
||||
AutoSendPingInterval = 10
|
||||
};
|
||||
socket.Opened += (o, s) => Handle(openhandlers);
|
||||
socket.Closed += (o, s) => Handle(closehandlers);
|
||||
socket.Error += (o, s) => Handle(errorhandlers, s.Exception);
|
||||
@ -108,7 +109,7 @@ namespace CryptoExchange.Net.Implementation
|
||||
var handler = new EventHandler((o, a) => evnt.Set());
|
||||
socket.Closed += handler;
|
||||
socket.Close();
|
||||
bool triggered = evnt.WaitOne(3000);
|
||||
evnt.WaitOne(3000);
|
||||
socket.Closed -= handler;
|
||||
log.Write(LogVerbosity.Debug, "Websocket closed");
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Security.Authentication;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using CryptoExchange.Net.Interfaces;
|
||||
|
||||
@ -39,7 +38,7 @@ namespace CryptoExchange.Net.Implementation
|
||||
{
|
||||
if (!HasConnection)
|
||||
{
|
||||
OnError(new Exception("No connection"));
|
||||
OnError?.Invoke(new Exception("No connection"));
|
||||
return Task.FromResult(false);
|
||||
}
|
||||
|
||||
@ -54,7 +53,7 @@ namespace CryptoExchange.Net.Implementation
|
||||
{
|
||||
if (!HasConnection)
|
||||
{
|
||||
OnError(new Exception("No connection"));
|
||||
OnError?.Invoke(new Exception("No connection"));
|
||||
Close();
|
||||
return;
|
||||
}
|
||||
|
@ -6,18 +6,17 @@ namespace CryptoExchange.Net.Logging
|
||||
{
|
||||
public class ThreadSafeFileWriter: TextWriter
|
||||
{
|
||||
private static object openedFilesLock = new object();
|
||||
private static List<string> openedFiles = new List<string>();
|
||||
private static readonly object openedFilesLock = new object();
|
||||
private static readonly List<string> openedFiles = new List<string>();
|
||||
|
||||
private StreamWriter logWriter;
|
||||
private object writeLock;
|
||||
private readonly object writeLock;
|
||||
|
||||
public override Encoding Encoding => Encoding.ASCII;
|
||||
|
||||
public ThreadSafeFileWriter(string path)
|
||||
{
|
||||
logWriter = new StreamWriter(File.Open(path, FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite));
|
||||
logWriter.AutoFlush = true;
|
||||
logWriter = new StreamWriter(File.Open(path, FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite)) {AutoFlush = true};
|
||||
writeLock = new object();
|
||||
|
||||
lock(openedFilesLock)
|
||||
@ -37,8 +36,11 @@ namespace CryptoExchange.Net.Logging
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
logWriter.Close();
|
||||
logWriter = null;
|
||||
lock (writeLock)
|
||||
{
|
||||
logWriter.Close();
|
||||
logWriter = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
using System;
|
||||
|
||||
namespace CryptoExchange.Net
|
||||
namespace CryptoExchange.Net.Objects
|
||||
{
|
||||
public class ApiProxy
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
namespace CryptoExchange.Net
|
||||
namespace CryptoExchange.Net.Objects
|
||||
{
|
||||
public class CallResult<T>
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
namespace CryptoExchange.Net
|
||||
namespace CryptoExchange.Net.Objects
|
||||
{
|
||||
public abstract class Error
|
||||
{
|
||||
|
@ -2,10 +2,9 @@
|
||||
using System.IO;
|
||||
using CryptoExchange.Net.Authentication;
|
||||
using CryptoExchange.Net.Logging;
|
||||
using CryptoExchange.Net.Objects;
|
||||
using CryptoExchange.Net.RateLimiter;
|
||||
|
||||
namespace CryptoExchange.Net
|
||||
namespace CryptoExchange.Net.Objects
|
||||
{
|
||||
/// <summary>
|
||||
/// Options
|
||||
|
Loading…
x
Reference in New Issue
Block a user