예제 #1
0
        public void UpdateFeedsPerDuration(UpdateDuration duration)
        {
            var delaytime  = TimeSpan.Parse(duration.DelayTime);
            var Partnumber = delaytime.Hours * 60 / Config.GetTimeInterval();//20 min intervall
            var TopCount   = (duration.FeedsCount / Partnumber) != 0 ? (duration.FeedsCount / Partnumber) : (duration.FeedsCount % Partnumber);

            var feeds = FeedBiz.GetList().Where(x => x.UpdateDurationId.Value == duration.Id &&
                                                ((int)x.Deleted < 1 || (int)x.Deleted > 10)).OrderBy(feed => feed.Id).Skip(duration.StartIndex).Take(TopCount).ToList();

            if (TopCount == 0)
            {
                return;
            }

            GeneralLogs.WriteLog("Start updating duration " + duration.Code + " Start at:" + duration.StartIndex, TypeOfLog.Start, typeof(FeedUpdater));

            foreach (var feed in feeds)
            {
                GeneralLogs.WriteLog("Feed updating. Id:" + feed.Id, TypeOfLog.Start, typeof(FeedUpdater));
                UpdatingFeed(feed);
            }

            duration.FeedsCount = FeedBiz.GetList().Where(x => x.UpdateDurationId.Value == duration.Id && ((int)x.Deleted < 1 || (int)x.Deleted > 10)).Count();
            duration.StartIndex = (duration.StartIndex + TopCount) >= duration.FeedsCount ? 0 : (duration.StartIndex + TopCount);
            var res = DurationBiz.Edit(duration);

            if (res.Status)
            {
                GeneralLogs.WriteLog("Duration updated. Id:" + duration.Id + " Start Index: " + duration.StartIndex, TypeOfLog.OK, typeof(FeedUpdater));
            }
        }
예제 #2
0
        public virtual ActionResult FeedsCheck()
        {
            var badFeeds   = new List <FeedContract>();
            var baseserver = new BaseServer(_appConfigBiz, _feedBusiness, _feedItemBusiness, _updaterDurationBusiness);
            var feeds      = _feedBusiness.GetList().Where(f => f.Deleted == DeleteStatus.Temporary && f.UpdatingErrorCount < 7).ToList();

            ViewBag.OldCount = feeds.Count;
            foreach (var feed in feeds)
            {
                FeedContract feedContract = new FeedContract();
                try
                {
                    feedContract = feed.ToViewModel <FeedContract>();
                    feedContract = (new ClientUpdater(baseserver, _feedBusiness, _appConfigBiz, true)).FeedUpdateAsService(feedContract, new List <string>());
                    if (!feedContract.FeedItems.Any())
                    {
                        badFeeds.Add(feedContract);
                    }

                    feed.Deleted            = DeleteStatus.Active;
                    feed.UpdatingErrorCount = 0;
                }
                catch (Exception ex)
                {
                    feed.UpdatingErrorCount = (byte)(feed.UpdatingErrorCount + 1);
                    feedContract.SiteTitle  = ex.Message.SubstringETC(0, 200) + (ex.InnerException != null && ex.InnerException.Message != null ? ex.InnerException.Message.SubstringETC(0, 200) : string.Empty);
                    badFeeds.Add(feedContract);
                }
                _feedBusiness.Edit(feed);
            }
            ViewBag.NewCount = feeds.Count - badFeeds.Count;
            return(View(badFeeds));
        }
예제 #3
0
        public bool UpdateFeeds(List <FeedContract> feeds)
        {
            //var context = new TazehaContext();
            var ids     = feeds.Select(x => x.Id).ToList();
            var dbFeeds = _feedBusiness.GetList().Where(x => ids.Any(f => f == x.Id)).ToList();

            foreach (var dbfeed in dbFeeds)
            {
                dbfeed.LastUpdatedItemUrl = feeds.FirstOrDefault(x => x.Id == dbfeed.Id).LastFeedItemUrl;
                if (!string.IsNullOrEmpty(dbfeed.LastUpdatedItemUrl) && feeds.SingleOrDefault(f => f.Id == dbfeed.Id).FeedItems.Count > 0)
                {
                    dbfeed.UpdatingCount      = dbfeed.UpdatingCount == null ? 1 : dbfeed.UpdatingCount + 1;
                    dbfeed.LastUpdateDateTime = DateTime.Now;
                    _feedBusiness.CheckForChangeDuration(dbfeed, true);
                }
                else
                {
                    _feedBusiness.CheckForChangeDuration(dbfeed, false);
                }

                dbfeed.LastUpdaterVisit = DateTime.Now;

                _feedBusiness.Edit(dbfeed);
            }
            //context.SaveChanges();
            GeneralLogs.WriteLog("UpdateFeeds[AsService] : " + string.Join("[br /]", dbFeeds.Select(x => x.Link)), TypeOfLog.OK);
            return(true);
        }
예제 #4
0
        public virtual ActionResult Index(int page = 1)
        {
            var model = new DashboardModel();
            var today = DateTime.Today;

            model.SitesCount = _siteBusiness.GetList().Count();

            model.Feeds            = _feedBusiness.GetList().OrderByDescending(f => f.LastUpdateDateTime).Take(10).ToList();
            model.ActiveFeedsCount = _feedBusiness.GetList().Where(f => f.Deleted == Common.Share.DeleteStatus.Active).Count();
            model.TodayFeedsCount  = _feedBusiness.GetList().Where(f => f.LastUpdateDateTime >= today).Count();

            model.Comments   = _commentBiz.GetList().OrderByDescending(c => c.Id).Take(8).ToList();
            model.Posts      = _postBiz.GetList().Where(p => p.PostType == PostType.News).OrderByDescending(p => p.Id).Take(8).ToList();
            model.PostsCount = _postBiz.GetList().Count();

            model.UsersCount = _userBusiness.GetList().Count();
            model.Users      = _userBusiness.GetList().OrderByDescending(u => u.Id).Take(8).ToList();

            model.MessagesCount = _contactBusiness.GetList().Count();

            model.TodayItemsCount = _feedItemBusiness.GetList().Where(t => t.CreateDate >= today).Count();

            return(View(model));
        }
예제 #5
0
        public virtual JsonResult Feeds_Read([DataSourceRequest] DataSourceRequest request, long?siteId, long?catId, string term)
        {
            var query = _feedBusiness.GetList();

            if (siteId.HasValue && siteId > 0)
            {
                query = query.Where(f => f.SiteId == siteId);
            }
            if (catId.HasValue && catId > 0)
            {
                query = query.Where(f => f.Categories.Any(c => c.Id == catId.Value || c.ParentId == catId.Value));
            }
            else if (!string.IsNullOrEmpty(term))
            {
                query = query.Where(f => f.Site.SiteUrl.StartsWith(term));
            }
            //if (request.Filters == null || !request.Filters.Any())
            //    query = query.Take(20);

            var feeds = query.Select(f => new FeedViewModel()
            {
                Id                  = f.Id,
                Title               = f.Title,
                Link                = f.Link,
                SiteId              = f.SiteId,
                SiteSiteTitle       = f.Site.SiteTitle,
                SiteSiteUrl         = f.Site.SiteUrl,
                Deleted             = f.Deleted,
                UpdateDurationTitle = f.UpdateDuration.Title,
                UpdateDurationId    = f.UpdateDurationId,
                LastUpdateDateTime  = f.LastUpdateDateTime,
                LastUpdaterVisit    = f.LastUpdaterVisit
            });

            return(Json(feeds.ToDataSourceResult(request), JsonRequestBehavior.AllowGet));
        }
예제 #6
0
        [OutputCache(Duration = CmsConfig.Cache5Min, VaryByParam = "Content;PageIndex")]//, VaryByCustom = "IsMobile"
        public virtual ActionResult Index(string content, int PageIndex = 0)
        {
            var model = new TagItemsPageModel();

            content = content.Replace("_", " ");
            content = content.Replace("+", " ");
            var TagCurrent      = new Tag();
            var LastItemPubDate = DateTime.Now.AddMinutes(15);

            //if (Content.EqualsX("All") || string.IsNullOrEmpty(Content))
            //    return RedirectToAction(MVC.Tag.Actions.ActionNames.All, MVC.Tag.Name);

            try
            {
                TagCurrent = _unitOfWork.Set <Tag>().SingleOrDefault(x => x.Title.Equals(content) || x.EnValue == content);
                //    if (TagCurrent.Value.Trim().Length != Content.Trim().Length && TagCurrent.EnValue.Trim().Length != Content.Trim().Length)
                //        return RedirectToAction(MVC.Key.ActionNames.Index, MVC.Key.Name, new { Content = Content, PageSize = PageSize, LastItemPubDate });
            }
            catch
            {
                var tagCurrents = _unitOfWork.Set <Tag>().Where(x => x.Value.StartsWith(content));
                if (tagCurrents.Any())
                {
                    TagCurrent = tagCurrents.First();
                }
                else
                {
                    return(RedirectToAction(MVC.Key.ActionNames.Index, MVC.Key.Name, new { Content = content, PageSize = PageSize, LastItemPubDate }));
                }
            }
            if (TagCurrent == null)
            {
                return(RedirectToAction(MVC.Key.ActionNames.Index, MVC.Key.Name, new { Content = content, PageSize = PageSize, LastItemPubDate }));
            }


            #region ViewBag
            //ViewBag.EntityCode = "Tag";
            ViewBag.EntityRef = TagCurrent.Id;
            //ViewBag.PageSize = PageSize;
            ViewBag.Toggle             = "1";
            ViewBag.SearchTextDir      = "text-align:right;direction:rtl";
            ViewBag.Title              = "اخبار " + TagCurrent.Title;
            ViewBag.ImageThumbnail     = TagCurrent.ImageThumbnail;
            ViewBag.HasBackgroundImage = TagCurrent.HasBackgroundImage;
            ViewBag.Content            = string.IsNullOrEmpty(TagCurrent.EnValue) ? TagCurrent.Value.Trim() : TagCurrent.EnValue;
            ViewBag.SearchExpersion    = "Tag:" + TagCurrent.Value;
            ViewBag.PageHeader         = "تازه ترین های " + TagCurrent.Title;
            ViewBag.Discription        = "تازه ترین های اخبار روز و مطالب " + TagCurrent.Title;
            ViewBag.KeyWords           = "," + TagCurrent.EnValue + "," + TagCurrent.Value.Replace("|", ",") + ",اخبار روز,تازه ترین خبرها,خبرخوان";
            ViewBag.TagCurrent         = TagCurrent;
            ViewBag.PageIndex          = PageIndex + 1;
            #endregion
            if (string.IsNullOrEmpty(TagCurrent.Value) && string.IsNullOrEmpty(TagCurrent.EnValue))
            {
                return(RedirectToAction(MVC.Tag.Name, MVC.Tag.ActionNames.All, null));
            }

            #region Body

            model.Items       = _feedItemBusiness.FeedItemsByTag(TagCurrent, PageSize, PageIndex);
            model.VisualItems = _feedItemBusiness.FeedItemsByTag(TagCurrent, _appConfigBiz.GetVisualPostCount() + _appConfigBiz.GetVisualPostCount(), PageIndex, true);
            model.Posts       = _postBiz.GetList().Where(p => !p.MetaData.IsDeleted && p.PublishDate < DateTime.Now && p.Tags.Any(tc => tc.Id == TagCurrent.Id || tc.ParentTagId == TagCurrent.Id))
                                .Take(_appConfigBiz.GetVisualPostCount()).ToList();
            #endregion
            #region SitesTags
            //----------------Top Site in this Tag-------
            var cats = TagCurrent.Categories.ToList();
            try
            {
                if (cats.Any())
                {
                    var catsid = cats.Select(x => x.Id).ToList();
                    var feeds  = _feedBusiness.GetList().Where(f => f.Categories.Any(cf => catsid.Contains(cf.Id)));
                    var sites  = feeds.Select(f => f.Site);
                    ViewBag.TopSites = sites.Distinct().Select(s => new SiteOnlyTitle()
                    {
                        SiteTitle = s.SiteTitle, SiteUrl = s.SiteUrl
                    }).Take(20).ToList();
                }
                //ViewBag.TopSites = context.Database.SqlQuery<SiteOnlyTitle>("Sites_Select_TopByTag {0},{1}", TagCurrent.TagId, 15).ToList();
            }
            catch { }

            var relatedTags = cats.SelectMany(c => c.Tags.Select(t => t)).Distinct().Take(25).ToList();
            //relatedTags.Remove(TagCurrent.Id);
            ViewBag.RelatedTags = relatedTags;

            #endregion
            //B_feeditem.IncreaseVisitCount(res as IEnumerable<FeedItem>);
            model.Items = _feedItemBusiness.DescriptClear(model.Items, TagCurrent.Value).ToList();
            //_feedItemBusiness.Add_FeedItemtoCache(content, PageIndex, View(res), 60);

            #region Tabs
            //var webParts = Ioc.RemoteWpBiz.GetByTag(TagCurrent.Id).ToList();
            //if (webParts.Any())
            //    ViewBag.RemoteWebParts = webParts;
            //else
            //    if (TagCurrent.Categories.Any())
            //    ViewBag.RemoteWebParts = Ioc.RemoteWpBiz.GetByCats(TagCurrent.Categories.Select(c => c.Id).ToList()).ToList();

            //ViewBag.Pages = TagCurrent.Posts.Where(p => p.PostType == PostType.Tab).ToList();

            #endregion
            return(View("Index." + CmsConfig.ThemeName, model));
        }