Exemple #1
0
        private void SendAutomatedTweet()
        {
            string nextLocation = upcomingLocations.Items[0].ToString();

            upcomingLocations.Items.RemoveAt(0);

            SendTweet(nextLocation);

            upcomingLocations.Items.Add(RandomPlaces.GetRandomLocation());
        }
Exemple #2
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            ResetTimeRemaining();

            dispatcherTimer.Tick    += new EventHandler(dispatcherTimer_Tick);
            dispatcherTimer.Interval = TimerInterval;

            for (int i = 0; i < 10; i++)
            {
                upcomingLocations.Items.Add(RandomPlaces.GetRandomLocation());
            }

            dispatcherTimer.Start();
        }
Exemple #3
0
        private void SendTweet(string location)
        {
            //Grab an Image
            ImageData imageToPost = null;
            var       client      = new HttpClient();

            client.BaseAddress = new Uri(_bigMarbleUrl);
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            HttpResponseMessage response = client.GetAsync("api/image/?address=" + Uri.EscapeDataString(location)).Result;

            if (response.IsSuccessStatusCode)
            {
                var images = response.Content.ReadAsAsync <IEnumerable <ImageData> >().Result;

                ImageData[] imageArray = images.ToArray();
                Random      newRandom  = new Random();
                int         imageID    = newRandom.Next(imageArray.Count());

                imageToPost = imageArray[imageID];
            }

            //found an image
            if (imageToPost != null)
            {
                string tweetText = string.Format(RandomPlaces.GetRandomMessage(), location);
                tweetText += " " + imageToPost.Lowresurl;

                TwitterService service = new TwitterService(ConsumerKey, ConsumerSecret);
                service.AuthenticateWith(AccessToken, AccessTokenSecret);

                try
                {
                    TwitterStatus status = service.SendTweet(new SendTweetOptions
                    {
                        Status             = tweetText,
                        Lat                = imageToPost.Latitude,
                        Long               = imageToPost.Longitude,
                        DisplayCoordinates = true
                    });

                    tweetHistory.Items.Add(string.Format("{0} {1}: {2}", DateTime.Now.ToShortDateString(), DateTime.Now.ToLongTimeString(), status.Text));
                }
                catch (Exception ex)
                {
                    tweetHistory.Items.Add("Exception:");
                    tweetHistory.Items.Add(ex);
                }
            }
        }