Exemple #1
0
        public FeedReaderResult Read(string feedUrl, string cacheKey = "")
        {
            var feedSource       = FeedSource.Cache;
            var feedReaderResult = new FeedReaderResult();

            var data = this.CacheHandler.GetData(cacheKey);

            if (string.IsNullOrEmpty(data))
            {
                try
                {
                    feedSource = FeedSource.Feed;

                    var httpClient = new HttpClient();
                    var feedData   = httpClient.GetAsync(feedUrl).Result;
                    data = feedData.Content.ReadAsStringAsync().Result;

                    data = this.FilterFeedResult.Filter(data);

                    this.CacheStorage.SaveDate(data, cacheKey);
                }
                catch
                {
                    feedSource = FeedSource.None;
                }
            }

            feedReaderResult.FeedSource = feedSource;
            feedReaderResult.Data       = data;

            return(feedReaderResult);
        }
Exemple #2
0
        public FeedReaderResult Read(string feedUrl, string cacheKey = "")
        {
            var feedReaderResult = new FeedReaderResult();
            var cacheResult      = this.CacheStorage.GetData(cacheKey);
            var data             = cacheResult.Data;
            var feedSource       = FeedSource.Cache;

            if (string.IsNullOrEmpty(data))
            {
                feedSource = FeedSource.Feed;
                feedUrl    = feedUrl.ConvertToApplicationRootPath();

                if (File.Exists(feedUrl))
                {
                    data = File.ReadAllText(feedUrl);
                    data = this.FilterFeedResult.Filter(data);
                }

                this.CacheStorage.SaveDate(data, cacheKey);
            }

            feedReaderResult.FeedSource = feedSource;
            feedReaderResult.Data       = data;

            return(feedReaderResult);
        }