From b2721dbd8fe6f7a3901dc90cf4bdae9fd85db4d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A6=82=E6=84=8F=20=E5=BD=AD?= <2417589739@qq.com> Date: Wed, 21 Sep 2022 15:32:24 +0800 Subject: [PATCH] =?UTF-8?q?=E9=85=8D=E7=BD=AE=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BPASmart.ConfigurationSoftware/Global.cs | 32 --------------- .../MainWindowViewModel.cs | 10 ++--- .../{ => Model}/MainCanvasPageModel.cs | 0 .../NewProjectViewModel.cs | 4 +- .../ProjectDataServer.cs | 40 ------------------- .../ProjectModel.cs | 35 ---------------- .../FileConfigModel.cs | 19 +++++++-- BPASmart.Model/LocalPar.cs | 5 +++ .../NewProjectModel.cs | 4 +- BPASmart.VariableManager/App.xaml.cs | 4 +- .../ViewModels/CommunicationSetViewModel.cs | 4 +- .../Views/CommunicationSetView.xaml.cs | 2 +- .../Views/VariableConfig.xaml.cs | 2 +- 13 files changed, 36 insertions(+), 125 deletions(-) delete mode 100644 BPASmart.ConfigurationSoftware/Global.cs rename BPASmart.ConfigurationSoftware/{ => Model}/MainCanvasPageModel.cs (100%) delete mode 100644 BPASmart.ConfigurationSoftware/ProjectDataServer.cs delete mode 100644 BPASmart.ConfigurationSoftware/ProjectModel.cs rename {BPASmart.VariableManager => BPASmart.Model}/FileConfigModel.cs (52%) rename BPASmart.ConfigurationSoftware/Model/NewDataModel.cs => BPASmart.Model/NewProjectModel.cs (85%) diff --git a/BPASmart.ConfigurationSoftware/Global.cs b/BPASmart.ConfigurationSoftware/Global.cs deleted file mode 100644 index f86d5c5e..00000000 --- a/BPASmart.ConfigurationSoftware/Global.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BPASmart.ConfigurationSoftware -{ - public class Global - { - /// - /// 页面文件夹名称 - /// - public const string PageDirectoryName = "Layouts"; - - - /// - /// 项目路径 - /// - public static string ProjectPath { get; set; } = string.Empty; - - /// - /// 项目名称 - /// - public static string ProjectName { get; set; } - - /// - /// 变量管理器路径 - /// - public static string VarManagerPath => $"{AppDomain.CurrentDomain.BaseDirectory}BPASmart.VariableManager.exe"; - } -} diff --git a/BPASmart.ConfigurationSoftware/MainWindowViewModel.cs b/BPASmart.ConfigurationSoftware/MainWindowViewModel.cs index 23be174e..928e793c 100644 --- a/BPASmart.ConfigurationSoftware/MainWindowViewModel.cs +++ b/BPASmart.ConfigurationSoftware/MainWindowViewModel.cs @@ -65,7 +65,7 @@ namespace BPASmart.ConfigurationSoftware ActionManage.GetInstance.Register(new Action((o) => { Pages.Add(o.ToString()); - string path = $"{ Json.Data.ProjectPath}\\{Global.PageDirectoryName}"; + string path = $"{ Json.Data.ProjectPath}\\{FileConfigModel.PageDirectoryName}"; Directory.CreateDirectory(path); File.WriteAllText($"{path}\\{o.ToString()}.lay", null, Encoding.Unicode); Json.Data.Pages.TryAdd(o.ToString(), $"{path}\\{o.ToString()}.lay"); @@ -77,7 +77,7 @@ namespace BPASmart.ConfigurationSoftware bool? result = newProjectView.ShowDialog(); if (result != null && result == true) { - if (newProjectView.Tag != null && newProjectView.Tag is NewDataModel objModel) + if (newProjectView.Tag != null && newProjectView.Tag is NewProjectModel objModel) { string path = $"{objModel.ProjectPath}\\{objModel.ProjectName}"; Directory.CreateDirectory(path); @@ -100,19 +100,19 @@ namespace BPASmart.ConfigurationSoftware { Json.Data.ProjectPath = Json.Data.ProjectPath; Json.Save(); - if (File.Exists(Global.VarManagerPath)) + if (File.Exists(FileConfigModel.VarManagerPath)) { Process[] pro = Process.GetProcesses(); if (pro?.ToList().FirstOrDefault(p => p.ProcessName.Contains("BPASmart.VariableManager")) == null) { - Process.Start(Global.VarManagerPath); + Process.Start(FileConfigModel.VarManagerPath); } } }); SelectedPageCommand = new RelayCommand((o) => { - string path = $"{Json.Data.ProjectPath}\\{Global.PageDirectoryName}\\{o.ToString()}.lay"; + string path = $"{Json.Data.ProjectPath}\\{FileConfigModel.PageDirectoryName}\\{o.ToString()}.lay"; if (mainCanvasPanels.FirstOrDefault(p => p.PageName == o.ToString()) == null) { mainCanvasPanels.Add(new MainCanvasPageModel() diff --git a/BPASmart.ConfigurationSoftware/MainCanvasPageModel.cs b/BPASmart.ConfigurationSoftware/Model/MainCanvasPageModel.cs similarity index 100% rename from BPASmart.ConfigurationSoftware/MainCanvasPageModel.cs rename to BPASmart.ConfigurationSoftware/Model/MainCanvasPageModel.cs diff --git a/BPASmart.ConfigurationSoftware/NewProjectViewModel.cs b/BPASmart.ConfigurationSoftware/NewProjectViewModel.cs index ea53afb7..df97f7b1 100644 --- a/BPASmart.ConfigurationSoftware/NewProjectViewModel.cs +++ b/BPASmart.ConfigurationSoftware/NewProjectViewModel.cs @@ -59,8 +59,8 @@ namespace BPASmart.ConfigurationSoftware } - public NewDataModel NewData { get { return _mNewData; } set { _mNewData = value; OnPropertyChanged(); } } - private NewDataModel _mNewData = new NewDataModel(); + public NewProjectModel NewData { get { return _mNewData; } set { _mNewData = value; OnPropertyChanged(); } } + private NewProjectModel _mNewData = new NewProjectModel(); public string ErrorInfo { get { return _mErrorInfo; } set { _mErrorInfo = value; OnPropertyChanged(); } } diff --git a/BPASmart.ConfigurationSoftware/ProjectDataServer.cs b/BPASmart.ConfigurationSoftware/ProjectDataServer.cs deleted file mode 100644 index db811b7f..00000000 --- a/BPASmart.ConfigurationSoftware/ProjectDataServer.cs +++ /dev/null @@ -1,40 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Runtime.Serialization.Formatters.Binary; -using System.Text; -using System.Threading.Tasks; - -namespace BPASmart.ConfigurationSoftware -{ - public class ProjectDataServer where TClass : class, new() - { - public static TClass Data { get; set; } = new TClass(); - - /// - /// 保存数据 - /// - public static void Save(string path) - { - FileStream fs = new FileStream(path, FileMode.Create); - BinaryFormatter bf = new BinaryFormatter();//创建一个二进制格式化器 - bf?.Serialize(fs, Data); - fs.Close(); - } - - /// - /// 获取保存的数据 - /// - public static void Read(string path) - { - if (File.Exists(path)) - { - FileStream fs = new FileStream(path, FileMode.Open); - BinaryFormatter bf = new BinaryFormatter(); - var res = (TClass)bf.Deserialize(fs); - fs.Close(); - } - } - } -} diff --git a/BPASmart.ConfigurationSoftware/ProjectModel.cs b/BPASmart.ConfigurationSoftware/ProjectModel.cs deleted file mode 100644 index 3dfd6002..00000000 --- a/BPASmart.ConfigurationSoftware/ProjectModel.cs +++ /dev/null @@ -1,35 +0,0 @@ -//using System; -//using System.Collections.Generic; -//using System.Linq; -//using System.Text; -//using System.Threading.Tasks; -//using System.Collections.Concurrent; -//using System.Runtime.Serialization; - -//namespace BPASmart.ConfigurationSoftware -//{ -// public class ProjectModel -// { -// /// -// /// 项目名称 -// /// -// public string ProjectName { get; set; } - -// /// -// /// 项目路径 -// /// -// public string ProjectPath { get; set; } - -// /// -// /// 页面集合 -// /// key 是页面名称 -// /// value 是页面路径 -// /// -// public Dictionary Pages { get; set; } = new Dictionary(); - -// /// -// /// 变量表配置路径 -// /// -// public string VariableTabPath { get; set; } -// } -//} diff --git a/BPASmart.VariableManager/FileConfigModel.cs b/BPASmart.Model/FileConfigModel.cs similarity index 52% rename from BPASmart.VariableManager/FileConfigModel.cs rename to BPASmart.Model/FileConfigModel.cs index 8491d794..fd826312 100644 --- a/BPASmart.VariableManager/FileConfigModel.cs +++ b/BPASmart.Model/FileConfigModel.cs @@ -5,13 +5,16 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace BPASmart.VariableManager +namespace BPASmart.Model { public class FileConfigModel { - public static string ConstPath = string.Empty; + public static string ConstPath { get; set; } = string.Empty; - public static string GetPath + /// + /// Json文件配置路径 + /// + public static string JsonPath { get { @@ -25,5 +28,15 @@ namespace BPASmart.VariableManager return ReturnValue; } } + + /// + /// 变量管理器路径 + /// + public static string VarManagerPath => $"{AppDomain.CurrentDomain.BaseDirectory}BPASmart.VariableManager.exe"; + + /// + /// 页面文件夹名称 + /// + public static string PageDirectoryName { get; set; } = "Layouts"; } } diff --git a/BPASmart.Model/LocalPar.cs b/BPASmart.Model/LocalPar.cs index 8cf8afbb..ff508a42 100644 --- a/BPASmart.Model/LocalPar.cs +++ b/BPASmart.Model/LocalPar.cs @@ -12,5 +12,10 @@ namespace BPASmart.Model /// 项目路径 /// public string ProjectPath { get; set; } = string.Empty; + + /// + /// 项目上次保存的目录 + /// + public string ProjectDefaultPath { get; set; } = string.Empty; } } diff --git a/BPASmart.ConfigurationSoftware/Model/NewDataModel.cs b/BPASmart.Model/NewProjectModel.cs similarity index 85% rename from BPASmart.ConfigurationSoftware/Model/NewDataModel.cs rename to BPASmart.Model/NewProjectModel.cs index 8145fcc3..d23a719d 100644 --- a/BPASmart.ConfigurationSoftware/Model/NewDataModel.cs +++ b/BPASmart.Model/NewProjectModel.cs @@ -5,9 +5,9 @@ using System.Text; using System.Threading.Tasks; using BPASmart.Model; -namespace BPASmart.ConfigurationSoftware +namespace BPASmart.Model { - public class NewDataModel : NoticeBase + public class NewProjectModel : NoticeBase { public string ProjectName { get { return _mProjectName; } set { _mProjectName = value; OnPropertyChanged(); } } private string _mProjectName; diff --git a/BPASmart.VariableManager/App.xaml.cs b/BPASmart.VariableManager/App.xaml.cs index 5bf67fbd..cb628556 100644 --- a/BPASmart.VariableManager/App.xaml.cs +++ b/BPASmart.VariableManager/App.xaml.cs @@ -131,12 +131,12 @@ namespace BPASmart.VariableManager private void DataSave() { - Json.Save(FileConfigModel.GetPath); + Json.Save(FileConfigModel.JsonPath); } private void DataRead() { - Json.Read(FileConfigModel.GetPath); + Json.Read(FileConfigModel.JsonPath); } } diff --git a/BPASmart.VariableManager/ViewModels/CommunicationSetViewModel.cs b/BPASmart.VariableManager/ViewModels/CommunicationSetViewModel.cs index 0c2034d2..487b6337 100644 --- a/BPASmart.VariableManager/ViewModels/CommunicationSetViewModel.cs +++ b/BPASmart.VariableManager/ViewModels/CommunicationSetViewModel.cs @@ -20,12 +20,12 @@ namespace BPASmart.VariableManager.ViewModels { public CommunicationSetViewModel() { - Json.Read(FileConfigModel.GetPath); + Json.Read(FileConfigModel.JsonPath); communicationDevices = Json.Data.CommunicationDevices; DataListInit(); NewConnectCommand = new RelayCommand(() => { NewConnect(); }); RemoveDeviceCommand = new RelayCommand(RemoveDevice); - SaveConnectSetCommand = new RelayCommand(() => { Json.Save(FileConfigModel.GetPath); }); + SaveConnectSetCommand = new RelayCommand(() => { Json.Save(FileConfigModel.JsonPath); }); DelegationNotifi.GetInstance.AddDeviceVerify = new Func((p) => { diff --git a/BPASmart.VariableManager/Views/CommunicationSetView.xaml.cs b/BPASmart.VariableManager/Views/CommunicationSetView.xaml.cs index 1627c692..1342c32c 100644 --- a/BPASmart.VariableManager/Views/CommunicationSetView.xaml.cs +++ b/BPASmart.VariableManager/Views/CommunicationSetView.xaml.cs @@ -30,7 +30,7 @@ namespace BPASmart.VariableManager.Views private void CommunicationSetView_Unloaded(object sender, RoutedEventArgs e) { - Json.Save(FileConfigModel.GetPath); + Json.Save(FileConfigModel.JsonPath); } } } diff --git a/BPASmart.VariableManager/Views/VariableConfig.xaml.cs b/BPASmart.VariableManager/Views/VariableConfig.xaml.cs index db6f920d..52f4e3a3 100644 --- a/BPASmart.VariableManager/Views/VariableConfig.xaml.cs +++ b/BPASmart.VariableManager/Views/VariableConfig.xaml.cs @@ -33,7 +33,7 @@ namespace BPASmart.VariableManager.Views private void VariableConfig_Unloaded(object sender, RoutedEventArgs e) { - Json.Save(FileConfigModel.GetPath); + Json.Save(FileConfigModel.JsonPath); } private void VariableConfig_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)