Пример #1
0
        private void ShowStartupTaskDialog()
        {
            var td     = CommonTaskDialogs.Wait(this, null);
            var openCt = new CancellationTokenSource();

            td.Opened += async(o, args) =>
            {
                await Task.Factory.StartNew(async() =>
                {
                    foreach (var service in ServiceRegistry.Default)
                    {
                        if (service.Settings.Response == null)
                        {
                            continue;
                        }
                        var result         = false;
                        td.InstructionText = $"Signing into {service.Name}...";
                        td.Text            = $"Signing in as {service.Settings.Response.UserName}";
                        try
                        {
                            openCt.Token.ThrowIfCancellationRequested();
                            result = await service.RestoreSessionAsync(service.Settings.Response);
                        }
                        catch (NotImplementedException)
                        {
                            result = service.RestoreSession(service.Settings.Response);
                        }
                        finally
                        {
                            if (result)
                            {
                            }
                            else
                            {
                                MessageBox.Show($"Failed to sign in to {service.Name}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }
                    }
                    td.Close();
                }, openCt.Token);
            };
            if (td.Show() == TaskDialogResult.Cancel)
            {
                openCt.Cancel(true);
            }
        }
Пример #2
0
        private void okButton_Click(object sender, EventArgs e)
        {
            var waitForm = CommonTaskDialogs.Wait($"Signing into {svc.Info.Name}...", this);

            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();
        }
Пример #3
0
        private void okButton_Click(object sender, EventArgs e)
        {
            var waitForm = CommonTaskDialogs.Wait(this, $"Signing into {svc.Name}...");

            waitForm.Opened += async(o, args) => {
                Result = await svc.LoginAsync(emailTextBox.Text, passwordTextBox.Text);

                waitForm.Close();
                if (Result != null)
                {
                    svc.Settings.Response = Result;
                    Program.DefaultSettings.Save();
                    DialogResult = DialogResult.OK;
                }
                else
                {
                    errorLabel.Text = "An error occurred while signing in. Please check your credentials and try again.";
                    SystemSounds.Hand.Play();
                }
            };
            waitForm.Show();
        }
Пример #4
0
        private void ShowStartupTaskDialog()
        {
            var td     = CommonTaskDialogs.Wait(owner: this);
            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}");
                            CommonTaskDialogs.Message(owner: this, caption: $"Failed to sign in to {service.Info.Name}",
                                                      message: null, icon: TaskDialogStandardIcon.Error).Show();
                        }
                    }
                    td.Close();
                }, openCt.Token);
            };
            if (td.Show() == TaskDialogResult.Cancel)
            {
                openCt.Cancel(true);
            }
        }