示例#1
0
        async Task <bool> LoadContext()
        {
            bool result = false;

            if (File.Exists(fileName))
            {
                // string content = await File.ReadAllTextAsync(fileName);
                // TODO: Investigate why this doesn't work
                string content = File.ReadAllText(fileName);
                _context = JsonConvert.DeserializeObject <Context>(content);
                result   = true;
            }

            return(result);
        }
示例#2
0
 async Task <Context> GetContext()
 {
     if (_context is null)
     {
         if (!await LoadContext())
         {
             _context = new Context
             {
                 Basket = new Order()
             };
         }
         else
         {
             if (_context.LastModified < DateTime.Now.AddHours(Constants.MaxAge))
             {
                 _context = new Context
                 {
                     Basket = new Order()
                 };
             }
         }
     }
     return(_context);
 }