public async Task CreateLanguageFile(LanguageList languageList) { languageList.Languages = await GetLanguageListFromAPI(languageList.Languages); languageList.LastUpdated = DateTime.Now; SaveDataToFile(languageList, languageListFileName); }
public async Task UpdateLanguageList(LanguageList languageList) { LanguageList languageListCurrent = GetLanguageListFromFile(languageList); List<Language> languageListFromWeb = await GetLanguageListFromAPI(new List<Language>()); languageListCurrent.Languages = AddLanguages(languageListCurrent.Languages, languageListFromWeb); languageListCurrent.Languages = DeleteLanguages(languageListCurrent.Languages, languageListFromWeb); languageListCurrent.Languages = await UpdateLanguages(languageListCurrent.Languages, languageListFromWeb); languageListCurrent.LastUpdated = DateTime.Now; SaveDataToFile(languageListCurrent, languageListFileName); }
public LanguageList GetLanguageListFromFile(LanguageList languageList) { languageList = RetrieveLocalData(languageListFileName); return languageList; }
private void SaveDataToFile(LanguageList languageList, string fileName) { if (File.Exists(fileName)) { File.Delete(fileName); } string jsonContents = JsonConvert.SerializeObject(languageList); File.WriteAllText(fileName, jsonContents); }
private LanguageList RetrieveLocalData(string fileName) { LanguageList languageList = new LanguageList(); try { if (File.Exists(fileName)) { languageList = JsonConvert.DeserializeObject<LanguageList>(File.ReadAllText(fileName)); return languageList; } else { //System.Diagnostics.Debug.WriteLine("Retrieve Language File: file does not exist"); return null; } } catch (Exception exception) { //System.Diagnostics.Debug.WriteLine("Language File: " + exception.Message); return null; } return languageList; }