diff --git a/framework/src/Volo.Abp.Core/Volo/Abp/Telemetry/EnvironmentInspection/Contracts/IDeviceInfoProvider.cs b/framework/src/Volo.Abp.Core/Volo/Abp/Telemetry/EnvironmentInspection/Contracts/IDeviceInfoProvider.cs deleted file mode 100644 index 13ff5049d7..0000000000 --- a/framework/src/Volo.Abp.Core/Volo/Abp/Telemetry/EnvironmentInspection/Contracts/IDeviceInfoProvider.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using Volo.Abp.Telemetry.Constants.Enums; - -namespace Volo.Abp.Telemetry.EnvironmentInspection.Contracts; - -public interface IDeviceInfoProvider -{ - Guid GetDeviceId(); - OperationSystem GetOperatingSystem(); - DeviceType GetDeviceType(); - string GetLanguage(); - string GetCountry(); -} \ No newline at end of file diff --git a/framework/src/Volo.Abp.Core/Volo/Abp/Telemetry/Helpers/MutexExecutor.cs b/framework/src/Volo.Abp.Core/Volo/Abp/Telemetry/Helpers/MutexExecutor.cs index 97176af56e..a7a9be5506 100644 --- a/framework/src/Volo.Abp.Core/Volo/Abp/Telemetry/Helpers/MutexExecutor.cs +++ b/framework/src/Volo.Abp.Core/Volo/Abp/Telemetry/Helpers/MutexExecutor.cs @@ -5,7 +5,7 @@ using System.Threading.Tasks; namespace Volo.Abp.Telemetry.Helpers; -static internal class MutexExecutor +public static class MutexExecutor { private const int MaxRetries = 5; private const int RetryDelay = 100; @@ -14,51 +14,50 @@ static internal class MutexExecutor public async static Task ExecuteAsync(string mutexName, Func> action) { using var mutex = new Mutex(false, mutexName); + return await ExecuteWithRetriesAsync(mutex, action); + } - for (int attempt = 1; attempt <= MaxRetries; attempt++) + private async static Task ExecuteWithRetriesAsync(Mutex mutex, Func> action) + { + for (var attempt = 1; attempt <= MaxRetries; attempt++) { - if (!await WaitAsync(mutex)) + if (await TryExecuteActionAsync(mutex, action) is { } result) { - if (attempt == MaxRetries) - { - return default; - } - - await Task.Delay(RetryDelay); - continue; + return result; } - try + if (attempt == MaxRetries) { - return await action(); - } - catch (AbandonedMutexException) - { - if (attempt == MaxRetries) - { - return default; - } - - await Task.Delay(RetryDelay); + return default; } - catch (IOException) - { - if (attempt == MaxRetries) - { - return default; - } - await Task.Delay(RetryDelay); - } - finally - { - ReleaseSafely(mutex); - } + await Task.Delay(RetryDelay); } return default; } + private async static Task TryExecuteActionAsync(Mutex mutex, Func> action) + { + if (!await WaitAsync(mutex)) + { + return default; + } + + try + { + return await action(); + } + catch (Exception ex) when (ex is AbandonedMutexException or IOException) + { + return default; + } + finally + { + ReleaseSafely(mutex); + } + } + private async static Task WaitAsync(Mutex mutex) { return await Task.Run(() => mutex.WaitOne(Timeout)); @@ -66,10 +65,13 @@ static internal class MutexExecutor private static void ReleaseSafely(Mutex mutex) { - try { mutex.ReleaseMutex(); } + try + { + mutex.ReleaseMutex(); + } catch { - //ignored + // ignored intentionally } } } \ No newline at end of file