diff --git a/StartServerWPF.Models/ApmsModel.cs b/StartServerWPF.Models/ApmsModel.cs index 912eb7e..5cf4ea2 100644 --- a/StartServerWPF.Models/ApmsModel.cs +++ b/StartServerWPF.Models/ApmsModel.cs @@ -94,42 +94,6 @@ namespace StartServerWPF.Models [JsonProperty("Locate.clusted_otime")] public string clusted_otime { get; set; } - // public string delaytime { get; set; } - public List CreateStationFromCSV(string fn) - { - if (!File.Exists(fn)) return null; - List stations = new List(); - Aspose.Cells.TxtLoadOptions lo = new TxtLoadOptions(); - lo.Encoding = Encoding.Default;//设置编码方式 - Workbook workbook = new Workbook(fn, lo); - - //配置读取文件的类型(CSV) - workbook.FileFormat = FileFormatType.Csv;//可在此配置Excel文件类型 - Worksheet worksheet = workbook.Worksheets[0];//默认第一个Sheet页 - - Cells cells = worksheet.Cells; - - //读取到DataTable中 - DataTable dt = cells.ExportDataTableAsString(0, 0, cells.MaxDataRow + 1, cells.MaxColumn + 1, true); - for (int i = 0; i < dt.Rows.Count; i++) - { - DataRow row = dt.Rows[i]; - StationControlModel model = new StationControlModel(); - model.NetWork = row[0].ToString(); - model.Num = row[1].ToString(); - model.Coordinate = new Coordinate3D(double.Parse(row[2].ToString()), double.Parse(row[3].ToString()), double.Parse(row[4].ToString())); - model.Sens = double.Parse(row[5].ToString()); - model.BeginUseTime = DateTime.Parse(row[6].ToString()); - model.StopUseTime = DateTime.Parse(row[7].ToString()); - // model.Location = this.StationConfig.Location; - stations.Add(model); - } - //释放资源 - workbook = null; - worksheet = null; - return stations; - } - } public class TTime : BindableBase @@ -139,26 +103,22 @@ namespace StartServerWPF.Models [JsonProperty("station")] public string station { get; set; } - [JsonProperty("ttime")] - public string ttime { get; set; } + // [JsonProperty("ttime")] + // public string ttime { get; set; } [JsonProperty("ttime2d")] public string ttime2d { get => ttime2d1; set => SetProperty(ref ttime2d1, value); } } - public class StationChannelsModel : BindableBase + public class StationChannelsModel { - private string station1; - public string network { get; set; } public string location { get; set; } public string channels { get; set; } - public string station { get => station1; - set => SetProperty(ref station1, value); - } + public string station { get ; set; } } } diff --git a/StartServerWPF.Models/JsonParser.cs b/StartServerWPF.Models/JsonParser.cs index ea292f5..fbf039b 100644 --- a/StartServerWPF.Models/JsonParser.cs +++ b/StartServerWPF.Models/JsonParser.cs @@ -12,6 +12,7 @@ namespace StartServerWPF.Models public static string systemConfigPath = "SystemConfig.json"; public static string serverVision = "20230517"; + public const string workareaPath = "serverprogram\\workarea"; public SystemConfigModel ReadSystemJsonFile(string jsonFile) { diff --git a/StartServerWPF.Models/VpnInfo.cs b/StartServerWPF.Models/VpnInfo.cs index fe5d1eb..840e178 100644 --- a/StartServerWPF.Models/VpnInfo.cs +++ b/StartServerWPF.Models/VpnInfo.cs @@ -43,9 +43,5 @@ namespace StartServerWPF.Models /// 系统日志路径 /// public string SystemLogPath { get => systemLogPath; set => SetProperty(ref systemLogPath, value); } - /// - /// 数据存储路径 - /// - public string DataSavePath { get => dataSavePath; set => SetProperty(ref dataSavePath, value); } } } diff --git a/StartServerWPF.Models/WorkareaModel.cs b/StartServerWPF.Models/WorkareaModel.cs index 4683591..e4383ec 100644 --- a/StartServerWPF.Models/WorkareaModel.cs +++ b/StartServerWPF.Models/WorkareaModel.cs @@ -7,18 +7,17 @@ using System.Text; using System.Threading.Tasks; using Aspose.Cells; using Newtonsoft.Json; +using Prism.Mvvm; namespace StartServerWPF.Models { - public class WorkareaModel - { - - [JsonProperty("StationConfig")] - public StationConfigModel StationConfig { get; set; } - [JsonIgnore] - public List Stations { get; set; } - public List CreateStationFromCSV(string fn) + public class WorkareaModelArray + { + public int selectIndex { get; set; } + public List workarea { get;set;} + + public List CreateStationFromCSV(string fn,string location) { if (!File.Exists(fn)) return null; List stations = new List(); @@ -41,11 +40,11 @@ namespace StartServerWPF.Models StationControlModel model = new StationControlModel(); model.NetWork = row[0].ToString(); model.Num = row[1].ToString(); - model.Coordinate=new Coordinate3D(double.Parse(row[2].ToString()), double.Parse(row[3].ToString()), double.Parse(row[4].ToString())); + model.Coordinate = new Coordinate3D(double.Parse(row[2].ToString()), double.Parse(row[3].ToString()), double.Parse(row[4].ToString())); model.Sens = double.Parse(row[5].ToString()); model.BeginUseTime = DateTime.Parse(row[6].ToString()); model.StopUseTime = DateTime.Parse(row[7].ToString()); - model.Location=this.StationConfig.Location; + model.Location = location; stations.Add(model); } //释放资源 @@ -54,24 +53,72 @@ namespace StartServerWPF.Models return stations; } } + public class WorkareaModel : BindableBase + { + private string workareaname1; + private bool apmpush2wx1; + private bool toolpush2wx1; + private string savepath1; + private string chartsavepath1; + private string apmsavepath1; + private string toolsavepath1; + private int delayTime1; + private ApmsModel apmModel1; + + [JsonProperty("workareaname")] + public string workareaname { get => workareaname1; set => SetProperty(ref workareaname1, value); } + + [JsonProperty("savepath")] + public string savepath { get => savepath1; set => SetProperty(ref savepath1, value); } + + [JsonProperty("chartsavepath")] + public string chartsavepath { get => chartsavepath1; set => SetProperty(ref chartsavepath1, value); } + + [JsonProperty("apmsavepath")] + public string apmsavepath { get => apmsavepath1; set => SetProperty(ref apmsavepath1, value); } + + [JsonProperty("toolsavepath")] + public string toolsavepath { get => toolsavepath1; set => SetProperty(ref toolsavepath1, value); } + + [JsonProperty("apmpush2wx")] + public bool apmpush2wx { get => apmpush2wx1; set => SetProperty(ref apmpush2wx1, value); } + + [JsonProperty("toolpush2wx")] + public bool toolpush2wx { get => toolpush2wx1; set => SetProperty(ref toolpush2wx1, value); } + + [JsonProperty("delayTime")] + public int delayTime { get => delayTime1; set => SetProperty(ref delayTime1, value); } + public ApmsModel apmModel { get => apmModel1; set => SetProperty(ref apmModel1, value); } + public StationConfigModel StationConfig { get; set; } + } - public class StationConfigModel + public class StationConfigModel: BindableBase { - [JsonProperty("Network")] + private List stations1; + + [JsonProperty("network")] public string Network { get; set; } - [JsonProperty("Location")] + [JsonProperty("location")] public string Location { get; set; } - [JsonProperty("Channels")] - public string[] Channels { get; set; } + [JsonProperty("channels")] + public string Channels { get; set; } - [JsonProperty("StationCoordCsvPath")] - public string StationCoordCsvPath { get; set; } + [JsonProperty("stations")] + public List Stations { get => stations1; set => SetProperty(ref stations1, value); } } + public class StationState: BindableBase + { + private string name; + private bool isEnable; + + public string Name { get => name; set => SetProperty(ref name, value); } + public bool IsEnable { get => isEnable; set => SetProperty(ref isEnable, value); } + } public class Coordinate3D { [JsonProperty("X")] @@ -93,9 +140,4 @@ namespace StartServerWPF.Models Z= z; } } - public enum WellType - { - Wellhead=0, - TargetLayer=1 - } } diff --git a/StartServerWPF.Modules.Main/MainModule.cs b/StartServerWPF.Modules.Main/MainModule.cs index 526d889..5abf6ca 100644 --- a/StartServerWPF.Modules.Main/MainModule.cs +++ b/StartServerWPF.Modules.Main/MainModule.cs @@ -21,6 +21,7 @@ namespace StartServerWPF.Modules.Main containerRegistry.RegisterForNavigation(); containerRegistry.RegisterForNavigation(); containerRegistry.RegisterForNavigation(); + containerRegistry.RegisterForNavigation(); containerRegistry.RegisterForNavigation(); containerRegistry.RegisterForNavigation(); diff --git a/StartServerWPF.Modules.Main/ViewModels/DataProcessViewModel.cs b/StartServerWPF.Modules.Main/ViewModels/DataProcessViewModel.cs new file mode 100644 index 0000000..d88fbee --- /dev/null +++ b/StartServerWPF.Modules.Main/ViewModels/DataProcessViewModel.cs @@ -0,0 +1,290 @@ +using Newtonsoft.Json; +using Prism.Commands; +using Prism.Ioc; +using Prism.Mvvm; +using Prism.Services.Dialogs; +using StartServerWPF.Models; +using StartServerWPF.Modules.Main.Models; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Input; + +namespace StartServerWPF.Modules.Main.ViewModels +{ + public class DataProcessViewModel : BindableBase + { + public DataProcessViewModel(MainViewModel mainViewModel, SystemConfigModel configModel, WorkareaModelArray modelArray) + { + this._mainViewModel = mainViewModel; + this._systemConfig = configModel; + this.modelArray = modelArray; + } + private string _title = "应用列表"; + public string Title => _title; + + private readonly MainViewModel _mainViewModel; + private SystemConfigModel _systemConfig; + private readonly WorkareaModelArray modelArray; + private WorkareaModel _workareaModel; + private string _dataPath; + public string DataPath + { + get => _dataPath; + set { SetProperty(ref _dataPath, value); } + } + + private string _savePath; + public string SavePath + { + get => _savePath; + set { SetProperty(ref _savePath, value); } + } + + private DateTime _startSelectedDate; + public DateTime StartSelectedDate + { + get => _startSelectedDate; + set { SetProperty(ref _startSelectedDate, value); } + } + + private DateTime _endSelectedDate; + public DateTime EndSelectedDate + { + get => _endSelectedDate; + set { SetProperty(ref _endSelectedDate, value); } + } + + private int _wareaSelectedIndex; + public int WareaSelectedIndex + { + get => _wareaSelectedIndex; + set + { + if (value >= 0) + { + _workareaModel = modelArray.workarea[value]; + } + SetProperty(ref _wareaSelectedIndex, value); + } + } + private ObservableCollection _workareaNameSource; + public ObservableCollection WorkareaNameSource + { + get => _workareaNameSource; + set { SetProperty(ref _workareaNameSource, value); } + } + + private ObservableCollection _apmsEventSource = new ObservableCollection(); + public ObservableCollection ApmsEventSource + { + get => _apmsEventSource; + set => SetProperty(ref _apmsEventSource, value); + } + + public DelegateCommand LoadedCommand => new(() => + { + StartSelectedDate = DateTime.Now; + EndSelectedDate = DateTime.Now; + this._workareaModel = modelArray.workarea[modelArray.selectIndex]; + WorkareaNameSource = new ObservableCollection(); + modelArray.workarea.Select(n => n.workareaname).ToList().ForEach(a => WorkareaNameSource.Add(a)); + WareaSelectedIndex = modelArray.selectIndex; + }); + + + public DelegateCommand SelectFileCommand => new((obj) => + { + string para = obj.ToString(); + System.Windows.Forms.FolderBrowserDialog fbd = new System.Windows.Forms.FolderBrowserDialog(); + // fbd.SelectedPath = MainModel.DataSavePath; + fbd.ShowNewFolderButton = true; + if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK) + { + string path = fbd.SelectedPath.Replace("\\", "/"); + if (para == "SavePath") + { + SavePath = path; + } + else if (para == "DataPath") + { + DataPath = path; + } + + } + }); + + + public ICommand StartCommand + { + get => new DelegateCommand(() => + { + // 数据校验(关键字段不能为空、年龄做数字区间的校验、做UserName的唯一检查(自定义特性检查) + if (string.IsNullOrEmpty(DataPath) || string.IsNullOrEmpty(SavePath)) + { + MessageBox.Show("内容不能为空", "提示", MessageBoxButton.OK); + return; + } + if (MessageBox.Show("确认修改?", "参数设置", MessageBoxButton.OKCancel, + MessageBoxImage.Exclamation) == MessageBoxResult.OK) + { + var time = (EndSelectedDate - StartSelectedDate); + if (time.TotalMinutes < 1) + { + MessageBox.Show("结束时间必需大于开始时间", "提示", MessageBoxButton.OK); + return; + } + DateTime dateTime = StartSelectedDate; + string temPath = Path.GetPathRoot( _workareaModel.savepath) + "temPath"; + if (!Directory.Exists(temPath)) + { + Directory.CreateDirectory(temPath); + } + while ((EndSelectedDate - dateTime).TotalMinutes >= 1) + { + string path = Path.GetFullPath($"{DataPath}\\{dateTime.Month.ToString().PadLeft(2, '0')}\\{dateTime.Day.ToString().PadLeft(2, '0')}\\{dateTime.Hour.ToString().PadLeft(2, '0')}\\{dateTime.Minute.ToString().PadLeft(2, '0')}"); + dateTime= dateTime.AddMinutes(1); + if( !Directory.Exists(path)) + { + continue; + } + var mseedFiles = new DirectoryInfo(path).EnumerateFiles("*.mseed"); + // var mseedFiles = files.Where(i => i.Extension == ".mseed"); + Parallel.ForEach(mseedFiles, (item) => + { + Debug.WriteLine($"***************path:{path},{item.FullName}"); + File.Copy(item.FullName, Path.Combine( temPath, item.Name), true); + }); + } + + ProcessInfo process = _systemConfig.dataProTools; + int index = process.ProParams.IndexOf("-wave"); + string str = process.ProParams.Substring(0, index) + "-wave"; + process.ProParams = $"{str} {temPath}"; + + //gw.tools.exe配置更新 + ApmsModel tools = _workareaModel.apmModel; + // tools.savepath = SavePath; // _workareaModel.savepath + "/" +SavePath;; + tools.station = Path.GetFullPath(Path.Combine(JsonParser.workareaPath, _workareaModel.apmModel.station)).Replace("\\", "/"); + tools.ttime[0].ttime2d = Path.GetFullPath(Path.Combine(JsonParser.workareaPath, _workareaModel.apmModel.ttime[0].ttime2d)).Replace("\\", "/"); + + tools.push2wx = _workareaModel.toolpush2wx ? "YES" : "NO"; + tools.channels = new List + { + new StationChannelsModel() + { + location = _workareaModel.StationConfig.Location, + network = _workareaModel.StationConfig.Network, + channels = _workareaModel.StationConfig.Channels, + station = string.Join(",", _workareaModel.StationConfig.Stations.Where(p => p.IsEnable).Select(n => n.Name)) + } + }; + JsonParser.WriteSystemConfigFile(Path.Combine(_systemConfig.dataProTools.ProPath, "apms.json"), tools); + + this.StartProcess(process); + } + }); + } + + private bool CMDStartProcess(ProcessInfo proInfo) + { + //* Create your Process + Process process = new Process(); + process.Exited += Process_Exited; + process.EnableRaisingEvents = true; + process.StartInfo.FileName = Path.GetFullPath(proInfo.ProPath + proInfo.ProName + ".exe"); + process.StartInfo.WorkingDirectory = Path.GetFullPath(proInfo.ProPath); + process.StartInfo.Arguments = proInfo.ProParams; + process.StartInfo.UseShellExecute = false; + process.StartInfo.RedirectStandardOutput = true; + process.StartInfo.RedirectStandardError = true; + + process.StartInfo.CreateNoWindow = true; + //* Set your output and error (asynchronous) handlers + + //* Start process and handlers + bool res = process.Start(); + // process.WaitForExit(); + return res; + } + + private void Process_Exited(object? sender, EventArgs e) + { + var fileName = Directory.GetFiles(SavePath, "*.index"); + if (!File.Exists( fileName.FirstOrDefault())) + { + return; + } + string[] text = File.ReadAllLines(fileName.FirstOrDefault()); + Application.Current.Dispatcher.BeginInvoke(() => + { + foreach (var item in text) + { + ApmsEventSource.Add(new MsEventModel(item)); + } + }); + } + + + /// + /// 启动进程 + /// + /// + /// 进程启动返回值 + public int StartProcess(ProcessInfo proInfo) + { + bool res = CMDStartProcess(proInfo); + int seInd = res ? 0 : 37; + return seInd; + } + /// + /// 结束进程 + /// + /// + /// 0=成功;1=未找到进程;-1=失败 + public int KillProcess(ProcessInfo processInfo) + { + int ri = 0; + if (processInfo != null) + { + if (processInfo.ProName != null) + { + try + { + Process[] localByName = Process.GetProcessesByName(processInfo.ProName); + if (localByName.Length == 0) + { + ri = 1; + return ri; + } + foreach (var item in localByName) + { + Console.WriteLine(item.Id); + item.Kill(); + } + return ri; + } + catch (Exception) + { + return -1; + } + } + else + { + return 0; + } + } + else + { + return 0; + } + } + + } +} diff --git a/StartServerWPF.Modules.Main/ViewModels/MainViewModel.cs b/StartServerWPF.Modules.Main/ViewModels/MainViewModel.cs index aa7cccd..cdfb7f6 100644 --- a/StartServerWPF.Modules.Main/ViewModels/MainViewModel.cs +++ b/StartServerWPF.Modules.Main/ViewModels/MainViewModel.cs @@ -34,15 +34,8 @@ namespace StartServerWPF.Modules.Main.ViewModels Message = "View A" ; Console.WriteLine(System.Environment.CurrentDirectory + "\\" + JsonParser.systemConfigPath); _systemConfig = systemConfig; - // int moniTimeInd = sc.proMonitor.ProParams.IndexOf("-btime"); - // string moniTimeStr = sc.proMonitor.ProParams.Substring(moniTimeInd + 7); - // int moniTimeIndEnd = moniTimeStr.IndexOf(">"); - //moniTimeStr = moniTimeStr.Substring(0, moniTimeIndEnd - 1); - // MoniStartTime = DateTime.Parse(moniTimeStr); + InitializeParams(); - JsonParser.UpdateApmsJson(_systemConfig.proApms.ProPath + "apms.json", _systemConfig.vpnInfo.DataSavePath); - JsonParser.UpdateRecvJson(_systemConfig.proRecv.ProPath + "gw.recvftp.json", _systemConfig.vpnInfo.DataSavePath); - // sc.proMonitor.ProParams = JsonParser.CreateMonitorStartParam(sc.vpnInfo.DataSavePath, MoniStartTime); StartTime = DateTime.Now; Console.WriteLine(System.Environment.CurrentDirectory); Console.WriteLine(_systemConfig.remoteDb.ServerAddress + "\t" + _systemConfig.remoteDb.ServerPort diff --git a/StartServerWPF.Modules.Main/ViewModels/SetParamDialogViewModel.cs b/StartServerWPF.Modules.Main/ViewModels/SetParamDialogViewModel.cs index e394b41..9296d17 100644 --- a/StartServerWPF.Modules.Main/ViewModels/SetParamDialogViewModel.cs +++ b/StartServerWPF.Modules.Main/ViewModels/SetParamDialogViewModel.cs @@ -58,15 +58,9 @@ namespace StartServerWPF.Modules.Main.ViewModels { updateJson = false; System.Windows.Forms.FolderBrowserDialog fbd = new System.Windows.Forms.FolderBrowserDialog(); - fbd.SelectedPath = MainModel.DataSavePath; fbd.ShowNewFolderButton = true; if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { - MainModel.DataSavePath = fbd.SelectedPath; - if (MainModel.DataSavePath != _systemConfig.vpnInfo.DataSavePath) - { - updateJson = true; - } } }); public DelegateCommand LogPathSaveCommand=> new(() => @@ -101,11 +95,7 @@ namespace StartServerWPF.Modules.Main.ViewModels JsonParser.WriteSystemConfigFile(JsonParser.systemConfigPath, _systemConfig); - if (updateJson) - { - JsonParser.UpdateRecvJson(_systemConfig.proRecv.ProPath + _systemConfig.proRecv.JsonPath, _systemConfig.vpnInfo.DataSavePath); - JsonParser.UpdateApmsJson(_systemConfig.proApms.ProPath + _systemConfig.proApms.JsonPath, _systemConfig.vpnInfo.DataSavePath); - } + RequestClose?.Invoke(new DialogResult(ButtonResult.OK)); } }); diff --git a/StartServerWPF.Modules.Main/ViewModels/SetParamViewModel.cs b/StartServerWPF.Modules.Main/ViewModels/SetParamViewModel.cs index f26b53f..34692b9 100644 --- a/StartServerWPF.Modules.Main/ViewModels/SetParamViewModel.cs +++ b/StartServerWPF.Modules.Main/ViewModels/SetParamViewModel.cs @@ -10,6 +10,8 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.IO; using System.Linq; +using System.Runtime.Serialization; +using System.Runtime.Serialization.Formatters.Binary; using System.Text; using System.Threading.Tasks; using System.Windows; @@ -19,178 +21,127 @@ namespace StartServerWPF.Modules.Main.ViewModels { public class SetParamViewModel : BindableBase { - public SetParamViewModel(MainViewModel mainViewModel,SystemConfigModel configModel) + public SetParamViewModel(SystemConfigModel configModel, WorkareaModelArray workareaModelArray) { _systemConfig = configModel; + this._workareaModelArray = workareaModelArray; MainModel = _systemConfig.vpnInfo; - MoniTime = mainViewModel.MoniStartTime; + WorkareaNameSource = new ObservableCollection(); + _workareaModelArray.workarea.Select(n=>n.workareaname).ToList().ForEach(a=> WorkareaNameSource.Add(a)); - string sapm = File.ReadAllText(configModel.proApms.ProPath+ "apms.json"); - AModel = JsonConvert.DeserializeObject(sapm); - ApmsJsonName = _systemConfig.proApms.JsonPath; - var apmsStation = ToolsModel.CreateStationFromCSV(configModel.proApms.ProPath + AModel.station); - ApmsStationSource = new ObservableCollection(); - foreach (var item in apmsStation) - { - if (item.Enable) - { - ApmsStationSource.Add(item); - } - } - IsApmswxNotity = AModel.push2wx == "NO" ? false : true; - - string tool = File.ReadAllText(configModel.proTools.ProPath + "apms.json"); - ToolsModel = JsonConvert.DeserializeObject(tool); - ToolsJsonName = _systemConfig.proTools.JsonPath; - - var st= ToolsModel.CreateStationFromCSV(configModel.proTools.ProPath + AModel.station); - ToolsStationSource = new ObservableCollection(); - foreach (var item in st) - { - if (item.Enable) - { - ToolsStationSource.Add(item); - } - } - IsToolswxNotity = ToolsModel.push2wx == "NO" ? false : true; - int index= _systemConfig.proTools.ProParams.IndexOf("-delay"); - int.TryParse (_systemConfig.proTools.ProParams.Substring(index+ "-delay".Length), out int Time); - DelayTime = Time/60; - + WareaSelectedIndex = _workareaModelArray.selectIndex; + WareaModel = _workareaModelArray.workarea[WareaSelectedIndex]; } private string _title = "应用列表"; public string Title => _title; - + string apmStationFile = string.Empty; + string apmttime2dFile = string.Empty; private SystemConfigModel _systemConfig; - private string _apmsJsonName; - public string ApmsJsonName - { - get => _apmsJsonName; - set { SetProperty(ref _apmsJsonName, value); } - } - private bool _isApmswxNotity; - public bool IsApmswxNotity - { - get => _isApmswxNotity; - set { SetProperty(ref _isApmswxNotity, value); } - } - private ApmsModel _apmsModel = new ApmsModel(); - public ApmsModel AModel + private readonly WorkareaModelArray _workareaModelArray; + private ObservableCollection _workareaNameSource; + public ObservableCollection WorkareaNameSource { - get => _apmsModel; - set { SetProperty(ref _apmsModel, value); } + get => _workareaNameSource; + set { SetProperty(ref _workareaNameSource, value); } } - - private string _toolsJsonName; - public string ToolsJsonName - { - get => _toolsJsonName; - set { SetProperty(ref _toolsJsonName, value); } - } - private ApmsModel _toolsModel = new ApmsModel(); - public ApmsModel ToolsModel + + private int _wareaSelectedIndex; + public int WareaSelectedIndex { - get => _toolsModel; - set { SetProperty(ref _toolsModel, value); } + get => _wareaSelectedIndex; + set { + if (value >= 0) + { + WareaModel = _workareaModelArray.workarea[value]; + } + SetProperty(ref _wareaSelectedIndex, value); + } } - - private bool _isToolswxNotity; - public bool IsToolswxNotity + private WorkareaModel _wareaModel = new WorkareaModel(); + public WorkareaModel WareaModel { - get => _isToolswxNotity; - set { SetProperty(ref _isToolswxNotity, value); } + get => _wareaModel; + set { SetProperty(ref _wareaModel, value); } } - private int _delayTime; - public int DelayTime + private string _addWorkareaName; + public string AddWorkareaName { - get => _delayTime; - set { SetProperty(ref _delayTime, value); } + get => _addWorkareaName; + set { SetProperty(ref _addWorkareaName, value); } } - private ObservableCollection _toolsStationSource; - public ObservableCollection ToolsStationSource - { get => _toolsStationSource; set => SetProperty(ref _toolsStationSource, value); } - - private ObservableCollection _ApmsStationSource; - public ObservableCollection ApmsStationSource - { get => _ApmsStationSource; set => SetProperty(ref _ApmsStationSource, value); } - private VpnInfo _mainModel = new VpnInfo(); public VpnInfo MainModel { get => _mainModel; set { SetProperty(ref _mainModel, value); } } - - private DateTime _moniTime ; - public DateTime MoniTime + + public DelegateCommand LoadedCommand => new(() => { - get => _moniTime; - set { SetProperty(ref _moniTime, value); } - } + apmStationFile = string.Empty; + apmttime2dFile = string.Empty; + }); - public DelegateCommand SelectFileCommand => new((obj) => + + public DelegateCommand AddItemCommand => new(() => { - + string strJson= JsonConvert.SerializeObject(WareaModel, Formatting.Indented); + WorkareaModel workarea = JsonConvert.DeserializeObject(strJson); + + workarea.workareaname = AddWorkareaName; + var mod = _workareaModelArray.workarea.Where(w => w.workareaname == _addWorkareaName).FirstOrDefault(); + if (mod != null) + { + MessageBox.Show($"名称:{AddWorkareaName}已存在"); + return; + } + workarea.chartsavepath = "EVT2014"; + workarea.apmsavepath = "NET2014"; + workarea.toolsavepath = "post"; + workarea.StationConfig.Stations.ForEach(w => { w.IsEnable= true; }); + + _workareaModelArray.workarea.Add(workarea); + WorkareaNameSource.Add(AddWorkareaName); + }); + + public DelegateCommand SelectFileCommand => new((obj) => + { string para = obj.ToString(); System.Windows.Forms.OpenFileDialog fbd = new System.Windows.Forms.OpenFileDialog(); fbd.Multiselect = false; - if (para.Contains("apms")) - { - fbd.InitialDirectory = Path.GetFullPath(_systemConfig.proApms.ProPath); - } - else - { - fbd.InitialDirectory = Path.GetFullPath(_systemConfig.proTools.ProPath); - } - + // fbd.InitialDirectory = Path.GetFullPath(_wareaModel.savepath); if (fbd.ShowDialog()== System.Windows.Forms.DialogResult.OK) { switch (para) { case "apmsStation": - AModel.station = fbd.SafeFileName; + WareaModel.apmModel.savepath = fbd.SafeFileName; + apmStationFile = fbd.FileName; break; case "apmsttime2d": - AModel.ttime[0].ttime2d = fbd.SafeFileName; - break; - case "toolsStation": - ToolsModel.station = fbd.SafeFileName; + WareaModel.apmModel.ttime[0].ttime2d = fbd.SafeFileName; + apmttime2dFile = fbd.FileName; break; - case "toolsttime2d": - ToolsModel.ttime[0].ttime2d = fbd.SafeFileName; - break; - default: break; } } - - }); - public DelegateCommand FilePathSaveCommand=> new((obj)=> { string para= obj.ToString(); System.Windows.Forms.FolderBrowserDialog fbd = new System.Windows.Forms.FolderBrowserDialog(); - fbd.SelectedPath = MainModel.DataSavePath; + // fbd.SelectedPath = MainModel.DataSavePath; fbd.ShowNewFolderButton = true; if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { string path= fbd.SelectedPath.Replace("\\", "/"); - if (para == "systemSavepath") - { - MainModel.DataSavePath = path; - } - else if(para == "apmssavepath") + if (para == "savepath") { - AModel.savepath = path; - } - else if(para == "toolssavepath") - { - ToolsModel.savepath = path; + WareaModel.savepath = path; } } @@ -202,7 +153,6 @@ namespace StartServerWPF.Modules.Main.ViewModels fbd.ShowNewFolderButton = true; if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { - MainModel.SystemLogPath = fbd.SelectedPath; } }); @@ -220,37 +170,60 @@ namespace StartServerWPF.Modules.Main.ViewModels if (MessageBox.Show("确认修改?", "参数设置", MessageBoxButton.OKCancel, MessageBoxImage.Exclamation) == MessageBoxResult.OK) { - - AModel.channels[0].station = string.Join(",", ApmsStationSource.Where(p => p.Enable).Select(a => a.Num)); - if (_systemConfig.proApms.JsonPath != ApmsJsonName) + //1 Workarea配置更新 + string wmJson = JsonConvert.SerializeObject(_workareaModelArray, Formatting.Indented); + _wareaModel.apmModel.channels = new List + { + new StationChannelsModel() + { + location = _wareaModel.StationConfig.Location, + network = _wareaModel.StationConfig.Network, + channels = _wareaModel.StationConfig.Channels, + station = string.Join(",", _wareaModel.StationConfig.Stations.Where(p => p.IsEnable).Select(n => n.Name)) + } + }; + File.WriteAllText(Path.Combine(JsonParser.workareaPath, "Workarea.json"), wmJson); + if (!string.IsNullOrEmpty(apmStationFile)) { - _systemConfig.proApms.ProParams = _systemConfig.proApms.ProParams.Replace(_systemConfig.proApms.JsonPath, ApmsJsonName); - _systemConfig.proApms.JsonPath = ApmsJsonName; + string destFileName = Path.GetFullPath(Path.Combine(JsonParser.workareaPath, WareaModel.apmModel.savepath)); + File.Copy(apmStationFile, destFileName, true); + apmStationFile = null; } - JsonParser.WriteSystemConfigFile(_systemConfig.proApms.ProPath + ApmsJsonName, AModel); - - ToolsModel.channels[0].station = string.Join(",", ToolsStationSource.Where(p => p.Enable).Select(a => a.Num)); - if (_systemConfig.proTools.JsonPath != ToolsJsonName) + if(!string.IsNullOrEmpty(apmttime2dFile)) { - _systemConfig.proTools.ProParams = _systemConfig.proTools.ProParams.Replace(_systemConfig.proTools.JsonPath, ToolsJsonName); - _systemConfig.proTools.JsonPath = ToolsJsonName; + string destFileName = Path.GetFullPath(Path.Combine(JsonParser.workareaPath, WareaModel.apmModel.ttime[0].ttime2d)); + File.Copy(apmttime2dFile, destFileName, true); + apmttime2dFile = null; } - //if (_systemConfig.vpnInfo.DataSavePath != ToolsModel.savepath) - //{ - // _systemConfig.vpnInfo.DataSavePath = ToolsModel.savepath; - //} - JsonParser.WriteSystemConfigFile(_systemConfig.proTools.ProPath + ToolsJsonName, ToolsModel); - int index= _systemConfig.proTools.ProParams.IndexOf("-savepath"); - // int index = _systemConfig.proTools.ProParams.IndexOf("-delay"); - string str= _systemConfig.proTools.ProParams.Substring(0, index)+ "-savepath"; - _systemConfig.proTools.ProParams = $"{str} {ToolsModel.savepath} -delay {DelayTime * 60}"; - JsonParser.WriteSystemConfigFile(JsonParser.systemConfigPath, _systemConfig); + //2 gw.apms.exe配置更新 + { + ApmsModel apms = _wareaModel.apmModel; + apms.station = Path.GetFullPath(Path.Combine(JsonParser.workareaPath, WareaModel.apmModel.station)).Replace("\\","/"); + apms.ttime[0].ttime2d= Path.GetFullPath(Path.Combine(JsonParser.workareaPath, WareaModel.apmModel.ttime[0].ttime2d)).Replace("\\", "/"); ; + apms.savepath = _wareaModel.savepath + "/" + _wareaModel.apmsavepath; + apms.push2wx = _wareaModel.apmpush2wx ? "YES" : "NO"; + JsonParser.WriteSystemConfigFile(Path.Combine(_systemConfig.proApms.ProPath, "apms.json"), apms); + } + //3 gw.tools.exe配置更新 + { + ApmsModel tools = _wareaModel.apmModel; + tools.station = Path.GetFullPath(Path.Combine(JsonParser.workareaPath, WareaModel.apmModel.station)).Replace("\\", "/"); + tools.ttime[0].ttime2d = Path.GetFullPath(Path.Combine(JsonParser.workareaPath, WareaModel.apmModel.ttime[0].ttime2d)).Replace("\\", "/"); ; + tools.savepath = _wareaModel.savepath+"/"+ _wareaModel.toolsavepath; + tools.push2wx = _wareaModel.toolpush2wx ? "YES" : "NO"; ; + JsonParser.WriteSystemConfigFile(Path.Combine(_systemConfig.proTools.ProPath, "apms.json"), tools); + + //4 SystemConfig.json配置更新 + int index = _systemConfig.proTools.ProParams.IndexOf("-savepath"); + string str = _systemConfig.proTools.ProParams.Substring(0, index) + "-savepath"; + _systemConfig.proTools.ProParams = $"{str} {tools.savepath} -delay {_wareaModel.delayTime * 60}"; + JsonParser.WriteSystemConfigFile(JsonParser.systemConfigPath, _systemConfig); + } - JsonParser.UpdateRecvJson(_systemConfig.proRecv.ProPath + _systemConfig.proRecv.JsonPath, _systemConfig.vpnInfo.DataSavePath); - //JsonParser.UpdateApmsJson(_systemConfig.proApms.ProPath + _systemConfig.proApms.JsonPath, _systemConfig.vpnInfo.DataSavePath); - // RequestClose?.Invoke(new DialogResult(ButtonResult.OK)); + //5 gw.recvftp.exe配置更新 + JsonParser.UpdateRecvJson(Path.Combine(_systemConfig.proRecv.ProPath, _systemConfig.proRecv.JsonPath), _wareaModel.savepath + "/" + _wareaModel.chartsavepath); } }); } diff --git a/StartServerWPF.Modules.Main/Views/DataProcessView.xaml b/StartServerWPF.Modules.Main/Views/DataProcessView.xaml new file mode 100644 index 0000000..6b2bed9 --- /dev/null +++ b/StartServerWPF.Modules.Main/Views/DataProcessView.xaml @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +