예제 #1
0
        private async void ButtonSave_Click(object sender, RoutedEventArgs e)
        {
            if (!recorderLogic.CanSave)
            {
                MessageBox.Show("Nothing to save!");
                return;
            }

            var dialog = new SaveFileDialog
            {
                FileName = $"{DateTime.Now:yyyy-MM-dd-HH-mm}.flightrecorder",
                Filter   = "Recorded Flight|*.flightrecorder"
            };

            if (dialog.ShowDialog() == true)
            {
                var data       = recorderLogic.ToData(currentVersion);
                var dataString = JsonSerializer.Serialize(data);

                try
                {
                    using (var fileStream = new FileStream(dialog.FileName, FileMode.Create))
                    {
                        using var outStream = new ZipOutputStream(fileStream);

                        outStream.SetLevel(9);

                        var entry = new ZipEntry("data.json")
                        {
                            DateTime = DateTime.Now
                        };
                        outStream.PutNextEntry(entry);

                        var writer = new StreamWriter(outStream);
                        writer.Write(dataString);
                        writer.Flush();

                        outStream.Finish();
                    }

                    await stateMachine.TransitAsync(StateMachine.Event.Save);

                    logger.LogDebug("Saved file into {fileName}", dialog.FileName);
                }
                catch (UnauthorizedAccessException)
                {
                    MessageBox.Show("Flight Recorder cannot write the file to disk.\nPlease make sure the folder is accessible by Flight Recorder, and you are not overwriting a locked file.", "Flight Recorder", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }
예제 #2
0
        private async void ButtonSave_Click(object sender, RoutedEventArgs e)
        {
            if (!recorderLogic.CanSave)
            {
                MessageBox.Show("Nothing to save!");
                return;
            }

            var dialog = new SaveFileDialog
            {
                FileName = $"{DateTime.Now:yyyy-MM-dd-HH-mm}.flightrecorder",
                Filter   = "Recorded Flight|*.flightrecorder"
            };

            if (dialog.ShowDialog() == true)
            {
                var data       = recorderLogic.ToData(currentVersion);
                var dataString = JsonSerializer.Serialize(data);

                using (var fileStream = new FileStream(dialog.FileName, FileMode.Create))
                {
                    using var outStream = new ZipOutputStream(fileStream);

                    outStream.SetLevel(9);

                    var entry = new ZipEntry("data.json")
                    {
                        DateTime = DateTime.Now
                    };
                    outStream.PutNextEntry(entry);

                    var writer = new StreamWriter(outStream);
                    writer.Write(dataString);
                    writer.Flush();

                    outStream.Finish();

                    await stateMachine.TransitAsync(StateMachine.Event.Save);
                }

                logger.LogDebug("Save file into {fileName}", dialog.FileName);
            }
        }
예제 #3
0
 private bool StopRecording()
 {
     recorderLogic.StopRecording();
     replayLogic.FromData(null, recorderLogic.ToData(currentVersion));
     return(true);
 }