Ejemplo n.º 1
0
        public ContactUsPage(SurfaceWindow1 window, String name)
        {
            sw1 = window;
            InitializeComponent();

            /* As the user goes through the pages, the next page slides into focus from the right.
             * The current page slides to the left and disappears. Vice versa, as the user goes
             * back, the previous page slides into focus from the left and the current page slides
             * to the right and disappears.
             */
            if (name == "testNE")
            {
                sw1.hideP = (window.Resources["SlidePageLeftExit"] as Storyboard).Clone();
                sw1.showP = (window.Resources["SlidePageLeftEntry"] as Storyboard).Clone();
            }
            else
            {
                sw1.hideP = (window.Resources["SlidePageRightExit"] as Storyboard).Clone();
                sw1.showP = (window.Resources["SlidePageRightEntry"] as Storyboard).Clone();
            }

            //Reading in tweets form the XML file
            XDocument doc = XDocument.Load("Resources/xml/Tweets.xml");
            var tweetmes = doc.Element("Tweets").Elements("Tweet");

            ObservableCollection<TweetModel> result = new ObservableCollection<TweetModel>();
            foreach (XElement message in tweetmes)
            {
                TweetModel tweet = new TweetModel()
                {
                    Text = message.Attribute("Text").Value,

                    ScreenName = message.Attribute("ScreenName").Value,
                    UserName = "******" + message.Attribute("UserName").Value,
                    PublicationDate = message.Attribute("PublicationDate").Value,
                    Image = message.Attribute("Image").Value
                };

                result.Add(tweet);
            }

            //Changing the data context to update the tweetlist
            this.Tweets = result;
            this.tweetsListView.DataContext = this;
            this.DataContext = this;

            //UserTweetsWidget = new UserTweetsViewModel("ChildCancerNZ", 20);
            //this.DataContext = this;
        }
Ejemplo n.º 2
0
        //Method is responsible for comminucating with the Twitter REST v1.1 API and gather tweets
        private void GetTwitterUserTimeLine(string userName, int count)
        {
            try
            {
                ObservableCollection<TweetModel> result = new ObservableCollection<TweetModel>();

                //Packaging Authentication details
                var auth = new SingleUserAuthorizer
                {
                    Credentials = new SingleUserInMemoryCredentials
                    {
                        ConsumerKey = consumerKey,
                        ConsumerSecret = consumerSecret,
                        TwitterAccessToken = twitterAccessToken,
                        TwitterAccessTokenSecret = twitterAccessTokenSecret
                    }
                };

                auth.Authorize();

                //Creating a session
                TwitterContext twitterCtx = new TwitterContext(auth);

                //Retreiving tweets
                var tweets = twitterCtx.Status.Where(tweet => tweet.ScreenName == userName && tweet.Type == StatusType.User).Take(count).ToList();

                //Loading tweets into the tweet model.
                foreach (var item in tweets)
                {
                    TweetModel tweet = new TweetModel()
                    {
                        Text = item.Text,

                        ScreenName = item.User.Name,
                        UserName = "******" + item.ScreenName,
                        PublicationDate = GetElapsedPeriod(item.CreatedAt),
                        Image = item.User.ProfileImageUrl

                    };
                    result.Add(tweet);

                }

                //Writing all the tweets into an XML file for offline use.
                XmlWriterSettings settings = new XmlWriterSettings();
                settings.Indent = true;
                using (XmlWriter writer = XmlWriter.Create(@"Resources/xml/Tweets.xml", settings))
                {
                    writer.WriteStartDocument();

                    writer.WriteComment("This file is generated by the program.");
                    writer.WriteStartElement("Tweets");
                    foreach (var item in tweets)
                    {
                        writer.WriteStartElement("Tweet");
                        writer.WriteAttributeString("Text", item.Text);
                        writer.WriteAttributeString("ScreenName", item.User.Name);
                        writer.WriteAttributeString("UserName", "@" + item.ScreenName);
                        writer.WriteAttributeString("PublicationDate", GetElapsedPeriod(item.CreatedAt));
                        writer.WriteAttributeString("Image", item.User.ProfileImageUrl);
                        writer.WriteEndElement();
                    }
                    writer.WriteEndElement();
                    writer.WriteEndDocument();
                    writer.Flush();
                    writer.Close();
                }
            }
            catch(LinqToTwitter.TwitterQueryException e)
            {

            }
            //return result;
        }