public async Task FetchAsync(Func <string, T> addRawCallBack) { await _dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { this.Clear(); }); var lines = await FileIOEx.ReadFileAsync(_folder, _fileName, "Shift-JIS"); foreach (var line in lines) { var item = addRawCallBack(line); await _dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { this.Add(item); }); } }
private async Task RemoveItemToFileAsync(StorageFolder folder, string fileName, ICsvItem item) { var lines = await FileIOEx.ReadFileAsync(folder, fileName, "Shift-JIS"); var existIndex = -1; for (int i = 0; i < lines.Count; i++) { string[] cols = lines[i].Split(','); if (cols[0] == item.CsvRawName) { existIndex = i; break; } } if (existIndex != -1) { lines.RemoveAt(existIndex); } await FileIOEx.SaveFileAsync(folder, fileName, lines, "Shift-JIS"); }
private async Task AddItemToFileAsync(StorageFolder folder, string fileName, ICsvItem item) { var lines = await FileIOEx.ReadFileAsync(folder, fileName, "Shift-JIS"); var isExist = false; for (int i = 0; i < lines.Count; i++) { string[] cols = lines[i].Split(','); if (cols[0] == item.CsvRawName) { lines[i] = item.GetCsvRaw(); isExist = true; } } if (!isExist) { lines.Add(item.GetCsvRaw()); } await FileIOEx.SaveFileAsync(folder, fileName, lines, "Shift-JIS"); }