/// <summary>
        /// Renders the donut cache substitution.
        /// </summary>
        /// <param name="context">The Liquid rendering context.</param>
        /// <param name="result">Writer for rendered output.</param>
        public override void Render(Context context, TextWriter result)
        {
            var html = context.Registers["htmlHelper"] as HtmlHelper;

            if (html == null)
            {
                return;
            }

            var source             = NodeList.Cast <string>().Aggregate(new StringBuilder(), (sb, token) => sb.Append(token));
            var viewSupportsDonuts = context.ViewSupportsDonuts();

            context.Stack(() =>
            {
                // If donuts are supported then call the LiquidSubstitution action, otherwise render the liquid code directly.
                if (viewSupportsDonuts)
                {
                    var encodedSource = Convert.ToBase64String(Encoding.UTF8.GetBytes(source.ToString()));
                    result.Write(html.Action("LiquidSubstitution", "Layout", new { encodedSource }, viewSupportsDonuts));
                }
                else
                {
                    html.RenderLiquid(source.ToString(), "Substitution string, but donuts not supported", result);
                }
            });
        }
Esempio n. 2
0
        public List <string> GetFeed()
        {
            string content = string.Empty;
            string url     = @"https://www.flickr.com/services/feeds/photos_public.gne";

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

            request.AutomaticDecompression = DecompressionMethods.GZip;

            XmlNodeList NodeList;

            using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                using (Stream stream = response.GetResponseStream())
                {
                    XmlDocument xDoc = new XmlDocument();
                    xDoc.Load(stream);
                    NodeList = xDoc.GetElementsByTagName("link");
                }
            return(NodeList.Cast <XmlNode>().Select(node => node.Attributes["href"].Value).ToList());
        }