public async void ImportJson(string fileName) { bool isCloudLoadSucceeded = false; // todo: ask system if offline, to prevent having to timeout try { var wikiData = new WikiAccessFacadeShared.WikiAccessFacade(); string json = await wikiData.GetFoodIngredientImages(); var importResults = JsonConvert.DeserializeObject <ResultSet>(json); foreach (var result in importResults.Results.Images) { if (result.Image != null) { var state = _repo.CreateIngredientImageState(); state.Url = result.Image.Value; state.WikiDataId = int.Parse(result.WikiDataId.cleanValue); //Debug.WriteLine(state.WikiDataId.ToString()); _repo.UpdateIngredientImageState(state); } } _repo.PersistChanges(); // todo: persist retrieved data for offline situation isCloudLoadSucceeded = true; } catch (Exception ex) { Debug.WriteLine(ex.Message); // cloud load failed. Todo: user feedback? } if (!isCloudLoadSucceeded) { // load from file //string json = await loadFile(@"Import/" + language + "/" + fileName); } }
public async void ImportJson(string fileName, List <string> languages) { bool isCloudLoadSucceeded = false; // todo: ask system if offline, to prevent having to timeout try { var wikiData = new WikiAccessFacadeShared.WikiAccessFacade(); foreach (var language in languages) { string json = await wikiData.GetWikiDataFoodIngredients(language); var importResults = JsonConvert.DeserializeObject <ResultSet>(json); foreach (var result in importResults.Results.Ingredients) { Guid guid; if (!WikiDataIdToGuid.TryGetValue(result.WikiDataId.cleanValue, out guid)) { guid = Guid.NewGuid(); WikiDataIdToGuid.Add(result.WikiDataId.cleanValue, guid); } AddTranslation(guid, language, result); } } _repo.PersistChanges(); // todo: persist retrieved data for offline situation isCloudLoadSucceeded = true; } catch (Exception) { // cloud load failed. Todo: user feedback? } if (!isCloudLoadSucceeded) { // load from file //string json = await loadFile(@"Import/" + language + "/" + fileName); } }