diff --git a/src/Dynamicweb.Ecommerce.DynamicwebLiveIntegration/Dynamicweb.Ecommerce.DynamicwebLiveIntegration.csproj b/src/Dynamicweb.Ecommerce.DynamicwebLiveIntegration/Dynamicweb.Ecommerce.DynamicwebLiveIntegration.csproj index 08e555e..ceb2adb 100644 --- a/src/Dynamicweb.Ecommerce.DynamicwebLiveIntegration/Dynamicweb.Ecommerce.DynamicwebLiveIntegration.csproj +++ b/src/Dynamicweb.Ecommerce.DynamicwebLiveIntegration/Dynamicweb.Ecommerce.DynamicwebLiveIntegration.csproj @@ -1,6 +1,6 @@  - 10.4.17 + 10.4.18 1.0.0.0 Live Integration Live Integration diff --git a/src/Dynamicweb.Ecommerce.DynamicwebLiveIntegration/EndpointMonitoring/EndpointMonitoringService.cs b/src/Dynamicweb.Ecommerce.DynamicwebLiveIntegration/EndpointMonitoring/EndpointMonitoringService.cs index 66585ae..92d9377 100644 --- a/src/Dynamicweb.Ecommerce.DynamicwebLiveIntegration/EndpointMonitoring/EndpointMonitoringService.cs +++ b/src/Dynamicweb.Ecommerce.DynamicwebLiveIntegration/EndpointMonitoring/EndpointMonitoringService.cs @@ -2,7 +2,6 @@ using Dynamicweb.Ecommerce.DynamicwebLiveIntegration.Connectors; using Dynamicweb.Ecommerce.DynamicwebLiveIntegration.Logging; using System.Collections.Concurrent; -using System.Collections.Generic; using System.Threading; namespace Dynamicweb.Ecommerce.DynamicwebLiveIntegration.EndpointMonitoring @@ -13,7 +12,7 @@ namespace Dynamicweb.Ecommerce.DynamicwebLiveIntegration.EndpointMonitoring internal class EndpointMonitoringService { private static readonly ConcurrentDictionary EndpointCollection = new ConcurrentDictionary(); - private static readonly List EndpointsInPing = new List(); + private static readonly ConcurrentDictionary EndpointsInPing = new ConcurrentDictionary(); private static readonly ConcurrentDictionary PingTimers = new ConcurrentDictionary(); /// @@ -26,7 +25,7 @@ public static bool IsStillValid(Settings settings, EndpointInfo endpoint, out bo { connectionAvailable = false; - if (EndpointsInPing.Contains(endpoint.Id)) + if (EndpointsInPing.ContainsKey(endpoint.Id)) { return true; } @@ -72,6 +71,7 @@ public static void Success(EndpointInfo endpoint) PingTimers.TryRemove(endpoint.Id, out Timer timer); timer?.Dispose(); } + EndpointsInPing.TryRemove(endpoint.Id, out _); status.SetSuccess(); } @@ -87,7 +87,7 @@ public static void Error(Settings settings, EndpointInfo endpoint) status = new EndpointStatus(); EndpointCollection.TryAdd(url, status); } - if (!EndpointsInPing.Contains(endpoint.Id) && !Environment.ExecutingContext.IsBackEnd()) + if (!EndpointsInPing.ContainsKey(endpoint.Id) && !Environment.ExecutingContext.IsBackEnd()) { PingEndpoint(settings, endpoint); } @@ -133,9 +133,9 @@ private static void PingEndpoint(Settings settings, EndpointInfo endpoint) { return; } - if (!EndpointsInPing.Contains(endpoint.Id) && !PingTimers.ContainsKey(endpoint.Id)) + if (!EndpointsInPing.ContainsKey(endpoint.Id) && !PingTimers.ContainsKey(endpoint.Id)) { - EndpointsInPing.Add(endpoint.Id); + EndpointsInPing.TryAdd(endpoint.Id, null); var statusChecker = new EndpointMonitoringService(); var timer = new Timer(statusChecker.Ping, settings, 0, autoPingInterval.Value * 1000); PingTimers.TryAdd(endpoint.Id, timer); @@ -158,10 +158,7 @@ private void Ping(object stateInfo) currentConnector = new WebServiceConnector(settings, logger); endpoint = new EndpointInfo(settings.WebServiceURI); } - if (EndpointsInPing.Contains(endpoint.Id)) - { - EndpointsInPing.RemoveAll(e => e == endpoint.Id); - } + EndpointsInPing.TryRemove(endpoint.Id, out _); currentConnector.IsWebServiceConnectionAvailable(); } }