示例#1
0
        public void PostWebPage(User user, int userInterestId, string linkUrl)
        {
            UserInterest interest = user.Interests.First(x => x.Id == userInterestId);

            linkUrl = linkUrl.FormatWebAddress();
            string html = _webContentService.GetHtmlFromUrl(linkUrl);
            PageDetails details = _pageParsingService.GetDetails(html);

            string description = details.Description;

            var uri = new Uri(linkUrl);
            var domain = uri.GetLeftPart(UriPartial.Authority).Replace(uri.GetLeftPart(UriPartial.Scheme), "");

            var medium = new WebPage { LinkUrl = linkUrl, WebPageDomainName = domain, Title = details.Title, CreateDate = DateTime.UtcNow };
            var post = new Post { Description = description, CreateDate = DateTime.UtcNow, Medium = medium };

            //determine if image is available
            if (!string.IsNullOrWhiteSpace(details.ImageUrl))
            {
                byte[] data = _webContentService.GetDataFromUrl(details.ImageUrl);
                string fileName = Path.GetFileName(details.ImageUrl);
                using (var memoryStream = new MemoryStream(data))
                {
                    var fileStreamDto = new FileStreamDto(memoryStream, fileName);
                    SaveImageForUser(
                        fileStreamDto, user.Username + "-Interest-WebPage-Image-" + interest.Interest.Name, imgFileNamesDto =>
                                                                                                            medium.AddImage(
                                                                                                                new ImageData(fileName, imgFileNamesDto.ThumbFilename, imgFileNamesDto.MediumFilename, imgFileNamesDto.FullFilename)));
                }
            }

            user.AddPost(post, interest.Interest);
        }
示例#2
0
 public void PostStatus(User user, int userInterestId, string description)
 {
     UserInterest interest = user.Interests.First(x => x.Id == userInterestId);
     var post = new Post { Description = description, CreateDate = DateTime.UtcNow };
     user.AddPost(post, interest.Interest);
 }
示例#3
0
        public void PostVideo(User user, int userInterestId, string videoUrl)
        {
            UserInterest interest = user.Interests.First(x => x.Id == userInterestId);

            videoUrl = videoUrl.FormatWebAddress();
            string html = _webContentService.GetHtmlFromUrl(videoUrl);
            PageDetails details = _pageParsingService.GetDetails(html);

            string description = details.Description;

            if (string.IsNullOrWhiteSpace(details.VideoUrl))
            {
                throw new RulesException("Description", "Invalid video");
            }

            var medium = new Video { VideoUrl = details.VideoUrl, Title = details.Title, CreateDate = DateTime.UtcNow };

            var post = new Post { Medium = medium, Description = description, CreateDate = DateTime.UtcNow };

            //determine if image is available
            if (!string.IsNullOrWhiteSpace(details.ImageUrl))
            {
                byte[] data = _webContentService.GetDataFromUrl(details.ImageUrl);
                string fileName = Path.GetFileName(details.ImageUrl);
                using (var memoryStream = new MemoryStream(data))
                {
                    var fileStreamDto = new FileStreamDto(memoryStream, fileName);
                    SaveImageForUser(
                        fileStreamDto, user.Username + "-Interest-Video-Image-" + interest.Interest.Name, imgFileNamesDto =>
                                                                                                          medium.AddImage(
                                                                                                              new ImageData(fileName, imgFileNamesDto.ThumbFilename, imgFileNamesDto.MediumFilename, imgFileNamesDto.FullFilename)));
                }
            }

            user.AddPost(post, interest.Interest);
        }
示例#4
0
 public void PostImage(User user, FileStreamDto interestImage, int userInterestId, string description)
 {
     UserInterest interest = user.Interests.First(x => x.Id == userInterestId);
     SaveImageForUser(
         interestImage,
         user.Username + "-Interest-Image-" + interest.Interest.Name,
         imgFileNamesDto =>
         user.AddPost(
             new Post
             {
                 Description = description,
                 CreateDate = DateTime.UtcNow,
                 Medium =
                     new Image
                     {
                         ImageData =
                             new ImageData(
                             interestImage.FileName
                             , imgFileNamesDto.ThumbFilename
                             , imgFileNamesDto.MediumFilename
                             , imgFileNamesDto.FullFilename),
                         CreateDate = DateTime.UtcNow
                     }
             }, interest.Interest));
 }