/// <summary> /// Select a logging profile. /// </summary> private async void selectProfile_Click(object sender, EventArgs e) { OpenFileDialog dialog = new OpenFileDialog(); dialog.AddExtension = true; dialog.CheckFileExists = true; dialog.AutoUpgradeEnabled = true; dialog.CheckPathExists = true; dialog.DefaultExt = ".profile"; dialog.Multiselect = false; dialog.ValidateNames = true; dialog.Filter = "Logging profiles (*.profile)|*.profile"; if (dialog.ShowDialog() == DialogResult.OK) { await this.LoadProfile(dialog.FileName); } else { this.profileAndMath = null; this.profileName = null; } this.UpdateStartStopButtonState(); }
/// <summary> /// Load the profile from the given path. /// </summary> private async Task LoadProfile(string path) { try { LogProfile profile; if (path.EndsWith(".json.profile")) { using (Stream stream = File.OpenRead(path)) { LogProfileReader reader = new LogProfileReader(stream); profile = await reader.ReadAsync(); } string newPath = Path.GetFileNameWithoutExtension(Path.GetFileNameWithoutExtension(path)) + ".xml.profile"; using (Stream xml = File.OpenWrite(newPath)) { LogProfileXmlWriter writer = new LogProfileXmlWriter(xml); writer.Write(profile); } } else if (path.EndsWith(".xml.profile")) { using (Stream stream = File.OpenRead(path)) { LogProfileXmlReader reader = new LogProfileXmlReader(stream); profile = reader.Read(); } } else { return; } this.profilePath.Text = path; this.profileName = Path.GetFileNameWithoutExtension(this.profilePath.Text); MathValueConfigurationLoader loader = new MathValueConfigurationLoader(this); loader.Initialize(); this.profileAndMath = new LogProfileAndMath(profile, loader.Configuration); this.logValues.Text = string.Join(Environment.NewLine, this.profileAndMath.GetColumnNames()); LoggerConfiguration.ProfilePath = path; } catch (Exception exception) { this.logValues.Text = exception.Message; this.AddDebugMessage(exception.ToString()); this.profilePath.Text = "[no profile loaded]"; this.profileName = null; } }
/// <summary> /// Constructor. /// </summary> public Logger(Vehicle vehicle, LogProfileAndMath profileAndMath, MathValueConfiguration mathValueConfiguration) { this.vehicle = vehicle; this.profileAndMath = profileAndMath; }