From e89beed9ef67dc72044ae1f90be7739fbbcd9240 Mon Sep 17 00:00:00 2001 From: JKorf Date: Thu, 1 Mar 2018 12:13:51 +0100 Subject: [PATCH] adjusted some resharper things --- Authentication/AuthenticationProvider.cs | 2 +- ExchangeClient.cs | 13 +++++-------- Interfaces/IExchangeClient.cs | 5 +---- Interfaces/IRequestFactory.cs | 3 +-- RateLimiter/RateLimitObject.cs | 4 ++-- RateLimiter/RateLimiterPerEndpoint.cs | 10 +++++----- RateLimiter/RateLimiterTotal.cs | 6 +++--- Requests/Request.cs | 7 ++----- 8 files changed, 20 insertions(+), 30 deletions(-) diff --git a/Authentication/AuthenticationProvider.cs b/Authentication/AuthenticationProvider.cs index a51c322..bff695b 100644 --- a/Authentication/AuthenticationProvider.cs +++ b/Authentication/AuthenticationProvider.cs @@ -17,7 +17,7 @@ namespace CryptoExchange.Net.Authentication protected string ByteToString(byte[] buff) { var sbinary = ""; - foreach (byte t in buff) + foreach (var t in buff) sbinary += t.ToString("X2"); /* hex format */ return sbinary; } diff --git a/ExchangeClient.cs b/ExchangeClient.cs index 33941c8..209bc2f 100644 --- a/ExchangeClient.cs +++ b/ExchangeClient.cs @@ -102,22 +102,19 @@ namespace CryptoExchange.Net foreach (var limiter in rateLimiters) { - double limitedBy = limiter.LimitRequest(uri.AbsolutePath); + var limitedBy = limiter.LimitRequest(uri.AbsolutePath); if (limitedBy > 0) log.Write(LogVerbosity.Debug, $"Request {uri.AbsolutePath} was limited by {limitedBy}ms by {limiter.GetType().Name}"); } log.Write(LogVerbosity.Debug, $"Sending request to {uriString}"); var result = await ExecuteRequest(request); - if (result.Error != null) - return new CallResult(null, result.Error); - - return Deserialize(result.Data); + return result.Error != null ? new CallResult(null, result.Error) : Deserialize(result.Data); } private async Task> ExecuteRequest(IRequest request) { - string returnedData = ""; + var returnedData = ""; try { var response = request.GetResponse(); @@ -136,11 +133,11 @@ namespace CryptoExchange.Net var reader = new StreamReader(response.GetResponseStream()); responseData = reader.ReadToEnd(); } - catch (Exception e) + catch (Exception) { } - string infoMessage = "No response from server"; + var infoMessage = "No response from server"; if (response == null) return new CallResult(null, new WebError(infoMessage)); diff --git a/Interfaces/IExchangeClient.cs b/Interfaces/IExchangeClient.cs index 0f37f72..e6dc273 100644 --- a/Interfaces/IExchangeClient.cs +++ b/Interfaces/IExchangeClient.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; -using CryptoExchange.Net.RateLimiter; +using CryptoExchange.Net.RateLimiter; namespace CryptoExchange.Net.Interfaces { diff --git a/Interfaces/IRequestFactory.cs b/Interfaces/IRequestFactory.cs index 1bbf5ac..5acdb4b 100644 --- a/Interfaces/IRequestFactory.cs +++ b/Interfaces/IRequestFactory.cs @@ -1,5 +1,4 @@ - -namespace CryptoExchange.Net.Interfaces +namespace CryptoExchange.Net.Interfaces { public interface IRequestFactory { diff --git a/RateLimiter/RateLimitObject.cs b/RateLimiter/RateLimitObject.cs index 04efdb6..1618252 100644 --- a/RateLimiter/RateLimitObject.cs +++ b/RateLimiter/RateLimitObject.cs @@ -15,11 +15,11 @@ namespace CryptoExchange.Net.RateLimiter Times = new List(); } - public double GetWaitTime(DateTime time, int limit, TimeSpan perTimePeriod) + public int GetWaitTime(DateTime time, int limit, TimeSpan perTimePeriod) { Times.RemoveAll(d => d < time - perTimePeriod); if (Times.Count >= limit) - return (Times.First() - (time - perTimePeriod)).TotalMilliseconds; + return (int)Math.Round((Times.First() - (time - perTimePeriod)).TotalMilliseconds); return 0; } diff --git a/RateLimiter/RateLimiterPerEndpoint.cs b/RateLimiter/RateLimiterPerEndpoint.cs index 2586a1e..60e56f4 100644 --- a/RateLimiter/RateLimiterPerEndpoint.cs +++ b/RateLimiter/RateLimiterPerEndpoint.cs @@ -12,9 +12,9 @@ namespace CryptoExchange.Net.RateLimiter { internal Dictionary history = new Dictionary(); - private int limitPerEndpoint; - private TimeSpan perTimePeriod; - private object historyLock = new object(); + private readonly int limitPerEndpoint; + private readonly TimeSpan perTimePeriod; + private readonly object historyLock = new object(); /// /// Create a new RateLimiterPerEndpoint. This rate limiter limits the amount of requests per time period to a certain limit, counts the request per endpoint. @@ -29,7 +29,7 @@ namespace CryptoExchange.Net.RateLimiter public double LimitRequest(string url) { - double waitTime; + int waitTime; RateLimitObject rlo; lock (historyLock) { @@ -50,7 +50,7 @@ namespace CryptoExchange.Net.RateLimiter if (waitTime != 0) { Thread.Sleep(Convert.ToInt32(waitTime)); - waitTime += sw.ElapsedMilliseconds; + waitTime += (int)sw.ElapsedMilliseconds; } rlo.Add(DateTime.UtcNow); diff --git a/RateLimiter/RateLimiterTotal.cs b/RateLimiter/RateLimiterTotal.cs index 67f72c4..683c2fd 100644 --- a/RateLimiter/RateLimiterTotal.cs +++ b/RateLimiter/RateLimiterTotal.cs @@ -13,9 +13,9 @@ namespace CryptoExchange.Net.RateLimiter { internal List history = new List(); - private int limit; - private TimeSpan perTimePeriod; - private object requestLock = new object(); + private readonly int limit; + private readonly TimeSpan perTimePeriod; + private readonly object requestLock = new object(); /// /// Create a new RateLimiterTotal. This rate limiter limits the amount of requests per time period to a certain limit, counts the total amount of requests. diff --git a/Requests/Request.cs b/Requests/Request.cs index b4ac071..33bb914 100644 --- a/Requests/Request.cs +++ b/Requests/Request.cs @@ -23,14 +23,11 @@ namespace CryptoExchange.Net.Requests get => request.Method; set => request.Method = value; } - public Uri Uri - { - get => request.RequestUri; - } + public Uri Uri => request.RequestUri; public void SetProxy(string host, int port) { - request.Proxy = new WebProxy(host, port); ; + request.Proxy = new WebProxy(host, port); } public IResponse GetResponse()