Beispiel #1
0
        private void WatchThread()
        {
            Stopwatch watchStopwatch = new Stopwatch();

            try
            {
                for (; ;)
                {
                    Thread.Sleep(1000);
                    if (this.State == ManagerState.Stop)
                    {
                        return;
                    }

                    if (!watchStopwatch.IsRunning || watchStopwatch.Elapsed.TotalSeconds >= 60)
                    {
                        watchStopwatch.Restart();

                        lock (this.ThisLock)
                        {
                            foreach (var item in _settings.BackgroundDownloadItems.ToArray())
                            {
                                if (item.State != BackgroundDownloadState.Error)
                                {
                                    continue;
                                }

                                this.Remove(item);
                            }

                            foreach (var item in _settings.BackgroundDownloadItems.ToArray())
                            {
                                if (this.SearchSignatures.Contains(item.Seed.Certificate.ToString()))
                                {
                                    continue;
                                }

                                this.Remove(item);
                            }

                            foreach (var signature in this.SearchSignatures.ToArray())
                            {
                                _connectionsManager.SendSeedsRequest(signature);

                                // Link
                                {
                                    Seed linkSeed;

                                    if (null != (linkSeed = _connectionsManager.GetLinkSeed(signature)) &&
                                        linkSeed.Length < 1024 * 1024 * 32)
                                    {
                                        var item = _settings.BackgroundDownloadItems
                                                   .Where(n => n.Type == BackgroundItemType.Link)
                                                   .FirstOrDefault(n => n.Seed.Certificate.ToString() == signature);

                                        if (item == null)
                                        {
                                            this.Download(linkSeed, BackgroundItemType.Link, null);
                                        }
                                        else if (linkSeed.CreationTime > item.Seed.CreationTime)
                                        {
                                            this.Remove(item);
                                            this.Download(linkSeed, BackgroundItemType.Link, item.Value);
                                        }
                                    }
                                }

                                // Store
                                {
                                    Seed storeSeed;

                                    if (null != (storeSeed = _connectionsManager.GetStoreSeed(signature)) &&
                                        storeSeed.Length < 1024 * 1024 * 32)
                                    {
                                        var item = _settings.BackgroundDownloadItems
                                                   .Where(n => n.Type == BackgroundItemType.Store)
                                                   .FirstOrDefault(n => n.Seed.Certificate.ToString() == signature);

                                        if (item == null)
                                        {
                                            this.Download(storeSeed, BackgroundItemType.Store, null);
                                        }
                                        else if (storeSeed.CreationTime > item.Seed.CreationTime)
                                        {
                                            this.Remove(item);
                                            this.Download(storeSeed, BackgroundItemType.Store, item.Value);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }