Beispiel #1
0
        ChooseFuzzyMatchesResult ChooseFuzzyMatches(ReportingTaskBase taskContext, ChooseFuzzyMatchesState state)
        {
            int left = state.FuzzyMatches.Count();

            taskContext.TotalItems = left;

            bool autoUpdateSingleMatches = false, autoUpdateFullyRelevant = false, discardRemaining = false;

            foreach (var fuzzyMatch in state.FuzzyMatches)
            {
                taskContext.Description = "Choosing fuzzy match for '" + fuzzyMatch.Scrobble.Artist + " - " + fuzzyMatch.Scrobble.Title + "'";

                // Invoke in host form's thread and wait for completion
                state.HostForm.EndInvoke(state.HostForm.BeginInvoke((Action) delegate
                {
                    using (var chooser = new TrackChooser
                    {
                        FilesLeft = left--,
                        FuzzyMatch = fuzzyMatch,
                        DiscardRemaining = discardRemaining,
                        AutoUpdateFullyRelevant = autoUpdateFullyRelevant,
                        AutoUpdateSingleMatches = autoUpdateSingleMatches,
                    })
                    {
                        if ((autoUpdateSingleMatches && fuzzyMatch.Matches.Count() == 1) ||
                            (autoUpdateFullyRelevant && chooser.ChosenLibraryTracks.Count() > 0) ||
                            (!discardRemaining && chooser.ShowDialog(state.HostForm) == DialogResult.OK))
                        {
                            foreach (var media in chooser.ChosenLibraryTracks)
                            {
                                try
                                {
                                    if (media.TryUpdate(fuzzyMatch.Scrobble))
                                    {
                                        state.Updated++;
                                    }
                                    else
                                    {
                                        state.AlreadyUpToDate++;
                                    }
                                }
                                catch (COMException e)
                                {
                                    state.Errors.Enqueue(new QualifiedError(media.ToString(), InterpretErrorCode(e.ErrorCode)));
                                    state.UpdateFailed++;
                                }
                            }

                            autoUpdateSingleMatches = chooser.AutoUpdateSingleMatches;
                            autoUpdateFullyRelevant = chooser.AutoUpdateFullyRelevant;
                            discardRemaining        = chooser.DiscardRemaining;
                        }
                    }
                }));

                taskContext.ReportItemCompleted();
            }

            return(new ChooseFuzzyMatchesResult(state.Updated, state.AlreadyUpToDate, state.UpdateFailed, state.Errors.ToArray()));
        }
        ChooseFuzzyMatchesResult ChooseFuzzyMatches(ReportingTaskBase taskContext, ChooseFuzzyMatchesState state)
        {
            int left = state.FuzzyMatches.Count();
            taskContext.TotalItems = left;

            bool autoUpdateSingleMatches = false, autoUpdateFullyRelevant = false, discardRemaining = false;

            foreach (var fuzzyMatch in state.FuzzyMatches)
            {
                taskContext.Description = "Choosing fuzzy match for '" + fuzzyMatch.Scrobble.Artist + " - " + fuzzyMatch.Scrobble.Title + "'";

                // Invoke in host form's thread and wait for completion
                state.HostForm.EndInvoke(state.HostForm.BeginInvoke((Action)delegate
                {
                    using (var chooser = new TrackChooser
                    {
                        FilesLeft = left--,
                        FuzzyMatch = fuzzyMatch,
                        DiscardRemaining = discardRemaining,
                        AutoUpdateFullyRelevant = autoUpdateFullyRelevant,
                        AutoUpdateSingleMatches = autoUpdateSingleMatches,
                    })
                    {
                        if ((autoUpdateSingleMatches && fuzzyMatch.Matches.Count() == 1) ||
                            (autoUpdateFullyRelevant && chooser.ChosenLibraryTracks.Count() > 0) ||
                            (!discardRemaining && chooser.ShowDialog(state.HostForm) == DialogResult.OK))
                        {
                            foreach (var media in chooser.ChosenLibraryTracks)
                                try
                                {
                                    if (media.TryUpdate(fuzzyMatch.Scrobble))
                                        state.Updated++;
                                    else
                                        state.AlreadyUpToDate++;
                                }
                                catch (COMException e)
                                {
                                    state.Errors.Enqueue(new QualifiedError(media.ToString(), InterpretErrorCode(e.ErrorCode)));
                                    state.UpdateFailed++;
                                }

                            autoUpdateSingleMatches = chooser.AutoUpdateSingleMatches;
                            autoUpdateFullyRelevant = chooser.AutoUpdateFullyRelevant;
                            discardRemaining = chooser.DiscardRemaining;
                        }
                    }
                }));

                taskContext.ReportItemCompleted();
            }

            return new ChooseFuzzyMatchesResult(state.Updated, state.AlreadyUpToDate, state.UpdateFailed, state.Errors.ToArray());
        }