Example #1
0
 public Twitter()
     : base()
 {
     DroneDataSource    = new TwitterDataSource();
     DroneDataComponent = new TwitterDataComponent();
     Context            = new TwitterContext {
         Status = "waiting", TimeOfStatus = DateTime.Now, DurationPreviousStatus = TimeSpan.FromSeconds(0)
     };
 }
Example #2
0
        /// <summary>
        /// Populates the page with content passed during navigation.  Any saved state is also
        /// provided when recreating a page from a prior session.
        /// </summary>
        /// <param name="sender">
        /// The source of the event; typically <see cref="NavigationHelper"/>
        /// </param>
        /// <param name="e">Event data that provides both the navigation parameter passed to
        /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested and
        /// a dictionary of state preserved by this page during an earlier
        /// session.  The state will be null the first time a page is visited.</param>
        async void navigationHelper_LoadState(object sender, LoadStateEventArgs e)
        {
            if (SharedState.Authorizer == null)
            {
                var auth = new WindowsStoreAuthorizer
                {
                    CredentialStore = new InMemoryCredentialStore
                    {
                        ConsumerKey    = "",
                        ConsumerSecret = ""
                    },
                    Callback = "http://linqtotwitter.codeplex.com/"
                };

                await auth.AuthorizeAsync();

                SharedState.Authorizer = auth;
            }

            var twitterDataGroups = await TwitterDataSource.GetGroupsAsync();

            this.DefaultViewModel["Groups"] = twitterDataGroups;
        }
Example #3
0
        /// <summary>
        /// Get all tweets with "GoDaddy" in them.
        /// 100 per page, up to 15 pages if we loop and make seperate calls for each page
        /// </summary>
        internal Dictionary <int, List <Status> > GetAllMentionsByQuery(TwitterContext cont)
        {
            Dictionary <int, List <Status> > allTwitterMentions = new Dictionary <int, List <Status> >();

            if (XMLUtility.IsComponentEnabled(Xml, ProcessorName))
            {
                int countPerPage; int pageCount;
                TwitterDataSource data = new TwitterDataSource();
                TweetManager      tm   = new TweetManager();

                XMLUtility.GetPageResultCounts(Xml, ProcessorName, out countPerPage, out pageCount, 100, 3);
                List <Keyword> queries    = data.GetTweetQueries();
                bool           useSinceId = XMLUtility.UseSinceId(Xml, ProcessorName);

                //create backup of current keys in case of failure at db level
                lock (cont) cont.prevRunLatestTweetIDs = cont.LatestTweetIDs.ToDictionary(entry => entry.Key, entry => entry.Value);

                foreach (Keyword item in queries)
                {
                    try
                    {
                        long sinceId = 0;
                        if (useSinceId)
                        {
                            //get the last recorded id for this query and use it
                            if (!Object.Equals(cont, null))
                            {
                                lock (cont)
                                {
                                    if (cont.LatestTweetIDs.ContainsKey(item.KeywordId))
                                    {
                                        cont.LatestTweetIDs.TryGetValue(item.KeywordId, out sinceId);
                                    }
                                }
                            }
                        }

                        //call the mention object in the API wrapper
                        TwitterDataComponent _dataComponent = DroneDataComponent as TwitterDataComponent;
                        KeywordStatus        ks             = new KeywordStatus();
                        ks.KeywordId = item.KeywordId;

                        ks.StatusList = tm.GetTweetsByQuery(countPerPage, item.KeywordValue + (sinceId > 0 ? "&since_id=" + sinceId : string.Empty), Utility.GetOAuthToken(Xml));
                        allTwitterMentions.Add(ks.KeywordId, ks.StatusList);

                        _dataComponent.KeywordStatus = ks;
                        DroneDataSource.Process(_dataComponent);

                        //if there was a failure saving to the db, reset the since id to gather and try again
                        if (_dataComponent.SaveFailure)
                        {
                            lock (cont) cont.LatestTweetIDs = cont.prevRunLatestTweetIDs.ToDictionary(entry => entry.Key, entry => entry.Value);
                        }

                        //get the last id for this query and store it
                        if (!Object.Equals(cont, null) && allTwitterMentions.ContainsKey(item.KeywordId) && allTwitterMentions[item.KeywordId].Count > 0)
                        {
                            long latestID;
                            long.TryParse(allTwitterMentions[item.KeywordId][0].id.ToString(), out latestID);

                            lock (cont)
                            {
                                if (cont.LatestTweetIDs.ContainsKey(item.KeywordId))
                                {
                                    cont.LatestTweetIDs[item.KeywordId] = latestID;
                                }
                                else
                                {
                                    cont.LatestTweetIDs.Add(item.KeywordId, latestID);
                                }
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        ExceptionExtensions.LogError(e, "Twitter.GetAllMentionsByQuery()", "Keyword name: " + item.KeywordName);
                    }
                }
            }
            return(allTwitterMentions);
        }
Example #4
0
 public QueueTwitter()
     : base()
 {
     QueueComponentDataSource = new TwitterDataSource();
 }