Пример #1
0
        private async void btnTweet_Click(object sender, EventArgs e)
        {
            if (Message.Tag == null)
            {
                MessageBox.Show("Text is required!", "Ouch!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            List <string> media_ids = null;

            // images
            if (UploadedImages.Controls.Count > 0)
            {
                media_ids = new List <string>();

                foreach (PictureBox image in UploadedImages.Controls)
                {
                    media_ids.Add(image.Tag.ToString());
                }
            }

            SetEnabledStatus(false);
            SetStatus("Sending tweet...", Properties.Resources.loader2);

            var result = await TwitterApi.SendTweet(Message.Text, media_ids);

            if (result.IsSuccessfully)
            {
                var tweet = new Tweet(result);
                Tweets.Controls.Add(tweet);
                Tweets.ScrollControlIntoView(tweet);
                Message.Text = null;
                Message_Leave(Message, null);
                UploadedImages.Controls.Clear();

                SetEnabledStatus(true);
                SetStatus("Tweet successfully published!", Properties.Resources.success);
            }
            else
            {
                ErrorResult(result);
            }
        }
Пример #2
0
        private async void GetTweets()
        {
            SetEnabledStatus(false);
            SetStatus("Loading tweets...");

            var result = await TwitterApi.GetTweets(LastTweetId);

            if (result.IsSuccessfully)
            {
                SetEnabledStatus(true);
                SetStatus("Tweets successfully received!", Properties.Resources.success);

                Tweet first = null;

                for (int i = 0; i <= result.Count - 1; i++)
                {
                    if (i == 0 && !String.IsNullOrEmpty(LastTweetId))
                    {
                        continue;
                    }

                    var tweet = new Tweet(result[i]);

                    Tweets.Controls.Add(tweet);
                    Tweets.Controls.SetChildIndex(tweet, 0);

                    LastTweetId = result[i]["id_str"].ToString();

                    if (first == null)
                    {
                        first = tweet;
                    }
                }

                Tweets.ScrollControlIntoView(first);
            }
            else
            {
                ErrorResult(result);
            }
        }