Exemplo n.º 1
0
        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");
            }
        }
Exemplo n.º 2
0
        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");
            }
        }
Exemplo n.º 3
0
        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");
            }
        }