Exemplo n.º 1
0
        private bool ResultCache_CheckUri(object sender, string uri)
        {
            _succeededUris.Update();
            _failedUris.Update();

            if (_succeededUris.Contains(uri))
            {
                return(true);
            }
            if (_failedUris.Contains(uri))
            {
                return(false);
            }

            if (this.CheckUri(uri))
            {
                _succeededUris.Add(uri);

                return(true);
            }
            else
            {
                _failedUris.Add(uri);

                return(false);
            }
        }
Exemplo n.º 2
0
        public void Refresh()
        {
            lock (_lockObject)
            {
                var lockedSignatures = new HashSet <OmniSignature>(this.OnGetLockedSignaturesEvent());
                var lockedChannels   = new HashSet <Channel>(_aliveChannels);

                _aliveChannels.Update();

                // Broadcast
                {
                    {
                        var removeTypes = new HashSet <string>(_broadcastTypes.OrderBy(n => n.Value).Select(n => n.Key).Take(_broadcastTypes.Count - 32));

                        foreach (string type in removeTypes)
                        {
                            _broadcastTypes.Remove(type);
                        }

                        foreach (string type in _BroadcastClues.Keys.ToArray())
                        {
                            if (!removeTypes.Contains(type))
                            {
                                continue;
                            }
                            _BroadcastClues.Remove(type);
                        }
                    }

                    foreach (var dic in _BroadcastClues.Values)
                    {
                        var keys = dic.Keys.Where(n => !lockedSignatures.Contains(n)).ToList();

                        foreach (var key in keys.Randomize().Take(keys.Count - 1024))
                        {
                            dic.Remove(key);
                        }
                    }
                }

                // Unicast
                {
                    {
                        var removeTypes = new HashSet <string>(_unicastTypes.OrderBy(n => n.Value).Select(n => n.Key).Take(_unicastTypes.Count - 32));

                        foreach (string type in removeTypes)
                        {
                            _unicastTypes.Remove(type);
                        }

                        foreach (string type in _UnicastClues.Keys.ToArray())
                        {
                            if (!removeTypes.Contains(type))
                            {
                                continue;
                            }
                            _UnicastClues.Remove(type);
                        }
                    }

                    foreach (var dic in _UnicastClues.Values)
                    {
                        var keys = dic.Keys.Where(n => !lockedSignatures.Contains(n)).ToList();

                        foreach (var key in keys.Randomize().Take(keys.Count - 1024))
                        {
                            dic.Remove(key);
                        }
                    }

                    foreach (var dic in _UnicastClues.Values.SelectMany(n => n.Values))
                    {
                        var keys = dic.Keys.Where(n => !lockedSignatures.Contains(n)).ToList();

                        foreach (var key in keys.Randomize().Take(keys.Count - 32))
                        {
                            dic.Remove(key);
                        }
                    }

                    foreach (var hashset in _UnicastClues.Values.SelectMany(n => n.Values.SelectMany(m => m.Values)).ToArray())
                    {
                        if (hashset.Count <= 32)
                        {
                            continue;
                        }

                        var list = hashset.ToList();
                        list.Sort((x, y) => x.CreationTime.CompareTo(y.CreationTime));

                        foreach (var value in list.Take(list.Count - 32))
                        {
                            hashset.Remove(value);
                        }
                    }
                }

                // Multicast
                {
                    {
                        var removeTypes = new HashSet <string>(_multicastTypes.OrderBy(n => n.Value).Select(n => n.Key).Take(_multicastTypes.Count - 32));

                        foreach (string type in removeTypes)
                        {
                            _multicastTypes.Remove(type);
                        }

                        foreach (string type in _MulticastClues.Keys.ToArray())
                        {
                            if (!removeTypes.Contains(type))
                            {
                                continue;
                            }
                            _MulticastClues.Remove(type);
                        }
                    }

                    foreach (var dic in _MulticastClues.Values)
                    {
                        var keys = dic.Keys.Where(n => !lockedChannels.Contains(n)).ToList();

                        foreach (var key in keys.Randomize().Take(keys.Count - 1024))
                        {
                            dic.Remove(key);
                        }
                    }

                    foreach (var dic in _MulticastClues.Values.SelectMany(n => n.Values))
                    {
                        var keys = dic.Keys.Where(n => !lockedSignatures.Contains(n)).ToList();

                        foreach (var key in keys.Randomize().Take(keys.Count - 32))
                        {
                            dic.Remove(key);
                        }
                    }

                    foreach (var hashset in _MulticastClues.Values.SelectMany(n => n.Values.SelectMany(m => m.Values)).ToArray())
                    {
                        if (hashset.Count <= 32)
                        {
                            continue;
                        }

                        var list = hashset.ToList();
                        list.Sort((x, y) => x.CreationTime.CompareTo(y.CreationTime));

                        foreach (var value in list.Take(list.Count - 32))
                        {
                            hashset.Remove(value);
                        }
                    }
                }
            }
        }