public IEnumerable <FileKeyPathDto> GetJsonFiles() { var dir = new DirectoryInfo(Options.FolderPath); if (!dir.Exists) { yield break; } var files = dir.GetFiles("*.json", SearchOption.AllDirectories); foreach (var file in files) { var displayName = Path.GetFileNameWithoutExtension(file.FullName); var language = DefaultLanguage; int lastIndexOfDot = displayName.LastIndexOf('.'); if (lastIndexOfDot != -1) { var parts = displayName.Split('.'); displayName = parts[0]; language = parts[1]; } var dtoItem = new FileKeyPathDto { Key = Path.GetFileName(file.FullName), FilePath = file.FullName, DisplayName = displayName, Language = language }; yield return(dtoItem); } }
public async Task SaveJsonData(FileKeyPathDto fileData, IDictionary <string, string> data) { var saveData = data.OrderBy(o => o.Key).ToList(); var jsonSettings = new JsonSerializerSettings { Formatting = Formatting.Indented, ContractResolver = new DefaultContractResolver() }; var jsonData = CustomJsonSerialize(data); await File.WriteAllTextAsync(fileData.FilePath, jsonData, Encoding.Latin1); }
public async Task <Dictionary <string, string> > GetJsonData(FileKeyPathDto fileData) { if (!File.Exists(fileData.FilePath)) { return(new Dictionary <string, string>()); } var fileString = await File.ReadAllTextAsync(fileData.FilePath, Encoding.Latin1); var data = JsonConvert.DeserializeObject <Dictionary <string, string> >(fileString); return(data.OrderBy(o => o.Key).ToDictionary(k => k.Key, v => v.Value)); }