Exemple #1
0
        public static List <Video> LoadVideos()
        {
            var videos = new RootVideo
            {
                Videos = new List <Video>()
            };

            using (var storageFolder = IsolatedStorageFile.GetUserStoreForApplication())
            {
                if (!storageFolder.FileExists(PostsFileName))
                {
                    return(videos.Videos);
                }
                using (var stream = storageFolder.OpenFile(VideoFileName, FileMode.Open))
                {
                    using (var reader = new StreamReader(stream))
                    {
                        var json = reader.ReadToEnd();
                        videos = JsonConvert.DeserializeObject <RootVideo>(json);
                    }
                }
            }

            return(videos.Videos);
        }
Exemple #2
0
        public static async Task CreateVideos()
        {
            var search = await GetVideosSearch();

            var videos = new RootVideo
            {
                Videos = new List <Video>()
            };

            foreach (var videoToAdd in from item in search.items where item.id.videoId != null select CreateVideoItem(item))
            {
                videos.Videos.Add(videoToAdd);
            }

            var json = JsonConvert.SerializeObject(videos);

            using (var storageFolder = IsolatedStorageFile.GetUserStoreForApplication())
            {
                if (storageFolder.FileExists(VideoFileName))
                {
                    storageFolder.DeleteFile(VideoFileName);
                }

                using (var stream = storageFolder.CreateFile(VideoFileName))
                {
                    using (var writter = new StreamWriter(stream))
                    {
                        writter.Write(json);
                    }
                }
            }
        }