コード例 #1
0
ファイル: ServiceSettingsView.cs プロジェクト: viatour/Athame
 private async void signInButton_Click(object sender, EventArgs e)
 {
     if (!authenticatable.IsAuthenticated)
     {
         var authenticatableAsync = service.AsAuthenticatableAsync();
         if (authenticatableAsync == null)
         {
             var dlg = new CredentialsForm(service);
             dlg.ShowDialog();
             servicePlugin.SettingsFile.Save();
         }
         else
         {
             await authenticatableAsync.AuthenticateAsync();
         }
         signInStatusLabel.Text = String.Format(sspSignInStatus.Get(authenticatable.IsAuthenticated),
                                                LocalisableAccountNameFormat.GetFormattedName(authenticatable.Account));
         sspSignInButton.Update(authenticatable.IsAuthenticated);
     }
     else
     {
         authenticatable.Reset();
         sspSignInStatus.Update(false);
         sspSignInButton.Update(false);
     }
 }
 public async Task <AuthenticationResult> Authenticate(MusicService service)
 {
     ServiceBeginAuthenticating(service);
     try
     {
         return(new AuthenticationResult(service, await service.AsAuthenticatableAsync().AuthenticateAsync()));
     }
     finally
     {
         ServiceEndAuthenticating(service);
     }
 }
コード例 #3
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();
        }
コード例 #4
0
 public async Task <AuthenticationResult> Authenticate(MusicService service)
 {
     ServiceBeginAuthenticating(service);
     try
     {
         return(new AuthenticationResult(service, await service.AsAuthenticatableAsync().AuthenticateAsync(), null));
     }
     catch (Exception ex)
     {
         return(new AuthenticationResult(service, false, ex));
     }
     finally
     {
         ServiceEndAuthenticating(service);
     }
 }
コード例 #5
0
 private async void signInButton_Click(object sender, EventArgs e)
 {
     if (!authenticatable.IsAuthenticated)
     {
         var authenticatableAsync = service.AsAuthenticatableAsync();
         if (authenticatableAsync == null)
         {
             var dlg = new CredentialsForm(service);
             dlg.ShowDialog();
         }
         else
         {
             await authenticatableAsync.AuthenticateAsync();
         }
     }
     else
     {
         authenticatable.Reset();
     }
     UpdateLabels();
     servicePlugin.SettingsFile.Save();
 }
コード例 #6
0
        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);
        }