コード例 #1
0
        private void MusicDatabaseWindow_Loaded(object sender, System.Windows.RoutedEventArgs e)
        {
            this.task = new Task(() => {
                try
                {
                    this.collectionStatistics = this.generator.ComputeStatistics();

                    if (this.collectionStatistics != null)
                    {
                        this.Dispatcher.BeginInvokeAction(this.UpdateUI);
                    }
                }
                catch (Exception ex)
                {
                    Utility.WriteToErrorLog(ex.ToString());
                    Dialogs.Error("Error calculating statistics: " + ex.Message);
                }
                finally
                {
                    this.canClose = true;
                    this.Dispatcher.BeginInvokeAction(() => this.busyIndicator.IsBusy = false);
                    if (this.shouldCancel)
                    {
                        this.Dispatcher.BeginInvokeAction(this.Close);
                    }
                }
            });
            this.task.Start();
        }
コード例 #2
0
        public CollectionStatistics ComputeStatistics()
        {
            CollectionStatistics statistics = new CollectionStatistics();

            HashSet <string> albumArtists = new HashSet <string>();
            HashSet <Artist> artists      = new HashSet <Artist>();

            Release[] releases = this.collectionManager.Releases.ToArray();

            int processedReleases = 0;

            foreach (Release release in releases)
            {
                statistics.TotalReleases     += 1;
                statistics.TotalAlbumArtists += albumArtists.Add(release.JoinedAlbumArtists) ? 1 : 0;
                statistics.TotalArtists      += release.Artists.Select(a => artists.Add(a.Artist) ? 1 : 0).Sum();
                statistics.TotalArtists      += release.Tracklist.Select(t => t.Artists.Select(a => artists.Add(a.Artist) ? 1 : 0).Sum()).Sum();
                statistics.TotalTracks       += release.Tracklist.Count;

                bool isPerfect = this.IsReleasePerfect(release);

                if (isPerfect)
                {
                    statistics.PerfectReleases += 1;
                }

                if (release.Images.Count > 0)
                {
                    statistics.ReleasesWithImages += 1;
                }

                statistics.TotalImages              += release.Images.Count;
                statistics.TotalImageBytes          += release.Images.Select(i => this.collectionManager.ImageHandler.GetImageByteLength(i)).Sum();
                statistics.TotalAdditionalFiles     += release.AdditionalFiles.Count;
                statistics.TotalAdditionalFileBytes += release.AdditionalFiles.Select(f => f.File.Length).Sum();
                statistics.FlaggedReleases          += release.IsFlagged ? 1 : 0;

                ++processedReleases;
                ProgressChangedEventArgs eventArgs = new ProgressChangedEventArgs((double)processedReleases / releases.Length);
                this.OnProgressChanged(eventArgs);
                if (eventArgs.Cancel)
                {
                    return(null);
                }
            }

            return(statistics);
        }
コード例 #3
0
        public CollectionStatistics ComputeStatistics()
        {
            CollectionStatistics statistics = new CollectionStatistics();

            HashSet<string> albumArtists = new HashSet<string>();
            HashSet<Artist> artists = new HashSet<Artist>();

            Release[] releases = this.collectionManager.Releases.ToArray();

            int processedReleases = 0;
            foreach (Release release in releases)
            {
                statistics.TotalReleases += 1;
                statistics.TotalAlbumArtists += albumArtists.Add(release.JoinedAlbumArtists) ? 1 : 0;
                statistics.TotalArtists += release.Artists.Select(a => artists.Add(a.Artist) ? 1 : 0).Sum();
                statistics.TotalArtists += release.Tracklist.Select(t => t.Artists.Select(a => artists.Add(a.Artist) ? 1 : 0).Sum()).Sum();
                statistics.TotalTracks += release.Tracklist.Count;

                bool isPerfect = this.IsReleasePerfect(release);

                if (isPerfect)
                {
                    statistics.PerfectReleases += 1;
                }

                if (release.Images.Count > 0)
                {
                    statistics.ReleasesWithImages += 1;
                }

                statistics.TotalImages += release.Images.Count;
                statistics.TotalImageBytes += release.Images.Select(i => this.collectionManager.ImageHandler.GetImageByteLength(i)).Sum();
                statistics.TotalAdditionalFiles += release.AdditionalFiles.Count;
                statistics.TotalAdditionalFileBytes += release.AdditionalFiles.Select(f => f.File.Length).Sum();
                statistics.FlaggedReleases += release.IsFlagged ? 1 : 0;

                ++processedReleases;
                ProgressChangedEventArgs eventArgs = new ProgressChangedEventArgs((double)processedReleases / releases.Length);
                this.OnProgressChanged(eventArgs);
                if (eventArgs.Cancel)
                {
                    return null;
                }
            }

            return statistics;
        }