Exemple #1
0
        public void TweetWithImage()
        {
            try
            {
                //ステータスリスト
                List <TwitterService> ResponseList = new List <TwitterService>();

                //各アカウントでつぶやく
                foreach (Core.ApplicationSetting.AccountClass account in AccountList)
                {
                    //ファイルのストリームを取得
                    System.IO.Stream stream  = Song.getAlbumArtworkFileStream();
                    TwitterService   service = new TwitterService(Core.Twitter.CONSUMERKEY, Core.Twitter.CONSUMERSECRET);
                    service.AuthenticateWith(account.Token, account.TokenSecret);
                    SendTweetWithMediaOptions opt = new SendTweetWithMediaOptions();
                    opt.Status = Core.Replace.ReplaceText(TweetText, Song); // ツイートする内容
                    //テキストを自動的に削るやつ
                    if (AutoDeleteText == true && opt.Status.Length > 117)
                    {
                        opt.Status  = opt.Status.Remove(114);//...の三文字分含めて削除
                        opt.Status += "...";
                    }
                    //opt.Status = HttpUtility.UrlEncode(opt.Status);
                    opt.Images = new Dictionary <string, System.IO.Stream> {
                        { "image", stream }
                    };
                    //Luaの関数を走らせる
                    try
                    {
                        bool luaRet = (bool)luaFunc.Call(Song, opt, isCustomTweet)[0];
                        if (luaRet == true)
                        {
                            service.SendTweetWithMedia(opt);
                            ResponseList.Add(service);
                        }
                    }
                    catch (Exception ex2)
                    {
                        //Luaが失敗しても死なないようにする
                        Trace.WriteLine("Lua error.");
                        Trace.WriteLine(ex2.ToString());
                        service.SendTweetWithMedia(opt);
                        ResponseList.Add(service);
                    }
                    stream.Close();
                    stream.Dispose();
                }
                //完了イベントを投げる
                onProcessFinished(ResponseList);
            }
            catch (Exception ex)
            {
                Trace.WriteLine("[TwitterPost ERROR]" + ex.ToString());
            }
        }
Exemple #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                //アカウントのリストを作成する
                List <Core.ApplicationSetting.AccountClass> acclist = new List <Core.ApplicationSetting.AccountClass>();
                foreach (ListViewItem listviewitem in AccountList.CheckedItems)
                {
                    Core.ApplicationSetting.AccountClass account = new Core.ApplicationSetting.AccountClass();
                    account.AccountName = listviewitem.Text;
                    account.Token       = listviewitem.SubItems[1].Text;
                    account.TokenSecret = listviewitem.SubItems[2].Text;
                    account.Enabled     = true;
                    acclist.Add(account);
                }

                //バックグラウンドで実行する
                Twitter.TwitterPost twitterpost = new Twitter.TwitterPost();
                twitterpost.isCustomTweet      = true;
                twitterpost.AccountList        = acclist;
                twitterpost.Song               = song;
                twitterpost.TweetText          = textBox1.Text;
                twitterpost.onProcessFinished += twitterpost_onProcessFinished;
                if (EnableAlbumArtTweet.Checked == true && song.getAlbumArtworkFileStream() != null)
                {
                    Thread thread = new Thread(twitterpost.TweetWithImage);
                    thread.IsBackground = true;
                    thread.Start();
                }
                else
                {
                    Thread thread = new Thread(twitterpost.Tweet);
                    thread.IsBackground = true;
                    thread.Start();
                }
                this.Enabled = false;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "エラー", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }