internal void SetResult(CredentialClaimResult result, IProvider provider)
        {
            this.claimResult = result;
            this.provider    = provider;

            this.labelUsername.Text = result.UserName;

            this.SetShown(false);

            if (!this.host.Database.IsOpen)
            {
                this.buttonSave.Visible = false;
            }
        }
        private void buttonNext_Click(object sender, EventArgs e)
        {
            switch (this.wizardState)
            {
            case WizardState.UrlEntry:
                this.BackgroundDisplay(true);
                var urlOperation = new AsyncOperationWithSynchronizationContext(() =>
                {
                    this.credentialConfigurationProvier = this.selectionForm.SelectedProvider.CredentialConfigurationProvider;
                    this.credentialConfigurationProvier.Initialize();
                },
                                                                                // continuation
                                                                                () =>
                {
                    LaunchUrl(this.credentialConfigurationProvier.GetExternalAuthorizationUrl());

                    this.panelContainer.Controls.Remove(this.selectionForm);
                    if (this.credentialConfigurationProvier is IOAuth1CredentialConfigurationProvider)
                    {
                        this.panelContainer.Controls.Add(this.authorizationForm);
                        // invoke authentication process
                        this.wizardState = WizardState.AwaitingAuthorization;
                    }
                    else if (this.credentialConfigurationProvier is IOAuth2CredentialConfigurationProvider)
                    {
                        this.panelContainer.Controls.Add(this.exchangeForm);
                        this.wizardState = WizardState.ExchangeCode;
                    }
                },
                                                                                // catch
                                                                                ecxeption =>
                {
                    MessageBox.Show(ecxeption.Message, "Error");
                    this.StartOver();
                },
                                                                                // finally
                                                                                () =>
                {
                    this.BackgroundDisplay(false);
                });
                urlOperation.Run();

                break;

            case WizardState.ExchangeCode:
            {
                this.BackgroundDisplay(true);
                CredentialClaimResult result = null;
                var exchangeCodeOperation    = new AsyncOperationWithSynchronizationContext(() =>
                    {
                        var provider = this.credentialConfigurationProvier as IOAuth2CredentialConfigurationProvider;
                        result       = provider.ExchangeCode(this.exchangeForm.textBoxCode.Text);
                    },
                                                                                            // continuation
                                                                                            () =>
                    {
                        if (result.IsSuccess)
                        {
                            this.panelContainer.Controls.Remove(this.exchangeForm);
                            this.successForm.SetResult(result, this.selectionForm.SelectedProvider);
                            this.panelContainer.Controls.Add(this.successForm);
                            this.wizardState          = WizardState.Success;
                            this.buttonCancel.Visible = false;
                            this.buttonNext.Text      = "Done";
                        }
                        else
                        {
                            MessageBox.Show("Couldn't exchange authorization code for an access token", "Error");
                            this.StartOver();
                        }
                    },
                                                                                            // catch
                                                                                            ecxeption =>
                    {
                        MessageBox.Show(ecxeption.Message, "Error");
                        this.StartOver();
                    },
                                                                                            // finally
                                                                                            () =>
                    {
                        this.BackgroundDisplay(false);
                    });
                exchangeCodeOperation.Run();
                break;
            }

            case WizardState.AwaitingAuthorization:
            {
                this.BackgroundDisplay(true);
                CredentialClaimResult result       = null;
                var awaitingAuthorizationOperation = new AsyncOperationWithSynchronizationContext(() =>
                    {
                        var provider = this.credentialConfigurationProvier as IOAuth1CredentialConfigurationProvider;
                        result       = provider.Claim();
                    },
                                                                                                  // continuation
                                                                                                  () =>
                    {
                        if (result.IsSuccess)
                        {
                            this.panelContainer.Controls.Remove(this.authorizationForm);
                            this.successForm.SetResult(result, this.selectionForm.SelectedProvider);
                            this.panelContainer.Controls.Add(this.successForm);
                            this.wizardState          = WizardState.Success;
                            this.buttonCancel.Visible = false;
                            this.buttonNext.Text      = "Done";
                        }
                        else
                        {
                            MessageBox.Show("Couldn't authorize with account", "Error");
                            this.StartOver();
                        }
                    },
                                                                                                  // catch
                                                                                                  ecxeption =>
                    {
                        MessageBox.Show(ecxeption.Message, "Error");
                        this.StartOver();
                    },
                                                                                                  // finally
                                                                                                  () =>
                    {
                        this.BackgroundDisplay(false);
                    });
                awaitingAuthorizationOperation.Run();
                break;
            }

            case WizardState.Success:
                this.Close();
                break;
            }
        }