Esempio n. 1
0
        public static async Task <bool> SaveNewsData(NewsResults _News)
        {
            try
            {
                StorageFile file = await ApplicationData.Current.LocalFolder.CreateFileAsync("News.json", CreationCollisionOption.ReplaceExisting);

                string data = JsonConvert.SerializeObject(_News);
                await FileIO.WriteTextAsync(file, data);

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Esempio n. 2
0
        public static async Task <NewsResults> GetSavedNews()
        {
            NewsResults result = new NewsResults();

            try
            {
                var file = await ApplicationData.Current.LocalFolder.GetFileAsync("News.json");

                string content = await FileIO.ReadTextAsync(file);

                result = JsonConvert.DeserializeObject <NewsResults>(content);
            }
            catch (Exception)
            {
                result = null;
            }
            return(result);
        }