增加手动处理配置

master
mzhifa 9 months ago
parent f625adbc77
commit 6d6e518909

@ -4,6 +4,7 @@ using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
namespace StartServerWPF.Models
{
@ -14,7 +15,7 @@ namespace StartServerWPF.Models
public static string serverVision = "20230517";
public const string workareaPath = "serverprogram\\workarea";
public SystemConfigModel ReadSystemJsonFile(string jsonFile)
public SystemConfigModel ReadSystemJsonFile(string jsonFile)
{
//try
{
@ -115,7 +116,7 @@ namespace StartServerWPF.Models
saveStr = saveStr.Replace(strs2, $"\"{savePath}\"");
reader.Close();
File.WriteAllText(apmsJsonPath, saveStr);
}
}
}
public static void UpdateRecvJson(string recvJsonPath, string savePath)
{
@ -142,24 +143,33 @@ namespace StartServerWPF.Models
return moniSp;
}
public static ApmsModel ReadApmsJson(string apmsJsonPath)
public static T DeepCopy<T>(T obj)
{
ApmsModel model = new ApmsModel();
using (StreamReader sr = File.OpenText(apmsJsonPath))
object retval;
using (MemoryStream ms = new MemoryStream())
{
JsonTextReader reader = new JsonTextReader(sr);
JObject jobj = (JObject)JToken.ReadFrom(reader);
model.station = jobj["station"].ToString();
// model.ttime2d = jobj["ttime2d"].ToString();
model.savepath = jobj["Main.savepath"].ToString();
model.push2wx = jobj["push2wx"].ToString();
var jor = jobj["channels"].First;
JObject jordb = JObject.Parse(jor.ToString());
string sta = jordb["station"].ToString();
// model.channels = JsonConvert.DeserializeObject<StationChannelsModel>(jor.ToString());
BinaryFormatter bf = new BinaryFormatter();
//序列化成流
bf.Serialize(ms, obj);
ms.Seek(0, SeekOrigin.Begin);
//反序列化成对象
retval = bf.Deserialize(ms);
ms.Close();
}
return model;
return (T)retval;
}
//public static T DeepCopy<T>(T obj)
//{
// object retval;
// using (MemoryStream ms = new MemoryStream())
// {
// DataContractSerializer ser = new DataContractSerializer(typeof(T));
// ser.WriteObject(ms, obj);
// ms.Seek(0, SeekOrigin.Begin);
// retval = ser.ReadObject(ms);
// ms.Close();
// }
// return (T)retval;
//}
}
}

@ -1,4 +1,5 @@
using Prism.Commands;
using Newtonsoft.Json;
using Prism.Commands;
using Prism.Mvvm;
using Prism.Services.Dialogs;
using StartServerWPF.Models;
@ -78,13 +79,19 @@ namespace StartServerWPF.Modules.Main.ViewModels
MessageBox.Show("工区名称和目录不能为空", "提示", MessageBoxButton.OK);
return;
}
if (MessageBox.Show("确认修改?", "参数设置", MessageBoxButton.OKCancel,
if (MessageBox.Show("确认添加?", "提示", MessageBoxButton.OKCancel,
MessageBoxImage.Exclamation) == MessageBoxResult.OK)
{
string str = File.ReadAllText(Path.Combine(JsonParser.workareaPath, "Workarea.json"));
WorkareaModel workareaModel = JsonConvert.DeserializeObject<WorkareaModel>(str);
var dialog = new DialogResult(ButtonResult.OK);
Workareas workareas = new Workareas();
workareas.workareaname = WorkAreaName;
workareas.filepath = WorkAreaPath;
workareaModel.savepath = WorkAreaPath;
workareaModel.workareaname = WorkAreaName;
//生成工区默认配置文件
File.WriteAllText(Path.Combine(WorkAreaPath, Path.GetFileName(WorkAreaPath) + ".json"), JsonConvert.SerializeObject(workareaModel));
dialog.Parameters.Add("param1", workareas);
RequestClose?.Invoke( dialog);
}

@ -188,9 +188,12 @@ namespace StartServerWPF.Modules.Main.ViewModels
string str = process.ProParams.Substring(0, index) + "-wave";
process.ProParams = $"{str} {temPath}";
//dataProtools配置更新
ApmsModel tools = _workareaModel.apmModel;
//dataProtools 配置更新
var area = JsonParser.DeepCopy<WorkareaModel>(_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);
var mfile = new DirectoryInfo(temPath).EnumerateFiles("*.mseed");

@ -1,4 +1,5 @@
using Newtonsoft.Json;
using Google.Protobuf.WellKnownTypes;
using Newtonsoft.Json;
using Prism.Commands;
using Prism.Ioc;
using Prism.Mvvm;
@ -56,13 +57,17 @@ namespace StartServerWPF.Modules.Main.ViewModels
set {
if (value >= 0)
{
string file = Path.Combine(_workareasModelArray.workarea[value].filepath, "workarea.json");
if (!File.Exists(file))
try
{
JsonParser.WriteSystemConfigFile(file, WareaModel);
var area = _workareasModelArray.workarea[value];
string file = Path.Combine(area.filepath, Path.GetFileName(area.filepath) + ".json");
string json = File.ReadAllText(file);
WareaModel = JsonConvert.DeserializeObject<WorkareaModel>(json);
}
catch (Exception ex)
{
MessageBox.Show("当前工区目录配置文件不存在," + ex.Message);
}
string json = File.ReadAllText(file);
WareaModel = JsonConvert.DeserializeObject<WorkareaModel>(json);
_workareasModelArray.selectIndex = value;
}
SetProperty(ref _wareaSelectedIndex, value);
@ -92,6 +97,7 @@ namespace StartServerWPF.Modules.Main.ViewModels
{
apmStationFile = string.Empty;
apmttime2dFile = string.Empty;
// WareaModel.apmModel = ;
});
public DelegateCommand AddItemCommand => new(() =>
@ -106,17 +112,38 @@ namespace StartServerWPF.Modules.Main.ViewModels
if (result != null && result.Result == ButtonResult.OK)
{
var area = result.Parameters.GetValue<Workareas>("param1");
WareaModel.savepath = area.filepath;
var file = _workareasModelArray.workarea.Where(f => f.filepath == area.filepath).FirstOrDefault();
var file = _workareasModelArray.workarea.Where(f => f.workareaname == area.workareaname).FirstOrDefault();
if (file == null)
{
_workareasModelArray.workarea.Add(area);
WorkareaNameSource.Add(area.workareaname);
WareaSelectedIndex= WorkareaNameSource.Count()-1;
}
else
{
//更新当前工区目录
file.filepath = area.filepath;
WareaSelectedIndex = _workareasModelArray.selectIndex;
}
}
}));
});
public DelegateCommand DeleteItemCommand => new(() =>
{
if (MessageBox.Show($"删除{WareaModel.workareaname}工区所有文件?", "提示", MessageBoxButton.OKCancel,
MessageBoxImage.Exclamation) == MessageBoxResult.OK)
{
if (Directory.Exists(WareaModel.savepath))
{
Directory.Delete(WareaModel.savepath, true);
}
var area= _workareasModelArray.workarea.Where(a => a.workareaname == WareaModel.workareaname).FirstOrDefault();
WorkareaNameSource.Remove(WareaModel.workareaname);
_workareasModelArray.workarea.Remove(area);
WareaSelectedIndex =0;
}
});
public DelegateCommand<object> SelectFileCommand => new((obj) =>
{
string para = obj.ToString();
@ -183,7 +210,6 @@ namespace StartServerWPF.Modules.Main.ViewModels
if (MessageBox.Show("确认修改?", "参数设置", MessageBoxButton.OKCancel,
MessageBoxImage.Exclamation) == MessageBoxResult.OK)
{
//1 Workarea配置更新选择的索引
JsonParser.WriteSystemConfigFile(Path.Combine(JsonParser.workareaPath, "Workareas.json"), _workareasModelArray);
_wareaModel.apmModel.channels = new List<StationChannelsModel>
@ -197,8 +223,8 @@ namespace StartServerWPF.Modules.Main.ViewModels
}
};
JsonParser.WriteSystemConfigFile(Path.Combine(_wareaModel.savepath, "Workarea.json"), _wareaModel);
string wareaJson = JsonConvert.SerializeObject(_wareaModel);
var curWorkarea = JsonConvert.DeserializeObject<WorkareaModel>(wareaJson);
var curWorkarea = JsonParser.DeepCopy<WorkareaModel>(_wareaModel);
if (!string.IsNullOrEmpty(apmStationFile))
{
string destFileName = Path.GetFullPath(Path.Combine(curWorkarea.savepath, curWorkarea.apmModel.station));

@ -200,6 +200,7 @@
</StackPanel>
<StackPanel Orientation="Horizontal" VerticalAlignment="Bottom" HorizontalAlignment="Center" Grid.Row="3" Grid.Column="2" Margin="0,0,0,30">
<Button Content="添加工区" Width="100" Height="30" Background="#FF0ABEFF" Foreground="White" Command="{Binding AddItemCommand}"/>
<Button Content="删除工区" Width="100" Height="30" Background="#FF0ABEFF" Foreground="White" Command="{Binding DeleteItemCommand}"/>
<Button Content="应用" Margin="30,0,0,0" Width="100" Height="30" Background="#FF0ABEFF" Foreground="White" Command="{Binding ConfirmCommand}"/>
</StackPanel>
</Grid>

@ -43,23 +43,29 @@ namespace StartServerWPF
containerRegistry.RegisterSingleton<SystemConfigModel>(() => sc);
string st = File.ReadAllText(Path.Combine(JsonParser.workareaPath, "Workareas.json"));
var wm = JsonConvert.DeserializeObject<WorkareasModelArray>(st);
var item = wm.workarea[wm.selectIndex];
string workarea = File.ReadAllText(Path.Combine(item.filepath, "Workarea.json"));
var currentWorkarea = JsonConvert.DeserializeObject<WorkareaModel>(workarea);
string areaPath = Path.Combine(item.filepath, Path.GetFileName(item.filepath)+".json");
var currentWorkarea =new WorkareaModel();
if (File.Exists(areaPath))
{
string workarea = File.ReadAllText(areaPath);
currentWorkarea = JsonConvert.DeserializeObject<WorkareaModel>(workarea);
if (currentWorkarea.StationConfig.Stations == null)
if (currentWorkarea.StationConfig.Stations == null)
{
currentWorkarea.StationConfig.Stations = currentWorkarea.CreateStationFromCSV(Path.Combine(JsonParser.workareaPath, currentWorkarea.apmModel.station), currentWorkarea.StationConfig.Location)
?.Select(a => new StationState { IsEnable = a.Enable, Name = a.Num }).ToList();
}
}
else
{
currentWorkarea.StationConfig.Stations = currentWorkarea.CreateStationFromCSV(Path.Combine(JsonParser.workareaPath, currentWorkarea.apmModel.station), currentWorkarea.StationConfig.Location)
?.Select(a => new StationState { IsEnable = a.Enable, Name = a.Num }).ToList();
//加载默认配置数据
string workarea = File.ReadAllText(Path.Combine(JsonParser.workareaPath, "Workarea.json"));
currentWorkarea = JsonConvert.DeserializeObject<WorkareaModel>(workarea);
}
containerRegistry.RegisterSingleton<WorkareasModelArray>(() => wm);
containerRegistry.RegisterSingleton<WorkareaModel>(() => currentWorkarea);
}
protected override void ConfigureModuleCatalog(IModuleCatalog moduleCatalog)

@ -1,105 +1,101 @@
{
"selectIndex": 0,
"workarea": [
{
"workareaname": "n3103",
"savepath": "I:/DATA",
"chartsavepath": "chartsavepath",
"apmsavepath": "apmsavepath",
"toolsavepath": "toolsavepath",
"apmpush2wx": false,
"toolpush2wx": false,
"delayTime": 10,
"apmModel": {
"station": "N3102_staion_20230403.csv",
"ttime": [
{
"station": "ttime",
"ttime2d": "ttime_gw20210427.tab"
}
],
"Main.log_level": "DEBUG",
"Main.slice_seconds": 30,
"Main.overlap_seconds": 10,
"Main.is_mag": "YES",
"Main.is_write_slice": "NO",
"Main.lon": 38398463.49,
"Main.lat": 4031112.103,
"Main.height": 1102.63,
"Main.savepath": "I://yuwuN3102mseed//post",
"Main.push2wx": "NO",
"Main.push_url": "http://www.txgy.cloud/api/index/push",
"Main.push_mag": -1.0,
"Main.message_id": 1,
"Main.company_id": 1,
"Main.area_id": 8,
"Main.content": "通知事件",
"Main.push_key": "Y3qYFBQPMbfTt6m",
"RServer.host": "127.0.0.1",
"channels": [
{
"network": "HA",
"location": "06",
"channels": "SHZ:SHN:SHE",
"station": "N02,N03,N04,N05,N06,N07,N08,N09,N10,N11,N12,N13,N14,N15,N16,N17,N18,N19,N20,N21,N22,N23,N24,N25,N26,N27"
}
],
"Locate.log_level": "DEBUG",
"Locate.work_path": ".",
"Locate.xmin": 38396517,
"Locate.xmax": 38398317,
"Locate.ymin": 4029418,
"Locate.ymax": 4031218,
"Locate.zref": 1039,
"Locate.zmin": 300,
"Locate.zmax": 800,
"Locate.minstep": 10,
"Locate.method": "",
"Locate.clusted_otime": 0.5
},
"StationConfig": {
"workareaname": "n3103",
"savepath": "",
"chartsavepath": "chartsavepath",
"apmsavepath": "Realtime",
"toolsavepath": "Post",
"apmpush2wx": false,
"toolpush2wx": false,
"delayTime": 10,
"apmModel": {
"station": "",
"ttime": [
{
"station": "ttime",
"ttime2d": ""
}
],
"Main.log_level": "DEBUG",
"Main.slice_seconds": 30,
"Main.overlap_seconds": 10,
"Main.is_mag": "YES",
"Main.is_write_slice": "NO",
"Main.lon": 38398463.49,
"Main.lat": 4031112.103,
"Main.height": 1102.63,
"Main.savepath": "I://yuwuN3102mseed//post",
"Main.push2wx": "NO",
"Main.push_url": "http://www.txgy.cloud/api/index/push",
"Main.push_mag": -1.0,
"Main.message_id": 1,
"Main.company_id": 1,
"Main.area_id": 8,
"Main.content": "通知事件",
"Main.push_key": "Y3qYFBQPMbfTt6m",
"RServer.host": "127.0.0.1",
"channels": [
{
"network": "HA",
"location": "06",
"channels": "SHZ:SHN:SHE",
"stations": [
{
"Name": "N02",
"IsEnable": true
},
{
"Name": "N03",
"IsEnable": true
},
{
"Name": "N04",
"IsEnable": true
},
{
"Name": "N05",
"IsEnable": true
},
{
"Name": "N06",
"IsEnable": false
},
{
"Name": "N07",
"IsEnable": false
},
{
"Name": "N08",
"IsEnable": true
},
{
"Name": "N09",
"IsEnable": true
},
{
"Name": "N10",
"IsEnable": true
}
]
"station": "N02,N03,N04,N05,N06,N07,N08,N09,N10,N11,N12,N13,N14,N15,N16,N17,N18,N19,N20,N21,N22,N23,N24,N25,N26,N27"
}
],
"Locate.log_level": "DEBUG",
"Locate.work_path": ".",
"Locate.xmin": 38396517,
"Locate.xmax": 38398317,
"Locate.ymin": 4029418,
"Locate.ymax": 4031218,
"Locate.zref": 1039,
"Locate.zmin": 300,
"Locate.zmax": 800,
"Locate.minstep": 10,
"Locate.method": "",
"Locate.clusted_otime": 0.5
},
"StationConfig": {
"network": "HA",
"location": "06",
"channels": "SHZ:SHN:SHE",
"stations": [
{
"Name": "N02",
"IsEnable": true
},
{
"Name": "N03",
"IsEnable": true
},
{
"Name": "N04",
"IsEnable": true
},
{
"Name": "N05",
"IsEnable": true
},
{
"Name": "N06",
"IsEnable": false
},
{
"Name": "N07",
"IsEnable": false
},
{
"Name": "N08",
"IsEnable": true
},
{
"Name": "N09",
"IsEnable": true
},
{
"Name": "N10",
"IsEnable": true
}
}
]
]
}
}
Loading…
Cancel
Save