private async void MargeTrainDataButton_Click(object sender, RoutedEventArgs e) { var folderBrowserDialog = new FolderBrowserDialog() { Description = "結合対象の運行情報データがあるフォルダーを選択", }; folderBrowserDialog.ShowDialog(); var directories = Directory.GetDirectories(folderBrowserDialog.SelectedPath); var directoryDatas = await Task.WhenAll(directories.Select(async dir => await Task.WhenAll(Directory.GetFiles(dir, "*.json") .Select(file => SaveFileReader.ReadJsonDataAsync(file))))); var dict = GetTrainDataDictionary(directoryDatas); var result = dict.Select(kvp => TrainDataFile.MargeTrainDataFile(kvp.Value.ToArray())); var folderBrowserDialog2 = new FolderBrowserDialog() { Description = "結合結果の保存先を選択", }; folderBrowserDialog2.ShowDialog(); foreach (var data in result) { using (var streamWriter = new StreamWriter (folderBrowserDialog2.SelectedPath + $"\\{data.Station.Name} {data.GetedDateTime.ToString("yyyy-MM-dd")}.json", false, Encoding.UTF8)) { streamWriter.Write(JsonConvert.SerializeObject(AnalyzedTrainFile.FromTrainDataFile(data))); } } }
private async void MargeTrainDataSameFolder() { var openFileDialog = new OpenFileDialog() { Filter = "*.json", Multiselect = true, }; openFileDialog.ShowDialog(); var files = await Task.WhenAll(openFileDialog.FileNames.Select(file => TrainInfoReader.GetTrainDataAsync(file))); var margeData = TrainDataFile.MargeTrainDataFile(files); var str = JsonConvert.SerializeObject(margeData); }