async void setDataContext()
        {
            favecasts = new PodcastCollection();
            //progressRing.IsActive = true;
            StorageFile file = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(@"Assets\data\Favorites.xml"); //OpenForReadAsync();
            //StorageFile defaultImage = await Package.Current.InstalledLocation.GetFileAsync(@"Assets\face.jpg");
            string text = await FileIO.ReadTextAsync(file);

            //Debug.WriteLine(text);

            PodcastsXMLParser parser = new PodcastsXMLParser(text);
            Debug.WriteLine("total podcasts: " + parser.itemCount);

            foreach (Podcast pcast in parser.Podcasts)
            {
                //CHECK time w/o image 1969 with 2370 TDOD: add a async image download
                favecasts.addItem(pcast);
            }

            //foreach (Podcast pcast in favecasts.Items)
            //{
            //    string imageurl = pcast.imageurl;
            //    pcast.thumbnail = null;
            //    if (!imageurl.Equals(String.Empty) && (imageurl.StartsWith("http://") || imageurl.StartsWith("ms-appx:/")))
            //    {
            //        pcast.thumbnail = new BitmapImage(new Uri(imageurl));
            //        Debug.WriteLine("adding images with http");
            //    }
            //    if (pcast.thumbnail == null)
            //    {
            //        pcast.thumbnail = new BitmapImage(new Uri("ms-appx:/Assets/no-image-512-bg.png"));
            //        Debug.WriteLine("adding images no image");
            //    }
                
            //}
            //DEBUG
            
            //foreach (Podcast p in favecasts.Items)
            //{
            //    Debug.WriteLine(p.ToJson());

            //}
            string jsonStr = JsonSerialization.WriteFromObject(favecasts.Items);
            Debug.WriteLine("jason result" + jsonStr);

            IStorageFile fileout = await Windows.Storage.ApplicationData.Current.LocalFolder.CreateFileAsync(@"data\fav.json", CreationCollisionOption.OpenIfExists);
            await FileIO.WriteTextAsync(fileout, jsonStr);
            text = await FileIO.ReadTextAsync(fileout);

            var podObj = JsonSerialization.ReadToObject(text);
            Debug.WriteLine("fav count" + podObj.Count);
            Debug.WriteLine("first object" + podObj[0]);
            //progressRing.IsActive = false;
        }
Пример #2
0
        public static async Task<List<Podcast>> loadLocalDataAsync()
        {
            //progressRing.IsActive = true;
            StorageFile file = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(@"Assets\data\Podcast.xml"); 
            string xmlString = await FileIO.ReadTextAsync(file);

            //Debug.WriteLine(text);

            PodcastsXMLParser parser = new PodcastsXMLParser(xmlString);
            Debug.WriteLine("total podcasts: " + parser.itemCount);
            return parser.Podcasts;
        }