コード例 #1
0
        private static async void Load()
        {
            _loading = true;
            var data = await LoadFromDisk();

            Log.Info($"Loaded from disk: {data}");
            if (data?.IsStale ?? true)
            {
                Log.Info("Cached data was not found or stale. Fetching latest...");
                data = await ApiWrapper.GetAvailableDecks();

                if (data == null)
                {
                    Log.Warn("No data. Can retry in 30 minutes.");
                    data = new DecksData
                    {
                        ClientTimeStamp = DateTime.Now.Subtract(TimeSpan.FromHours(23.5)),
                    };
                }
                await WriteToDisk(data);
            }
            _data = data;
            Log.Info($"Complete: {data}");
            OnLoaded?.Invoke();
            _loading = false;
        }
コード例 #2
0
 private static async Task <bool> WriteToDisk(DecksData data)
 {
     Log.Info("Writing data to disk...");
     try
     {
         using (var sw = new StreamWriter(CacheFilePath))
             await sw.WriteAsync(JsonConvert.SerializeObject(data));
     }
     catch (Exception e)
     {
         Log.Error(e);
         return(false);
     }
     return(true);
 }