public ActionResult EditDetails(FeedSelectionViewModel vm) { if (vm == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ; //if user tickled add to feed radio button , add this to the list of feeds current user is following. try { var id = vm.FeedID; FeedChannel chn = (FeedChannel)db.Channels.First(ch => ch.FeedChannelID == id); profile.SelectedChannels.Add(chn); db.SaveChanges(); } catch (Exception ex) { ModelState.AddModelError(string.Empty, $@"Unable to save the record. {ex.Message}"); return(View(vm)); } return(RedirectToAction("FeedsIndex")); }
public ActionResult RenderFeed(byte channel, byte view, string area, string place, string tag) { try { int temp; byte?tagID = null; if (int.TryParse(tag, out temp)) { tagID = (byte)temp; } int?areaID = null; if (int.TryParse(area, out temp)) { areaID = temp; } int?placeID = null; if (int.TryParse(place, out temp)) { placeID = temp; } FeedView feedView = (FeedView)view; FeedChannel feedChannel = (FeedChannel)channel; return(View("FeedItemList", GetFeedItemsForViewSettings(feedChannel, feedView, areaID, placeID, tagID))); } catch (Exception ex) { CFLogger.RecordException(ex); SetPageMetaData(); return(View("UrlGone")); } }
public async Task <IEnumerable <Event> > ProcessAsync(Event evnt) { var newsFeedPulsed = evnt.GetBody <NewsFeedPulsed>(); var client = new HttpClient(); var stream = await client.GetStreamAsync(newsFeedPulsed.Url); var feedChannel = new FeedChannel(newsFeedPulsed.Url); var feed = SyndicationFeed.Load(XmlReader.Create(stream)); var offset = DateTimeOffset.MinValue; if (await _channelStore.ExistsAsync(feedChannel.Id)) { feedChannel = await _channelStore.GetAsync(feedChannel.Id); offset = feedChannel.LastOffset; } feedChannel.LastOffset = feed.Items.Max(x => x.PublishDate); await _channelStore.UpsertAsync(feedChannel); return(feed.Items.OrderByDescending(x => x.PublishDate) .TakeWhile(y => offset < y.PublishDate) .Select(z => new Event(new NewsItemCaptured() { Item = z.ToFeedItem() }))); }
public Task Update(User user, FeedChannel channel) { if (!channel.UserId.Equals(user.Id, StringComparison.OrdinalIgnoreCase)) { return(Task.CompletedTask); } return(_channelRepository.Update(channel)); }
public async Task <FeedChannel> Add(FeedChannel channel) { channel.Id = ObjectId.GenerateNewId().ToString(); await _channelRepository.Create(channel); return(channel); }
/// <summary> /// FeedChannel to FeedChannelViewModel mapping /// </summary> public static FeedChannelViewModel ToModel(this FeedChannel channelItem) { return(new FeedChannelViewModel { Hidden = channelItem.Hidden, Id = channelItem.Id, Name = channelItem.Name, Url = channelItem.Url }); }
protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); Doujin.Describe(modelBuilder); Collection.Describe(modelBuilder); Tag.Describe(modelBuilder); Guild.Describe(modelBuilder); FeedChannel.Describe(modelBuilder); }
public new FeedSettings UpdateIfNecessary(Guid id, FeedChannel channel, int?areaID, int?placeID) { LinqToSql_FeedSettings lt = GetLinqTypeByID(id); if (lt.CurrentChannelType != (byte)channel || lt.AreaID != areaID || lt.PlaceID != placeID) { lt.PlaceID = placeID; lt.AreaID = areaID; lt.CurrentChannelType = (byte)channel; return(Update(lt)); } return(MapType(lt)); }
public IActionResult RssFeed() { var rssItems = new List <FeedItem> { new FeedItem { Title = "News 1", AuthorName = "VahidN", Content = "line1<br/>line2", Categories = new List <string> { "MVC", "ASP.NET" }, Url = Url.Action(nameof(Article), typeof(FeedResultController).ControllerName(), new { id = 1 }, this.HttpContext.Request.Scheme), LastUpdatedTime = DateTimeOffset.UtcNow.AddDays(-1), PublishDate = DateTimeOffset.UtcNow.AddDays(-2) }, new FeedItem { Title = "News 2 - خبر 2", AuthorName = "VahidN", Content = "line1<br/>سطر دوم", Categories = new List <string> { "MVC", "ASP.NET" }, Url = Url.Action(nameof(Article), typeof(FeedResultController).ControllerName(), new { id = 2 }, this.HttpContext.Request.Scheme), LastUpdatedTime = DateTimeOffset.UtcNow.AddDays(-1), PublishDate = DateTimeOffset.UtcNow.AddDays(-2) } }; var channel = new FeedChannel { FeedTitle = ".NET Core News", FeedDescription = "Latest .NET Core News", FeedCopyright = "DNT", FeedImageContentPath = "", FeedImageTitle = "", RssItems = rssItems, CultureName = "fa-IR" }; return(new FeedResult(channel)); }
private async Task <List <FeedItem> > GetFeedFromChannelCached(FeedChannel channel) { var channelFeed = await _distributedCache.GetAsync <List <FeedItem> >($"channel_url_{channel.Url}"); if (channelFeed != null && channelFeed.Count != 0) { return(channelFeed); } channelFeed = await _rssClient.GetFeed(channel); if (channelFeed.Any()) { await _distributedCache.SetAsync($"channel_url_{channel.Url}", channelFeed, new DistributedCacheEntryOptions() { AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(30) }); } return(channelFeed); }
public async Task <List <FeedItem> > GetFeed(FeedChannel channel) { try { using (var result = await _httpClient.GetAsync(channel.Url)) { var xmlRss = await result.Content.ReadAsStringAsync(); return(xmlRss.IsAtomRss() ? xmlRss.FeedFromAtomRss(channel) : xmlRss.FeedFromRss(channel)); } } catch (Exception e) { _logger.LogError( "Can not get rss feed from \nchannel: {channelName}\nurl: {channelUrl}\n with error: {message} ", channel.Name, channel.Url, e.Message); return(new List <FeedItem>()); } }
public async Task <IEnumerable <FeedItem> > GetFeed(User user, FeedChannel channel, int?offset = null, int count = 10) { if (!channel.UserId.Equals(user.Id, StringComparison.OrdinalIgnoreCase)) { return(new List <FeedItem>()); } var feed = await _distributedCache.GetAsync <List <FeedItem> >($"channel_url_{channel.Url}"); if (feed != null && feed.Count != 0) { return(feed.GetChunkedFeed(offset, count)); } feed = await _rssClient.GetFeed(channel); await _distributedCache.SetAsync($"channel_url_{channel.Url}", feed, new DistributedCacheEntryOptions() { AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(30) }); return(feed.GetChunkedFeed(offset, count)); }
private List <IFeedItem> GetFeedItemsForViewSettings(FeedChannel channel, FeedView view, int?areaID, int?placeID, byte?tagID) { int numberOfPostsToDisplay = 40; int displayClimbingCount = 0, displayPartnerCallCount = 0, displayMovieCount = 0; FeedSettings settings = controller.UpdateFeedSettingsIfNecessary(UserID, channel, areaID, placeID); settings.TagID = tagID; // decided not to persist the tag in the db at this point in time. //-- Need to do on client side //if (Settings.HasPlace) { CurrentPlaceLkB.Text = CurrentFeedPlace.ShortName.Take(12); } //if (Settings.HasArea) { CurrentAreaLkB.Text = CurrentFeedArea.Name.Take(12); } //if (Settings.TagID.HasValue) { CurrentTagLB.Text = GetTagsString(Settings.TagID.Value); } if (view == FeedView.Posted) { //SelectLkB(PLkB); if (settings.TagID.HasValue) { displayClimbingCount = numberOfPostsToDisplay; } else { displayClimbingCount = 12; displayPartnerCallCount = 5; displayMovieCount = 3; } } else if (view == FeedView.Movies) { //SelectLkB(MLkB); settings.TagID = null; displayMovieCount = 15; } else if (view == FeedView.Climbing) { //SelectLkB(DCLkb); displayClimbingCount = numberOfPostsToDisplay; } else if (view == FeedView.PartnerCalls) { //SelectLkB(PCLkB); settings.TagID = null; displayPartnerCallCount = 17; } if (channel == FeedChannel.All) { //SelectLkB(AllLkB); } else if (channel == FeedChannel.Area) { //SelectLkB(CurrentAreaLkB); //FeedFocus = CurrentFeedArea.Name; } else if (channel == FeedChannel.Place) { //SelectLkB(CurrentPlaceLkB); //FeedFocus = CurrentFeedPlace.Name; } //else if (channel == FeedChannel.Climbers) //{ //SelectLkB(ClLkB); // settings.WatchedClimbers = controller.GetClimbersUserIsWatching(UserID); //FeedFocus = "climbers you're watching"; //} List <IFeedItem> FeedItems = new List <IFeedItem>(); List <FeedMoviePost> MoviePosts = new List <FeedMoviePost>(); List <FeedPartnerCallPost> PartnerCallPosts = new List <FeedPartnerCallPost>(); List <FeedClimbingPost> ClimbingPosts = new List <FeedClimbingPost>(); if (displayClimbingCount > 0) { ClimbingPosts = controller.GetPostsBySettings(settings, view, numberOfPostsToDisplay); } //-- Fill the feed if we don't have enough posts if (view == FeedView.Posted && !settings.TagID.HasValue) { if (ClimbingPosts.Count < numberOfPostsToDisplay) { byte numberToFill = (byte)(numberOfPostsToDisplay - ClimbingPosts.Count); displayMovieCount++; displayPartnerCallCount = (byte)(numberToFill - 1); } } if (displayMovieCount > 0 && !settings.TagID.HasValue) { MoviePosts = controller.GetFeedMoviesBySettings(settings, displayMovieCount); } if (displayPartnerCallCount > 0 && (!settings.TagID.HasValue || settings.TagID.Value != 1) && channel != FeedChannel.Climbers) { PartnerCallPosts = controller.GetFeedPartnerCallPostsBySettings(settings, displayPartnerCallCount); } foreach (FeedClimbingPost cp in ClimbingPosts) { FeedItems.Add(cp); } foreach (FeedMoviePost mp in MoviePosts) { FeedItems.Add(mp); } foreach (FeedPartnerCallPost pcp in PartnerCallPosts) { FeedItems.Add(pcp); } if (view == FeedView.Posted) { FeedItems = (from c in FeedItems orderby c.PostedDateTime descending select c).ToList(); } return(FeedItems); }
public async Task <bool> UpdateAsync(FeedChannel channel, CancellationToken cancellationToken = default) { // get discord channel var context = new FeedUpdateContext { Client = _discord, Channel = _discord.GetGuild(channel.GuildId)?.GetTextChannel(channel.Id), GuildSettings = channel.Guild }; var tagIds = channel.Tags.Select(t => t.TagId).ToArray(); var queue = new Queue <Doujin>(); for (var i = 0; i < _maxSendCount; i++) { if (queue.Count == 0) { var doujins = await _db.GetDoujinsAsync( q => query(q).Take(_loadChunkSize), // load in chunks cancellationToken); foreach (var d in doujins) { queue.Enqueue(d); } } // no more doujin if (!queue.TryDequeue(out var doujin) || doujin == null) { break; } // send doujin interactive using (context.BeginTyping()) { // make updates more even await Task.Delay(TimeSpan.FromSeconds(1), cancellationToken); await _interactive.SendInteractiveAsync( new DoujinMessage(doujin, true), context, cancellationToken, false); _logger.LogInformation("Sent feed update of doujin {0} '{1}'.", doujin.Id, doujin.OriginalName); } channel.LastDoujin = doujin; } // set last sent doujin to the latest value channel.LastDoujin = (await _db.GetDoujinsAsync(q => query(q).Take(1), cancellationToken))[0] ?? channel.LastDoujin; await _db.SaveAsync(cancellationToken); _logger.LogInformation("Feed channel {0} is now at doujin {1}.", channel.Id, channel.LastDoujin.Id); return(true); IQueryable <Doujin> query(IQueryable <Doujin> q) { q = q .AsNoTracking() .Where(d => d.ProcessTime > channel.LastDoujin.ProcessTime); switch (channel.WhitelistType) { case FeedChannelWhitelistType.Any: q = q.Where(d => d.Tags.Any(x => tagIds.Contains(x.TagId))); break; case FeedChannelWhitelistType.All: q = q.Where(d => d.Tags.All(x => tagIds.Contains(x.TagId))); break; } return(q.OrderBy(d => d.ProcessTime)); } }
private List<IFeedItem> GetFeedItemsForViewSettings(FeedChannel channel, FeedView view, int? areaID, int? placeID, byte? tagID) { int numberOfPostsToDisplay = 40; int displayClimbingCount = 0, displayPartnerCallCount = 0, displayMovieCount = 0; FeedSettings settings = controller.UpdateFeedSettingsIfNecessary(UserID, channel, areaID, placeID); settings.TagID = tagID; // decided not to persist the tag in the db at this point in time. //-- Need to do on client side //if (Settings.HasPlace) { CurrentPlaceLkB.Text = CurrentFeedPlace.ShortName.Take(12); } //if (Settings.HasArea) { CurrentAreaLkB.Text = CurrentFeedArea.Name.Take(12); } //if (Settings.TagID.HasValue) { CurrentTagLB.Text = GetTagsString(Settings.TagID.Value); } if (view == FeedView.Posted) { //SelectLkB(PLkB); if (settings.TagID.HasValue) { displayClimbingCount = numberOfPostsToDisplay; } else { displayClimbingCount = 12; displayPartnerCallCount = 5; displayMovieCount = 3; } } else if (view == FeedView.Movies) { //SelectLkB(MLkB); settings.TagID = null; displayMovieCount = 15; } else if (view == FeedView.Climbing) { //SelectLkB(DCLkb); displayClimbingCount = numberOfPostsToDisplay; } else if (view == FeedView.PartnerCalls) { //SelectLkB(PCLkB); settings.TagID = null; displayPartnerCallCount = 17; } if (channel == FeedChannel.All) { //SelectLkB(AllLkB); } else if (channel == FeedChannel.Area) { //SelectLkB(CurrentAreaLkB); //FeedFocus = CurrentFeedArea.Name; } else if (channel == FeedChannel.Place) { //SelectLkB(CurrentPlaceLkB); //FeedFocus = CurrentFeedPlace.Name; } //else if (channel == FeedChannel.Climbers) //{ //SelectLkB(ClLkB); // settings.WatchedClimbers = controller.GetClimbersUserIsWatching(UserID); //FeedFocus = "climbers you're watching"; //} List<IFeedItem> FeedItems = new List<IFeedItem>(); List<FeedMoviePost> MoviePosts = new List<FeedMoviePost>(); List<FeedPartnerCallPost> PartnerCallPosts = new List<FeedPartnerCallPost>(); List<FeedClimbingPost> ClimbingPosts = new List<FeedClimbingPost>(); if (displayClimbingCount > 0) { ClimbingPosts = controller.GetPostsBySettings(settings, view, numberOfPostsToDisplay); } //-- Fill the feed if we don't have enough posts if (view == FeedView.Posted && !settings.TagID.HasValue) { if (ClimbingPosts.Count < numberOfPostsToDisplay) { byte numberToFill = (byte)(numberOfPostsToDisplay - ClimbingPosts.Count); displayMovieCount++; displayPartnerCallCount = (byte)(numberToFill - 1); } } if (displayMovieCount > 0 && !settings.TagID.HasValue) { MoviePosts = controller.GetFeedMoviesBySettings(settings, displayMovieCount); } if (displayPartnerCallCount > 0 && (!settings.TagID.HasValue || settings.TagID.Value != 1) && channel != FeedChannel.Climbers) { PartnerCallPosts = controller.GetFeedPartnerCallPostsBySettings(settings, displayPartnerCallCount); } foreach (FeedClimbingPost cp in ClimbingPosts) { FeedItems.Add(cp); } foreach (FeedMoviePost mp in MoviePosts) { FeedItems.Add(mp); } foreach (FeedPartnerCallPost pcp in PartnerCallPosts) { FeedItems.Add(pcp); } if (view == FeedView.Posted) { FeedItems = (from c in FeedItems orderby c.PostedDateTime descending select c).ToList(); } return FeedItems; }
public FeedSettings UpdateFeedSettingsIfNecessary(Guid userID, FeedChannel channel, int?areaID, int?placeID) { return(new FeedSettingsDA().UpdateIfNecessary(userID, channel, areaID, placeID)); }