Beispiel #1
0
        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());
        }
Beispiel #2
0
        private void findInDBButton_Click(object sender, EventArgs e)
        {
            System.Threading.CancellationTokenSource tokenSource = new System.Threading.CancellationTokenSource();
            TaskProgressMonitor monitor = new TaskProgressMonitor(this, StringResources.FindingFilesInDB, tokenSource);

            monitor.IncreaseProgress(0.1, StringResources.ExtractingMusicIds);
            Ares.TagsImport.SequentialProgressMonitor musicIdMonitor = new TagsImport.SequentialProgressMonitor(monitor, 0.1, 89.9);
            var task  = Ares.TagsImport.MusicIdentification.UpdateMusicIdentificationAsync(musicIdMonitor, m_Files, Ares.Settings.Settings.Instance.MusicDirectory, tokenSource.Token);
            var task2 = task.ContinueWith((t) =>
            {
                var dbRead  = Ares.Tags.TagsModule.GetTagsDB().ReadInterface;
                var fileIds = dbRead.GetIdentificationForFiles(m_Files);
                return(Ares.TagsImport.TagsFromIds.FindTagsByIdsAsync(monitor, fileIds, m_Files, 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();
                try
                {
                    int result = task2.Result;
                    MessageBox.Show(this, String.Format(StringResources.TagsDownloadStats, result, m_Files.Count), StringResources.Ares, MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                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.TagsDbError);
                }
            }, 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());
        }
Beispiel #3
0
        private void Editor_DragDrop(object sender, DragEventArgs e)
        {
            int row = 0;

            if (ContainerControl.PerformDrop(e, out row))
            {
                return;
            }
            FileDragInfo info = e.Data.GetData(typeof(FileDragInfo)) as FileDragInfo;

            if (info != null && info.DraggedItems != null)
            {
                if (info.DraggedItems.Count > 1 || info.DraggedItems[0].NodeType == DraggedItemType.Directory)
                {
                    System.Threading.CancellationTokenSource tokenSource = new System.Threading.CancellationTokenSource();
                    TaskProgressMonitor monitor = new TaskProgressMonitor(this, StringResources.AddingFiles, tokenSource);
                    monitor.IncreaseProgress(0.1, StringResources.GettingTitles);
                    var task = DragAndDrop.GetElementsFromDroppedItemsAsync(info, tokenSource.Token, monitor);
                    task.ContinueWith((t) =>
                    {
                        monitor.Close();
                        try
                        {
                            var result = task.Result;
                            if (result != null)
                            {
                                ContainerControl.AddElements(result, row);
                            }
                        }
                        catch (AggregateException)
                        {
                        }
                    }, tokenSource.Token, System.Threading.Tasks.TaskContinuationOptions.OnlyOnRanToCompletion, System.Threading.Tasks.TaskScheduler.FromCurrentSynchronizationContext());
                    task.ContinueWith((t) =>
                    {
                        monitor.Close();
                    }, tokenSource.Token, System.Threading.Tasks.TaskContinuationOptions.NotOnRanToCompletion, System.Threading.Tasks.TaskScheduler.FromCurrentSynchronizationContext());
                }
                else
                {
                    List <Ares.Data.IElement> elements = new List <Ares.Data.IElement>(DragAndDrop.GetElementsFromDroppedItems(info));
                    ContainerControl.AddElements(elements, row);
                }
            }
        }
Beispiel #4
0
        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());
        }