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))); } } }
/// <summary> /// 駅の列車データを取得します。 /// </summary> /// <returns></returns> private async Task GetStationData() { TrainDataFile data = null; try { data = await TrainInfoReader.GetTrainDataAsync(station.StationId); trainDataFile = data; } catch (Exception ex) { EventHandler <DialogClickEventArgs> eventHandler = (object sender, DialogClickEventArgs e) => { if (e.Which == -1) { GetStationData(); } if (e.Which == -2) { Finish(); } }; new AlertDialog.Builder(this) .SetTitle("ネットワークエラー") .SetMessage($"データを取得できませんでした。端末のネットワーク接続状況をご確認ください。{System.Environment.NewLine}エラーの詳細:{ex.Message}") .SetPositiveButton("再試行", eventHandler) .SetNegativeButton("戻る", eventHandler) .Show(); return; } }
public void RenderData(TrainDataFile trainDataFile) { Title = $"{trainDataFile.Station} - {trainDataFile.GetedDateTime.ToString()}"; RenderGridData(trainDataFile.DepartureTrainDatas, false, DiparturesGrid); RenderGridData(trainDataFile.ArrivalTrainDatas, true, ArrivalsGrid); }
private async void SearchButton_Click(object sender, RoutedEventArgs e) { var station = StationReader.GetStationByName(StationSerchTextBox.Text); if (station is null) { MessageBox.Show($"{StationSerchTextBox.Text}は見つかりませんでした"); } else { SelectedSource = await TrainInfoReader.GetTrainDataAsync(station.StationId); this.Close(); } }
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); }
public async Task SaveTrainData(int id) { var jsonData = await TrainInfoReader.GetTrainDataJsonAsync(id); TrainDataFile td = null; if (id < 5) { td = await TrainInfoReader.GetTrainDataAsync(jsonData); } else { td = (await TrainInfoReader.GetSpecialTrainDatasAsync(jsonData)).FirstOrDefault(); } var path = $"{FolderPath}\\{GetSaveFileName(id, td?.GetedDateTime ?? DateTime.Now)}.json"; SaveJsonData(path, jsonData); }
private async void OpenLocalFileButton_Click(object sender, RoutedEventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "Jsonファイル(*.json)|*.json"; openFileDialog.Title = "開く列車情報を選択"; openFileDialog.ShowDialog(); var file = openFileDialog.FileName; var trainDataFile = TryPaeseTrainDataFile(file); if (trainDataFile != null) { this.SelectedSource = trainDataFile; this.Close(); } else { var data = await SaveFileReader.ReadJsonDataAsync(file); this.SelectedSource = data; this.Close(); } }
public StationDataView(TrainDataFile trainDataFile) { TrainDataFile = trainDataFile; InitializeComponent(); SetData(); }