예제 #1
0
        private static void StoreCache()
        {
            var launchData = new CacheData
            {
                NextLaunch = CacheManager.NextLaunch,
                CacheRockets = CacheManager.CachedRockets,
                LaunchRangeList = CacheManager.CachedLaunches,
                PeopleInSpace = CacheManager.People
            };

            var newsDataString = CacheManager.CachedCacheNewsFeed.ConvertToJsonString();

            var launchDataString = launchData.ConvertToJsonString();
            var settingsDataString = App.Settings.ConvertToJsonString();

            Task.Run(() => DependencyService.Get<IStoreCache>().SaveCache(settingsDataString, CacheType.SettingsData));
            Task.Run(() => DependencyService.Get<IStoreCache>().SaveCache(launchDataString, CacheType.LaunchData));
            Task.Run(() => DependencyService.Get<IStoreCache>().SaveCache(newsDataString, CacheType.NewsData));
        }
예제 #2
0
        private static void LoadCache()
        {
            CacheData cacheData = new CacheData();
            CacheNews newsData = new CacheNews();

            try
            {
                var launchDataString = DependencyService.Get<IStoreCache>().LoadCache(CacheType.LaunchData);
                cacheData = launchDataString.ConvertToObject<CacheData>();
            }
            catch (Exception)
            {
                cacheData.NextLaunch = new LaunchData {CacheTimeOut = DateTime.Now};
                cacheData.CacheRockets = new List<CacheRocket>();
                cacheData.LaunchRangeList = new LaunchRangeList
                {
                    CacheTimeOut = DateTime.Now,
                    LaunchPairs = new List<LaunchData>()
                };
                cacheData.PeopleInSpace = new CachePeople()
                {
                    Astronouts = new List<Person>(),
                    CacheTimeOut = DateTime.Now
                };

            }

            try
            {
                var newsDataString = DependencyService.Get<IStoreCache>().LoadCache(CacheType.NewsData);
                newsData = newsDataString.ConvertToObject<CacheNews>();
            }
            catch (Exception)
            {
                newsData = new CacheNews { NewsFeeds = new List<NewsFeed>(), CacheTimeOut = DateTime.Now };
            }

            CacheManager.UpdateCache(cacheData, newsData);
        }
예제 #3
0
 public static void UpdateCache(CacheData cacheData, CacheNews newsData)
 {
     NextLaunch = cacheData?.NextLaunch;
     CachedRockets = cacheData?.CacheRockets;
     CachedLaunches = cacheData?.LaunchRangeList;
     People = cacheData?.PeopleInSpace;
     CachedCacheNewsFeed = newsData;            
 }