Represents the result of the uploaded media.
Inheritance: CoreBase
        /* ----------------------------------- */
        /* ツイート送信 */
        private void sendTweet_Click(object sender, RoutedEventArgs e)
        {
            if(string.IsNullOrEmpty(tweetText))
            {
                MessageBox.Show("文字を入力してください");
                return;
            }

            if (imageTrue_False == true)
            {
                if (imageCount == 1)
                    tokens.Statuses.Update(status => tweetText, media_ids => image0);
                else if (imageCount == 2)
                    tokens.Statuses.Update(status => tweetText, media_ids => new long[] { image0.MediaId, image1.MediaId });
                else if (imageCount == 3)
                    tokens.Statuses.Update(status => tweetText, media_ids => new long[] { image0.MediaId, image1.MediaId, image2.MediaId });
                else if (imageCount >= 4)
                    tokens.Statuses.Update(status => tweetText, media_ids => new long[] { image0.MediaId, image1.MediaId, image2.MediaId, image3.MediaId });
            }
            else
                tokens.Statuses.Update(status => tweetText);
            imageTrue_False = false;
            /* 初期化ごり押し */
            image0 = new MediaUploadResult();
            image1 = new MediaUploadResult();
            image2 = new MediaUploadResult();
            image3 = new MediaUploadResult();
            tweet.Clear();
        }
Ejemplo n.º 2
0
        private void button_Tweet_Click(object sender, RoutedEventArgs e)
        {
            string tweetString = this.textBox_Confi.Text;
            Tokens tokens = new Tokens();

            //トークンが取得できていなかったら新規取得
            if (String.IsNullOrWhiteSpace(Properties.Settings.Default.AccessToken))
            {
                var session = OAuth.Authorize(ck, cks);
                var url = session.AuthorizeUri;
                Process.Start(url.AbsoluteUri);

                GetTwitterPin window = new GetTwitterPin();
                window.ShowDialog();

                string pin = (string)dataBanker["PIN"];
                tokens = session.GetTokens(pin);

                Properties.Settings.Default.AccessToken = tokens.AccessToken;
                Properties.Settings.Default.AccessTokenSecret = tokens.AccessTokenSecret;
                Properties.Settings.Default.Save();
            }
            else
            {
                tokens = Tokens.Create(ck, cks,
                        Properties.Settings.Default.AccessToken,
                        Properties.Settings.Default.AccessTokenSecret);
            }

            string filename = "tweet.png";
            MediaUploadResult result = new MediaUploadResult();

            //画像ツイート機能
            if (Properties.Settings.Default.checkBox_IsTweetImage)
            {
                //画像の投稿
                result = tokens.Media.Upload(media => new FileInfo(filename));
            }

            //文字数オーバー
            if (Properties.Settings.Default.checkBox_IsTweetOver)
            {
                switch (Properties.Settings.Default.checkBox_IsTweetImage)
                {
                    case true:
                        if (tweetString.Length >= 110)
                        {
                            tweetString = tweetString.Substring(0, 110);
                        }
                        tokens.Statuses.Update(status => tweetString + "...", media_ids => new long[] { result.MediaId });
                        break;

                    case false:
                        if (tweetString.Length >= 135)
                        {
                            tweetString = tweetString.Substring(0, 135);
                        }
                        tokens.Statuses.Update(new { status = tweetString + "..." });
                        break;
                }
            }
            else
            {
                if (tweetString.Length >= 140)
                {
                    MessageBox.Show(String.Format("文字数がオーバーしました。 ({0})", tweetString.Length), "エラー",
                    MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
                else
                {
                    tokens.Statuses.Update(new { status = tweetString });
                }
            }

            MessageBox.Show("Tweetしました。\n" + tweetString, "情報", MessageBoxButton.OK, MessageBoxImage.Information);
            tweetString = "";
            this.Close();
        }
 /* 画像選択ダイアログの召喚 */
 private void imageCollect_Click(object sender, RoutedEventArgs e)
 {
     OpenFileDialog dialog = new OpenFileDialog();
     dialog.FileName = "";
     dialog.DefaultExt = "*.jpg, *.jpeg, *.png, *.gif";
     if (dialog.ShowDialog() == true)
     {
         if (imageCount == 0)
             image0 = tokens.Media.Upload(media => new FileInfo(dialog.FileName));
         else if (imageCount == 1)
             image1 = tokens.Media.Upload(media => new FileInfo(dialog.FileName));
         else if (imageCount == 2)
             image2 = tokens.Media.Upload(media => new FileInfo(dialog.FileName));
         else if (imageCount >= 3)
             image3 = tokens.Media.Upload(media => new FileInfo(dialog.FileName));
         imageTrue_False = true;
         imageCount++;
     }
 }