예제 #1
0
        private void ProcessTwitterLogin(string SettingsSection = "Authenticate")
        {
            TwitterApi twitter = loginTemp ?? (loginTemp = TwitterApi.Login(settings, SettingsSection));

            switch (twitter.Status)
            {
            case UserStatus.NO_APIKEY:
                RegisterApiKeyForm rakform = new RegisterApiKeyForm()
                {
                    TargetSection = SettingsSection
                };
                if (DialogResult.OK == rakform.ShowDialog(this))
                {
                    loginTemp = twitter = TwitterApi.Login(settings, SettingsSection);
                    SetStatusLabel(twitter.Status.ToString());
                    ProcessTwitterLogin(SettingsSection);
                }
                break;

            case UserStatus.NO_CREDITIONAL:
                MessageBox.Show(this, @"Unable to access your account! Please try login again.", @"No Creditional", MessageBoxButtons.OK,
                                MessageBoxIcon.Warning);
                ProcessTwitterLogin(SettingsSection);
                break;

            case UserStatus.LOGIN_REQUESTED:
                LoginProgressForm lpform = new LoginProgressForm(twitter);
                if (DialogResult.OK == lpform.ShowDialog(this))
                {
                    loginTemp = twitter = TwitterApi.Login(settings, SettingsSection);
                    SetStatusLabel(twitter.Status.ToString());
                    ProcessTwitterLogin(SettingsSection);
                }
                break;

            case UserStatus.INVALID_CREDITIONAL:
                loginTemp = null;
                MessageBox.Show(this, @"Unable to access your account! Please try login from menu.", @"Invalid Creditional",
                                MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                break;

            case UserStatus.LOGIN_SUCCESS:
                try
                {
                    loginTemp = null;
                    string apikey = SettingsSection.Equals("Authenticate") ? "Default" : SettingsSection;
                    CredentialManager.Instance.AddCredential(apikey, twitter);
                    manageAPIKeysToolStripMenuItem.DropDownItems.Add(new ToolStripMenuItem(apikey)
                    {
                        Name = apikey
                    });
                    removeAPIKeyToolStripMenuItem.DropDownItems.Add(new ToolStripMenuItem(apikey)
                    {
                        Name = apikey
                    });

                    loginToolStripMenuItem.Enabled = false;
                    loginToolStripMenuItem.Text    = @"Logged in as " + twitter.MyUserInfo.screen_name;
                }
                catch (InvalidCredentialException e)
                {
                    settings.DeleteSection(SettingsSection);
                    settings.Save();

                    MessageBox.Show(this, e.Message, @"Invalid Creditional", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                break;
            }
        }