private void SaveAndExitButton_Click(object sender, RoutedEventArgs e) { var configFile = new RegexTesterConfigurationFile { CurrentExpression = ExpressionTextBox.Text, CurrentReplacementText = ReplacementTextTextBox.Text, CurrentTestData = DataTextBox.Text }; configFile.Save(); Application.Current.Shutdown(); }
public MainWindow() { InitializeComponent(); regexWorker.DoWork += RegexWorkerDoWork; regexWorker.RunWorkerCompleted += RegexWorkerWorkComplete; var configFile = RegexTesterConfigurationFile.Load(); if (configFile != null) { DataTextBox.Text = configFile.CurrentTestData; ExpressionTextBox.Text = configFile.CurrentExpression; ReplacementTextTextBox.Text = configFile.CurrentReplacementText; } SetupAndRunRegexWorker(); }
public static RegexTesterConfigurationFile Load() { RegexTesterConfigurationFile config = null; if (File.Exists(CFG_FILE_NAME)) { var serializer = new BinaryFormatter(); FileStream configStream = File.OpenRead(CFG_FILE_NAME); if (configStream != null) { try { config = (RegexTesterConfigurationFile)serializer.Deserialize(configStream); } catch (Exception) { } configStream.Close(); } } return(config); }