コード例 #1
0
        private void Archives_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (ignoreChanges)
            {
                return;
            }

            ignoreChanges = true;

            // If the collection was reset, then e.OldItems is empty. Just clear and reload.
            if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Reset)
            {
                Archives.Clear();

                foreach (var archive in index.Archives)
                {
                    Archives.Add(new ArchiveViewModel(archive, this));
                }
            }
            else
            {
                // Remove items from collection.
                var toRemove = new List <ArchiveViewModel>();

                if (null != e.OldItems && e.OldItems.Count > 0)
                {
                    foreach (var item in e.OldItems)
                    {
                        foreach (var existingItem in Archives)
                        {
                            if (existingItem.IsViewFor((Archive)item))
                            {
                                toRemove.Add(existingItem);
                            }
                        }
                    }
                }

                foreach (var item in toRemove)
                {
                    Archives.Remove(item);
                }

                // Add new items to the collection.
                if (null != e.NewItems && e.NewItems.Count > 0)
                {
                    foreach (var item in e.NewItems)
                    {
                        Archives.Add(new ArchiveViewModel((Archive)item, this));
                    }
                }
            }
            ignoreChanges = false;
        }
コード例 #2
0
        private void CloseArchiveButton_Click(object sender, RoutedEventArgs e)
        {
            Button button = e.OriginalSource as Button;

            if ((object)button != null)
            {
                foreach (Archive archive in Archives.Where(archive => (int)button.DataContext == archive.ID).ToList())
                {
                    Archives.Remove(archive);
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// Removes the specified archive and all children from the index.</summary>
        /// <param name="writeToDb">If true, the object will be removed from the Database.</param>
        public async Task RemoveArchiveAsync(Archive archive, bool writeToDb)
        {
            if (archive is null)
            {
                return;
            }

            if (Archives.Where(x => x.Volume.Equals(archive.Volume)).Count() < 2)
            {
                // No other archive shares the logical volume of the
                // set that's about to be deleted, it can therefore be removed
                LogicalVolumes.Remove(archive.Volume);
                if (writeToDb)
                {
                    await Database.DeleteLogicalVolumeAsync(archive.Volume);
                }
            }

            // Get a list of all hashes related to the current archive,
            // remove all nodes from these hashes.
            var archiveHashes = archive.GetFileHashes();
            await archive.ClearAsync();

            archive.Dispose();

            // Get hashes in the collection with node count 0
            // these can be removed from the index
            var emptyHashes = archiveHashes.Where(x => x.NodeCount.Equals(0)).ToList();

            emptyHashes.ForEach(x => Hashes.Remove(x));

            if (writeToDb)
            {
                await Database.BatchDeleteFileHashAsync(emptyHashes);
            }

            Archives.Remove(archive);
            //NotifyPropertyChanged("Archive");
            if (writeToDb)
            {
                await Database.DeleteArchiveAsync(archive);
            }
        }