private void RemoveOutOfPeriodErrors(IEnumerable <KeyValuePair <long, DateTimeOffset> > tripsInPeriod)
        {
            var outDatedTimeStamps = _errorDates
                                     .Except(tripsInPeriod)
                                     .ToList();

            foreach (var outDatedTimeStamp in outDatedTimeStamps)
            {
                _errorDates.TryRemove(outDatedTimeStamp.Key, out _);
            }
        }
Example #2
0
        private async Task RefreshTenantRegistry(int timeout = 1000)
        {
            var wc = new HttpClient();
            //wc.BaseAddress = _tenantUrl;

            string json;

            try
            {
                using (var cts = new CancellationTokenSource(timeout))
                {
                    using (var response = await wc.GetAsync(_tenantUrl, cts.Token))
                    {
                        json = await response.Content.ReadAsStringAsync();
                    }
                }
            }
            catch (TaskCanceledException ex)
            {
                // Fall over to another backup, perhaps local copy on disk, local list of tenants, etc.
                json = @"{}";
                _logger.WriteCritical($"Remote tenant repository failed to respond after {new TimeSpan(0, 0, 0, 0, timeout).TotalSeconds} seconds.");
            }

            var tenantRegistry = JsonConvert.DeserializeObject <IDictionary <string, bool> >(json);

            var newItems     = tenantRegistry.Except(_items.Join(tenantRegistry, x => string.Join(":", x.Key, x.Value), x => string.Join(":", x.Key, x.Value), (a, b) => b));
            var deletedItems = _items.Except(tenantRegistry.Join(_items, x => x.Key, x => x.Key, (a, b) => b)).Select(x => x.Key);

            foreach (var item in newItems)
            {
                _items.AddOrUpdate(item.Key, x => new TenantRegistryItem(item.Key, item.Value), (x, old) => new TenantRegistryItem(item.Key, item.Value));
            }

            ITenantRegistryItem dummy;

            foreach (var item in deletedItems)
            {
                _items.TryRemove(item, out dummy);
            }
        }
Example #3
0
        //public List<string> GetLanIPs()
        //{
        //    if (macCache == null) return null;
        //    return macCache.Values.Distinct().ToList();
        //}

        /// <summary>
        /// Infinatelly loops to fire off MAC notification events. On same thread.
        /// </summary>
        public void WatchNetwork()
        {
            while (true)
            {
                var macs = new NetworkMACWatcher().GetMacsInLan();

                if (macCache == null)
                {
                    macCache = new ConcurrentDictionary <string, string>(macs);
                    if (this.FirstAddressesLoaded != null)
                    {
                        ConsoleDebug(macs);
                        FirstAddressesLoaded(this, new Dictionary <string, string>(macCache));
                    }
                }

                var newlyconnected = macs.Except(macCache);
                var disconnected   = macCache.Except(macs);

                foreach (var mac in disconnected)
                {
                    if (this.MacDisconnected != null)
                    {
                        this.MacDisconnected(this, mac);
                    }
                }

                foreach (var mac in newlyconnected)
                {
                    if (this.MacConnected != null)
                    {
                        this.MacConnected(this, mac);
                    }
                }

                macCache = new ConcurrentDictionary <string, string>(macs);

                System.Threading.Thread.Sleep(1000);
            }
        }