Пример #1
0
        private async void OpenJsonButton_Click(object sender, RoutedEventArgs e)
        {
            var openFileDialog = new System.Windows.Forms.OpenFileDialog
            {
                Filter = "Jsonファイル|*.json"
            };

            openFileDialog.ShowDialog();
            var fileName = openFileDialog.FileName;

            if (SaveFileReader.TryGetIdInFileName(Path.GetFileName(fileName), out var n))
            {
                if (n > 0 && n < 6)
                {
                    var data = await SaveFileReader.ReadSpecialJsonDataAsync(fileName);

                    var trainDataFileViewer = new TrainDataFileViewer();
                    trainDataFileViewer.RenderData(data.First());
                    trainDataFileViewer.Show();
                }
                else
                {
                    var data = await SaveFileReader.ReadJsonDataAsync(fileName);

                    var trainDataFileViewer = new TrainDataFileViewer();
                    trainDataFileViewer.RenderData(data);
                    trainDataFileViewer.Show();
                }
            }
        }
Пример #2
0
        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();
            }
        }
Пример #3
0
        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)));
                }
            }
        }