Exemple #1
0
        private async void signInButton_Click(object sender, EventArgs e)
        {
            if (!authenticatable.IsAuthenticated)
            {
                if (!am.CanAuthenticate(service))
                {
                    TaskDialogHelper.ShowMessage(caption: "Cannot authenticate this service right now.",
                                                 message: "The service is already being authenticated in the background. Please try again in a moment.",
                                                 icon: TaskDialogStandardIcon.Error, buttons: TaskDialogStandardButtons.Ok, owner: Handle);
                    return;
                }
                var authenticatableAsync = service.AsAuthenticatableAsync();
                if (authenticatableAsync == null)
                {
                    var dlg = new CredentialsForm(service);
                    dlg.ShowDialog();
                }
                else
                {
                    var result = await am.Authenticate(service);

                    if (result.Result)
                    {
                        return;
                    }
                    if (result.Exception != null)
                    {
                        Log.WriteException(Level.Error, Lag, result.Exception, "AM custom auth");
                        TaskDialogHelper.ShowExceptionDialog(result.Exception,
                                                             "An error occurred while attempting to sign in.",
                                                             "Make sure you have entered the correct credentials and your device has an active internet connection.\n\n" +
                                                             "The information below may be useful to the plugin's author.", Handle);
                    }
                    else
                    {
                        TaskDialogHelper.ShowMessage("An error occurred while attempting to sign in.",
                                                     "Make sure you have entered the correct credentials and your device has an active internet connection.",
                                                     TaskDialogStandardButtons.Ok, TaskDialogStandardIcon.Error, Handle);
                    }
                }
            }
            else
            {
                authenticatable.Reset();
            }
            UpdateViews();
            servicePlugin.SettingsFile.Save();
        }
        public async Task <bool> Authenticate(MusicService service)
        {
            if (!am.CanAuthenticate(service))
            {
                TaskDialogHelper.ShowMessage(caption: "Cannot authenticate this service right now.",
                                             message: "The service is already being authenticated in the background. Please try again in a moment.",
                                             icon: TaskDialogStandardIcon.Error, buttons: TaskDialogStandardButtons.Ok, owner: parent.Handle);
                return(false);
            }
            var authenticatableAsync = service.AsAuthenticatableAsync();

            if (authenticatableAsync == null)
            {
                var dlg = new CredentialsForm(service);
                return(dlg.ShowDialog() == DialogResult.OK);
            }
            var result = await am.Authenticate(service);

            if (result.Result)
            {
                return(true);
            }
            if (result.Exception != null)
            {
                Log.WriteException(Level.Error, Tag, result.Exception, "AM custom auth");
                TaskDialogHelper.ShowExceptionDialog(result.Exception,
                                                     "An error occurred while attempting to sign in.",
                                                     "Make sure you have entered the correct credentials and your device has an active internet connection.\n\n" +
                                                     "The information below may be useful to the plugin's author.", parent.Handle);
            }
            else
            {
                TaskDialogHelper.ShowMessage("An error occurred while attempting to sign in.",
                                             "Make sure you have entered the correct credentials and your device has an active internet connection.",
                                             TaskDialogStandardButtons.Ok, TaskDialogStandardIcon.Error, parent.Handle);
            }
            return(false);
        }