Exemplo n.º 1
0
        public async Task CreateLanguageFile(LanguageList languageList)
        {
            languageList.Languages = await GetLanguageListFromAPI(languageList.Languages);
            languageList.LastUpdated = DateTime.Now;

            SaveDataToFile(languageList, languageListFileName);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
 public LanguageList GetLanguageListFromFile(LanguageList languageList)
 {
     languageList = RetrieveLocalData(languageListFileName);
     
     return languageList;
 }
Exemplo n.º 4
0
        private void SaveDataToFile(LanguageList languageList, string fileName)
        {
            if (File.Exists(fileName))
            {
                File.Delete(fileName);
            }

            string jsonContents = JsonConvert.SerializeObject(languageList);

            File.WriteAllText(fileName, jsonContents);
        }
Exemplo n.º 5
0
        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;
        }