Esempio n. 1
0
        private void saveFeedImage(BlogFeed blogFeed, bool saveLocal = false)
        {
            var targetFolder = Path.Combine("images/blogfeed", blogFeed.BlogId.ToString());

            this._fileStorageManager.MaxWidth = 250;
            var result = this._fileStorageManager.SaveImageFromUrl(
                "blogfeed",
                blogFeed.ImageUrl,
                DateTime.Now.ToString("yyyy_MM_dd_hh_mm") + ".jpg",
                targetFolder
                );

            if (result.Error == null)
            {
                blogFeed.Photo = new Photo()
                {
                    StorageType  = this._fileStorageManager.GetStorageType("blogfeed"),
                    Url          = result.Url,
                    ThumbnailUrl = result.Url,
                    IconUrl      = result.Url,
                    PublicId     = result.PublicId,
                };
                _blogRepo.SaveAll();
            }
        }
Esempio n. 2
0
        public async Task DeleteFeed(BlogFeed feed)
        {
            await DeleteFeedLikes(feed.Id);
            await DeleteFeedComments(feed.Id);

            if (feed.Photo != null)
            {
                Delete(feed.Photo);
            }
            Delete(feed);
        }
        public async Task AddNotificationNewPostOnFeedComment(int appUserId, BlogFeed blogFeed)
        {
            var user = await _context.AppUsers.FirstOrDefaultAsync(au => au.Id == appUserId);

            await AddNotificationIfNotExist(new Notification()
            {
                AppUserId         = blogFeed.Blog.OwnerId,
                NotificationType  = NotificationEnum.NewPostOnFeedComment,
                RecordType        = "BlogFeed",
                RecordId          = blogFeed.Id,
                FromUserName      = user.DisplayName,
                TargetRecordTitle = blogFeed.Title,
                //Message = "あなたのブログフィード『" + blogFeed.Title + "』に新しいコメントがあります"
            });
        }
Esempio n. 4
0
        private async Task <BlogFeed> readRss(Blog blog)
        {
            if (blog.RSS == null || blog.IsActive == false)
            {
                return(null);
            }

            var feed = await FeedReader.ReadAsync(blog.RSS);

            if (feed == null)
            {
                return(null);
            }

            // string result = "";
            // result += "Feed Title: " + feed.Title + "\n";
            // result += "Feed Description: " + feed.Description + "\n";
            // result += "Feed Image: " + feed.ImageUrl + "\n";
            if (feed.Items.Count > 0)
            {
                var latestFeed = await _repo.GetLatestBlogFeed(blog);

                var firstItem = feed.Items.First();

                if (latestFeed == null || latestFeed.PublishingDate < firstItem.PublishingDate)
                {
                    string firstImageUrl = "";
                    if (firstItem.Content != null)
                    {
                        firstImageUrl = Regex.Match(firstItem.Content, "<img.+?src=[\"'](.+?)[\"'].*?>", RegexOptions.IgnoreCase).Groups[1].Value;
                    }
                    var blogFeed = new BlogFeed()
                    {
                        BlogId         = blog.Id,
                        Blog           = blog,
                        Title          = firstItem.Title,
                        ImageUrl       = string.IsNullOrEmpty(firstImageUrl) ? null : firstImageUrl,
                        PublishingDate = firstItem.PublishingDate == null ? DateTime.Now : firstItem.PublishingDate,
                        Url            = firstItem.Link
                    };
                    return(blogFeed);
                }
            }
            return(null);
        }
        public async Task AddNotificationRepliedForFeedComment(BlogFeed blogFeed)
        {
            var previousOwnerReply = await _context.BlogFeedComments.Where(fc => fc.BlogFeedId == blogFeed.Id && fc.AppUserId == blogFeed.Blog.OwnerId)
                                     .OrderByDescending(tr => tr.DateCreated).FirstOrDefaultAsync();

            List <BlogFeedComment> notifyingReplies = null;

            if (previousOwnerReply == null)
            {
                notifyingReplies = await _context.BlogFeedComments.Where(fc =>
                                                                         fc.BlogFeedId == blogFeed.Id
                                                                         ).GroupBy(fc => fc.AppUserId)
                                   .Select(g => g.First())
                                   .ToListAsync();
            }
            else
            {
                notifyingReplies = await _context.BlogFeedComments.Where(fc =>
                                                                         fc.BlogFeedId == blogFeed.Id &&
                                                                         fc.DateCreated > previousOwnerReply.DateCreated
                                                                         ).GroupBy(fc => fc.AppUserId)
                                   .Select(g => g.First())
                                   .ToListAsync();
            }

            var blogOwner = await _context.AppUsers.FirstOrDefaultAsync(au => au.Id == blogFeed.Blog.OwnerId);

            foreach (var reply in notifyingReplies)
            {
                if (reply.AppUserId != null)
                {
                    await AddNotificationIfNotExist(new Notification()
                    {
                        AppUserId         = (int)reply.AppUserId,
                        NotificationType  = NotificationEnum.RepliedOnFeedComment,
                        RecordType        = "BlogFeed",
                        RecordId          = (int)reply.BlogFeedId,
                        Photo             = blogFeed.Photo,
                        FromUserName      = blogOwner.DisplayName,
                        TargetRecordTitle = blogFeed.Title,
                        //Message = "あなたがコメントしたブログフィード『" + blogFeed.Title + "』に返信があります"
                    });
                }
            }
        }
Esempio n. 6
0
        private async Task <BlogFeed> readRss(Blog blog)
        {
            if (blog.RSS == null || blog.IsActive == false)
            {
                return(null);
            }

            var feed = await FeedReader.ReadAsync(blog.RSS);

            if (feed == null)
            {
                return(null);
            }

            // string result = "";
            // result += "Feed Title: " + feed.Title + "\n";
            // result += "Feed Description: " + feed.Description + "\n";
            // result += "Feed Image: " + feed.ImageUrl + "\n";
            if (feed.Items.Count > 0)
            {
                var latestFeed = await _blogRepo.GetLatestBlogFeed(blog.Id);

                var firstItem = feed.Items.First();

                if (latestFeed == null || latestFeed.PublishingDate < firstItem.PublishingDate)
                {
                    bool     jpgOnly        = blog.RSS.Contains("yahoo.co.jp");
                    var      firstImageUrl  = extractFeedImage(feed.Type, firstItem, jpgOnly);
                    DateTime PublishingDate = firstItem.PublishingDate == null ? System.DateTime.Now : (DateTime)firstItem.PublishingDate;

                    var blogFeed = new BlogFeed()
                    {
                        BlogId         = blog.Id,
                        Blog           = blog,
                        Title          = System.Net.WebUtility.HtmlDecode(firstItem.Title),
                        ImageUrl       = firstImageUrl,
                        PublishingDate = PublishingDate,
                        Url            = firstItem.Link
                    };
                    return(blogFeed);
                }
            }
            return(null);
        }
Esempio n. 7
0
        public BlogFeed GetFeed()
        {
            var rssManager = new C9RssFeedManager();

            int currentIndex;

            if (!int.TryParse(Request.QueryString["p"], out currentIndex))
            {
                currentIndex = 1;
            }

            BlogFeed feed = rssManager.ViewFeed(currentIndex, SiteConstants.Page_Size);

            if (feed == null)
            {
                throw new ArgumentNullException("feed");
            }

            return(feed);
        }
Esempio n. 8
0
 public Task AddNotificationRepliedForFeedComment(BlogFeed blogFeed)
 {
     throw new System.NotImplementedException();
 }
Esempio n. 9
0
 public Task AddNotificationNewPostOnFeedComment(int appUserId, BlogFeed blogFeed)
 {
     throw new System.NotImplementedException();
 }