public virtual JsonResult AddFeedToCat(int catId, int feedId) { var feed = _feedBusiness.Get(feedId); var cat = _categoryBusiness.Get(catId); feed.Categories.Add(cat); _feedBusiness.Edit(feed); return(Json(true, JsonRequestBehavior.AllowGet)); }
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)); }
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); }
public virtual JsonResult Feed_CreateEdit(Feed feed) { OperationStatus status; if (feed.Id == 0) { status = _feedBusiness.CreateEdit(feed); } else { status = _feedBusiness.Edit(feed); } return(Json(status, JsonRequestBehavior.AllowGet)); }
public int UpdatingFeed(Feed dbfeed, bool saveItems = true) { int NumberOfNewItem = 0; var items = new List <FeedItem>(); var log = new FeedLog() { FeedId = dbfeed.Id }; try { if (dbfeed.FeedType == 0 || !dbfeed.FeedType.HasValue) { #region Feed RssFeed feed = RssFeed.Read(dbfeed.Link); //-----------shart check kardane inke feed aslan update shode dar site marja ya kheir------------ if (feed == null) { dbfeed.Deleted = Common.Share.DeleteStatus.NotWork; } else if (feed.Channels.Count > 0) { //--------Feed has new items----------- if (feed.Channels.Count > 0) { RssChannel channel = (RssChannel)feed.Channels[0]; if (channel.Items.LatestPubDate() != channel.Items[0].PubDate) { items = new FeedItemsOperation(_appConfigBiz).RssItemsToFeedItems(channel.ItemsSorted, dbfeed); } else { items = new FeedItemsOperation(_appConfigBiz).RssItemsToFeedItems(channel.Items, dbfeed); } //----------Visual Items--------- //NumberOfNewItem = listReturnBack.Count; //if (NumberOfNewItem > 0) //{ // if (dbfeed.InIndex == 1) // { // if (dbfeed.Site.HasSocialTag.HasValue && dbfeed.Site.HasSocialTag.Value) // Updater.FeedItemImage.setFeedItemsImage(dbfeed, listReturnBack, 5); // //else // // FeedItemsOperation.insertFeedItemsIndex(dbfeed, listReturnBack, 5); // } // entiti.SaveChanges(); //} } } #endregion } else if (dbfeed.FeedType.HasValue && dbfeed.FeedType.Value == Common.Share.FeedType.Atom) { #region Atom XmlReader reader = XmlReader.Create(dbfeed.Link); SyndicationFeed atomfeed = SyndicationFeed.Load(reader); int i = 0; if (atomfeed == null) { dbfeed.Deleted = Common.Share.DeleteStatus.NotWork; } else if (atomfeed.Items.Any()) { foreach (SyndicationItem item in atomfeed.Items) { i++; break; } if (i > 0) { items = new FeedItemsOperation(_appConfigBiz).AtomItemsToFeedItems(atomfeed.Items, dbfeed); } } #endregion } if (items.Any()) { if (dbfeed.Site.HasImage != HasImage.NotSupport) { new FeedItemImage(_appConfigBiz).SetItemsImage(items, dbfeed); } if (saveItems) { NumberOfNewItem = ItemBiz.AddItems(items); if (NumberOfNewItem > 0) { dbfeed.LastUpdatedItemUrl = items.Last().Link.SubstringM(0, 400); } } GeneralLogs.WriteLog("Updating feed " + dbfeed.Id + " Items:" + NumberOfNewItem + " New:" + NumberOfNewItem + " " + dbfeed.Link.Replace("http://", ""), TypeOfLog.OK, typeof(FeedUpdater)); } } catch (Exception ex) { if (ex.Message.IndexOf("404") > 0) { dbfeed.Deleted = Common.Share.DeleteStatus.NotFound; } else if (ex.Message.IndexOf("403") > 0) { dbfeed.Deleted = Common.Share.DeleteStatus.Forbidden; } else if (ex.Message.IndexOfX("timed out") > 0) { dbfeed.Deleted = Common.Share.DeleteStatus.RequestTimeOut; } else { dbfeed.Deleted = Common.Share.DeleteStatus.Temporary; } log.HasError = true; log.Message = "Error:" + (ex.InnerException != null ? ex.InnerException.Message.SubstringM(0, 512) : ex.Message.SubstringM(0, 512)); FeedBiz.CreateFeedLog(log); var msg = "FeedId " + dbfeed.Id + " " + dbfeed.Link.SubstringM(0, 40) + " Error:" + (ex.InnerException != null ? ex.InnerException.Message.SubstringM(0, 512) : ex.Message.SubstringM(0, 512)); GeneralLogs.WriteLog(msg, TypeOfLog.Error, typeof(FeedUpdater)); FeedBiz.Edit(dbfeed); return(NumberOfNewItem); } dbfeed.LastUpdaterVisit = DateTime.Now; if (saveItems) { FeedBiz.CheckForChangeDuration(dbfeed, NumberOfNewItem > 0 ? true : false); if (NumberOfNewItem > 0) { dbfeed.LastUpdateDateTime = DateTime.Now; } } var res = FeedBiz.Edit(dbfeed); if (saveItems && res.Status) { log.HasError = false; log.Message = "Successfull Updat Feed " + dbfeed.Title.SubstringM(0, 16) + " " + dbfeed.Link.Replace("http://", "").SubstringM(0, 24); log.ItemsCount = NumberOfNewItem; FeedBiz.CreateFeedLog(log); } return(saveItems ? NumberOfNewItem : items.Count); }