Пример #1
0
        private void ShowDetails()
        {
            var tag = (MediaItemTag)mCurrentlySelectedQueueItem?.Tag;

            if (tag?.Exception == null)
            {
                return;
            }
            using (var dialog = CommonTaskDialogs.Exception(tag.Exception, "An error occurred while downloading this track",
                                                            "Check you can play this track on the web, check that you have a subscription, or try signing in and out.",
                                                            this))
            {
                dialog.Show();
            }
        }
Пример #2
0
        private void PresentException(Exception ex)
        {
            Log.WriteException(Level.Error, Tag, ex, "PresentException");
            SetGlobalProgressState(ProgressBarState.Error);
            var th = "An unknown error occurred";

            if (ex is ResourceNotFoundException)
            {
                th = "Resource not found";
            }
            else if (ex is InvalidSessionException)
            {
                th = "Invalid session/subscription expired";
            }
            CommonTaskDialogs.Exception(ex, th, "You may need to sign into this service again.", this).Show();
        }
Пример #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (isListViewDirty)
            {
                collectionStatusLabel.Text  = "Ready to begin.";
                collectionProgressBar.Value = 0;
                SetGlobalProgress(0);
                SetGlobalProgressState(ProgressBarState.Normal);
                totalProgressBar.Value = 0;
                totalStatusLabel.Text  = "Ready";
                queueListView.Groups.Clear();
                queueListView.Items.Clear();
                isListViewDirty = false;
            }
#if !DEBUG
            try
            {
#endif
            // Don't add if the item is already enqueued.
            var isAlreadyInQueue = mediaDownloadQueue.ItemById(mResult.Id) != null;
            if (isAlreadyInQueue)
            {
                using (
                    var td = CommonTaskDialogs.Message(owner: this, icon: TaskDialogStandardIcon.Error,
                                                       caption: "Cannot add to download queue", message: "This item already exists in the download queue."))
                {
                    td.Show();
                    return;
                }
            }

            // Ask for the location if required before we begin retrieval
            var prefType = PreferenceForType(mResult.Type);
            var saveDir  = prefType.SaveDirectory;
            if (prefType.AskForLocation)
            {
                using (var folderSelectionDialog = new FolderBrowserDialog {
                    Description = "Select a destionation for this media:"
                })
                {
                    if (folderSelectionDialog.ShowDialog(this) == DialogResult.OK)
                    {
                        saveDir = folderSelectionDialog.SelectedPath;
                    }
                    else
                    {
                        return;
                    }
                }
            }

            // Filter out types we can't process right now
            if (mResult.Type != MediaType.Album && mResult.Type != MediaType.Playlist &&
                mResult.Type != MediaType.Track)
            {
                using (var noTypeTd = CommonTaskDialogs.Message(owner: this, icon: TaskDialogStandardIcon.Warning,
                                                                caption: $"'{mResult.Type}' is not supported yet.",
                                                                message: "You may be able to download it in a later release."))
                {
                    noTypeTd.Show();
                    return;
                }
            }

            // Build wait dialog
            var retrievalWaitTaskDialog = new TaskDialog
            {
                Cancelable        = false,
                Caption           = "Athame",
                InstructionText   = $"Getting {mResult.Type.ToString().ToLower()} details...",
                Text              = $"{mService.Info.Name}: {mResult.Id}",
                StandardButtons   = TaskDialogStandardButtons.Cancel,
                OwnerWindowHandle = Handle,
                ProgressBar       = new TaskDialogProgressBar {
                    State = TaskDialogProgressBarState.Marquee
                }
            };
            // Open handler
            retrievalWaitTaskDialog.Opened += async(o, args) =>
            {
                LockUi();
                var pathFormat = Path.Combine(saveDir, prefType.GetPlatformSaveFormat());
                try
                {
                    switch (mResult.Type)
                    {
                    case MediaType.Album:
                        // Get album and display it in listview
                        var album = await mService.GetAlbumAsync(mResult.Id, true);

                        AddToQueue(mService, album, pathFormat);
                        break;

                    case MediaType.Playlist:
                        // Get playlist and display it in listview
                        var playlist = await mService.GetPlaylistAsync(mResult.Id);

                        AddToQueue(mService, playlist, pathFormat);
                        break;

                    case MediaType.Track:
                        var track = await mService.GetTrackAsync(mResult.Id);

                        AddToQueue(mService, track.AsCollection(), pathFormat);
                        break;
                    }
                }
                catch (ResourceNotFoundException)
                {
                    CommonTaskDialogs.Message(caption: "This media does not exist.",
                                              message: "Ensure the provided URL is valid, and try again", owner: this).Show();
                }
                catch (Exception ex)
                {
                    CommonTaskDialogs.Exception(ex,
                                                "An error occurred while trying to retrieve information for this media.",
                                                "The provided URL may be invalid or unsupported.", this).Show();
                }
                idTextBox.Clear();
                UnlockUi();
                retrievalWaitTaskDialog.Close();
            };
            // Show dialog
            retrievalWaitTaskDialog.Show();
#if !DEBUG
        }

        catch (Exception ex)
        {
            PresentException(ex);
        }
#endif
        }