Esempio n. 1
0
        public void Import(string feed)
        {
            Ensure.That(() => feed).IsNotNull();

            FacebookImportLog entry = new FacebookImportLog
            {
                FacebookFeedId = feed,
                StartDate = DateTime.UtcNow
            };
            DateTime? since = logRepository.GetFacebookImportDate(feed);

            FacebookImportOptions options = new FacebookImportOptions
            {
                Feed = feed,
                Log = entry,
                Since = since
            };
            importerService.Import(options);

            entry.Duration = DateTime.UtcNow - entry.StartDate;

            logRepository.UpdateFacebookImportLog(entry);
        }
Esempio n. 2
0
        internal IList<FacebookPost> FetchAll(string url, DateTime? since, FacebookImportLog importLog)
        {
            int queryCount = 0;
            List<FacebookPost> posts = new List<FacebookPost>();
            do
            {
                FacebookPostCollection response = Fetch(url);
                posts.AddRange(response.Data);

                queryCount++;

                if (since.HasValue && response.Data.Any(p => p.UpdatedTime <= since.Value)) // prevent unnecessary over-querying.
                {
                    posts.RemoveAll(p => p.UpdatedTime <= since.Value); // removed already-evaluated posts.
                    break;
                }
                if (response.Paging == null || response.Paging.Next == url) // sanity
                {
                    break;
                }
                url = response.Paging.Next;
            } while (url != null);

            importLog.QueryCount = queryCount;
            importLog.PostCount = posts.Count;
            importLog.PostUpdated = posts.MaxOrDefault(p => (DateTime?)p.UpdatedTime);
            return posts;
        }