public ActionResult GetFeed(string name, string feedName) { var id = RiverWall.NewId(name); var wall = RavenSession.Load<RiverWall>(id.Full()); var feedTarget = GetFeed(wall, feedName); if (!feedTarget.IsFound) return HttpNotFound(); var hostTarget = feedTarget.Item.Host; var pathTarget = feedTarget.Item.Path; ViewBag.FeedUrl = hostTarget + pathTarget; var cache = this.HttpContext.Cache[ViewBag.FeedUrl]; if (cache == null) { var fetch = new RiverFetcher(); try { var output = fetch.Download(hostTarget, pathTarget); var river = fetch.Serialize(output); HttpContext.Cache.Add(ViewBag.FeedUrl, river, null, Cache.NoAbsoluteExpiration, new TimeSpan(0, 10, 0), CacheItemPriority.Default, null); var renderer = new FeedTemplateRenderer(river, wall.Template.FeedTemplate); this.CompressAndSetLongExpirationCache(); return Content(renderer.Render().ToString(), "text/html"); } catch (Exception ex) { return Content("Sorry, we really try to process " + ViewBag.FeedUrl + " but fate has decided on something else. " + ex.Message); } } else { var renderer = new FeedTemplateRenderer(cache as FeedsRiver, wall.Template.FeedTemplate); this.CompressAndSetLongExpirationCache(); return Content(renderer.Render().ToString(), "text/html"); } }
public ActionResult Feed(string feedName) { var feedTarget = GetFeed(feedName); if (!feedTarget.IsFound) return HttpNotFound(); var hostTarget = feedTarget.Item.Host; var pathTarget = feedTarget.Item.Path; ViewBag.FeedUrl = hostTarget + pathTarget; var cache = this.HttpContext.Cache[ViewBag.FeedUrl]; if (cache == null) { var fetch = new RiverFetcher(); try { var output = fetch.Download(hostTarget, pathTarget); var river = fetch.Serialize(output); HttpContext.Cache.Add(ViewBag.FeedUrl, river, null, Cache.NoAbsoluteExpiration, new TimeSpan(0, 10, 0), CacheItemPriority.Default, null); ViewBag.CacheStatus = "No Cache"; var renderer = new FeedTemplateRenderer(river, _template); this.Compress(); return Content(renderer.Render().ToString(), "text/html"); } catch (Exception ex) { return Content("Sorry, we really try to process " + ViewBag.FeedUrl + " but fate has decided on something else. " + ex.Message); } } else { ViewBag.CacheStatus = "Cached for 10 minutes"; var renderer = new FeedTemplateRenderer(cache as FeedsRiver, _template); this.Compress(); return Content(renderer.Render().ToString(), "text/html"); } }
public ActionResult Feed(string name) { var hostTarget = Texts.FromUriHost(this.Request.Url); var pathTarget = "/s/riverjs/" + name; ViewBag.FeedUrl = hostTarget + pathTarget; FeedsRiver cache = SyndicationFeedCache.Get(ViewBag.FeedUrl as string, HttpContext.Cache); if (cache == null) { var fetch = new RiverFetcher(); try { var output = fetch.Download(hostTarget, pathTarget); var river = fetch.Serialize(output); SyndicationFeedCache.Store(ViewBag.Url as string, river, HttpContext.Cache); ViewBag.CacheStatus = "No Cache"; var renderer = new FeedTemplateRenderer(river, _template); this.Compress(); return Content(renderer.Render().ToString(), "text/html"); } catch (Exception ex) { return Content("Sorry, we really try to process " + ViewBag.FeedUrl + " but fate has decided on something else. " + ex.Message); } } else { ViewBag.CacheStatus = "Cached for 10 minutes"; var renderer = new FeedTemplateRenderer(cache, _template); this.Compress(); return Content(renderer.Render().ToString(), "text/html"); } }
public ActionResult AddSource(string riverGuid, string title, string uri) { if (string.IsNullOrWhiteSpace(riverGuid)) this.PropertyValidationMessage("RiverGuid", "A critical id is missing. Please refresh your page and try again"); if (string.IsNullOrWhiteSpace(title)) this.PropertyValidationMessage("Title", "Title is required"); if (string.IsNullOrWhiteSpace(uri)) this.PropertyValidationMessage("Uri", "Uri is required"); Uri jsonUrl = null; try { jsonUrl = new Uri(uri); } catch { this.PropertyValidationMessage("Uri", "Given Uri is invalid. Please do not forget to include http://"); } if (!ModelState.IsValid) { var errors = this.ProduceAJAXErrorMessage(ModelState); return HttpDoc<EmptyHttpReponse>.PreconditionFailed(errors.ToJson()).ToJson(); } var wall = RavenSession.Query<RiverWall>().Where(x => x.Guid == riverGuid).FirstOrDefault(); if (wall == null) this.PropertyValidationMessage("RiverGuid", "The River Id is not valid. Please refresh your page."); else { try { var fetcher = new RiverFetcher(); var content = fetcher.Download(Texts.FromUriHost(jsonUrl), jsonUrl.PathAndQuery); var river = fetcher.Serialize(content); var name = Texts.ConvertTitleToName(title); wall.Sources.Items.Add(new RiverSubscriptionItem { Name = name, Text = title, JSONPUri = jsonUrl }); RavenSession.Store(wall); this.RavenSession.SaveChanges(); return HttpDoc<dynamic>.OK(new { Message = "Source added", Name = name }).ToJson(); } catch { this.PropertyValidationMessage("Uri", "Given Uri does not exist or is an invalid river format. Please try again."); } } if (!ModelState.IsValid) { var errors = this.ProduceAJAXErrorMessage(ModelState); return HttpDoc<EmptyHttpReponse>.PreconditionFailed(errors.ToJson()).ToJson(); } return HttpDoc<dynamic>.OK(new { Message = "Source added" }).ToJson(); }