예제 #1
0
        /// <summary>
        /// Loads the cache from disk
        /// </summary>
        /// <returns>RSSCache as it was persisted</returns>
        public static RSSCache Load()
        {
            RSSCache cache = null;

            using (IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication())
            {
                using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream("rssCache.dat", System.IO.FileMode.OpenOrCreate, file))
                {
                    if (stream.Length > 0)
                    {
                        App.Log("Reading cache from file");
                        DataContractSerializer serializer = new DataContractSerializer(typeof(RSSCache));
                        cache = serializer.ReadObject(stream) as RSSCache;
                    }
                }
            }

            // File was not found, create a new cache
            if (cache == null)
            {
                App.Log("Creating a new cache");
                cache = new RSSCache();
            }

            return(cache);
        }
예제 #2
0
        /// <summary>
        /// Parses the OPML file and returns it as a list of RSSPages
        /// </summary>
        /// <param name="stream">The OPML file stream</param>
        /// <returns>List of RSSPages</returns>
        private static List <RSSPage> ParseOPML(Stream stream)
        {
            RSSCache       cache         = GetDataModel();
            List <RSSPage> rssCategories = null;

            if (cache.Cache.Count == 0)
            {
                XDocument xDocument = XDocument.Load(stream);

                // XML parsed using Linq
                rssCategories = (from outline in xDocument.Descendants("outline")
                                 where outline.Attribute("xmlUrl") == null
                                 select new RSSPage()
                {
                    Title = outline.Attribute("title").Value,
                    Feeds = (from o in outline.Descendants("outline")
                             select new RSSFeed
                    {
                        URL = o.Attribute("xmlUrl").Value,
                        ImageURL = "/Resources/rss-icon.jpg",
                        Title = o.Attribute("title").Value,
                        IsVisible = true
                    }).ToList <RSSFeed>()
                }).ToList <RSSPage>();
            }

            return(rssCategories);
        }
예제 #3
0
        /// <summary>
        /// Initializes the feeds. Called from App.xaml.cs
        /// when the application starts
        /// </summary>
        public static void InitializeFeeds()
        {
            RSSCache pages = GetDataModel();

            CachedItems = RSSCache.Load();

            foreach (RSSPage page in CachedItems.Cache)
            {
                pages.Cache.Add(page);
            }

            CachedItems = pages;

            if (CachedItems.Cache.Count == 0)
            {
                FirstLaunch();
            }
        }