diff --git a/StartServerWPF.Models/ProcessInfo.cs b/StartServerWPF.Models/ProcessInfo.cs index 6869d9c..81ff8ea 100644 --- a/StartServerWPF.Models/ProcessInfo.cs +++ b/StartServerWPF.Models/ProcessInfo.cs @@ -29,6 +29,12 @@ namespace StartServerWPF.Models get { return proTitle; } set { proTitle = value; } } + private bool isEnable; + public bool IsEnable + { + get { return isEnable; } + set { isEnable = value; } + } private string proPath; /// diff --git a/StartServerWPF.Models/WorkareaModel.cs b/StartServerWPF.Models/WorkareaModel.cs index 420ca1e..97d9807 100644 --- a/StartServerWPF.Models/WorkareaModel.cs +++ b/StartServerWPF.Models/WorkareaModel.cs @@ -92,6 +92,7 @@ namespace StartServerWPF.Models model.Location = location; stations.Add(model); } + stations = stations.OrderBy(x => x.Num).ToList(); //释放资源 workbook = null; worksheet = null; diff --git a/StartServerWPF.Modules.Main/ViewModels/DataProcessViewModel.cs b/StartServerWPF.Modules.Main/ViewModels/DataProcessViewModel.cs index b51c754..cad0c2a 100644 --- a/StartServerWPF.Modules.Main/ViewModels/DataProcessViewModel.cs +++ b/StartServerWPF.Modules.Main/ViewModels/DataProcessViewModel.cs @@ -72,11 +72,21 @@ namespace StartServerWPF.Modules.Main.ViewModels { if(value >= 0) { - var model = _workareasModelArray.workarea[value]; - string jsonStr = File.ReadAllText(Path.Combine(model.filepath, "datapro.json")); - var datas = JsonConvert.DeserializeObject>(jsonStr); - NameSource = new ObservableCollection(); - datas.ForEach(d => { NameSource.Add(d); }); + string path = string.Empty; + try + { + var model = _workareasModelArray.workarea[value]; + path = Path.Combine(model.filepath, "datapro.json"); + string jsonStr = File.ReadAllText(path); + var datas = JsonConvert.DeserializeObject>(jsonStr); + NameSource = new ObservableCollection(); + datas.ForEach(d => { NameSource.Add(d); }); + } + catch (Exception ex) + { + MessageBox.Show("加载配置失败,"+path); + } + } SetProperty(ref _wareaSelectedIndex, value); } @@ -174,9 +184,23 @@ namespace StartServerWPF.Modules.Main.ViewModels }); public DelegateCommand SaveCommand => new(() => { + var item = NameSource[DataSelectedIndex]; + item.DataPath = DataPath; + item.ResultPath = SavePath; + item.StartTime = StartSelectedDate; + item.EndTime=EndSelectedDate; string jsonStr = JsonConvert.SerializeObject(NameSource, Formatting.Indented); var model = _workareasModelArray.workarea[WareaSelectedIndex]; File.WriteAllText(Path.Combine(model.filepath, "datapro.json"), jsonStr); + + //dataProtools 配置更新 + string temJson = JsonConvert.SerializeObject(_workareaModel); + var area = JsonConvert.DeserializeObject(temJson); + ApmsModel tools = area.apmModel; + tools.savepath = SavePath; + tools.station = Path.GetFullPath(Path.Combine(area.savepath, area.apmModel.station)).Replace("\\", "/"); + tools.ttime[0].ttime2d = Path.GetFullPath(Path.Combine(area.savepath, area.apmModel.ttime[0].ttime2d)).Replace("\\", "/"); + JsonParser.WriteSystemConfigFile(Path.Combine(_systemConfig.dataProTools.ProPath, "apms.json"), tools); }); public DelegateCommand SelectFileCommand => new((obj) => @@ -206,78 +230,66 @@ namespace StartServerWPF.Modules.Main.ViewModels 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) + // 数据校验(关键字段不能为空、年龄做数字区间的校验、做UserName的唯一检查(自定义特性检查) + if (string.IsNullOrEmpty(DataPath) || string.IsNullOrEmpty(SavePath)) { - 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); - } - Task.Run(() => + MessageBox.Show("内容不能为空", "提示", MessageBoxButton.OK); + return; + } + + var time = (EndSelectedDate.AddSeconds(-EndSelectedDate.Second) - StartSelectedDate.AddSeconds(-StartSelectedDate.Second)); + 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); + } + Task.Run(() => + { + IsBusy = false; + while ((EndSelectedDate - dateTime).TotalMinutes >= 1) { - IsBusy = false; - 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)) { - 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); - }); + 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}"; - - //dataProtools 配置更新 - string temJson= JsonConvert.SerializeObject(_workareaModel); - var area = JsonConvert.DeserializeObject(temJson); //JsonParser.DeepCopy(_workareaModel); - - ApmsModel tools = area.apmModel; - tools.savepath = SavePath; - tools.station = Path.GetFullPath(Path.Combine(area.savepath, area.apmModel.station)).Replace("\\", "/"); - tools.ttime[0].ttime2d = Path.GetFullPath(Path.Combine(area.savepath, area.apmModel.ttime[0].ttime2d)).Replace("\\", "/"); - JsonParser.WriteSystemConfigFile(Path.Combine(_systemConfig.dataProTools.ProPath, "apms.json"), tools); + ProcessInfo process = _systemConfig.dataProTools; + int index = process.ProParams.IndexOf("-wave"); + string str = process.ProParams.Substring(0, index) + "-wave"; + process.ProParams = $"{str} {temPath}"; - var mfile = new DirectoryInfo(temPath).EnumerateFiles("*.mseed"); - if (mfile.Any()) - { - isStart = true; - if (fileDic.Count != 0) fileDic.Clear(); - this.StartProcess(process); - } - else + var mfile = new DirectoryInfo(temPath).EnumerateFiles("*.mseed"); + if (mfile.Any()) + { + isStart = true; + if (fileDic.Count != 0) fileDic.Clear(); + this.StartProcess(process); + } + else + { + IsBusy=true; + Application.Current.Dispatcher.InvokeAsync(() => { - Application.Current.Dispatcher.InvokeAsync(() => - { - AddItems(ProcessSliceSource, new ProcessingInformationModel { ProcessMes = "没有需要处理的文件", MonitorTime = DateTime.Now.ToString() }); - }, DispatcherPriority.ApplicationIdle); - } - }); - } + AddItems(ProcessSliceSource, new ProcessingInformationModel { ProcessMes = "没有需要处理的文件", MonitorTime = DateTime.Now.ToString() }); + }, DispatcherPriority.ApplicationIdle); + } + }); }); } @@ -290,6 +302,7 @@ namespace StartServerWPF.Modules.Main.ViewModels process.StartInfo.FileName = Path.GetFullPath(proInfo.ProPath + proInfo.ProName + ".exe"); process.StartInfo.WorkingDirectory = Path.GetFullPath(proInfo.ProPath); process.StartInfo.Arguments = proInfo.ProParams; + Debug.WriteLine($"*******name:{process.StartInfo.FileName}, arguments:{process.StartInfo.Arguments}*********"); process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardError = true; @@ -312,7 +325,7 @@ namespace StartServerWPF.Modules.Main.ViewModels { return; } - list.Add(t1); + list.Insert(0,t1); if (list.Count > 30) { T item = list[0]; @@ -362,16 +375,27 @@ namespace StartServerWPF.Modules.Main.ViewModels private void Process_Exited(object? sender, EventArgs e) { + Debug.WriteLine($"****数据处理程序退出,{e.ToString()}******************"); IsBusy = true; - var fileName = Directory.GetFiles(SavePath, "*.index"); - if (!File.Exists( fileName.FirstOrDefault())) + //处理完成后删除临时文件 + string temPath = Path.GetPathRoot(_workareaModel.savepath) + "temPath"; + if (Directory.Exists(temPath)) { - return; + Directory.Delete(temPath, true); + } + //解析处理后的事件文件 + var fileName = Directory.GetFiles(SavePath, "*.index", SearchOption.AllDirectories); + List lines = new List(); + foreach (var file in fileName) + { + string[] text = File.ReadAllLines(file); + var data = text.Where(p => StartSelectedDate <= Convert.ToDateTime(p.Split(" ")[0]) + && EndSelectedDate >= Convert.ToDateTime(p.Split(" ")[0])); + lines.AddRange(data); } - string[] text = File.ReadAllLines(fileName.FirstOrDefault()); Application.Current.Dispatcher.BeginInvoke(() => { - foreach (var item in text) + foreach (var item in lines) { ApmsEventSource.Add(new MsEventModel(item)); } diff --git a/StartServerWPF.Modules.Main/ViewModels/MainViewModel.cs b/StartServerWPF.Modules.Main/ViewModels/MainViewModel.cs index c7ae7b5..855f7ca 100644 --- a/StartServerWPF.Modules.Main/ViewModels/MainViewModel.cs +++ b/StartServerWPF.Modules.Main/ViewModels/MainViewModel.cs @@ -34,7 +34,8 @@ namespace StartServerWPF.Modules.Main.ViewModels Message = "View A" ; Console.WriteLine(System.Environment.CurrentDirectory + "\\" + JsonParser.systemConfigPath); _systemConfig = systemConfig; - + ApmsIsEnable = _systemConfig.proApms.IsEnable; + ToolsIsEnable= _systemConfig.proTools.IsEnable; InitializeParams(); StartTime = DateTime.Now; Console.WriteLine(System.Environment.CurrentDirectory); @@ -196,6 +197,29 @@ namespace StartServerWPF.Modules.Main.ViewModels get { return isIndeterminate; } set { SetProperty(ref isIndeterminate, value); } } + + private bool apmsIsEnable; + public bool ApmsIsEnable + { + get { return apmsIsEnable; } + set + { + _systemConfig.proApms.IsEnable = value; + SetProperty(ref apmsIsEnable, value); + } + } + private bool toolsIsEnable; + public bool ToolsIsEnable + { + get { return toolsIsEnable; } + set + { + _systemConfig.proTools.IsEnable= value; + SetProperty(ref toolsIsEnable, value); + } + } + + private ObservableCollection _processDataSource =new ObservableCollection(); public ObservableCollection ProcessDataSource @@ -258,7 +282,7 @@ namespace StartServerWPF.Modules.Main.ViewModels { return; } - list.Add(t1); + list.Insert(0,t1); if (list.Count > 30) { T item = list[0]; @@ -385,7 +409,7 @@ namespace StartServerWPF.Modules.Main.ViewModels foreach (var item in _systemConfig.GetType().GetProperties()) { var pro = item.GetValue(_systemConfig) as ProcessInfo; - if (pro != null&& pro.ProTitle!= "数据处理") + if (pro != null&& pro.IsEnable && pro.ProTitle!= "数据处理") { StartTime = DateTime.Now; pro.Pid= StartProcess(pro); @@ -418,7 +442,7 @@ namespace StartServerWPF.Modules.Main.ViewModels foreach (var item in _systemConfig.GetType().GetProperties()) { var pro = item.GetValue(_systemConfig) as ProcessInfo; - if (pro != null&& pro.ProTitle != "数据处理") + if (pro != null&& pro.IsEnable && pro.ProTitle != "数据处理") { int indexPro = KillProcess(pro); var model= ProcessDataSource.Where(x => x.ProName == pro.ProName).FirstOrDefault(); diff --git a/StartServerWPF.Modules.Main/ViewModels/SetParamViewModel.cs b/StartServerWPF.Modules.Main/ViewModels/SetParamViewModel.cs index 01db09e..97d3a92 100644 --- a/StartServerWPF.Modules.Main/ViewModels/SetParamViewModel.cs +++ b/StartServerWPF.Modules.Main/ViewModels/SetParamViewModel.cs @@ -1,5 +1,6 @@ using Google.Protobuf.WellKnownTypes; using Newtonsoft.Json; +using Newtonsoft.Json.Linq; using Prism.Commands; using Prism.Ioc; using Prism.Mvvm; @@ -29,11 +30,11 @@ namespace StartServerWPF.Modules.Main.ViewModels this._dialogService = dialogService; _systemConfig = configModel; WareaModel = workareaModel; + wareaModelSingleton = workareaModel; this._workareasModelArray = workareasModelArray; MainModel = _systemConfig.vpnInfo; WorkareaNameSource = new ObservableCollection(); - _workareasModelArray.workarea.Select(n=>n.workareaname).ToList().ForEach(a=> WorkareaNameSource.Add(a)); - WareaSelectedIndex = _workareasModelArray.selectIndex; + _workareasModelArray.workarea.Select(n=>n.workareaname).ToList().ForEach(a=> WorkareaNameSource.Add(a)); } private string _title = "应用列表"; public string Title => _title; @@ -77,12 +78,12 @@ namespace StartServerWPF.Modules.Main.ViewModels File.WriteAllText(file, JsonConvert.SerializeObject(WareaModel)); //MessageBox.Show("当前工区目录配置文件不存在," + ex.Message); - } - _workareasModelArray.selectIndex = value; + } } SetProperty(ref _wareaSelectedIndex, value); } } + private WorkareaModel wareaModelSingleton = null; private WorkareaModel _wareaModel = new WorkareaModel(); public WorkareaModel WareaModel { @@ -107,6 +108,7 @@ namespace StartServerWPF.Modules.Main.ViewModels { apmStationFile = string.Empty; apmttime2dFile = string.Empty; + WareaSelectedIndex = _workareasModelArray.selectIndex; }); public DelegateCommand AddItemCommand => new(() => @@ -206,8 +208,11 @@ namespace StartServerWPF.Modules.Main.ViewModels { case "apmsStation": WareaModel.apmModel.station = fbd.SafeFileName; - apmStationFile = fbd.FileName; - break; + apmStationFile = fbd.FileName; + + WareaModel.StationConfig.Stations= WareaModel.CreateStationFromCSV(apmStationFile, WareaModel.StationConfig.Location) + ?.Select(a => new StationState { IsEnable = a.Enable, Name = a.Num }).ToList(); + break; case "apmsttime2d": WareaModel.apmModel.ttime[0].ttime2d = fbd.SafeFileName; apmttime2dFile = fbd.FileName; @@ -261,6 +266,7 @@ namespace StartServerWPF.Modules.Main.ViewModels MessageBoxImage.Exclamation) == MessageBoxResult.OK) { //1 Workarea配置更新,选择的索引 + _workareasModelArray.selectIndex = WareaSelectedIndex; JsonParser.WriteSystemConfigFile(Path.Combine(JsonParser.workareaPath, "Workareas.json"), _workareasModelArray); _wareaModel.apmModel.channels = new List { @@ -272,6 +278,18 @@ namespace StartServerWPF.Modules.Main.ViewModels station = string.Join(",", _wareaModel.StationConfig.Stations.Where(p => p.IsEnable).Select(n => n.Name)) } }; + + wareaModelSingleton.workareaname = _wareaModel.workareaname; + wareaModelSingleton.apmpush2wx =_wareaModel.apmpush2wx; + wareaModelSingleton.toolpush2wx =_wareaModel.toolpush2wx; + wareaModelSingleton.savepath =_wareaModel.savepath; + wareaModelSingleton.chartsavepath=_wareaModel.chartsavepath; + wareaModelSingleton.apmsavepath =_wareaModel.apmsavepath; + wareaModelSingleton.toolsavepath =_wareaModel.toolsavepath; + wareaModelSingleton.delayTime =_wareaModel.delayTime; + wareaModelSingleton.apmModel = _wareaModel.apmModel; + wareaModelSingleton.StationConfig = _wareaModel.StationConfig; + JsonParser.WriteSystemConfigFile(Path.Combine(_wareaModel.savepath, Path.GetFileName(_wareaModel.savepath) + ".json"), _wareaModel); string temJson = JsonConvert.SerializeObject(_wareaModel); @@ -317,7 +335,7 @@ namespace StartServerWPF.Modules.Main.ViewModels //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 {curWorkarea.delayTime * 60}"; + _systemConfig.proTools.ProParams = $"{str} {Path.Combine(curWorkarea.savepath, curWorkarea.chartsavepath).Replace("\\", "/")} -delay {curWorkarea.delayTime * 60}"; JsonParser.WriteSystemConfigFile(JsonParser.systemConfigPath, _systemConfig); } //dataProTools配置更新 diff --git a/StartServerWPF.Modules.Main/Views/DataProcessView.xaml b/StartServerWPF.Modules.Main/Views/DataProcessView.xaml index 0f49deb..1e31030 100644 --- a/StartServerWPF.Modules.Main/Views/DataProcessView.xaml +++ b/StartServerWPF.Modules.Main/Views/DataProcessView.xaml @@ -56,18 +56,18 @@