Exemple #1
0
        private void WatchThread(CancellationToken token)
        {
            for (; ;)
            {
                var searchItems = new List <SearchListViewItemInfo>();

                {
                    var seedInfos = new HashSet <(Seed, Signature)>();

                    var storeMetadatas       = new HashSet <Metadata>();
                    var cacheMetadatas       = new HashSet <Metadata>();
                    var downloadingMetadatas = new HashSet <Metadata>();
                    var downloadedMetadatas  = new HashSet <Metadata>();

                    foreach (var store in _messageManager.GetStores())
                    {
                        var seedHashSet = new HashSet <Seed>();
                        {
                            var boxList = new List <Box>();
                            boxList.AddRange(store.Value.Boxes);

                            for (int i = 0; i < boxList.Count; i++)
                            {
                                boxList.AddRange(boxList[i].Boxes);
                                seedHashSet.UnionWith(boxList[i].Seeds);
                            }
                        }

                        foreach (var seed in seedHashSet)
                        {
                            seedInfos.Add((seed, store.AuthorSignature));
                            storeMetadatas.Add(seed.Metadata);
                        }
                    }

                    {
                        var signature = SettingsManager.Instance.AccountInfo.DigitalSignature.GetSignature();

                        foreach (var seed in _serviceManager.GetCacheContentReports()
                                 .Select(n => new Seed(Path.GetFileName(n.Path), n.Length, n.CreationTime, n.Metadata)).ToArray())
                        {
                            seedInfos.Add((seed, signature));
                            cacheMetadatas.Add(seed.Metadata);
                        }
                    }

                    downloadingMetadatas.UnionWith(_serviceManager.GetDownloadContentReports().Select(n => n.Metadata));

                    {
                        var downloadedSeeds = SettingsManager.Instance.DownloadedSeeds.ToArray();

                        foreach (var seed in SettingsManager.Instance.DownloadedSeeds.ToArray())
                        {
                            if (!storeMetadatas.Contains(seed.Metadata) && !cacheMetadatas.Contains(seed.Metadata))
                            {
                                seedInfos.Add((seed, null));
                            }

                            downloadedMetadatas.Add(seed.Metadata);
                        }
                    }

                    foreach (var(seed, signature) in seedInfos)
                    {
                        var viewModel = new SearchListViewItemInfo();
                        viewModel.Icon         = IconUtils.GetImage(seed.Name);
                        viewModel.Name         = seed.Name;
                        viewModel.Signature    = signature;
                        viewModel.Length       = seed.Length;
                        viewModel.CreationTime = seed.CreationTime;

                        SearchState state = 0;
                        if (storeMetadatas.Contains(seed.Metadata))
                        {
                            state |= SearchState.Store;
                        }
                        if (cacheMetadatas.Contains(seed.Metadata))
                        {
                            state |= SearchState.Cache;
                        }
                        if (downloadingMetadatas.Contains(seed.Metadata))
                        {
                            state |= SearchState.Downloading;
                        }
                        if (downloadedMetadatas.Contains(seed.Metadata))
                        {
                            state |= SearchState.Downloaded;
                        }

                        viewModel.State = state;
                        viewModel.Model = seed;

                        searchItems.Add(viewModel);
                    }
                }

                lock (_cache_SearchItems.LockObject)
                {
                    _cache_SearchItems.Clear();
                    _cache_SearchItems.AddRange(searchItems);
                }

                this.SetCount(this.TabViewModel.Value, searchItems, token);

                if (token.WaitHandle.WaitOne(1000 * 20))
                {
                    return;
                }
            }
        }