Ejemplo n.º 1
0
        public IList<FacebookPost> GetPostsInFeed(FacebookImportOptions opts)
        {
            Ensure.That(() => opts).IsNotNull();

            DateTime? since = opts.Since;
            string url = GRAPH_FEED_LIMITED.FormatWith(opts.Feed, PAGE_LIMIT);

            if (since.HasValue)
            {
                string date = since.Value.ToIso8601();
                url = GRAPH_FEED_SINCE.FormatWith(url, date);
            }

            IList<FacebookPost> result = FetchAll(url, since, opts.Log);
            return result;
        }
        /// <summary>
        /// Imports a list of posts from Facebook, filters them and inserts into the persistance storage.
        /// </summary>
        public void Import(FacebookImportOptions opts)
        {
            int insertCount = 0;
            const string LINK_EXISTS = "Link exists: {0}";
            const string LINK_INSERTION = "Inserted Link #{0}";
            const string POST_INSERTION = "Inserted Post #{0}";

            IEnumerable<FacebookPost> posts = fbRepository.GetPostsInFeed(opts);

            foreach (FacebookPost fbPost in posts)
            {
                if (fbPost.Link == null || fbPost.Type != FacebookPostType.Link) // only links.
                {
                    continue;
                }
                Link link = linkRepository.GetByReferenceUri(fbPost.Link);
                if (link != null)
                {
                    log.Debug(LINK_EXISTS.FormatWith(link.ReferenceUri));
                    if (link.PostId.HasValue) // if link exists and it has a related post, ignore it.
                    {
                        continue;
                    }
                }
                else
                {
                    link = mapper.Map<FacebookPost, Link>(fbPost);
                    linkRepository.Insert(link);
                    log.Debug(LINK_INSERTION.FormatWith(link.Id));
                }
                Post post = mapper.Map<FacebookPost, Post>(fbPost);
                User user = userRepository.GetByFacebookGraphId(post.FacebookUserId);

                post.LinkId = link.Id;
                post.UserId = user == null ? (long?)null : user.Id;
                postRepository.Insert(post);
                log.Debug(POST_INSERTION.FormatWith(post.Id));

                insertCount++;
            }

            opts.Log.InsertCount = insertCount;
        }
Ejemplo n.º 3
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);
        }