Example #1
0
        public RssItem[] EndGetRss(IAsyncResult asyncResult)
        {
            CustomAsyncResult <WebRequestState> myAsyncResult = (CustomAsyncResult <WebRequestState>)asyncResult;
            WebRequestState myState = myAsyncResult.AdditionalData;

            var result = RssHelper.ConvertXmlToRss(XElement.Load(new XmlTextReader(CompleteGetUrl(asyncResult))), myState.Count).ToArray();

            WebOperationContext.Current.OutgoingResponse.ContentType = "application/json; charset=utf-8";
            return(result);
        }
Example #2
0
 private string GetCachedJSON()
 {
     if (Services.Get <ICache>().Contains(this.Url))
     {
         var    cachedRSS = XElement.Load(new StringReader(Services.Get <ICache>().Get(this.Url) as string));
         var    rss       = RssHelper.ConvertXmlToRss(cachedRSS, this.Count);
         string json      = new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(rss);
         return(json);
     }
     else
     {
         return(null);
     }
 }
Example #3
0
    private void ShowFeeds()
    {
        try
        {
            string url   = State.Element("url").Value;
            int    count = State.Element("count") == null ? 3 : int.Parse(State.Element("count").Value);

            var rss = default(XElement);
            if (Services.Get <ICache>().Contains(this.Url))
            {
                string cachedXml = Services.Get <ICache>().Get(this.Url) as string;
                rss = XElement.Parse(cachedXml);
            }
            else
            {
                rss = XElement.Load(this.Url);
                Services.Get <ICache>().Add(this.Url, rss.Xml());
            }

            if (null == rss)
            {
                Message.Text    = "There was a problem loading the feed";
                Message.Visible = true;
            }
            else
            {
                FeedList.DataSource = RssHelper.ConvertXmlToRss(rss, count);
                FeedList.DataBind();
            }
        }
        catch
        {
        }

        //Cache[url] = feed;
    }