Example #1
0
        public void Handle(GenerateThumbnailForPost command)
        {
            var post = _postService.GetPostById(command.PostId);

            if (post == null)
            {
                return;
            }

            if (!command.Force && !string.IsNullOrEmpty(post.Thumb))
            {
                // already created and we aren't trying to for it to be recreated
                return;
            }

            try
            {
                Image image = null;
                try
                {
                    if (post.PostType == PostType.Link)
                    {
                        // grab an image from the url of the post
                        image = _mediaScraper.GetThumbnailForUrl(post.Url);
                    }
                    else if (post.PostType == PostType.Text)
                    {
                        // this is a text post
                        // let's see if there are any links in the users post.
                        var links = _mediaScraper.ExtractLinksFromHtml(post.ContentFormatted);
                        if (links.Count > 0)
                        {
                        }

                        // TODO
                    }

                    if (image != null)
                    {
                        // we found an image for the link
                        _postService.UpdateThumbnailForPost(post.Id, _postThumbnailService.UploadImage(image));
                    }
                }
                finally
                {
                    if (image != null)
                    {
                        image.Dispose();
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.Error("There was an error trying to get a thumbnail for the post " + post.Id, ex);
            }
        }
Example #2
0
        public void Can_extract_urls_from_html()
        {
            // arrange
            var html = string.Empty;

            html += "<a href=\"http://test1.com\">test1</a>";
            html += "<a href=\"\">test2</a>";
            html += "<a>test3</a>";
            html += "<a href='http://test4.com\'>test4</a>";
            html += "<a href='http://test5.com\'></a>";

            // act
            var urls = _mediaScrapper.ExtractLinksFromHtml(html);

            // assert
            urls.Count.Should().Be(3);
            urls[0].Should().Be("http://test1.com");
            urls[1].Should().Be("http://test4.com");
            urls[2].Should().Be("http://test5.com");
        }
Example #3
0
        public void Can_extract_urls_from_html()
        {
            // arrange
            var html = string.Empty;

            html += "<a href=\"http://test1.com\">test1</a>";
            html += "<a href=\"\">test2</a>";
            html += "<a>test3</a>";
            html += "<a href='http://test4.com\'>test4</a>";
            html += "<a href='http://test5.com\'></a>";

            // act
            var urls = _mediaScrapper.ExtractLinksFromHtml(html);

            // assert
            Assert.That(urls, Has.Count.EqualTo(3));
            Assert.That(urls[0], Is.EqualTo("http://test1.com"));
            Assert.That(urls[1], Is.EqualTo("http://test4.com"));
            Assert.That(urls[2], Is.EqualTo("http://test5.com"));
        }