diff --git a/Signal Generator/MainWindow.xaml b/Signal Generator/MainWindow.xaml index 99a2495..d714933 100644 --- a/Signal Generator/MainWindow.xaml +++ b/Signal Generator/MainWindow.xaml @@ -5,7 +5,7 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:Signal_Generator" mc:Ignorable="d" - Title="Генератор сигналов" Height="450" Width="600"> + Title="Генератор сигналов" Height="450" Width="600" Closing="Window_Closing"> diff --git a/Signal Generator/MainWindow.xaml.cs b/Signal Generator/MainWindow.xaml.cs index 74253d3..6c15f68 100644 --- a/Signal Generator/MainWindow.xaml.cs +++ b/Signal Generator/MainWindow.xaml.cs @@ -28,6 +28,8 @@ namespace Signal_Generator public MainWindow() { InitializeComponent(); + var c = Properties.Settings.LoadSignals(); + if (c != null) multiSignal.signals = c; signals_ListBox.Items.Clear(); signals_ListBox.ItemsSource = multiSignal.signals; } @@ -69,5 +71,10 @@ namespace Signal_Generator var x = signals_ListBox.SelectedItem as IAnalogSignal; multiSignal.Remove(x); } + + private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) + { + Properties.Settings.SaveSignals(multiSignal.signals); + } } } diff --git a/Signal Generator/Settings.cs b/Signal Generator/Settings.cs index 58529f6..760ce1b 100644 --- a/Signal Generator/Settings.cs +++ b/Signal Generator/Settings.cs @@ -1,4 +1,8 @@ -namespace Signal_Generator.Properties { +using System.Collections.ObjectModel; +using System.IO; +using System.Runtime.Serialization.Formatters.Binary; + +namespace Signal_Generator.Properties { // Этот класс позволяет обрабатывать определенные события в классе параметров: @@ -11,9 +15,9 @@ public Settings() { // // Для добавления обработчиков событий для сохранения и изменения параметров раскомментируйте приведенные ниже строки: // - // this.SettingChanging += this.SettingChangingEventHandler; + this.SettingChanging += this.SettingChangingEventHandler; // - // this.SettingsSaving += this.SettingsSavingEventHandler; + this.SettingsSaving += this.SettingsSavingEventHandler; // } @@ -24,5 +28,24 @@ private void SettingsSavingEventHandler(object sender, System.ComponentModel.CancelEventArgs e) { // Добавьте здесь код для обработки события SettingsSaving. } + + public static void SaveSignals(ObservableCollection signals) + { + BinaryFormatter formatter = new BinaryFormatter(); + using (FileStream fs = new FileStream("settings.dat", FileMode.OpenOrCreate)) + { + formatter.Serialize(fs, signals); + } + } + + public static ObservableCollection LoadSignals() + { + BinaryFormatter formatter = new BinaryFormatter(); + using (FileStream fs = new FileStream("settings.dat", FileMode.Open)) + { + if (!fs.CanRead) return null; + return (ObservableCollection)formatter.Deserialize(fs); + } + } } } diff --git a/Signal Generator/Signal/Base/AnalogSignalMethods.cs b/Signal Generator/Signal/Base/AnalogSignalMethods.cs index f33c087..ed44ef7 100644 --- a/Signal Generator/Signal/Base/AnalogSignalMethods.cs +++ b/Signal Generator/Signal/Base/AnalogSignalMethods.cs @@ -7,6 +7,7 @@ using System.Threading.Tasks; namespace Signal_Generator { + [Serializable] class AnalogSignalMethods { protected string paramsToString(Collection paramsCollection) diff --git a/Signal Generator/Signal/Base/Parameter.cs b/Signal Generator/Signal/Base/Parameter.cs index 90abca8..a2ab08c 100644 --- a/Signal Generator/Signal/Base/Parameter.cs +++ b/Signal Generator/Signal/Base/Parameter.cs @@ -6,6 +6,7 @@ using System.Threading.Tasks; namespace Signal_Generator { + [Serializable] class Parameter { public string name { get; set; } diff --git a/Signal Generator/Signal/FmSignal.cs b/Signal Generator/Signal/FmSignal.cs index c0bcf16..8f0e190 100644 --- a/Signal Generator/Signal/FmSignal.cs +++ b/Signal Generator/Signal/FmSignal.cs @@ -7,6 +7,7 @@ using System.Threading.Tasks; namespace Signal_Generator { + [Serializable] class FmSignal : AnalogSignalMethods, IAnalogSignal { public Collection paramsCollection { get; set; } diff --git a/Signal Generator/Signal/MultiSignal.cs b/Signal Generator/Signal/MultiSignal.cs index e9a8e5a..744afee 100644 --- a/Signal Generator/Signal/MultiSignal.cs +++ b/Signal Generator/Signal/MultiSignal.cs @@ -10,7 +10,7 @@ namespace Signal_Generator public class MultiSignal : IAnalogSignal { private static MultiSignal instance; - internal ObservableCollection signals { get; private set; } + internal ObservableCollection signals { get; set; } private MultiSignal() { diff --git a/Signal Generator/Signal/SinusoidalSignal.cs b/Signal Generator/Signal/SinusoidalSignal.cs index 168a64d..da1ec6b 100644 --- a/Signal Generator/Signal/SinusoidalSignal.cs +++ b/Signal Generator/Signal/SinusoidalSignal.cs @@ -7,6 +7,7 @@ using System.Threading.Tasks; namespace Signal_Generator { + [Serializable] class SinusoidalSignal : AnalogSignalMethods, IAnalogSignal { public string typeToString => "SIN сигнал";