Example #1
0
        /// <summary>
        /// リストの更新
        /// </summary>
        /// <param name="twitterAccount">Twitterアカウント</param>
        private void UpdateTwitterListView(Twitter.Twitter twitterAccount)
        {
            twitterListView.Items.Clear();
            twitterListView.BeginUpdate();

            twitterStatuses = null;

            if (UserSetting.CheckList == UserSetting.CheckLists.Friends)
            {
                twitterStatuses = twitterAccount.FriendTimeline();
            }
            else if (UserSetting.CheckList == UserSetting.CheckLists.Public)
            {
                twitterStatuses = twitterAccount.PublicTimeline();
            }

            foreach (Twitter.StatusInfomation statusInfomation in twitterStatuses)
            {
                string date = string.Empty;
                if (DateTime.Today <= statusInfomation.CreatedAt)
                {
                    date = statusInfomation.CreatedAt.ToString("HH':'mm");
                }
                else
                {
                    date = statusInfomation.CreatedAt.ToString("M'/'d");
                }

                string[] str = { statusInfomation.User.Name, statusInfomation.Text, date };

                ListViewItem item = new ListViewItem(str);
                if (statusInfomation.User.ProfileImageUrl != null)
                {
                    item.ImageIndex = GetProfileImage(statusInfomation.User.ProfileImageUrl);
                }
                twitterListView.Items.Add(item);
            }

            twitterListView.EndUpdate();

            if (twitterStatuses.Length == 0)
            {
                MessageBox.Show("ステータスがありません。", "情報");
            }
        }
Example #2
0
        /// <summary>
        /// Twitterのチェックと投稿
        /// </summary>
        /// <param name="post">trueの場合、テキストボックスの内容を投稿する。</param>
        private void CheckTwitterUpdate(bool post)
        {
            // CheckHeadline()が処理の場合は何もせず終了
            if (checkTwitterUpdateNowFlag == true)
            {
                return;
            }

            // 排他処理のためのフラグを立てる
            checkTwitterUpdateNowFlag = true;

            #region UI前処理

            // フォームをいったん選択不可にする
            menuMenuItem.Enabled    = false;
            updateMenuItem.Enabled  = false;
            twitterListView.Enabled = false;
            updateButton.Enabled    = false;

            #endregion

            Twitter.Twitter twitterAccount = new TwitterAway.Twitter.Twitter(UserSetting.UserName, UserSetting.Password);
            try
            {
                if (post == false || doingPostTextBox.Text == string.Empty)
                {
                    UpdateTwitterListView(twitterAccount);
                }
                else
                {
                    twitterAccount.Update(doingPostTextBox.Text);
                    doingPostTextBox.Text = string.Empty;
                    UpdateTwitterListView(twitterAccount);
                }
            }
            catch (WebException ex)
            {
                if (ex.Status == WebExceptionStatus.ProtocolError)
                {
                    MessageBox.Show("ステータスをアップデートできませんでした。Twitterのユーザー名とパスワードが間違っている可能性があります。");
                }
                else if (ex.Status == WebExceptionStatus.Timeout)
                {
                    MessageBox.Show("ステータスをアップデートできませんでした。接続がタイムアウトしました。", "警告");
                }
                else
                {
                    MessageBox.Show("ステータスをアップデートできませんでした。", "警告");
                }
            }
            catch (UriFormatException)
            {
                MessageBox.Show("ステータスをアップデートできませんでした。ステータスが長すぎる可能性があります。", "警告");
            }
            finally
            {
                #region  UI後処理

                // フォームを選択可能に回復する
                menuMenuItem.Enabled    = true;
                updateMenuItem.Enabled  = true;
                twitterListView.Enabled = true;
                updateButton.Enabled    = true;

                #endregion

                // 排他処理のためのフラグを下げる
                checkTwitterUpdateNowFlag = false;
            }
        }