Exemplo n.º 1
0
        private void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            int err_count = 5;

            EXDocument doc   = new EXDocument();
            int        count = 0;

            while (count < tweet_count)
            {
                if (worker.CancellationPending == true)
                {
                    break;
                }

                // 直近の200件を取得
                string xml = GetTweets(username, max_id);
                if (xml == "")
                {
                    err_count--;
                    if (err_count < 0)
                    {
                        MessageBox.Show("取得エラー発生", APPTITLE, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        worker.CancelAsync();
                        return;
                    }
                    // 1秒待つ
                    System.Threading.Thread.Sleep(1000);
                    continue;
                }

                doc.LoadXML(xml);
                EXElements items = doc * "status";

                foreach (EXElement status in items)
                {
                    string id = status / "id";
                    if (max_id == id)
                    {
                        continue;
                    }

                    count++;
                    Tweet twi = new Tweet()
                    {
                        Num        = count,
                        ID         = status / "id",
                        text       = status / "text",
                        created_at = status / "created_at"
                    };
                    _tweets.Add(twi);
                    max_id = twi.ID;
                }
                worker.ReportProgress(count * 100 / tweet_count);
                if (items.Count < 200)
                {
                    break;
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 実行ボタン
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnGo_Click(object sender, EventArgs e)
        {
            if (accessToken == "")
            {
                // 初期設定の場合
                oauth.Initialize(consumerKey, consumerSecret, "", "", username);
                Uri authUri = new Uri("http://twitter.com/");
                oauth.AuthenticatePinFlowRequest(
                    "https://twitter.com/oauth/request_token",
                    "https://twitter.com/oauth/authorize", ref requestToken, ref authUri);
                Process pro = new Process();
                accessTokenUrl         = authUri.ToString();
                pro.StartInfo.FileName = authUri.ToString();
                pro.Start();
                return;
            }
            startTime = DateTime.Now;

            // 通常の取得
            username = textBox1.Text.Trim();
            if (username == "")
            {
                return;
            }
            labelTweets.Text  = "0";
            pictureBox1.Image = null;


            // ツイート数を取得
            string xml = GetUserInfo(username);

            if (xml == "")
            {
                MessageBox.Show("ユーザーが見つかりませんでした", APPTITLE, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            EXDocument doc = new EXDocument();

            doc.LoadXML(xml);
            string profile_image_url = doc * "profile_image_url";
            string statuses_count    = doc * "statuses_count";

            max_id           = doc * "status" / "id";
            tweet_count      = int.Parse(statuses_count);
            labelTweets.Text = tweet_count.ToString("#,##0");

            // 画像表示
            WebClient cl = new WebClient();

            byte[]       pic = cl.DownloadData(profile_image_url);
            MemoryStream st  = new MemoryStream(pic);

            pictureBox1.Image = new Bitmap(st);
            st.Close();

            _tweets = new List <Tweet>();
            worker.RunWorkerAsync();
        }