Esempio n. 1
0
        public Form_Main()
        {
            InitializeComponent();

            logger.Info("=== Activated. ===");

            this.ShowInTaskbar = false;
            this.notifyIcon.Icon = System.Drawing.SystemIcons.Application;

            string apiKey = "9LQZDfaCSJR88d2HLkkXrBFz0";
            string apiKeySecret = "HzupFEw0SFaLA2U4NGIBW0BFXybVY3M7uTgS33x1nByiEmjnI7";

            if (Properties.Settings.Default.AccessTokenList == null ||
                Properties.Settings.Default.AccessTokenList.Count == 0)
            {
                logger.Info("First activated.");

                var sessions = OAuth.Authorize(apiKey, apiKeySecret);
                var url = sessions.AuthorizeUri;

                using (Form_InputPinCode f = new Form_InputPinCode(url.ToString()))
                {
                    DialogResult dr = f.ShowDialog();
                    if (dr != DialogResult.OK)
                    {
                        return;
                    }

                    string pin = f.PinCode;
                    var t = OAuth.GetTokens(sessions, pin);
                    this.tokens = t;
                    this.user = t.Account.VerifyCredentials();
                }

                string tokenData = string.Format("{0},{1},{2},{3}",
                    this.user.ScreenName,
                    this.user.Name,
                    this.tokens.AccessToken,
                    this.tokens.AccessTokenSecret);
                Properties.Settings.Default.AccessTokenList = new System.Collections.Specialized.StringCollection();
                Properties.Settings.Default.AccessTokenList.Add(tokenData);
                Properties.Settings.Default.Save();

                logger.Info("Initializing has completed.");

                return;
            }

            string[] tokenDataArray = Properties.Settings.Default.AccessTokenList[Properties.Settings.Default.LastLoginUser].Split(',');

            this.tokens = Tokens.Create(
                apiKey,
                apiKeySecret,
                tokenDataArray[2],
                tokenDataArray[3]);
            this.user = this.tokens.Account.VerifyCredentials();

            logger.Info("Data has loaded.");
        }
Esempio n. 2
0
        private void addAccount()
        {
            string apiKey = "9LQZDfaCSJR88d2HLkkXrBFz0";
            string apiKeySecret = "HzupFEw0SFaLA2U4NGIBW0BFXybVY3M7uTgS33x1nByiEmjnI7";
            var sessions = OAuth.Authorize(apiKey, apiKeySecret);
            var url = sessions.AuthorizeUri;

            using (Form_InputPinCode ff = new Form_InputPinCode(url.ToString()))
            {
                DialogResult dr = ff.ShowDialog();
                if (dr != DialogResult.OK)
                {
                    return;
                }

                string pin = ff.PinCode;
                var t = OAuth.GetTokens(sessions, pin);

                foreach(string row in Properties.Settings.Default.AccessTokenList)
                {
                    string screenName = row.Split(',')[0];
                    if (screenName == t.Account.VerifyCredentials().ScreenName)
                    {
                        MessageBox.Show("This user has been added.",
                            "Information,",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Information);
                        return;
                    }
                }

                this.tokens = t;
                this.user = t.Account.VerifyCredentials();
            }

            show(this.tokens);

            if (this.disposable != null)
            {
                this.disposable.Dispose();
                logger.Debug("Streaming has disposed.");
            }

            streaming(this.tokens);

            string tokenData = string.Format("{0},{1},{2},{3}",
                this.user.ScreenName,
                this.user.Name,
                this.tokens.AccessToken,
                this.tokens.AccessTokenSecret);
            Properties.Settings.Default.AccessTokenList.Add(tokenData);
            Properties.Settings.Default.Save();
        }