示例#1
0
        private void UpdateStatus(IAsyncResult result)
        {
            HttpWebRequest request = (HttpWebRequest)result.AsyncState;

            try
            {
                HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(result);
                using (StreamReader reader = new StreamReader(response.GetResponseStream()))
                {
                    string   xml     = reader.ReadToEnd();
                    XElement element = XElement.Parse(xml);
                    Dispatcher.BeginInvoke(() =>
                    {
                        TwitterMessage myRetweet = new TwitterMessage(element);
                        tweetmessage.Text        = "Your message was posted";
                        TweetText = "";
                        VisualStateManager.GoToState(this, "Tweeted", true);
                    });
                }
            }
            catch (WebException exc)
            {
                Dispatcher.BeginInvoke(() =>
                {
                    if (ShowMessage != null)
                    {
                        ShowMessage(this, new TweetEventArgs("Failed to send message"));
                    }
                    tweetmessage.Text = "Failed to send message";
                    VisualStateManager.GoToState(this, "Tweeted", true);
                });
            }
        }
示例#2
0
 private void FetchReply(TwitterMessage message, StatusView statusView)
 {
     if (message.InReplyToId > 0)
     {
         TwitterClient client = new TwitterClient();
         client.GetStatusCompleted += (o, e) =>
         {
             if (e.Error == null)
             {
                 TwitterMessage newMessage = new TwitterMessage(XElement.Parse(e.Result));
                 // Create a new
                 var animatee = new AnimatableMessage()
                 {
                     TwitterMessage = newMessage
                 };
                 var timelines     = animatee.GetAnimations();
                 var parentMessage = animatemessages.First(a => a.TwitterMessage == message);
                 int index         = animatemessages.IndexOf(parentMessage);
                 animatemessages.Insert(index, animatee);
                 mainBoard.Stop();
                 foreach (var timeline in timelines)
                 {
                     mainBoard.Children.Add(timeline);
                 }
                 animatee.AnimateTo(parentMessage.X, parentMessage.Y + 300, parentMessage.Z);
                 MoveToMessage(index);
             }
         };
         client.GetStatusAsync(message.InReplyToId);
     }
 }
示例#3
0
 public SampleData()
 {
     TwitterMessage = new TwitterMessage
     {
         Id        = 12345678,
         CreatedAt = DateTime.Now.Subtract(TimeSpan.FromHours(1.5)),
         Text      = "This is a sample message. http://www.bbc.co.uk",
         User      = new TwitterUser
         {
             UserID          = 12345,
             Description     = "A user's description",
             FollowersCount  = 423,
             Name            = "Fredbloggs",
             ScreenName      = "Fred Bloggs",
             ProfileImageUrl = new Uri("http://a1.twimg.com/profile_images/74621100/Picture0002_normal.jpg", UriKind.Absolute)
         },
         RetweetUser = new TwitterUser
         {
             UserID          = 54321,
             Description     = "Someone else",
             FollowersCount  = 423,
             Name            = "Johnsmith",
             ScreenName      = "John Smith",
             ProfileImageUrl = new Uri("http://a1.twimg.com/profile_images/74621100/Picture0002_normal.jpg", UriKind.Absolute)
         },
         IsRetweet = true
     };
 }
示例#4
0
 public SampleData()
 {
     TwitterMessage = new TwitterMessage
     {
         Id = 12345678,
         CreatedAt = DateTime.Now.Subtract(TimeSpan.FromHours(1.5)),
         Text = "This is a sample message. http://www.bbc.co.uk",
         User = new TwitterUser
         {
             UserID = 12345,
             Description = "A user's description",
             FollowersCount = 423,
             Name = "Fredbloggs",
             ScreenName = "Fred Bloggs",
             ProfileImageUrl = new Uri("http://a1.twimg.com/profile_images/74621100/Picture0002_normal.jpg", UriKind.Absolute)
         },
         RetweetUser = new TwitterUser
         {
             UserID = 54321,
             Description = "Someone else",
             FollowersCount = 423,
             Name = "Johnsmith",
             ScreenName = "John Smith",
             ProfileImageUrl = new Uri("http://a1.twimg.com/profile_images/74621100/Picture0002_normal.jpg", UriKind.Absolute)
         },
         IsRetweet = true
     };
 }
示例#5
0
 protected void FetchReply(TwitterMessage twitterMessage)
 {
     if (twitterMessage.InReplyToId > 0)
     {
         SendLoadingMessage("Loading reply");
         MyWebClient client = new MyWebClient();
         client.OAuthHelper = OAuthHelper;
         //TwitterClient client = new TwitterClient();
         client.DoPostCompleted += (o, e) =>
         {
             if (e.Error == null)
             {
                 TwitterMessage newMessage = new TwitterMessage(XElement.Parse(e.Response));
                 // Create a new
                 int index = Messages.IndexOf(twitterMessage);
                 Messages.Insert(index, newMessage);
                 SendLoadedMessage("Reply loaded");
                 CurrentMessage = newMessage;
             }
             else
             {
                 SendErrorMessage("Error Fetching Reply");
             }
         };
         client.DoGetAsync(new Uri(string.Format("http://api.twitter.com/1/statuses/show/{0}.xml", twitterMessage.InReplyToId), UriKind.Absolute));
     }
 }
示例#6
0
 private void NextUserTweet_Click(object sender, RoutedEventArgs e)
 {
     if (StatusViewAction != null)
     {
         TwitterMessage message = (TwitterMessage)(sender as FrameworkElement).DataContext;
         StatusViewAction(this, new StatusClickEventArgs {
             Message = message, Type = ActionType.UserNext
         });
     }
 }
示例#7
0
 private void DisplayImage(string imgUri)
 {
     if (StatusViewAction != null)
     {
         TwitterMessage message = DataContext as TwitterMessage;
         StatusViewAction(this, new StatusClickEventArgs {
             ImageUri = imgUri, Message = message, Type = ActionType.ShowImage
         });
     }
 }
示例#8
0
        private void ReplyToThis_Click(object sender, RoutedEventArgs e)
        {
            TwitterMessage message = (TwitterMessage)(sender as FrameworkElement).DataContext;

            if (StatusViewAction != null)
            {
                StatusViewAction(this, new StatusClickEventArgs {
                    Message = message, Type = ActionType.ReplyToThis
                });
            }
        }
示例#9
0
        private void UndoRetweet_Click(object sender, RoutedEventArgs e)
        {
            VisualStateManager.GoToState(this, "Undoing", true);
            TwitterMessage message = DataContext as TwitterMessage;

            if (message != null && message.IsRetweetByMe)
            {
                string         uri     = "http://api.twitter.com/1/statuses/destroy/" + message.MyRetweetId + ".xml";
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri(uri, UriKind.Absolute));
                request.Method = "POST";
                request.BeginGetResponse(new AsyncCallback(DestroyRetweet), request);
            }
        }
示例#10
0
 void RetweetCompleted(object sender, DoPostCompletedEventArgs e)
 {
     if (e.Error == null)
     {
         string         xml       = e.Response;
         XElement       element   = XElement.Parse(xml);
         TwitterMessage myRetweet = new TwitterMessage(element);
         TwitterMessage message   = DataContext as TwitterMessage;
         if (message != null)
         {
             message.IsRetweetByMe = true;
             message.MyRetweetId   = myRetweet.ActualId;
         }
         VisualStateManager.GoToState(this, "Retweeted", true);
     }
 }
示例#11
0
 internal void Expand()
 {
     if (InReplyToMessage == null && InReplyToId > 0)
     {
         WebClient client = new WebClient();
         client.DownloadStringCompleted += (o, a) =>
         {
             if (a.Error == null)
             {
                 XElement element = XElement.Parse(a.Result);
                 InReplyToMessage = new TwitterMessage(element);
                 Replies.Add(InReplyToMessage);
                 InReplyToMessage.Replies.CollectionChanged += new NotifyCollectionChangedEventHandler(Replies_CollectionChanged);
                 InReplyToMessage.Expand();
             }
         };
         client.DownloadStringAsync(new Uri(string.Format("http://api.twitter.com/1/statuses/show/{0}.xml", InReplyToId), UriKind.Absolute));
     }
 }
示例#12
0
 private void StatusView_Action(object sender, StatusClickEventArgs e)
 {
     if (e.Type == ActionType.ShowReplies)
     {
         TwitterMessage message = e.Message;
         FetchReply(message, (StatusView)sender);
     }
     else if (e.Type == ActionType.UserPrevious)
     {
         var previous = from m in messages
                        where m.TwitterMessage.Id < e.Message.Id && m.TwitterMessage.User.UserID == e.Message.User.UserID
                        orderby m.TwitterMessage.Id descending
                        select m;
         if (previous.Count() > 0)
         {
             var prev = previous.First();
             currentIndex = messages.IndexOf(prev);
             MoveToItem(currentIndex);
         }
     }
     else if (e.Type == ActionType.UserNext)
     {
         var next = from m in messages
                    where m.TwitterMessage.Id > e.Message.Id && m.TwitterMessage.User.UserID == e.Message.User.UserID
                    orderby m.TwitterMessage.Id
                    select m;
         if (next.Count() > 0)
         {
             var nextmess = next.First();
             currentIndex = messages.IndexOf(nextmess);
             MoveToItem(currentIndex);
         }
     }
     else if (e.Type == ActionType.RetweetUsernameClicked)
     {
     }
     else if (e.Type == ActionType.ReplyToThis)
     {
         makeTweet.InReplyTo = e.Message;
         makeTweet.StartReply();
     }
 }
示例#13
0
 private void DoRetweet_Click(object sender, RoutedEventArgs e)
 {
     VisualStateManager.GoToState(this, "Retweeting", true);
     if (AlreadyRetweeted == false)
     {
         AlreadyRetweeted = true;
         TwitterMessage message = DataContext as TwitterMessage;
         if (message != null)
         {
             string      uri    = "http://api.twitter.com/1/statuses/retweet/" + message.Id + ".xml";
             MyWebClient client = new MyWebClient();
             client.OAuthHelper      = new OAuthHelper();
             client.DoPostCompleted += new EventHandler <DoPostCompletedEventArgs>(RetweetCompleted);
             client.DoPostAsync(new Uri(uri, UriKind.Absolute));
             //HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri(uri, UriKind.Absolute));
             //request.Method = "POST";
             //request.BeginGetResponse(new AsyncCallback(RetweetResponse), request);
         }
     }
 }
示例#14
0
 private void DestroyRetweet(IAsyncResult result)
 {
     HttpWebRequest request = result.AsyncState as HttpWebRequest;
     HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(result);
     using (StreamReader reader = new StreamReader(response.GetResponseStream()))
     {
         string xml = reader.ReadToEnd();
         XElement element = XElement.Parse(xml);
         TwitterMessage myRetweet = new TwitterMessage(element);
         Dispatcher.BeginInvoke(() =>
             {
                 TwitterMessage message = DataContext as TwitterMessage;
                 if (message != null)
                 {
                     message.IsRetweetByMe = false;
                     message.MyRetweetId = 0;
                 }
                 VisualStateManager.GoToState(this, "Normal", true);
             });
     }
 }
示例#15
0
 void TweetCompleted(object sender, DoPostCompletedEventArgs e)
 {
     if (e.Error == null)
     {
         string         xml       = e.Response;
         XElement       element   = XElement.Parse(xml);
         TwitterMessage myRetweet = new TwitterMessage(element);
         tweetmessage.Text = "Your message was posted";
         TweetText         = "";
         VisualStateManager.GoToState(this, "Tweeted", true);
     }
     else
     {
         if (ShowMessage != null)
         {
             ShowMessage(this, new TweetEventArgs("Failed to send message"));
         }
         tweetmessage.Text = "Failed to send message";
         VisualStateManager.GoToState(this, "Tweeted", true);
     }
 }
示例#16
0
 private void FetchReply(TwitterMessage message, StatusView statusView)
 {
     MessageViewModel.LoadingMessage = "Fetching previous message";
     if (message.InReplyToId > 0)
     {
         WebClient client = new WebClient();
         //TwitterClient client = new TwitterClient();
         client.DownloadStringCompleted += (o, e) =>
         {
             if (e.Error == null)
             {
                 TwitterMessage newMessage = new TwitterMessage(XElement.Parse(e.Result));
                 // Create a new
                 var animatee = new AnimatableMessage()
                 {
                     TwitterMessage = newMessage
                 };
                 var parentMessage = messages.First(a => a.TwitterMessage == message);
                 int index         = messages.IndexOf(parentMessage);
                 messages.Insert(index, animatee);
                 animatee.X = parentMessage.X;
                 animatee.Y = parentMessage.Y + 300;
                 animatee.Z = parentMessage.Z;
                 MessageViewModel.LoadedMessage = "Reply loaded";
                 //MoveToItem(index);
                 items.SelectedItem = animatee;
                 items.InvalidateMeasure();
             }
             else
             {
                 MessageViewModel.ErrorMessage = "Failed to load reply";
             }
         };
         client.DownloadStringAsync(new Uri(string.Format("http://api.twitter.com/1/statuses/show/{0}.xml", message.InReplyToId), UriKind.Absolute));
         //client.Credentials = new NetworkCredential("jimlynn", "xxxxxxxxxxxxxxxxx");
         //string result = client.DownloadString(string.Format("http://api.twitter.com/1/statuses/show/{0}.xml", statusID));
         //return result;
     }
 }
示例#17
0
        private void DestroyRetweet(IAsyncResult result)
        {
            HttpWebRequest  request  = result.AsyncState as HttpWebRequest;
            HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(result);

            using (StreamReader reader = new StreamReader(response.GetResponseStream()))
            {
                string         xml       = reader.ReadToEnd();
                XElement       element   = XElement.Parse(xml);
                TwitterMessage myRetweet = new TwitterMessage(element);
                Dispatcher.BeginInvoke(() =>
                {
                    TwitterMessage message = DataContext as TwitterMessage;
                    if (message != null)
                    {
                        message.IsRetweetByMe = false;
                        message.MyRetweetId   = 0;
                    }
                    VisualStateManager.GoToState(this, "Normal", true);
                });
            }
        }
示例#18
0
        public virtual void OnKeyPress(KeyEventArgs e)
        {
            if (e.Handled || Messages.Count == 0)
            {
                return;
            }

            int currentIndex = Messages.IndexOf(CurrentMessage);

            if (currentIndex < 0)
            {
                CurrentMessage = Messages.First();
                return;
            }

            switch (e.Key)
            {
            case Key.Up:
            case Key.Left:
                if (currentIndex == 0)
                {
                    return;
                }
                else
                {
                    CurrentMessage = Messages[currentIndex - 1];
                    return;
                }

            case Key.Down:
            case Key.Right:
                if (currentIndex + 1 == Messages.Count)
                {
                    return;
                }
                else
                {
                    CurrentMessage = Messages[currentIndex + 1];
                    return;
                }

            case Key.PageDown:
                currentIndex += 20;
                if (currentIndex >= Messages.Count)
                {
                    currentIndex = Messages.Count - 1;
                }
                CurrentMessage = Messages[currentIndex];
                return;

            case Key.PageUp:
                currentIndex -= 20;
                if (currentIndex < 0)
                {
                    currentIndex = 0;
                }
                CurrentMessage = Messages[currentIndex];
                return;

            case Key.Home:
                currentIndex   = 0;
                CurrentMessage = Messages[currentIndex];
                return;

            case Key.End:
                currentIndex   = Messages.Count - 1;
                CurrentMessage = Messages[currentIndex];
                return;

            default:
                return;
            }
        }
示例#19
0
 private void UpdateStatus(IAsyncResult result)
 {
     HttpWebRequest request = (HttpWebRequest)result.AsyncState;
     try
     {
         HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(result);
         using (StreamReader reader = new StreamReader(response.GetResponseStream()))
         {
             string xml = reader.ReadToEnd();
             XElement element = XElement.Parse(xml);
             Dispatcher.BeginInvoke(() =>
             {
                 TwitterMessage myRetweet = new TwitterMessage(element);
                 tweetmessage.Text = "Your message was posted";
                 TweetText = "";
                 VisualStateManager.GoToState(this, "Tweeted", true);
             });
         }
     }
     catch (WebException exc)
     {
         Dispatcher.BeginInvoke(() =>
             {
                 if (ShowMessage != null)
                 {
                     ShowMessage(this, new TweetEventArgs("Failed to send message"));
                 }
                 tweetmessage.Text = "Failed to send message";
                 VisualStateManager.GoToState(this, "Tweeted", true);
             });
     }
 }
示例#20
0
        void TweetCompleted(object sender, DoPostCompletedEventArgs e)
        {
            if (e.Error == null)
            {
                string xml = e.Response;
                XElement element = XElement.Parse(xml);
                TwitterMessage myRetweet = new TwitterMessage(element);
                tweetmessage.Text = "Your message was posted";
                TweetText = "";
                VisualStateManager.GoToState(this, "Tweeted", true);

            }
            else
            {
                if (ShowMessage != null)
                {
                    ShowMessage(this, new TweetEventArgs("Failed to send message"));
                }
                tweetmessage.Text = "Failed to send message";
                VisualStateManager.GoToState(this, "Tweeted", true);
            }
        }
示例#21
0
        private void StatusView_ShowRepliesClicked(object sender, StatusClickEventArgs e)
        {
            TwitterMessage message = e.Message;

            FetchReply(message, (StatusView)sender);
        }
示例#22
0
 void RetweetCompleted(object sender, DoPostCompletedEventArgs e)
 {
     if (e.Error == null)
     {
         string xml = e.Response;
         XElement element = XElement.Parse(xml);
         TwitterMessage myRetweet = new TwitterMessage(element);
         TwitterMessage message = DataContext as TwitterMessage;
         if (message != null)
         {
             message.IsRetweetByMe = true;
             message.MyRetweetId = myRetweet.ActualId;
         }
         VisualStateManager.GoToState(this, "Retweeted", true);
     }
 }
示例#23
0
        internal void Expand()
        {
            if (InReplyToMessage == null && InReplyToId > 0)
            {
                WebClient client = new WebClient();
                client.DownloadStringCompleted += (o, a) =>
                {
                    if (a.Error == null)
                    {
                        XElement element = XElement.Parse(a.Result);
                        InReplyToMessage = new TwitterMessage(element);
                        Replies.Add(InReplyToMessage);
                        InReplyToMessage.Replies.CollectionChanged += new NotifyCollectionChangedEventHandler(Replies_CollectionChanged);
                        InReplyToMessage.Expand();
                    }
                };
                client.DownloadStringAsync(new Uri(string.Format("http://api.twitter.com/1/statuses/show/{0}.xml", InReplyToId),UriKind.Absolute));

            }
        }
示例#24
0
 private void FetchReply(TwitterMessage message, StatusView statusView)
 {
     if (message.InReplyToId > 0)
     {
         TwitterClient client = new TwitterClient();
         client.GetStatusCompleted += (o, e) =>
         {
             if (e.Error == null)
             {
                 TwitterMessage newMessage = new TwitterMessage(XElement.Parse(e.Result));
                 // Create a new
                 var animatee = new AnimatableMessage() { TwitterMessage = newMessage };
                 var timelines = animatee.GetAnimations();
                 var parentMessage = animatemessages.First(a => a.TwitterMessage == message);
                 int index = animatemessages.IndexOf(parentMessage);
                 animatemessages.Insert(index, animatee);
                 mainBoard.Stop();
                 foreach (var timeline in timelines)
                 {
                     mainBoard.Children.Add(timeline);
                 }
                 animatee.AnimateTo(parentMessage.X, parentMessage.Y + 300, parentMessage.Z);
                 MoveToMessage(index);
             }
         };
         client.GetStatusAsync(message.InReplyToId);
     }
 }
示例#25
0
 public MakeTweetEventArgs(TwitterMessage message)
 {
     Message   = message;
     TweetType = TweetType.Reply;
 }
示例#26
0
 public MakeTweetEventArgs(TwitterMessage message, TweetType type)
 {
     Message   = message;
     TweetType = type;
 }
示例#27
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            TwitterMessage message = (TwitterMessage)(sender as FrameworkElement).DataContext;

            message.Favourite();
        }