From 7322129eb7b1f4cab23b5f1473cf7d8f5f4e5642 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0?= Date: Sun, 11 Nov 2018 12:31:16 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=B7=D0=B0=D0=B3=D1=80=D1=83=D0=B7=D0=BA=D0=B0?= =?UTF-8?q?=20=D0=B8=20=D1=81=D0=BE=D1=85=D1=80=D0=B0=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D1=81=D0=B8=D0=B3=D0=BD=D0=B0=D0=BB=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Signal Generator/MainWindow.xaml | 2 +- Signal Generator/MainWindow.xaml.cs | 7 +++++ Signal Generator/Settings.cs | 29 +++++++++++++++++-- .../Signal/Base/AnalogSignalMethods.cs | 1 + Signal Generator/Signal/Base/Parameter.cs | 1 + Signal Generator/Signal/FmSignal.cs | 1 + Signal Generator/Signal/MultiSignal.cs | 2 +- Signal Generator/Signal/SinusoidalSignal.cs | 1 + 8 files changed, 39 insertions(+), 5 deletions(-) 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 сигнал";