Example #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());
        }
Example #2
0
        private void id3Button_Click(object sender, EventArgs e)
        {
            Dialogs.AddID3TagsDialog dialog = new Dialogs.AddID3TagsDialog();
            if (dialog.ShowDialog(this) == DialogResult.OK)
            {
                bool interpret = dialog.Interpret;
                bool album     = dialog.Album;
                bool genre     = dialog.Genre;
                bool mood      = dialog.Mood;
                if (!interpret && !album && !genre && !mood)
                {
                    return;
                }

                int languageId = m_Project != null ? m_Project.TagLanguageId : -1;
                if (languageId == -1)
                {
                    try
                    {
                        languageId = Ares.Tags.TagsModule.GetTagsDB().TranslationsInterface.GetIdOfCurrentUILanguage();
                    }
                    catch (Ares.Tags.TagsDbException ex)
                    {
                        MessageBox.Show(this, String.Format(StringResources.TagsDbError, ex.Message), StringResources.Ares, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }

                var tokenSource = new System.Threading.CancellationTokenSource();
                Ares.CommonGUI.ProgressMonitorBase monitor = new TaskProgressMonitor(this, StringResources.ExtractingTags, tokenSource);

                var task = Ares.TagsImport.TagExtractor.ExtractTagsAsync(monitor, m_Files, Ares.Settings.Settings.Instance.MusicDirectory, languageId, interpret, album, genre, mood, tokenSource.Token);
                task.ContinueWith((task2) =>
                {
                    monitor.Close();
                    if (task.Exception != null)
                    {
                        TaskHelpers.HandleTaskException(this, task.Exception, StringResources.TagExtractionError);
                    }
                    else
                    {
                        Ares.Editor.Actions.TagChanges.Instance.FireTagsDBChanged(this);
                        UpdateAll();
                    }
                }, System.Threading.CancellationToken.None, System.Threading.Tasks.TaskContinuationOptions.None, System.Threading.Tasks.TaskScheduler.FromCurrentSynchronizationContext());
            }
        }
Example #3
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());
        }
Example #4
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);
                }
            }
        }
Example #5
0
        /// <summary>
        /// Download the files for all given ISearchResults to the locations specified by the given ITargetDirectoryProvider.
        /// based on their type (sound/music)
        /// </summary>
        /// <param name="results"></param>
        private void DeployRequiredFilesForSearchResults(IEnumerable <ISearchResult> results, ITargetDirectoryProvider targetDirectoryProvider)
        {
            // Collect the list of files to be deployed
            List <IDeployableAudioFile> filesToBeDeployed = new List <IDeployableAudioFile>();

            foreach (ISearchResult searchResult in results)
            {
                // Queue the ISearchResult itself for deployment if it's an IDeployableAudioFile in it's own right
                if (searchResult is IDeployableAudioFile)
                {
                    filesToBeDeployed.Add(searchResult as IDeployableAudioFile);
                }

                // Queue additional required files for deployment
                foreach (IDeployableAudioFile deployableFile in searchResult.RequiredFiles)
                {
                    filesToBeDeployed.Add(deployableFile);
                }
            }

            // Collect the total "cost" of all files to be deployed
            double totalDeploymentCost = 0;

            foreach (IDeployableAudioFile deployableFile in filesToBeDeployed)
            {
                totalDeploymentCost += deployableFile.DeploymentCost.GetValueOrDefault(1);
            }

            // Initialize a task monitor for the download process
            TaskProgressMonitor      baseMonitor     = new TaskProgressMonitor(this, StringResources.DownloadingAudio, new CancellationTokenSource());
            IAbsoluteProgressMonitor absoluteMonitor = new AbsoluteProgressMonitor(baseMonitor, totalDeploymentCost, StringResources.DownloadingAudio);

            // Start a separate task for downloading the files
            Task <List <AudioDeploymentResult> > task = Task.Factory.StartNew(() =>
            {
                absoluteMonitor.SetIndeterminate();
                List <AudioDeploymentResult> downloadResults = new List <AudioDeploymentResult>();

                // Go through all results
                foreach (IDeployableAudioFile deployableFile in filesToBeDeployed)
                {
                    // Download each one
                    downloadResults.Add(DeployFile(deployableFile, absoluteMonitor, targetDirectoryProvider));
                    absoluteMonitor.IncreaseProgress(deployableFile.DeploymentCost.GetValueOrDefault(1));
                }

                return(downloadResults);
            });

            // What to do when the downloads complete
            task.ContinueWith((t) =>
            {
                baseMonitor.Close();

                // TODO: Do something with the collected DownloadResults
                List <AudioDeploymentResult> downloadResults = task.Result;
            }, System.Threading.CancellationToken.None, System.Threading.Tasks.TaskContinuationOptions.NotOnFaulted, System.Threading.Tasks.TaskScheduler.FromCurrentSynchronizationContext());

            // What to do when the downloads fail
            task.ContinueWith((t) =>
            {
                baseMonitor.Close();
                if (t.Exception != null)
                {
                    TaskHelpers.HandleTaskException(this, t.Exception, StringResources.SearchError);
                }
            }, System.Threading.CancellationToken.None, System.Threading.Tasks.TaskContinuationOptions.OnlyOnFaulted, System.Threading.Tasks.TaskScheduler.FromCurrentSynchronizationContext());
        }
Example #6
0
        /// <summary>
        /// Execute a search with the given parameters (search query, page number, page size)
        /// The results will either be passed to ProcessSearchResults.
        /// </summary>
        /// <param name="query"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public Task <IEnumerable <ISearchResult> > SearchAsync(string query, string id, int pageIndex, int pageSize)
        {
            TaskProgressMonitor      baseMonitor     = new TaskProgressMonitor(this, StringResources.SearchingForAudio, new CancellationTokenSource());
            IAbsoluteProgressMonitor absoluteMonitor = new AbsoluteProgressMonitor(baseMonitor, 1, StringResources.SearchingForAudio);

            int?totalNumberOfResults = null;

            Task <IEnumerable <ISearchResult> > task = Task.Factory.StartNew(() =>
            {
                absoluteMonitor.SetIndeterminate();

                // Ask the AudioSource for (async) search results
                try {
                    if (!String.IsNullOrEmpty(query))
                    {
                        Task <IEnumerable <ISearchResult> > searchSubtask = this.m_selectedAudioSource.Search(query, pageSize, pageIndex, absoluteMonitor, out totalNumberOfResults);

                        return(searchSubtask.Result);
                    }
                    else if (!String.IsNullOrEmpty(id))
                    {
                        var searchSubtask = this.m_selectedAudioSource.SearchSimilar(id, pageSize, pageIndex, absoluteMonitor, out totalNumberOfResults);
                        return(searchSubtask.Result);
                    }
                    else
                    {
                        return(Enumerable.Empty <ISearchResult>());
                    }
                } catch (OperationCanceledException) {
                    this.m_searchQuery = String.Empty;
                    this.m_searchId    = String.Empty;
                    //this.searchBox.Text = this.m_searchQuery;
                    this.m_searchPageIndex = 0;
                    this.m_searchPageSize  = pageSize;

                    return(Enumerable.Empty <ISearchResult>());
                }
            });

            // What to do when the search fails
            task.ContinueWith((t) =>
            {
                // Close the progress monitor
                baseMonitor.Close();

                // If an actual exception occurred (which should be the case)...
                if (t.Exception != null)
                {
                    // ... show an error popup
                    TaskHelpers.HandleTaskException(this, t.Exception, StringResources.SearchError);
                }

                this.m_searchQuery = String.Empty;
                this.m_searchId    = String.Empty;
                //this.searchBox.Text = this.m_searchQuery;
                this.m_searchPageIndex = 0;
                this.m_searchPageSize  = pageSize;
            }, System.Threading.CancellationToken.None, System.Threading.Tasks.TaskContinuationOptions.OnlyOnFaulted, System.Threading.Tasks.TaskScheduler.FromCurrentSynchronizationContext());

            // What to do when the search completes
            return(task.ContinueWith((t) =>
            {
                // Close the progress monitor
                baseMonitor.Close();

                // Retrieve the results
                IEnumerable <ISearchResult> results = task.Result;

                // Perform an update on the results ListView
                this.resultsListView.BeginUpdate();
                // Process the results
                ProcessSearchResults(results, query, pageIndex, pageSize, totalNumberOfResults);
                this.resultsListView.EndUpdate();

                this.m_searchQuery = query;
                this.m_searchId = id;
                //this.searchBox.Text = this.m_searchQuery;
                this.m_searchPageIndex = pageIndex;
                this.m_searchPageSize = pageSize;

                return results;
            }, System.Threading.CancellationToken.None, System.Threading.Tasks.TaskContinuationOptions.NotOnFaulted, System.Threading.Tasks.TaskScheduler.FromCurrentSynchronizationContext()));
        }
Example #7
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());
        }