From e368afca1735ae2727b10554b673f8244d18496d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A0=D0=BE=D0=BC=D0=B0=D0=BD=D0=B5=D0=BD=D0=BA=D0=BE=20?= =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0=20=D0=A1=D1=82=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D1=81=D0=BB=D0=B0=D0=B2=D0=BE=D0=B2=D0=B8=D1=87?= Date: Wed, 28 Nov 2018 16:49:41 +0300 Subject: [PATCH] Add project files. --- SignalsMVVM.sln | 25 +++ SignalsMVVM/App.config | 6 + SignalsMVVM/App.xaml | 15 ++ SignalsMVVM/App.xaml.cs | 17 ++ SignalsMVVM/Assets/Styles.xaml | 13 ++ SignalsMVVM/Assets/Templates.xaml | 32 ++++ SignalsMVVM/FodyWeavers.xml | 5 + SignalsMVVM/FodyWeavers.xsd | 135 +++++++++++++++ .../BinaryFormatterSerialization.cs | 30 ++++ SignalsMVVM/HelperClasses/PropertyChanged.cs | 24 +++ SignalsMVVM/HelperClasses/RelayCommand.cs | 45 +++++ SignalsMVVM/Interfaces/IGraphicControl.cs | 10 ++ SignalsMVVM/Interfaces/IProcedureLogger.cs | 7 + SignalsMVVM/Interfaces/ISignalLoader.cs | 10 ++ SignalsMVVM/Interfaces/ISignalSaver.cs | 10 ++ SignalsMVVM/MainVM.cs | 106 ++++++++++++ SignalsMVVM/MainWindow.xaml | 126 ++++++++++++++ SignalsMVVM/MainWindow.xaml.cs | 13 ++ SignalsMVVM/Models/AmSignal.cs | 15 ++ SignalsMVVM/Models/BaseSignal.cs | 24 +++ SignalsMVVM/Models/FmSignal.cs | 11 ++ SignalsMVVM/Models/GraphicController.cs | 28 ++++ SignalsMVVM/Models/LogController.cs | 35 ++++ SignalsMVVM/Models/SignalController.cs | 45 +++++ SignalsMVVM/Properties/AssemblyInfo.cs | 55 +++++++ SignalsMVVM/Properties/Resources.Designer.cs | 71 ++++++++ SignalsMVVM/Properties/Resources.resx | 117 +++++++++++++ SignalsMVVM/Properties/Settings.Designer.cs | 30 ++++ SignalsMVVM/Properties/Settings.settings | 7 + SignalsMVVM/SignalsMVVM.csproj | 155 ++++++++++++++++++ SignalsMVVM/UI/Converters/HertzConverter.cs | 112 +++++++++++++ SignalsMVVM/UserControl1.xaml | 12 ++ SignalsMVVM/UserControl1.xaml.cs | 28 ++++ SignalsMVVM/packages.config | 7 + 34 files changed, 1381 insertions(+) create mode 100644 SignalsMVVM.sln create mode 100644 SignalsMVVM/App.config create mode 100644 SignalsMVVM/App.xaml create mode 100644 SignalsMVVM/App.xaml.cs create mode 100644 SignalsMVVM/Assets/Styles.xaml create mode 100644 SignalsMVVM/Assets/Templates.xaml create mode 100644 SignalsMVVM/FodyWeavers.xml create mode 100644 SignalsMVVM/FodyWeavers.xsd create mode 100644 SignalsMVVM/HelperClasses/BinaryFormatterSerialization.cs create mode 100644 SignalsMVVM/HelperClasses/PropertyChanged.cs create mode 100644 SignalsMVVM/HelperClasses/RelayCommand.cs create mode 100644 SignalsMVVM/Interfaces/IGraphicControl.cs create mode 100644 SignalsMVVM/Interfaces/IProcedureLogger.cs create mode 100644 SignalsMVVM/Interfaces/ISignalLoader.cs create mode 100644 SignalsMVVM/Interfaces/ISignalSaver.cs create mode 100644 SignalsMVVM/MainVM.cs create mode 100644 SignalsMVVM/MainWindow.xaml create mode 100644 SignalsMVVM/MainWindow.xaml.cs create mode 100644 SignalsMVVM/Models/AmSignal.cs create mode 100644 SignalsMVVM/Models/BaseSignal.cs create mode 100644 SignalsMVVM/Models/FmSignal.cs create mode 100644 SignalsMVVM/Models/GraphicController.cs create mode 100644 SignalsMVVM/Models/LogController.cs create mode 100644 SignalsMVVM/Models/SignalController.cs create mode 100644 SignalsMVVM/Properties/AssemblyInfo.cs create mode 100644 SignalsMVVM/Properties/Resources.Designer.cs create mode 100644 SignalsMVVM/Properties/Resources.resx create mode 100644 SignalsMVVM/Properties/Settings.Designer.cs create mode 100644 SignalsMVVM/Properties/Settings.settings create mode 100644 SignalsMVVM/SignalsMVVM.csproj create mode 100644 SignalsMVVM/UI/Converters/HertzConverter.cs create mode 100644 SignalsMVVM/UserControl1.xaml create mode 100644 SignalsMVVM/UserControl1.xaml.cs create mode 100644 SignalsMVVM/packages.config diff --git a/SignalsMVVM.sln b/SignalsMVVM.sln new file mode 100644 index 0000000..e7c63db --- /dev/null +++ b/SignalsMVVM.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.28307.106 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SignalsMVVM", "SignalsMVVM\SignalsMVVM.csproj", "{2F55AE30-8FA0-4175-83EB-236D1026F97D}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {2F55AE30-8FA0-4175-83EB-236D1026F97D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2F55AE30-8FA0-4175-83EB-236D1026F97D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2F55AE30-8FA0-4175-83EB-236D1026F97D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2F55AE30-8FA0-4175-83EB-236D1026F97D}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {EA5876EF-4AE7-40A4-AD8B-F47587567B11} + EndGlobalSection +EndGlobal diff --git a/SignalsMVVM/App.config b/SignalsMVVM/App.config new file mode 100644 index 0000000..731f6de --- /dev/null +++ b/SignalsMVVM/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/SignalsMVVM/App.xaml b/SignalsMVVM/App.xaml new file mode 100644 index 0000000..af64493 --- /dev/null +++ b/SignalsMVVM/App.xaml @@ -0,0 +1,15 @@ + + + + + + + + + + diff --git a/SignalsMVVM/App.xaml.cs b/SignalsMVVM/App.xaml.cs new file mode 100644 index 0000000..f236fed --- /dev/null +++ b/SignalsMVVM/App.xaml.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Data; +using System.Linq; +using System.Threading.Tasks; +using System.Windows; + +namespace SignalsMVVM +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + } +} diff --git a/SignalsMVVM/Assets/Styles.xaml b/SignalsMVVM/Assets/Styles.xaml new file mode 100644 index 0000000..d3cd742 --- /dev/null +++ b/SignalsMVVM/Assets/Styles.xaml @@ -0,0 +1,13 @@ + + + + + + + \ No newline at end of file diff --git a/SignalsMVVM/Assets/Templates.xaml b/SignalsMVVM/Assets/Templates.xaml new file mode 100644 index 0000000..176b397 --- /dev/null +++ b/SignalsMVVM/Assets/Templates.xaml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/SignalsMVVM/FodyWeavers.xml b/SignalsMVVM/FodyWeavers.xml new file mode 100644 index 0000000..743daa9 --- /dev/null +++ b/SignalsMVVM/FodyWeavers.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/SignalsMVVM/FodyWeavers.xsd b/SignalsMVVM/FodyWeavers.xsd new file mode 100644 index 0000000..3413e2f --- /dev/null +++ b/SignalsMVVM/FodyWeavers.xsd @@ -0,0 +1,135 @@ + + + + + + + + + + + Used to control if the On_PropertyName_Changed feature is enabled. + + + + + Used to change the name of the method that fires the notify event. This is a string that accepts multiple values in a comma separated form. + + + + + Used to control if equality checks should be inserted. If false, equality checking will be disabled for the project. + + + + + Used to control if equality checks should use the Equals method resolved from the base class. + + + + + Used to control if equality checks should use the static Equals method resolved from the base class. + + + + + + + + + + A list of assembly names to exclude from the default action of "embed all Copy Local references", delimited with line breaks + + + + + A list of assembly names to include from the default action of "embed all Copy Local references", delimited with line breaks. + + + + + A list of unmanaged 32 bit assembly names to include, delimited with line breaks. + + + + + A list of unmanaged 64 bit assembly names to include, delimited with line breaks. + + + + + The order of preloaded assemblies, delimited with line breaks. + + + + + + This will copy embedded files to disk before loading them into memory. This is helpful for some scenarios that expected an assembly to be loaded from a physical file. + + + + + Controls if .pdbs for reference assemblies are also embedded. + + + + + Embedded assemblies are compressed by default, and uncompressed when they are loaded. You can turn compression off with this option. + + + + + As part of Costura, embedded assemblies are no longer included as part of the build. This cleanup can be turned off. + + + + + Costura by default will load as part of the module initialization. This flag disables that behavior. Make sure you call CosturaUtility.Initialize() somewhere in your code. + + + + + Costura will by default use assemblies with a name like 'resources.dll' as a satellite resource and prepend the output path. This flag disables that behavior. + + + + + A list of assembly names to exclude from the default action of "embed all Copy Local references", delimited with | + + + + + A list of assembly names to include from the default action of "embed all Copy Local references", delimited with |. + + + + + A list of unmanaged 32 bit assembly names to include, delimited with |. + + + + + A list of unmanaged 64 bit assembly names to include, delimited with |. + + + + + The order of preloaded assemblies, delimited with |. + + + + + + + + 'true' to run assembly verification on the target assembly after all weavers have been finished. + + + + + A comma separated list of error codes that can be safely ignored in assembly verification. + + + + + \ No newline at end of file diff --git a/SignalsMVVM/HelperClasses/BinaryFormatterSerialization.cs b/SignalsMVVM/HelperClasses/BinaryFormatterSerialization.cs new file mode 100644 index 0000000..eb9390b --- /dev/null +++ b/SignalsMVVM/HelperClasses/BinaryFormatterSerialization.cs @@ -0,0 +1,30 @@ +using System.IO; +using System.Runtime.Serialization.Formatters.Binary; + +namespace SignalsMVVM.HelperClasses +{ + public static class BinaryFormatterSerialization + { + static private BinaryFormatter serializer = new BinaryFormatter(); + + public static T DeepCloneBinaryFormatter(this T obj) + { + return obj.SerializeBinaryFormatter().DeserializeBinaryFormatter(); + } + + public static byte[] SerializeBinaryFormatter(this T obj) + { + using (var ms = new MemoryStream()) + { + serializer.Serialize(ms, obj); + return ms.ToArray(); + } + } + + public static T DeserializeBinaryFormatter(this byte[] data) + { + using (var ms = new MemoryStream(data, false)) + return (T)serializer.Deserialize(ms); + } + } +} diff --git a/SignalsMVVM/HelperClasses/PropertyChanged.cs b/SignalsMVVM/HelperClasses/PropertyChanged.cs new file mode 100644 index 0000000..9dabbdf --- /dev/null +++ b/SignalsMVVM/HelperClasses/PropertyChanged.cs @@ -0,0 +1,24 @@ +using System; +using System.ComponentModel; +using System.Runtime.CompilerServices; + +namespace SignalsMVVM.HelperClasses +{ + [Serializable] + public class PropertyChangedClass : INotifyPropertyChanged + { + [field: NonSerialized] + public virtual event PropertyChangedEventHandler PropertyChanged; + + public virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } + + public virtual void OnPropertyChanged(params string[] propertyNames) + { + foreach (var property in propertyNames) + OnPropertyChanged(property); + } + } +} diff --git a/SignalsMVVM/HelperClasses/RelayCommand.cs b/SignalsMVVM/HelperClasses/RelayCommand.cs new file mode 100644 index 0000000..62f44f8 --- /dev/null +++ b/SignalsMVVM/HelperClasses/RelayCommand.cs @@ -0,0 +1,45 @@ +using System; +using System.Windows.Input; + +namespace SignalsMVVM.HelperClasses +{ + public class RelayCommand : ICommand + { + protected Action _execute; + protected Func _canExecute; + + protected RelayCommand() { } + + public RelayCommand(Action execute, Func canExecute) + { + if (execute == null) + throw new ArgumentNullException(nameof(execute)); + + _execute = execute; + _canExecute = canExecute ?? (p => true); + } + + public RelayCommand(Action execute) : this(execute, (Func)null) { } + public RelayCommand(Action execute, Func canExecute) : this(execute, p => canExecute()) { } + + public event EventHandler CanExecuteChanged + { + add { CommandManager.RequerySuggested += value; } + remove { CommandManager.RequerySuggested -= value; } + } + + public void Execute(object parameter) => _execute((T)parameter); + public bool CanExecute(object parameter) => _canExecute((T)parameter); + } + + public class RelayCommand : RelayCommand + { + public RelayCommand(Action execute, Func canExecute) : base(execute, canExecute) { } + + public RelayCommand(Action execute) : base(p => execute()) { } + public RelayCommand(Action execute, Func canExecute) : base(p => execute(), p => canExecute()) { } + + public RelayCommand(Action execute) : base(execute) { } + public RelayCommand(Action execute, Func canExecute) : base(execute, canExecute) { } + } +} diff --git a/SignalsMVVM/Interfaces/IGraphicControl.cs b/SignalsMVVM/Interfaces/IGraphicControl.cs new file mode 100644 index 0000000..8045452 --- /dev/null +++ b/SignalsMVVM/Interfaces/IGraphicControl.cs @@ -0,0 +1,10 @@ +using System.Windows.Media; + +namespace SignalsMVVM.Interfaces +{ + public interface IGraphicControl + { + void ClearGraphic(); + void DrawLine(double X1, double Y1, double X2, double Y2); + } +} diff --git a/SignalsMVVM/Interfaces/IProcedureLogger.cs b/SignalsMVVM/Interfaces/IProcedureLogger.cs new file mode 100644 index 0000000..04afd3a --- /dev/null +++ b/SignalsMVVM/Interfaces/IProcedureLogger.cs @@ -0,0 +1,7 @@ +namespace SignalsMVVM.Interfaces +{ + public interface IProcedureLogger + { + void ExecuteThread(); + } +} diff --git a/SignalsMVVM/Interfaces/ISignalLoader.cs b/SignalsMVVM/Interfaces/ISignalLoader.cs new file mode 100644 index 0000000..fdf69bd --- /dev/null +++ b/SignalsMVVM/Interfaces/ISignalLoader.cs @@ -0,0 +1,10 @@ +using SignalsMVVM.Models; +using System.Collections.Generic; + +namespace SignalsMVVM.Interfaces +{ + public interface ISignalLoader + { + IList LoadSignals(); + } +} diff --git a/SignalsMVVM/Interfaces/ISignalSaver.cs b/SignalsMVVM/Interfaces/ISignalSaver.cs new file mode 100644 index 0000000..a100a5b --- /dev/null +++ b/SignalsMVVM/Interfaces/ISignalSaver.cs @@ -0,0 +1,10 @@ +using SignalsMVVM.Models; +using System.Collections.Generic; + +namespace SignalsMVVM.Interfaces +{ + public interface ISignalSaver + { + void SaveSignals(IList signals); + } +} diff --git a/SignalsMVVM/MainVM.cs b/SignalsMVVM/MainVM.cs new file mode 100644 index 0000000..8976e22 --- /dev/null +++ b/SignalsMVVM/MainVM.cs @@ -0,0 +1,106 @@ +using SignalsMVVM.Models; +using SignalsMVVM.HelperClasses; +using System.Collections.ObjectModel; +using System.Threading; +using System.Windows; +using System.Windows.Threading; +using System; +using System.Collections.Generic; +using SignalsMVVM.Interfaces; +using Autofac; +using System.Windows.Media; + +namespace SignalsMVVM +{ + public class MainVM : PropertyChangedClass + { + public IList SignalPrototypes { get; set; } + public IList ListOfSignals { get; set; } + public IList ExecutionLog { get; set; } + + public BaseSignal SelectedSignalPrototype { get; set; } + public BaseSignal SelectedSignalInList { get; set; } + + public RelayCommand AddNewSignalToList { get; set; } + public RelayCommand RemoveSelectedSignalFromList { get; set; } + public RelayCommand StartProcedure { get; set; } + public RelayCommand AbortExecution { get; set; } + public RelayCommand SaveSettings { get; set; } + public RelayCommand LoadSettings { get; set; } + + public GeometryCollection CanvasGeometries { get; set; } + + public bool IsBusy { get; set; } + + private Thread CurrentThread; + + private Dispatcher dispatcher; + + private IContainer Container { get; set; } + + public MainVM() + { + SignalPrototypes = new ObservableCollection(); + SignalPrototypes.Add(new AmSignal("AM сигнал")); + SignalPrototypes.Add(new FmSignal("FM сигнал")); + ListOfSignals = new ObservableCollection(); + ExecutionLog = new ObservableCollection(); + CanvasGeometries = new GeometryCollection(); + + AddNewSignalToList = new RelayCommand(AddNew, () => { if (IsBusy) return false; return SelectedSignalPrototype != null; }); + RemoveSelectedSignalFromList = + new RelayCommand(RemoveSignalFromList, () => { if (IsBusy) return false; return SelectedSignalInList != null; }); + StartProcedure = new RelayCommand(Start, () => { if (IsBusy) return false; return ListOfSignals.Count > 0; }); + AbortExecution = new RelayCommand(AbortThreadExecution, () => IsBusy); + SaveSettings = new RelayCommand(SaveSettingsToFile, () => { if (IsBusy) return false; return ListOfSignals.Count > 0; }); + LoadSettings = new RelayCommand(LoadSettingsFromFile, () => !IsBusy); + + var builder = new ContainerBuilder(); + builder.RegisterType().As().As(); + builder.RegisterInstance(new GraphicController(CanvasGeometries)).As(); + Container = builder.Build(); + + dispatcher = Application.Current.Dispatcher; + + Action a = () => + { + Container.Resolve().DrawLine(0, 0, 100, 100); + }; + a.Invoke(); + } + + private void AddNew() + { + ListOfSignals.Add((BaseSignal)SelectedSignalPrototype.Clone()); + } + + private void RemoveSignalFromList() + { + ListOfSignals.Remove(SelectedSignalInList); + } + + private void Start() + { + ExecutionLog.Clear(); + IProcedureLogger logger = new LogController(dispatcher, ListOfSignals, ExecutionLog, (value) => IsBusy = value); + CurrentThread = new Thread(logger.ExecuteThread); + CurrentThread.Start(); + } + + private void AbortThreadExecution() + { + CurrentThread.Abort(); + IsBusy = false; + } + + private void SaveSettingsToFile() + { + Container.Resolve().SaveSignals(ListOfSignals); + } + + private void LoadSettingsFromFile() + { + ListOfSignals = Container.Resolve().LoadSignals(); + } + } +} diff --git a/SignalsMVVM/MainWindow.xaml b/SignalsMVVM/MainWindow.xaml new file mode 100644 index 0000000..27e8f7b --- /dev/null +++ b/SignalsMVVM/MainWindow.xaml @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + +