Browse Source

Добавлена загрузка и сохранение сигналов

master
Никита 6 years ago
parent
commit
7322129eb7
  1. 2
      Signal Generator/MainWindow.xaml
  2. 7
      Signal Generator/MainWindow.xaml.cs
  3. 29
      Signal Generator/Settings.cs
  4. 1
      Signal Generator/Signal/Base/AnalogSignalMethods.cs
  5. 1
      Signal Generator/Signal/Base/Parameter.cs
  6. 1
      Signal Generator/Signal/FmSignal.cs
  7. 2
      Signal Generator/Signal/MultiSignal.cs
  8. 1
      Signal Generator/Signal/SinusoidalSignal.cs

2
Signal Generator/MainWindow.xaml

@ -5,7 +5,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Signal_Generator" xmlns:local="clr-namespace:Signal_Generator"
mc:Ignorable="d" mc:Ignorable="d"
Title="Генератор сигналов" Height="450" Width="600"> Title="Генератор сигналов" Height="450" Width="600" Closing="Window_Closing">
<Grid Margin="10"> <Grid Margin="10">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="*"/> <RowDefinition Height="*"/>

7
Signal Generator/MainWindow.xaml.cs

@ -28,6 +28,8 @@ namespace Signal_Generator
public MainWindow() public MainWindow()
{ {
InitializeComponent(); InitializeComponent();
var c = Properties.Settings.LoadSignals();
if (c != null) multiSignal.signals = c;
signals_ListBox.Items.Clear(); signals_ListBox.Items.Clear();
signals_ListBox.ItemsSource = multiSignal.signals; signals_ListBox.ItemsSource = multiSignal.signals;
} }
@ -69,5 +71,10 @@ namespace Signal_Generator
var x = signals_ListBox.SelectedItem as IAnalogSignal; var x = signals_ListBox.SelectedItem as IAnalogSignal;
multiSignal.Remove(x); multiSignal.Remove(x);
} }
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
Properties.Settings.SaveSignals(multiSignal.signals);
}
} }
} }

29
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() { 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) { private void SettingsSavingEventHandler(object sender, System.ComponentModel.CancelEventArgs e) {
// Добавьте здесь код для обработки события SettingsSaving. // Добавьте здесь код для обработки события SettingsSaving.
} }
public static void SaveSignals(ObservableCollection<IAnalogSignal> signals)
{
BinaryFormatter formatter = new BinaryFormatter();
using (FileStream fs = new FileStream("settings.dat", FileMode.OpenOrCreate))
{
formatter.Serialize(fs, signals);
}
}
public static ObservableCollection<IAnalogSignal> LoadSignals()
{
BinaryFormatter formatter = new BinaryFormatter();
using (FileStream fs = new FileStream("settings.dat", FileMode.Open))
{
if (!fs.CanRead) return null;
return (ObservableCollection<IAnalogSignal>)formatter.Deserialize(fs);
}
}
} }
} }

1
Signal Generator/Signal/Base/AnalogSignalMethods.cs

@ -7,6 +7,7 @@ using System.Threading.Tasks;
namespace Signal_Generator namespace Signal_Generator
{ {
[Serializable]
class AnalogSignalMethods class AnalogSignalMethods
{ {
protected string paramsToString(Collection<Parameter> paramsCollection) protected string paramsToString(Collection<Parameter> paramsCollection)

1
Signal Generator/Signal/Base/Parameter.cs

@ -6,6 +6,7 @@ using System.Threading.Tasks;
namespace Signal_Generator namespace Signal_Generator
{ {
[Serializable]
class Parameter class Parameter
{ {
public string name { get; set; } public string name { get; set; }

1
Signal Generator/Signal/FmSignal.cs

@ -7,6 +7,7 @@ using System.Threading.Tasks;
namespace Signal_Generator namespace Signal_Generator
{ {
[Serializable]
class FmSignal : AnalogSignalMethods, IAnalogSignal class FmSignal : AnalogSignalMethods, IAnalogSignal
{ {
public Collection<Parameter> paramsCollection { get; set; } public Collection<Parameter> paramsCollection { get; set; }

2
Signal Generator/Signal/MultiSignal.cs

@ -10,7 +10,7 @@ namespace Signal_Generator
public class MultiSignal : IAnalogSignal public class MultiSignal : IAnalogSignal
{ {
private static MultiSignal instance; private static MultiSignal instance;
internal ObservableCollection<IAnalogSignal> signals { get; private set; } internal ObservableCollection<IAnalogSignal> signals { get; set; }
private MultiSignal() private MultiSignal()
{ {

1
Signal Generator/Signal/SinusoidalSignal.cs

@ -7,6 +7,7 @@ using System.Threading.Tasks;
namespace Signal_Generator namespace Signal_Generator
{ {
[Serializable]
class SinusoidalSignal : AnalogSignalMethods, IAnalogSignal class SinusoidalSignal : AnalogSignalMethods, IAnalogSignal
{ {
public string typeToString => "SIN сигнал"; public string typeToString => "SIN сигнал";

Loading…
Cancel
Save