private void downloadButton_Click(object sender, EventArgs e) { bool includeLog = Settings.Settings.Instance.ShowDialogAfterDownload; System.Threading.CancellationTokenSource tokenSource = new System.Threading.CancellationTokenSource(); TaskProgressMonitor monitor = new TaskProgressMonitor(this, StringResources.DownloadingTags, tokenSource); monitor.IncreaseProgress(0.1, StringResources.ExtractingMusicIds); var task = Ares.TagsImport.MusicIdentification.UpdateMusicIdentificationAsync(monitor, m_Files, Ares.Settings.Settings.Instance.MusicDirectory, tokenSource.Token); var task2 = task.ContinueWith((t) => { return(Ares.TagsImport.GlobalDbDownload.DownloadTagsAsync(monitor, m_Files, includeLog, tokenSource.Token)); }, System.Threading.CancellationToken.None, System.Threading.Tasks.TaskContinuationOptions.NotOnFaulted, System.Threading.Tasks.TaskScheduler.Default).Unwrap(); task2.ContinueWith((t) => { monitor.Close(); Ares.Editor.Actions.TagChanges.Instance.FireTagsDBChanged(this); UpdateAll(); if (includeLog) { try { String log = task2.Result.Result; var dialog = new Dialogs.OnlineDbResultDialog(); dialog.Log = log; dialog.SetIsDownload(m_Files.Count, task2.Result.NrOfFoundFiles, task.Result); dialog.ShowDialog(this); } catch (AggregateException) { } } }, System.Threading.CancellationToken.None, System.Threading.Tasks.TaskContinuationOptions.NotOnFaulted, System.Threading.Tasks.TaskScheduler.FromCurrentSynchronizationContext()); task2.ContinueWith((t) => { monitor.Close(); if (t.Exception != null) { TaskHelpers.HandleTaskException(this, t.Exception, StringResources.DownloadError); } }, System.Threading.CancellationToken.None, System.Threading.Tasks.TaskContinuationOptions.OnlyOnFaulted, System.Threading.Tasks.TaskScheduler.FromCurrentSynchronizationContext()); task.ContinueWith((t) => { monitor.Close(); if (t.Exception != null) { TaskHelpers.HandleTaskException(this, t.Exception, StringResources.MusicIdExtractionError); } }, System.Threading.CancellationToken.None, System.Threading.Tasks.TaskContinuationOptions.OnlyOnFaulted, System.Threading.Tasks.TaskScheduler.FromCurrentSynchronizationContext()); }
private void shareButton_Click(object sender, EventArgs e) { String user = Settings.Settings.Instance.OnlineDBUserId; if (String.IsNullOrEmpty(user)) { DialogResult res = MessageBox.Show(this, StringResources.OnlineDbUserIdRequired, StringResources.Ares, MessageBoxButtons.OKCancel); if (res == DialogResult.OK) { m_Parent.SetOnlineUserId(); user = Settings.Settings.Instance.OnlineDBUserId; } } if (String.IsNullOrEmpty(user)) { // cancelled or didn't set a user name return; } bool includeLog = Settings.Settings.Instance.ShowDialogAfterUpload; System.Threading.CancellationTokenSource tokenSource = new System.Threading.CancellationTokenSource(); TaskProgressMonitor monitor = new TaskProgressMonitor(this, StringResources.SharingTags, tokenSource); monitor.IncreaseProgress(0.1, StringResources.ExtractingMusicIds); List <String> usedFiles = new List <String>(); var readIf = Ares.Tags.TagsModule.GetTagsDB().GetReadInterfaceByLanguage(m_LanguageId); foreach (String file in m_Files) { if (readIf.GetTagsForFile(file).Count > 0) { usedFiles.Add(file); } } var task = Ares.TagsImport.MusicIdentification.UpdateMusicIdentificationAsync(monitor, usedFiles, Ares.Settings.Settings.Instance.MusicDirectory, tokenSource.Token); var task2 = task.ContinueWith((t) => { return(Ares.TagsImport.GlobalDbUpload.UploadTagsAsync(monitor, usedFiles, user, includeLog, tokenSource.Token)); }, System.Threading.CancellationToken.None, System.Threading.Tasks.TaskContinuationOptions.NotOnFaulted, System.Threading.Tasks.TaskScheduler.Default).Unwrap(); task2.ContinueWith((t) => { monitor.Close(); if (includeLog) { try { String log = task2.Result; var dialog = new Dialogs.OnlineDbResultDialog(); dialog.Log = log; dialog.SetIsUpload(usedFiles.Count, task.Result); dialog.ShowDialog(this); } catch (AggregateException) { } } }, System.Threading.CancellationToken.None, System.Threading.Tasks.TaskContinuationOptions.NotOnFaulted, System.Threading.Tasks.TaskScheduler.FromCurrentSynchronizationContext()); task.ContinueWith((t) => { monitor.Close(); if (t.Exception != null) { TaskHelpers.HandleTaskException(this, t.Exception, StringResources.UploadError); } }, System.Threading.CancellationToken.None, System.Threading.Tasks.TaskContinuationOptions.OnlyOnFaulted, System.Threading.Tasks.TaskScheduler.FromCurrentSynchronizationContext()); task2.ContinueWith((t) => { monitor.Close(); if (t.Exception != null) { TaskHelpers.HandleTaskException(this, t.Exception, StringResources.MusicIdExtractionError); } }, System.Threading.CancellationToken.None, System.Threading.Tasks.TaskContinuationOptions.OnlyOnFaulted, System.Threading.Tasks.TaskScheduler.FromCurrentSynchronizationContext()); }