Beispiel #1
0
        public async Task <List <Post> > GetPostsAsync(DateTime?lastSyncDate)
        {
            var importedPosts = new List <Post>();

            foreach (var page in _pagesId)
            {
                var facebookPosts = await _facebookPostCreator.GetRawPosts(page.PageId);

                var defaultTitle = _titleBuilder + await _facebookPostCreator.GetPageName(page.PageId);

                foreach (var fbPost in facebookPosts)
                {
                    var isNew      = DateTime.Parse(fbPost.Created_time) > lastSyncDate;
                    var hasContent = !string.IsNullOrEmpty(fbPost.Message);

                    if (isNew && hasContent)
                    {
                        var parsedPost = ExternalPostMapper.ConvertFacebookPostToPost(fbPost, defaultTitle);

                        var attachments = await _facebookPostCreator.GetPostAttachments(fbPost.Id);

                        if (attachments.FirstOrDefault() != null)
                        {
                            var attachmentTitle = attachments.First().Title;
                            if (!string.IsNullOrEmpty(attachmentTitle) && attachmentTitle.Length < 100)
                            {
                                parsedPost.Title = attachmentTitle;
                            }

                            if (attachments.First().Type == "share")
                            {
                                parsedPost.Content +=
                                    "Link: <a href=\"" + attachments.First().Url + "\" target=\"_blank\">" + attachments.First().Title + "</a>";
                            }
                            parsedPost.PostFiles = await _facebookPostCreator.GetPostImages(attachments.First(), fbPost.Id);
                        }
                        importedPosts.Add(parsedPost);
                    }
                }
            }
            return(importedPosts);
        }
        private async Task <IList <Post> > GetPostsWithImages(DateTime?lastSyncDate, SharePointList list)
        {
            var posts           = new List <Post>();
            var sharePointPosts = await _sharePointPostCreator.GetPosts(list);


            foreach (var spPost in sharePointPosts)
            {
                var isNew      = spPost.Created > lastSyncDate;
                var hasContent = !string.IsNullOrEmpty(spPost.Body) && !string.IsNullOrEmpty(spPost.Title);

                if (isNew && hasContent)
                {
                    var parsedPost = ExternalPostMapper.ConvertSharePointPostToPost(spPost);
                    parsedPost.PostFiles = new List <PostFile>();
                    if (spPost.ImagesInBodyPost.Count != 0)
                    {
                        var getImages = await _sharePointPostCreator.GetPostImages(spPost.ImagesInBodyPost, spPost.Id);

                        AddImages(getImages, parsedPost.PostFiles);
                    }

                    if (spPost.Attachment)
                    {
                        var getImages = await _sharePointPostCreator.GetImages(list, spPost.Id);

                        var getConvertImages = await _sharePointPostCreator.GetPostImages(getImages, spPost.Id);

                        AddImages(getConvertImages, parsedPost.PostFiles);
                    }
                    posts.Add(parsedPost);
                }
            }

            return(posts);
        }
 public void Mapper_ConvertFacebookPostToPost_should_throw_argument_null_exception_when_input_argument_is_null()
 {
     Assert.Throws <ArgumentNullException>(() => ExternalPostMapper.ConvertFacebookPostToPost(null, null));
 }