Пример #1
0
        private void OlderPostsUpTo(long currentID, long maxID)
        {
            MyWebClient getUserMessages = new MyWebClient();

            getUserMessages.OAuthHelper      = OAuthHelper;
            getUserMessages.DoPostCompleted += (sender, e) =>
            {
                if (e.Error != null)
                {
                    SendErrorMessage(e.Error.Message);
                }
                else
                {
                    int             currentCount = fetchList.Count;
                    XElement        element      = XElement.Parse(e.Response);
                    TwitterTimeline timeline     = new TwitterTimeline(element);
                    //var newmessages = AddNewMessages(timeline).ToList();
                    fetchList.AddRange(timeline);                    //newmessages);
                    fetchList = fetchList.Distinct(new CompareTwitters()).ToList();
                    //foreach (var mess in newmessages)
                    //{
                    //    _timelineMessages.Add(mess);
                    //}



                    if (fetchList.Count > currentCount)
                    {
                        if (fetchList.Min(m => m.ActualId) > currentID)
                        {
                            SendLoadingMessage("Loaded " + timeline.Count.ToString() + "... Still loading");
                            long newMaxId = fetchList.Min(m => m.ActualId);
                            OlderPostsUpTo(currentID, newMaxId);
                            return;
                        }
                    }

                    _timelineMessages.Clear();
                    foreach (var mess in fetchList.OrderBy(m => m.ActualId))
                    {
                        _timelineMessages.Add(mess);
                    }
                    SendLoadedMessage("Finished Loading timeline");
                    FirePropertyChanged("Messages");
                    CurrentMessage = Messages.FirstOrDefault(m => m.ActualId == currentID);
                }
            };
            if (maxID == 0)
            {
                getUserMessages.AddParameters(Params("count", "200", "include_entities", "true"));
                //uri = "http://api.twitter.com/1/statuses/home_timeline.xml?count=200";
            }
            else
            {
                getUserMessages.AddParameters(Params("count", "200", "max_id", maxID.ToString()));
                //uri = "http://api.twitter.com/1/statuses/home_timeline.xml?count=200&max_id=" + maxID.ToString();
            }
            getUserMessages.DoGetAsync(new Uri("http://api.twitter.com/1/statuses/home_timeline.xml", UriKind.Absolute));
        }
Пример #2
0
        private void OlderPosts(object sender, RoutedEventArgs e)
        {
            MessageViewModel.LoadingMessage = "Loading older posts";
            var earliestID = 0L;

            if (messages.Count == 0)
            {
                return;
            }

            earliestID = messages.Min(m => m.TwitterMessage.ActualId);

            //TwitterClient twitter = new TwitterClient();
            WebRequest.RegisterPrefix("http://", WebRequestCreator.ClientHttp);
            WebClient twitter = new WebClient();

            twitter.DownloadStringCompleted += (o, a) =>
            {
                if (a.Error == null)
                {
                    XElement        element     = XElement.Parse(a.Result);
                    TwitterTimeline timeline    = new TwitterTimeline(element);
                    var             newmessages = (from newm in timeline
                                                   join old in messages on newm.ActualId equals old.TwitterMessage.ActualId
                                                   into joined
                                                   from leftjoin in joined.DefaultIfEmpty()
                                                   where leftjoin == null
                                                   orderby newm.ActualId descending
                                                   select newm).ToList();
                    MessageViewModel.LoadedMessage = string.Format("Loaded {0} new messages", newmessages.Count);
                    foreach (var mess in newmessages)
                    {
                        messages.Insert(0, new AnimatableMessage
                        {
                            TwitterMessage = mess,
                            X = rnd.NextDouble() * 1200 - 600,
                            Y = rnd.NextDouble() * 1200 - 600
                        });
                    }
                    int depth = -300;
                    foreach (var tmess in messages)
                    {
                        tmess.Z = depth;
                        depth  -= 1000;
                    }
                    items.ItemsSource = messages;
                }
                else
                {
                    MessageViewModel.ErrorMessage = "Error while fetching timeline";
                }
            };
            string url = "http://api.twitter.com/1/statuses/home_timeline.xml?count=200&max_id=" + earliestID.ToString();

            twitter.DownloadStringAsync(new Uri(url, UriKind.Absolute));
        }
Пример #3
0
        private void FetchTestPosts(object sender, RoutedEventArgs e)
        {
            WebRequest.RegisterPrefix("http://", WebRequestCreator.ClientHttp);
            var currentID = 12345L;

            if (IsolatedStorageSettings.ApplicationSettings.Contains("CurrentMessage"))
            {
                currentID = (Int64)IsolatedStorageSettings.ApplicationSettings["CurrentMessage"];
            }
            WebClient client = new WebClient();

            //client.Credentials = new NetworkCredential("jimlynn", "xxxxxxxxxxxxxxxx");
            client.DownloadStringCompleted += (o, a) =>
            {
                if (a.Error == null)
                {
                    //messages.Clear();
                    XElement        element  = XElement.Parse(a.Result);
                    TwitterTimeline timeline = new TwitterTimeline(element);
                    double          depth    = -300;
                    if (messages.Count > 0)
                    {
                        depth = messages.OrderBy(m => m.Z).First().Z - 1000;
                    }
                    var cut = timeline.Take(4);
                    foreach (var mess in cut)
                    {
                        messages.Add(new AnimatableMessage
                        {
                            TwitterMessage = mess,
                            X = rnd.NextDouble() * 1200 - 600,
                            Y = rnd.NextDouble() * 1200 - 600,
                            Z = depth
                        });
                        depth -= 1000;
                    }
                    items.ItemsSource = messages;

                    var curmess = messages.FirstOrDefault(m => m.TwitterMessage.Id == currentID);
                    if (curmess != null)
                    {
                        currentIndex = messages.IndexOf(curmess);
                        //MoveToItem(currentIndex);
                    }
                }
                else
                {
                }
            };
            //client.DownloadStringAsync(new Uri("home_timeline.xml", UriKind.Relative));
            client.DownloadStringAsync(new Uri("http://api.twitter.com/1/statuses/home_timeline.xml?since_id=" + currentID.ToString(), UriKind.Absolute));
        }
Пример #4
0
 private void NewerPosts(object sender, RoutedEventArgs e)
 {
     MessageViewModel.LoadingMessage = "Loading newer posts";
     if (messages.Count > 0)
     {
         var       currentMax = messages.Max(m => m.TwitterMessage.ActualId);
         WebClient client     = new WebClient();
         client.DownloadStringCompleted += (o, a) =>
         {
             if (a.Error != null)
             {
                 MessageViewModel.ErrorMessage = "Error fetching new messages";
             }
             else
             {
                 XElement element  = XElement.Parse(a.Result);
                 var      timeline = new TwitterTimeline(element);
                 double   depth    = -300;
                 if (messages.Count > 0)
                 {
                     depth = messages.OrderBy(m => m.Z).First().Z - 1000;
                 }
                 var newmessages = (from newm in timeline
                                    join old in messages on newm.ActualId equals old.TwitterMessage.ActualId
                                    into joined
                                    from leftjoin in joined.DefaultIfEmpty()
                                    where leftjoin == null
                                    orderby newm.ActualId
                                    select newm).ToList();
                 MessageViewModel.LoadedMessage = string.Format("Loaded {0} messages", newmessages.Count);
                 foreach (var mess in newmessages)
                 {
                     messages.Add(new AnimatableMessage
                     {
                         TwitterMessage = mess,
                         X = rnd.NextDouble() * 1200 - 600,
                         Y = rnd.NextDouble() * 1200 - 600,
                         Z = depth
                     });
                     depth -= 1000;
                 }
                 items.ItemsSource = messages;
             }
         };
         string url = "http://api.twitter.com/1/statuses/home_timeline.xml?count=200&since_id=" + currentMax.ToString();
         client.DownloadStringAsync(new Uri(url, UriKind.Absolute));
     }
 }
Пример #5
0
        private void GetTimeline_Click(object sender, RoutedEventArgs e)
        {
            animatemessages = new ObservableCollection <AnimatableMessage>();
            mainBoard.Stop();
            mainBoard.Children.Clear();
            var currentID = 12345L;

            if (IsolatedStorageSettings.ApplicationSettings.Contains("CurrentMessage"))
            {
                currentID = (Int64)IsolatedStorageSettings.ApplicationSettings["CurrentMessage"];
            }
            TwitterClient twitter = new TwitterClient();

            twitter.GetTimelineSinceCompleted += (o, a) =>
            {
                if (a.Error == null)
                {
                    XElement        element  = XElement.Parse(a.Result);
                    TwitterTimeline timeline = new TwitterTimeline(element);
                    int             zorder   = timeline.Count;
                    foreach (var tmess in timeline)
                    {
                        var mess = new AnimatableMessage {
                            TwitterMessage = tmess
                        };
                        animatemessages.Insert(0, mess);
                        //animatemessages.Add(mess);
                    }
                    listbox.ItemsSource = null;
                    listbox.ItemsSource = animatemessages;

                    frontmost = animatemessages.Count - 1;
                    //CompositionTarget.Rendering += new EventHandler(CompositionTarget_Rendering);
                    BuildStoryboards(animatemessages);
                    currentItem = animatemessages.Count - 1;
                    var curmess = animatemessages.FirstOrDefault(m => m.TwitterMessage.Id == currentID);
                    if (curmess != null)
                    {
                        currentItem = animatemessages.IndexOf(curmess);
                    }
                    MoveToMessage(currentItem);
                }
            };
            twitter.GetTimelineSinceAsync(12345L);
        }
Пример #6
0
        private void GetTimelineSince(Int64 sinceID, Action <List <AnimatableMessage> > handler)
        {
            TwitterClient client = new TwitterClient();

            client.GetTimelineSinceCompleted += (o, a) =>
            {
                if (a.Error == null)
                {
                    XElement                 element  = XElement.Parse(a.Result);
                    TwitterTimeline          timeline = new TwitterTimeline(element);
                    List <AnimatableMessage> list     = new List <AnimatableMessage>();
                    var x = from m in timeline
                            select new AnimatableMessage {
                        TwitterMessage = m
                    };
                    handler(x.ToList());
                }
            };
            client.GetTimelineSinceAsync(sinceID);
        }
Пример #7
0
        protected void FetchTimeline(string Uri, IEnumerable <KeyValuePair <string, string> > parameters, string error, bool ShowFirst = false)
        {
            SendLoadingMessage("Fetching messages");
            MyWebClient getUserMessages = new MyWebClient();

            getUserMessages.OAuthHelper = OAuthHelper;
            getUserMessages.AddParameters(parameters);
            bool showfirst = ShowFirst;

            getUserMessages.DoPostCompleted += (sender, e) =>
            {
                if (e.Error != null)
                {
                    SendErrorMessage(error);
                }
                else
                {
                    XElement        element  = XElement.Parse(e.Response);
                    TwitterTimeline timeline = new TwitterTimeline(element);
                    var             added    = AddNewMessages(timeline).ToList();
                    foreach (var mess in added)
                    {
                        _timelineMessages.Add(mess);
                    }
                    if (added.Count > 0)
                    {
                        if (showfirst)
                        {
                            CurrentMessage = added.FirstOrDefault();
                        }
                        SendLoadedMessage(added.Count.ToString() + " Messages loaded");
                    }
                    else
                    {
                        SendLoadedMessage("No messages loaded");
                    }
                }
            };

            getUserMessages.DoGetAsync(new Uri(Uri, UriKind.Absolute));
        }
Пример #8
0
        private void OlderPostsUpTo(long oldestId, List <TwitterMessage> alreadyLoaded)
        {
            MessageViewModel.LoadingMessage = "Loading older posts";
            //TwitterClient twitter = new TwitterClient();
            WebRequest.RegisterPrefix("http://", WebRequestCreator.ClientHttp);
            WebClient twitter = new WebClient();

            twitter.DownloadStringCompleted += (o, a) =>
            {
                if (a.Error == null)
                {
                    XElement        element     = XElement.Parse(a.Result);
                    TwitterTimeline timeline    = new TwitterTimeline(element);
                    var             newmessages = (from newm in timeline
                                                   join old in alreadyLoaded on newm.ActualId equals old.ActualId
                                                   into joined
                                                   from leftjoin in joined.DefaultIfEmpty()
                                                   where leftjoin == null
                                                   orderby newm.ActualId descending
                                                   select newm).ToList();
                    alreadyLoaded.AddRange(newmessages);

                    if (alreadyLoaded.Min(m => m.ActualId) <= oldestId || newmessages.Count == 0)
                    {
                        MessageViewModel.LoadedMessage = string.Format("Loaded {0} new messages", alreadyLoaded.Count);
                        foreach (var mess in alreadyLoaded)
                        {
                            messages.Insert(0, new AnimatableMessage
                            {
                                TwitterMessage = mess,
                                X = rnd.NextDouble() * 1200 - 600,
                                Y = rnd.NextDouble() * 1200 - 600
                            });
                        }
                        int depth = -300;
                        foreach (var tmess in messages)
                        {
                            tmess.Z = depth;
                            depth  -= 1000;
                        }
                        var targetMessage = messages.FirstOrDefault(m => m.TwitterMessage.ActualId == oldestId);
                        if (targetMessage != null)
                        {
                            currentIndex = messages.IndexOf(targetMessage);
                        }
                        else
                        {
                            currentIndex = 0;
                        }
                        items.ItemsSource  = messages;
                        items.SelectedItem = targetMessage;
                    }
                    else
                    {
                        MessageViewModel.LoadingMessage = string.Format("Loaded {0} new messages, fetching more", alreadyLoaded.Count);
                        OlderPostsUpTo(oldestId, alreadyLoaded);
                    }
                }
                else
                {
                    MessageViewModel.ErrorMessage = "Error while fetching timeline";
                }
            };
            string url        = null;
            var    earliestID = 0L;

            if (alreadyLoaded.Count == 0)
            {
                url = "http://api.twitter.com/1/statuses/home_timeline.xml?count=200";
            }
            else
            {
                earliestID = alreadyLoaded.Min(m => m.ActualId);
                url        = "http://api.twitter.com/1/statuses/home_timeline.xml?count=200&max_id=" + earliestID.ToString();
            }
            twitter.DownloadStringAsync(new Uri(url, UriKind.Absolute));
        }
Пример #9
0
        private void FetchPosts(object sender, RoutedEventArgs e)
        {
            messageView.ViewModel.Message = "Fetching posts";
            messageView.ViewModel.State   = "InProgress";
            var currentID = 15315276793L;

            //if (IsolatedStorageSettings.ApplicationSettings.Contains("CurrentMessage"))
            //{
            //    currentID = (Int64)IsolatedStorageSettings.ApplicationSettings["CurrentMessage"];
            //}

            //TwitterClient twitter = new TwitterClient();
            WebRequest.RegisterPrefix("http://", WebRequestCreator.ClientHttp);
            WebClient twitter = new WebClient();

            twitter.DownloadStringCompleted += (o, a) =>
            {
                if (a.Error == null)
                {
                    XElement        element  = XElement.Parse(a.Result);
                    TwitterTimeline timeline = new TwitterTimeline(element);
                    double          depth    = -300;
                    if (messages.Count > 0)
                    {
                        depth = messages.OrderBy(m => m.Z).First().Z - 1000;
                    }
                    var newmessages = (from newm in timeline
                                       join old in messages on newm.ActualId equals old.TwitterMessage.ActualId
                                       into joined
                                       from leftjoin in joined.DefaultIfEmpty()
                                       where leftjoin == null
                                       orderby newm.ActualId
                                       select newm).ToList();
                    messageView.ViewModel.Message = string.Format("Loaded {0} messages", newmessages.Count);
                    foreach (var mess in newmessages)
                    {
                        messages.Add(new AnimatableMessage
                        {
                            TwitterMessage = mess,
                            X = rnd.NextDouble() * 1200 - 600,
                            Y = rnd.NextDouble() * 1200 - 600,
                            Z = depth
                        });
                        depth -= 1000;
                    }
                    items.ItemsSource = messages;
                    var curmess = messages.FirstOrDefault(m => m.TwitterMessage.Id == currentID);
                    if (curmess != null)
                    {
                        currentIndex = messages.IndexOf(curmess);
                        //MoveToItem(currentIndex);
                    }
                }
                else
                {
                    messageView.ViewModel.Message = "Error while fetching timeline";
                }
            };
            string url = "http://api.twitter.com/1/statuses/home_timeline.xml?count=200";

            twitter.DownloadStringAsync(new Uri(url, UriKind.Absolute));
            //twitter.GetTimelineSinceAsync(12345L);
        }