Exemplo n.º 1
0
        private void okButton_Click(object sender, EventArgs e)
        {
            var waitForm = TaskDialogHelper.CreateWaitDialog($"Signing into {svc.Info.Name}...", Handle);

            waitForm.Opened += async(o, args) => {
                var result = await usernamePasswordService.AuthenticateAsync(emailTextBox.Text, passwordTextBox.Text, true);

                waitForm.Close();
                if (result)
                {
                    DialogResult = DialogResult.OK;
                }
                else
                {
                    errorLabel.Text = "An error occurred while signing in. Please check your credentials and try again.";
                    SystemSounds.Hand.Play();
                }
            };
            waitForm.Show();
        }
        private void RestoreServices()
        {
            var am       = Program.DefaultAuthenticationManager;
            var taskList = Program.DefaultPluginManager.ServicesEnumerable()
                           .Where(am.CanRestore).Select(service => am.Restore(service));
            var td     = TaskDialogHelper.CreateWaitDialog(null, Handle);
            var openCt = new CancellationTokenSource();

            td.Opened += async(o, args) =>
            {
                await Task.Factory.StartNew(async() =>
                {
                    foreach (var service in Program.DefaultPluginManager.ServicesEnumerable())
                    {
                        var restorable = service.AsAuthenticatable();
                        if (restorable == null || !restorable.HasSavedSession)
                        {
                            continue;
                        }

                        var result         = false;
                        td.InstructionText = $"Signing into {service.Info.Name}...";
                        td.Text            = $"Signing in as {LocalisableAccountNameFormat.GetFormattedName(restorable.Account)}";
                        openCt.Token.ThrowIfCancellationRequested();
                        result = await restorable.RestoreAsync();
                        if (!result)
                        {
                            Log.Error(Tag, $"Failed to sign into {service.Info.Name}");
                            TaskDialogHelper.ShowMessage(owner: Handle, caption: $"Failed to sign in to {service.Info.Name}",
                                                         message: null, icon: TaskDialogStandardIcon.Error, buttons: TaskDialogStandardButtons.Ok);
                        }
                    }
                    td.Close();
                }, openCt.Token);
            };
            if (td.Show() == TaskDialogResult.Cancel)
            {
                openCt.Cancel(true);
            }
        }
Exemplo n.º 3
0
        private void okButton_Click(object sender, EventArgs e)
        {
            var waitForm = TaskDialogHelper.CreateWaitDialog($"Signing into {svc.Info.Name}...", Handle);

            waitForm.Opened += async(o, args) => {
                var result = await am.Authenticate(svc, emailTextBox.Text, passwordTextBox.Text, true);

                waitForm.Close();
                if (result.Result)
                {
                    DialogResult = DialogResult.OK;
                    return;
                }
                if (result.Exception != null)
                {
                    Log.WriteException(Level.Error, Lag, result.Exception, "AM credential auth");
                }

                errorLabel.Text = "An error occurred while signing in. Please check your credentials and try again.";
                SystemSounds.Hand.Play();
            };
            waitForm.Show();
        }