private void CreateNewPrinterSettingsFile() { printerSettings = new Settings { XAxis = new Axis { Minimum = 0, Maximum = 40, PointsPerMillimeter = 10}, YAxis = new Axis { Minimum = 0, Maximum = 20, PointsPerMillimeter = 10 }, ZAxis = new Axis { Minimum = 0, Maximum = 80, PointsPerMillimeter = 20 } }; var json = JsonConvert.SerializeObject(printerSettings); var createNewSettingsFileDialog = new SaveFileDialog { InitialDirectory = SettingsFolder, DefaultExt = ".json", Filter = "Files (.json)|*.json|All files (*.*)|*.*", CheckPathExists = true }; createNewSettingsFileDialog.ShowDialog(); if (createNewSettingsFileDialog.FileName != "") { SettingsFolder = Path.GetDirectoryName(createNewSettingsFileDialog.FileName); SettingsFile = Path.GetFileName(createNewSettingsFileDialog.FileName); LabelSettingsFolder.Content = SettingsFolder; TextSettingsFileName.Text = SettingsFile; File.WriteAllText(createNewSettingsFileDialog.FileName, json); } }
public void LoadJsonSettings() { using (var r = new StreamReader(Path.Combine(SettingsFolder, SettingsFile))) { var json = r.ReadToEnd(); printerSettings = JsonConvert.DeserializeObject<Settings>(json); } }