public async Task UpdateFaceMaskInDrugStoreData() { //call api var faceMaskData = await OpenDataService.Instance.GetFaceMaskData(); try { //有資料更新時重置 DB 的該 Table 所有資訊。 DrugStoresDbConnection.DropTable <Models.FaceMaskInDrugStore>(); DrugStoresDbConnection.CreateTable <Models.FaceMaskInDrugStore>(); System.Diagnostics.Debug.WriteLine($"DBService-FaceMaskInDrugStoreData Count: {faceMaskData?.Count}"); DrugStoresDbConnection.InsertAll(faceMaskData, true); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine($"DBService Exception: {ex.Message}"); } finally { Xamarin.Essentials.Preferences.Set("FaceMaskDataUpdateDateTime", DateTime.Now); } }
private async void BuildDrugStoreBaseData() { var drugStoreData = string.Empty; var dataStream = await Xamarin.Essentials.FileSystem.OpenAppPackageFileAsync("drugstore-data.txt"); using (var streamReader = new StreamReader(dataStream, Encoding.UTF8)) { drugStoreData = streamReader.ReadToEnd(); } var result = CheckDrugStoreIsNeedUpdate(ref drugStoreData); if (result.Item1) { try { //有資料更新時重置 DB 的該 Table 所有資訊。 DrugStoresDbConnection.DropTable <Models.DrugStore>(); DrugStoresDbConnection.CreateTable <Models.DrugStore>(); var drugStores = JsonConvert.DeserializeObject <List <Models.DrugStore> >(drugStoreData); System.Diagnostics.Debug.WriteLine($"DBService-DrugStoreData Count: {drugStores?.Count}"); DrugStoresDbConnection.InsertAll(drugStores, true); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine($"DBService Exception: {ex.Message}"); } finally { Xamarin.Essentials.Preferences.Set("DrugStore_Data_Var", result.Item2); } } }