1
0
mirror of https://github.com/JKorf/CryptoExchange.Net synced 2025-06-11 01:46:12 +00:00

Fixed some resharper warnings

This commit is contained in:
JKorf 2018-08-16 10:40:35 +02:00
parent bb227b4b12
commit b5833e5230
13 changed files with 33 additions and 32 deletions

View File

@ -10,6 +10,7 @@ using System.Threading.Tasks;
using CryptoExchange.Net.Authentication; using CryptoExchange.Net.Authentication;
using CryptoExchange.Net.Interfaces; using CryptoExchange.Net.Interfaces;
using CryptoExchange.Net.Logging; using CryptoExchange.Net.Logging;
using CryptoExchange.Net.Objects;
using CryptoExchange.Net.RateLimiter; using CryptoExchange.Net.RateLimiter;
using Moq; using Moq;
using Newtonsoft.Json; using Newtonsoft.Json;

View File

@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using CryptoExchange.Net.Authentication; using CryptoExchange.Net.Authentication;
using CryptoExchange.Net.Interfaces; using CryptoExchange.Net.Interfaces;
using CryptoExchange.Net.Objects;
namespace CryptoExchange.Net.UnitTests namespace CryptoExchange.Net.UnitTests
{ {

View File

@ -1,11 +1,8 @@
using System; using System;
using System.Collections.Generic;
using System.Text;
namespace CryptoExchange.Net.Attributes namespace CryptoExchange.Net.Attributes
{ {
public class JsonOptionalPropertyAttribute : Attribute public class JsonOptionalPropertyAttribute : Attribute
{ {
public JsonOptionalPropertyAttribute() { }
} }
} }

View File

@ -57,9 +57,10 @@ namespace CryptoExchange.Net.Authentication
} }
/// <summary> /// <summary>
/// Create Api credentials providing a private key for authenication /// Create Api credentials providing a api key and secret for authenciation
/// </summary> /// </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) public ApiCredentials(string key, string secret)
{ {
if (string.IsNullOrEmpty(key) || string.IsNullOrEmpty(secret)) if (string.IsNullOrEmpty(key) || string.IsNullOrEmpty(secret))

View File

@ -31,7 +31,7 @@ namespace CryptoExchange.Net
protected AuthenticationProvider authProvider; protected AuthenticationProvider authProvider;
private List<IRateLimiter> rateLimiters; private List<IRateLimiter> rateLimiters;
private static JsonSerializer defaultSerializer = JsonSerializer.Create(new JsonSerializerSettings() private static readonly JsonSerializer defaultSerializer = JsonSerializer.Create(new JsonSerializerSettings()
{ {
DateTimeZoneHandling = DateTimeZoneHandling.Utc DateTimeZoneHandling = DateTimeZoneHandling.Utc
}); });
@ -104,7 +104,7 @@ namespace CryptoExchange.Net
{ {
var ping = new Ping(); var ping = new Ping();
var uri = new Uri(baseAddress); var uri = new Uri(baseAddress);
PingReply reply = null; PingReply reply;
try try
{ {
reply = await ping.SendPingAsync(uri.Host); reply = await ping.SendPingAsync(uri.Host);
@ -115,8 +115,7 @@ namespace CryptoExchange.Net
{ {
if (e.InnerException is SocketException) if (e.InnerException is SocketException)
return new CallResult<long>(0, new CantConnectError() { Message = "Ping failed: " + ((SocketException)e.InnerException).SocketErrorCode }); 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 }); 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"); log.Write(LogVerbosity.Debug, $"Request {uri.AbsolutePath} failed because of rate limit");
return new CallResult<T>(null, limitResult.Error); 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}"); 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) 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); ((JsonPropertyAttribute)p.GetCustomAttributes(typeof(JsonPropertyAttribute), false).FirstOrDefault())?.PropertyName == prop);
var optional = propInfo.GetCustomAttributes(typeof(JsonOptionalPropertyAttribute), false).FirstOrDefault(); var optional = propInfo.GetCustomAttributes(typeof(JsonOptionalPropertyAttribute), false).FirstOrDefault();
if (optional != null) if (optional != null)

View File

@ -33,7 +33,7 @@ namespace CryptoExchange.Net
{ {
lock (source) lock (source)
{ {
string result = null; string result;
int length = source.Length; int length = source.Length;
IntPtr pointer = IntPtr.Zero; IntPtr pointer = IntPtr.Zero;
char[] chars = new char[length]; char[] chars = new char[length];

View File

@ -1,6 +1,5 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
using System.Security.Authentication; 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) public BaseSocket(Log log, string url, IDictionary<string, string> cookies, IDictionary<string, string> headers)
{ {
this.log = log; this.log = log;
socket = new WebSocket(url, cookies: cookies.ToList(), customHeaderItems: headers.ToList()); socket = new WebSocket(url, cookies: cookies.ToList(), customHeaderItems: headers.ToList())
socket.EnableAutoSendPing = true; {
socket.AutoSendPingInterval = 10; EnableAutoSendPing = true,
AutoSendPingInterval = 10
};
socket.Opened += (o, s) => Handle(openhandlers); socket.Opened += (o, s) => Handle(openhandlers);
socket.Closed += (o, s) => Handle(closehandlers); socket.Closed += (o, s) => Handle(closehandlers);
socket.Error += (o, s) => Handle(errorhandlers, s.Exception); socket.Error += (o, s) => Handle(errorhandlers, s.Exception);
@ -108,7 +109,7 @@ namespace CryptoExchange.Net.Implementation
var handler = new EventHandler((o, a) => evnt.Set()); var handler = new EventHandler((o, a) => evnt.Set());
socket.Closed += handler; socket.Closed += handler;
socket.Close(); socket.Close();
bool triggered = evnt.WaitOne(3000); evnt.WaitOne(3000);
socket.Closed -= handler; socket.Closed -= handler;
log.Write(LogVerbosity.Debug, "Websocket closed"); log.Write(LogVerbosity.Debug, "Websocket closed");
} }

View File

@ -1,7 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Security.Authentication; using System.Security.Authentication;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using CryptoExchange.Net.Interfaces; using CryptoExchange.Net.Interfaces;
@ -39,7 +38,7 @@ namespace CryptoExchange.Net.Implementation
{ {
if (!HasConnection) if (!HasConnection)
{ {
OnError(new Exception("No connection")); OnError?.Invoke(new Exception("No connection"));
return Task.FromResult(false); return Task.FromResult(false);
} }
@ -54,7 +53,7 @@ namespace CryptoExchange.Net.Implementation
{ {
if (!HasConnection) if (!HasConnection)
{ {
OnError(new Exception("No connection")); OnError?.Invoke(new Exception("No connection"));
Close(); Close();
return; return;
} }

View File

@ -6,18 +6,17 @@ namespace CryptoExchange.Net.Logging
{ {
public class ThreadSafeFileWriter: TextWriter public class ThreadSafeFileWriter: TextWriter
{ {
private static object openedFilesLock = new object(); private static readonly object openedFilesLock = new object();
private static List<string> openedFiles = new List<string>(); private static readonly List<string> openedFiles = new List<string>();
private StreamWriter logWriter; private StreamWriter logWriter;
private object writeLock; private readonly object writeLock;
public override Encoding Encoding => Encoding.ASCII; public override Encoding Encoding => Encoding.ASCII;
public ThreadSafeFileWriter(string path) public ThreadSafeFileWriter(string path)
{ {
logWriter = new StreamWriter(File.Open(path, FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite)); logWriter = new StreamWriter(File.Open(path, FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite)) {AutoFlush = true};
logWriter.AutoFlush = true;
writeLock = new object(); writeLock = new object();
lock(openedFilesLock) lock(openedFilesLock)
@ -37,8 +36,11 @@ namespace CryptoExchange.Net.Logging
protected override void Dispose(bool disposing) protected override void Dispose(bool disposing)
{ {
logWriter.Close(); lock (writeLock)
logWriter = null; {
logWriter.Close();
logWriter = null;
}
} }
} }
} }

View File

@ -1,6 +1,6 @@
using System; using System;
namespace CryptoExchange.Net namespace CryptoExchange.Net.Objects
{ {
public class ApiProxy public class ApiProxy
{ {

View File

@ -1,4 +1,4 @@
namespace CryptoExchange.Net namespace CryptoExchange.Net.Objects
{ {
public class CallResult<T> public class CallResult<T>
{ {

View File

@ -1,4 +1,4 @@
namespace CryptoExchange.Net namespace CryptoExchange.Net.Objects
{ {
public abstract class Error public abstract class Error
{ {

View File

@ -2,10 +2,9 @@
using System.IO; using System.IO;
using CryptoExchange.Net.Authentication; using CryptoExchange.Net.Authentication;
using CryptoExchange.Net.Logging; using CryptoExchange.Net.Logging;
using CryptoExchange.Net.Objects;
using CryptoExchange.Net.RateLimiter; using CryptoExchange.Net.RateLimiter;
namespace CryptoExchange.Net namespace CryptoExchange.Net.Objects
{ {
/// <summary> /// <summary>
/// Options /// Options