public static async Task <TrainDataFile[]> ReadSpecialJsonDataAsync(string path) { using (var streamReader = new StreamReader(path, encoding)) { return(await TrainInfoReader.GetSpecialTrainDatasAsync(streamReader.ReadToEnd())); } }
private async static Task <IEnumerable <TrainPositionData> > GetPositionDatas(IEnumerable <TrainDataFile> trainDataFiles) { Dictionary <int, TrainDataFile> dict = new Dictionary <int, TrainDataFile>(); foreach (var tdf in trainDataFiles) { dict.Add(tdf.Station.StationId, tdf); } var lines = Enum.GetValues(typeof(JrhLine)).Cast <JrhLine>(); var result = new List <TrainPositionData>(); foreach (var line in lines) { if (line == JrhLine.Sekisyo) { continue; } try { var(arrivalData, departureData) = await TrainInfoReader.GetTrainPositionDataAsync(line, dict); result.Add(arrivalData); result.Add(departureData); } catch (NotImplementedException ex) { } } return(result); }
/// <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; } }
private async void Window_Initialized(object sender, EventArgs e) { var data = await TrainInfoReader.GetTrainDataAsync(91); this.AddTab(new StationDataView(data), $"駅列車情報 - {data.Station.Name}"); MainTab.SelectedIndex = 0; this.AddHandler(ClosableTabItem.TabClosedEvent, new RoutedEventHandler(CloseTab)); }
private void DoRedirect_CheckedChange(object sender, CompoundButton.CheckedChangeEventArgs e) { if (e.IsChecked) { TrainInfoReader.SetRedirect(new InternalSavedDataReader()); } else { TrainInfoReader.ClearRedirect(); } }
private void DoRedirectCheckBox_Checked(object sender, RoutedEventArgs e) { if (Directory.Exists(redirectFolder)) { TrainInfoReader.SetRedirect(new SaveFileReader(redirectFolder)); } else { MessageBox.Show("リダイレクト元フォルダが存在しません"); DoRedirectCheckBox.IsChecked = false; } }
private static async Task <Dictionary <int, TrainDataFile> > GetTrainDatas(params int[] id) { var result = new Dictionary <int, TrainDataFile>(); var stations = id.Select(n => StationReader.GetStationById(n)); var inAreaStaion = stations.Where(std => std.StationArea == 0).ToArray(); var outAreaStation = stations.Where(std => std.StationArea != 0); var count = 0; if (inAreaStaion.Any()) { TrainDataFile[] array = default; do { array = await Task.WhenAll(inAreaStaion.Select(n => TrainInfoReader.GetTrainDataAsync(n.StationId))); for (var i = 0; i < array.Length; i++) { result.Add(inAreaStaion[i].StationId, array[i]); } count++; if (count > 3) { throw new TrainDataTimeSyncException(result, "時刻が同期できません"); } if (count > 1) { Debuggers.LogWriter.WriteLog($"列車位置計算用の列車情報の時刻同期に失敗...再試行します"); } }while (!CheckTrainDataFiles(array)); } if (outAreaStation.Any()) { var need = outAreaStation.Select(std => std.StationArea).Distinct().ToArray(); var array = await Task.WhenAll(need.Select(n => TrainInfoReader.GetSpecialTrainDatasAsync(n))); foreach (var station in outAreaStation) { var index = Array.IndexOf(need, station.StationArea); result.Add(station.StationId, array[index].First(td => td.Station == station)); } } return(result); }
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 SaveJsonButton_Click(object sender, RoutedEventArgs e) { if (TryGetStationId(StationIdTextBox.Text, out var id)) { var saveFileDialog = new System.Windows.Forms.SaveFileDialog() { FileName = SaveFileWriter.GetSaveFileName(id), Filter = "jsonファイル|*.json", }; saveFileDialog.ShowDialog(); var path = saveFileDialog.FileName; var data = await TrainInfoReader.GetTrainDataJsonAsync(id); SaveFileWriter.SaveJsonData(path, data); } else { MessageBox.Show("駅IDの入力が正しくありません。"); } }
private async void PreviewCurrentButton_Click(object sender, RoutedEventArgs e) { if (TryGetStationId(StationIdTextBox.Text, out var n)) { try { if (n > 5 || n == 1) { var data = await TrainInfoReader.GetTrainDataAsync(n); var trainDataFileViewer = new TrainDataFileViewer(); trainDataFileViewer.RenderData(data); trainDataFileViewer.Show(); } else { var data = await TrainInfoReader.GetSpecialTrainDatasAsync(n); var firstData = data.First(); var trainDataFileViewer = new TrainDataFileViewer(); trainDataFileViewer.RenderData(firstData); trainDataFileViewer.Show(); } } catch (System.Net.Http.HttpRequestException ex) { var result = MessageBox.Show($"データ取得中にエラーが発生しました。駅IDが不正な可能性があります。{Environment.NewLine}エラーの種類:{ex.ToString()}{Environment.NewLine}処理を続行しますか?", "エラー処理", MessageBoxButton.YesNo, MessageBoxImage.Error); if (result == MessageBoxResult.No) { throw; } } } else { MessageBox.Show("駅IDの入力が正しくありません。"); } }
private void DoRedirectCheckBox_Unchecked(object sender, RoutedEventArgs e) { TrainInfoReader.ClearRedirect(); }
public Window1() { TrainInfoReader.SetRedirect(new TrainInfo.Debuggers.InternalSavedDataReader()); InitializeComponent(); }
private async void RenderData(JrhLine jrhLine) { trainPostionLinearLayout.RemoveAllViews(); var(arrivalData, departureData) = await TrainInfoReader.GetTrainPositionDataAsync(jrhLine); for (var i = 0; i < arrivalData.Count; i++) { var lineRangeLinearLayout = new LinearLayout(this) { Orientation = Orientation.Horizontal }; var stationAreaLayout = new LinearLayout(this) { Orientation = Orientation.Vertical }; var stationLayoutParams = new LinearLayout.LayoutParams(0, -1) { Weight = 2 }; if (arrivalData[i].Item1.IsStation) { lineRangeLinearLayout.SetBackgroundColor(Android.Graphics.Color.Argb(0xff, 0xea, 0xea, 0xea)); var textView = new TextView(this) { Text = arrivalData[i].Item1.StartPos.Name, TextSize = 16, }; textView.SetPadding(30, 20, 0, 0); textView.Typeface = Typeface.DefaultBold; stationAreaLayout.AddView(textView); } else { lineRangeLinearLayout.SetBackgroundColor(Android.Graphics.Color.Argb(0xff, 0xff, 0xff, 0xff)); } lineRangeLinearLayout.AddView(stationAreaLayout, stationLayoutParams); var arrLayoutParams = new LinearLayout.LayoutParams(0, -1) { Weight = 3 }; var arrTrainLinearLayout = new LinearLayout(this) { Orientation = Orientation.Vertical }; var depLayoutParams = new LinearLayout.LayoutParams(0, -1) { Weight = 3 }; var depTrainLinearLayout = new LinearLayout(this) { Orientation = Orientation.Vertical }; foreach (var arr in arrivalData[i].Item2) { var textView = new TextView(this) { Text = $"↑{arr.Name.TrainType.GetName()} {arr.Destination.Name}行", }; arrTrainLinearLayout.AddView(textView); } foreach (var dep in departureData[i].Item2) { var textView = new TextView(this) { Text = $"↓{dep.Name.TrainType.GetName()} {dep.Destination.Name}行", }; depTrainLinearLayout.AddView(textView); } lineRangeLinearLayout.AddView(arrTrainLinearLayout, arrLayoutParams); lineRangeLinearLayout.AddView(depTrainLinearLayout, depLayoutParams); trainPostionLinearLayout.AddView(lineRangeLinearLayout, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, 250)); } GettedTimeTextView.Text = $"{ DateTime.Now.ToString()} 現在の情報"; }