コード例 #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.AccountSetting.DigitalSignature.GetSignature();

                        foreach (var seed in _amoebaInterfaceManager.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(_amoebaInterfaceManager.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;
                }
            }
        }
コード例 #2
0
        private void WatchThread(CancellationToken token)
        {
            for (; ;)
            {
                var subscribeStoreInfos = new List <StoreSignatureInfo>();

                try
                {
                    App.Current.Dispatcher.Invoke(() =>
                    {
                        if (token.IsCancellationRequested)
                        {
                            return;
                        }

                        var subscribeCategoryInfos = new List <StoreCategoryInfo>();
                        subscribeCategoryInfos.Add(this.TabViewModel.Value.Model);

                        for (int i = 0; i < subscribeCategoryInfos.Count; i++)
                        {
                            subscribeCategoryInfos.AddRange(subscribeCategoryInfos[i].CategoryInfos);
                            subscribeStoreInfos.AddRange(subscribeCategoryInfos[i].SignatureInfos);
                        }
                    }, DispatcherPriority.Background, token);
                }
                catch (OperationCanceledException)
                {
                    return;
                }

                foreach (var storeInfo in subscribeStoreInfos)
                {
                    if (token.IsCancellationRequested)
                    {
                        return;
                    }

                    var message = _amoebaInterfaceManager.GetStore(storeInfo.AuthorSignature, CancellationToken.None).Result;
                    if (message == null || storeInfo.UpdateTime == message.CreationTime)
                    {
                        continue;
                    }

                    var tempBoxInfos = new List <StoreBoxInfo>();

                    foreach (var targetBox in message.Value.Boxes)
                    {
                        tempBoxInfos.Add(CreateStoreBoxInfo(targetBox, storeInfo.BoxInfos.FirstOrDefault(n => n.Name == targetBox.Name)));
                    }

                    try
                    {
                        App.Current.Dispatcher.Invoke(() =>
                        {
                            if (token.IsCancellationRequested)
                            {
                                return;
                            }

                            storeInfo.UpdateTime = message.CreationTime;
                            storeInfo.IsUpdated  = true;
                            storeInfo.BoxInfos.Clear();
                            storeInfo.BoxInfos.AddRange(tempBoxInfos);

                            // Refresh
                            {
                                if (this.TabSelectedItem.Value is StoreSignatureViewModel selectedSignatureViewModel)
                                {
                                    if (selectedSignatureViewModel.Model == storeInfo)
                                    {
                                        this.Refresh();
                                    }
                                }
                                else if (this.TabSelectedItem.Value is StoreBoxViewModel selectedBoxViewModel)
                                {
                                    if (selectedBoxViewModel.GetAncestors().OfType <StoreSignatureViewModel>().First().Model == storeInfo)
                                    {
                                        this.Refresh();
                                    }
                                }
                            }
                        }, DispatcherPriority.Background, token);
                    }
                    catch (OperationCanceledException)
                    {
                        return;
                    }
                }

                {
                    var cacheMetadatas = new HashSet <Metadata>();
                    cacheMetadatas.UnionWith(_amoebaInterfaceManager.GetCacheContentReports().Select(n => n.Metadata));

                    var downloadingMetadatas = new HashSet <Metadata>();
                    downloadingMetadatas.UnionWith(_amoebaInterfaceManager.GetDownloadContentReports().Select(n => n.Metadata));

                    var downloadedMetadatas = new HashSet <Metadata>();
                    downloadedMetadatas.UnionWith(SettingsManager.Instance.DownloadedSeeds.Select(n => n.Metadata));

                    lock (_cacheStates.LockObject)
                    {
                        _cacheStates.Clear();

                        foreach (var metadata in cacheMetadatas)
                        {
                            _cacheStates.Add(metadata, SearchState.Cache);
                        }

                        foreach (var metadata in downloadingMetadatas)
                        {
                            _cacheStates.AddOrUpdate(metadata, SearchState.Downloading, (_, oldValue) => oldValue | SearchState.Downloading);
                        }

                        foreach (var metadata in downloadedMetadatas)
                        {
                            _cacheStates.AddOrUpdate(metadata, SearchState.Downloaded, (_, oldValue) => oldValue | SearchState.Downloaded);
                        }
                    }
                }

                if (token.WaitHandle.WaitOne(1000 * 30))
                {
                    return;
                }
            }
        }
コード例 #3
0
ファイル: MessageManager.cs プロジェクト: qq932024214/Amoeba
        private void UpdateSearchListViewItemInfos()
        {
            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 this.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.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 (_cacheSearchListViewItemInfos.LockObject)
            {
                _cacheSearchListViewItemInfos.Clear();
                _cacheSearchListViewItemInfos.AddRange(searchItems);
            }
        }