Exemplo n.º 1
0
        public async Task <bool> TryUpdateSchedule(IFileAccess fileAccess, string defaultDbFilename)
        {
            var result             = false;
            var lastNewsUpdateTime = _preferences.Get("lastScheduleUpdate", DateTime.MinValue);

            if ((DateTime.Now - lastNewsUpdateTime).TotalDays < SCHEDULE_UPDATE_DAYS)
            {
                return(false);
            }
            var filename = await _cloudService.GetLatestScheduleFilename();

            if (_preferences.Get("dbFilename", defaultDbFilename) != filename)
            {
                var path = await _firebaseStorage.DownloadFileToLocalStorage("/" + filename);

                await fileAccess.CopyToLocal(path, filename);

                _preferences.Set("dbFilename", filename);
                result = true;
            }
            _preferences.Set("lastScheduleUpdate", DateTime.Now);
            return(result);
        }
Exemplo n.º 2
0
        public static async Task <bool> TryUpdateSchedule(IFileAccess fileAccess)
        {
            var resolver     = TinyIoCContainer.Current;
            var cloudService = resolver.Resolve <ICloudService>();
            var cloudStorage = resolver.Resolve <IFirebaseStorage>();
            var preferences  = resolver.Resolve <IPreferences>();

            var filename = await cloudService.GetLatestScheduleFilename();

            if (preferences.Get("dbFilename", "sqlite20211129.db") != filename)
            {
                var path = await cloudStorage.DownloadFileToLocalStorage("/" + filename);

                await fileAccess.CopyToLocal(path, filename);

                preferences.Set("dbFilename", filename);
            }

            var dataProvider = resolver.Resolve <IDataProvider>();
            var databasePath = fileAccess.GetLocalFilePath(filename);

            dataProvider.SetDatabasePath(databasePath);
            return(true);
        }