From 0074decb23c64d893569641b25bfdcf615b799ce Mon Sep 17 00:00:00 2001 From: Sean Date: Wed, 5 Jun 2024 11:13:28 +1200 Subject: [PATCH] pr feedbacks --- .../Offline/OfflineStoreBase.cs | 6 ++++-- .../Offline/TimerBasedSendStrategy.cs | 2 ++ .../RaygunClientBase.cs | 13 ++++--------- Mindscape.Raygun4Net.NetCore/RaygunClient.cs | 11 +++++------ .../Storage/LocalApplicationDataCrashReportStore.cs | 5 ++--- 5 files changed, 17 insertions(+), 20 deletions(-) diff --git a/Mindscape.Raygun4Net.NetCore.Common/Offline/OfflineStoreBase.cs b/Mindscape.Raygun4Net.NetCore.Common/Offline/OfflineStoreBase.cs index 9ef5b71d..13359e7a 100644 --- a/Mindscape.Raygun4Net.NetCore.Common/Offline/OfflineStoreBase.cs +++ b/Mindscape.Raygun4Net.NetCore.Common/Offline/OfflineStoreBase.cs @@ -1,4 +1,4 @@ -#nullable enable +#nullable enable using System; using System.Collections.Generic; using System.Diagnostics; @@ -28,8 +28,10 @@ public virtual void SetSendCallback(SendHandler sendHandler) protected virtual async Task ProcessOfflineCrashReports() { if (SendCallback is null) + { return; - + } + try { var cachedCrashReports = await GetAll(CancellationToken.None); diff --git a/Mindscape.Raygun4Net.NetCore.Common/Offline/TimerBasedSendStrategy.cs b/Mindscape.Raygun4Net.NetCore.Common/Offline/TimerBasedSendStrategy.cs index 06b9b57b..3f6340a8 100644 --- a/Mindscape.Raygun4Net.NetCore.Common/Offline/TimerBasedSendStrategy.cs +++ b/Mindscape.Raygun4Net.NetCore.Common/Offline/TimerBasedSendStrategy.cs @@ -45,6 +45,8 @@ private async void SendOfflineErrors(object state) public void Start() { + // This sets the timer to trigger once at the interval, and then "never again". + // This inherently prevents the timer from being re-entrant _backgroundTimer.Change(Interval, TimeSpan.FromMilliseconds(int.MaxValue)); } diff --git a/Mindscape.Raygun4Net.NetCore.Common/RaygunClientBase.cs b/Mindscape.Raygun4Net.NetCore.Common/RaygunClientBase.cs index 1149eea1..a29da438 100644 --- a/Mindscape.Raygun4Net.NetCore.Common/RaygunClientBase.cs +++ b/Mindscape.Raygun4Net.NetCore.Common/RaygunClientBase.cs @@ -271,12 +271,7 @@ protected async Task OnCustomGroupingKey(Exception exception, RaygunMess protected bool ValidateApiKey() { - return ValidateApiKey(_settings.ApiKey); - } - - private bool ValidateApiKey(string apiKey) - { - if (string.IsNullOrEmpty(apiKey)) + if (string.IsNullOrEmpty(_settings.ApiKey)) { Debug.WriteLine("ApiKey has not been provided, exception will not be logged"); return false; @@ -449,8 +444,7 @@ protected virtual async Task StripAndSend(Exception exception, IList tag protected virtual IEnumerable StripWrapperExceptions(Exception exception) { - if (exception != null && _wrapperExceptions.Any(wrapperException => - exception.GetType() == wrapperException && exception.InnerException != null)) + if (exception != null && _wrapperExceptions.Any(wrapperException => exception.GetType() == wrapperException && exception.InnerException != null)) { var aggregate = exception as AggregateException; @@ -546,7 +540,8 @@ private async Task SendPayloadAsync(string payload, string apiKey, bool useOffli Debug.WriteLine($"Error Logging Exception to Raygun: {ex.Message}"); // If we got no response or an unexpected server error then add it to offline storage to send later - // we get no response if the send call fails for any other reason (network etc) + // we get no response if the send call fails for any other reason (network etc.) + // checking that response.StatusCode >= 500, is an efficient check for any server errors var shouldStoreMessage = response is null || response.StatusCode >= HttpStatusCode.InternalServerError; if (useOfflineStore && shouldStoreMessage) diff --git a/Mindscape.Raygun4Net.NetCore/RaygunClient.cs b/Mindscape.Raygun4Net.NetCore/RaygunClient.cs index a9242cd3..8005318a 100644 --- a/Mindscape.Raygun4Net.NetCore/RaygunClient.cs +++ b/Mindscape.Raygun4Net.NetCore/RaygunClient.cs @@ -1,6 +1,5 @@ using System; using System.Net.Http; -using Mindscape.Raygun4Net.Storage; namespace Mindscape.Raygun4Net; @@ -10,19 +9,19 @@ public class RaygunClient : RaygunClientBase public RaygunClient(string apiKey) : base(new RaygunSettings { ApiKey = apiKey }) { } - + [Obsolete("Use the RaygunClient(RaygunSettings, HttpClient) constructor instead")] public RaygunClient(string apiKey, HttpClient httpClient) : base(new RaygunSettings { ApiKey = apiKey }, httpClient) { } - + // ReSharper disable MemberCanBeProtected.Global // ReSharper disable SuggestBaseTypeForParameterInConstructor // ReSharper disable UnusedMember.Global public RaygunClient(RaygunSettings settings) : base(settings) { } - + public RaygunClient(RaygunSettings settings, HttpClient httpClient) : base(settings, httpClient) { } @@ -30,11 +29,11 @@ public RaygunClient(RaygunSettings settings, HttpClient httpClient) : base(setti public RaygunClient(RaygunSettings settings, IRaygunUserProvider userProvider) : base(settings, userProvider) { } - + public RaygunClient(RaygunSettings settings, HttpClient httpClient, IRaygunUserProvider userProvider) : base(settings, httpClient, userProvider) { } - + // ReSharper restore MemberCanBeProtected.Global // ReSharper restore SuggestBaseTypeForParameterInConstructor // ReSharper restore UnusedMember.Global diff --git a/Mindscape.Raygun4Net.NetCore/Storage/LocalApplicationDataCrashReportStore.cs b/Mindscape.Raygun4Net.NetCore/Storage/LocalApplicationDataCrashReportStore.cs index 35de5986..49a28709 100644 --- a/Mindscape.Raygun4Net.NetCore/Storage/LocalApplicationDataCrashReportStore.cs +++ b/Mindscape.Raygun4Net.NetCore/Storage/LocalApplicationDataCrashReportStore.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.IO; using System.Reflection; using System.Security.Cryptography; @@ -21,11 +20,11 @@ public LocalApplicationDataCrashReportStore(IBackgroundSendStrategy backgroundSe private static string GetLocalAppDirectory(string directoryName) { - directoryName ??= CreateUniqueDirectory(); + directoryName ??= CreateUniqueDirectoryName(); return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), directoryName); } - private static string CreateUniqueDirectory() + private static string CreateUniqueDirectoryName() { // Try to generate a unique id, from the executable location var uniqueId = Assembly.GetEntryAssembly()?.Location ?? throw new ApplicationException("Cannot determine unique application id");