Пример #1
0
        public async Task LoadSavedFeeds()
        {
            OBDebug.Log("Loading saved feeds (async)");
            ObservableCollection <Feed> feeds = null;

            try {
                // Will throw an exception if the object doesn't exist - I really do hate exceptions
                feeds = await BlobCache.LocalMachine.GetObject <ObservableCollection <Feed> >(Constants.Keys.SavedFeeds);
            } catch (Exception e) {
                OBDebug.Log(e);
            }
            if (feeds != null)
            {
                // Got our previous list of feeds
                OBDebug.Log("Got our last cache of feeds");
                foreach (var feed in feeds)
                {
                    MasterFeeds.Add(feed);
                }
            }
            else
            {
                // No existing cached feed list - make a new one
                OBDebug.Log("Making a new set of feeds");
                MasterFeeds.Add(new Feed {
                    Url = Constants.Urls.SkySportsFeed
                });
                MasterFeeds.Add(new Feed {
                    Url = Constants.Urls.TechRadarFeed
                });
            }
        }
Пример #2
0
 // Refactored out for code duplication's sake
 void FireActionWithNamedProperty <T>(string propertyName, Action <T> onPropertyChanged)
 {
     try {
         onPropertyChanged((T)GetType().GetRuntimeProperty(propertyName).GetValue(this));
     } catch (Exception ex) {
         OBDebug.Log("You dun goofed. Either your property name wasn't correct, or the specified type was incorrect.", propertyName, typeof(T), ex);
         throw ex;
     }
 }
Пример #3
0
        FeedManager()
        {
            // Set up Akavache
            try {
                BlobCache.ApplicationName = Constants.Keys.ApplicationName;
            } catch (Exception e) {
                OBDebug.Log("NUnit hates Akavache", e);
            }

            // Load the saved feeds
            MasterFeeds = new ObservableCollection <Feed>();
            Task.Run(async() => await LoadSavedFeeds());
        }
Пример #4
0
        public static async Task <XDocument> GetParsedRssXml(string url)
        {
            // If we're within 15 minutes, grab a cached copy of the url response
            string rawXml = string.Empty;

            try {
                rawXml = await BlobCache.LocalMachine.GetOrFetchObject(url, async() => await DownloadStringAtUrl(url), DateTimeOffset.UtcNow.AddMinutes(15));
            } catch (Exception e) {
                OBDebug.Log("Exception while using akavache", "Attempting manual download instead", e);
                rawXml = await DownloadStringAtUrl(url);
            }

            OBDebug.Log("Got raw xml response", url);
            return(XDocument.Parse(rawXml));
        }
Пример #5
0
        public async Task UpdateFeed(Feed feed)
        {
            OBDebug.Log("Updating feed (async)", feed.Url);
            feed.Items.Clear();

            var xmlDocument = await GetParsedRssXml(feed.Url);

            foreach (var item in ParseFeed(xmlDocument))
            {
                feed.Items.Add(item);
            }

            OBDebug.Log("Invoking OnFeedUpdated", feed.Url, feed.Items.Count);
            if (OnFeedUpdated != null)
            {
                OnFeedUpdated(this, feed);
            }
        }
Пример #6
0
 public void UpdateFeedInBackground(Feed feed)
 {
     OBDebug.Log("Scheduling background feed update", feed.Url);
     Task.Run(async() => await UpdateFeed(feed));
 }
Пример #7
0
 public static async Task <string> DownloadStringAtUrl(string url)
 {
     OBDebug.Log("Downloading string at url", url);
     return(await HttpClient.GetStringAsync(url));
 }