You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
165 lines
6.8 KiB
C#
165 lines
6.8 KiB
C#
using System;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Newtonsoft.Json.Linq;
|
|
using Newtonsoft.Json;
|
|
using System.IO;
|
|
using StartServerWPF.Modules.Main.Models;
|
|
|
|
namespace StartServerWPF.Modules.Main
|
|
{
|
|
public class JsonParser
|
|
{
|
|
// public static string zyProPath = @"\serverprogram";
|
|
|
|
public static string systemConfigPath = "SystemConfig.json";
|
|
public static string serverVision = "20230517";
|
|
|
|
public static SystemConfig ReadSystemJsonFile(string jsonFile)
|
|
{
|
|
//try
|
|
{
|
|
//StreamReader sr = File.OpenText(jsonFile);
|
|
//JsonTextReader reader = new JsonTextReader(sr);
|
|
//JObject jobj = (JObject)JToken.ReadFrom(reader);
|
|
SystemConfig sc = new SystemConfig();
|
|
string str = File.ReadAllText(jsonFile);
|
|
sc = JsonConvert.DeserializeObject<SystemConfig>(str);
|
|
//sc.SystemLogPath = jobj["SystemLogPath"].ToString();
|
|
//sc.DataSavePath = jobj["DataSavePath"].ToString();
|
|
|
|
////RemoteDb
|
|
//JObject jordb = JObject.Parse(jobj["remoteDb"].ToString());
|
|
//sc.remoteDb = new RemoteDataBase();
|
|
//sc.remoteDb.ServerAddress = jordb["ServerAddress"].ToString();
|
|
//sc.remoteDb.ServerPort = jordb["ServerPort"].ToString();
|
|
//sc.remoteDb.UserName = jordb["UserName"].ToString();
|
|
//sc.remoteDb.Password = jordb["Password"].ToString();
|
|
//sc.remoteDb.DataBase = jordb["DataBase"].ToString();
|
|
//sc.remoteDb.TableName = jordb["TableName"].ToString();
|
|
|
|
////VPN
|
|
//JObject jovpn = JObject.Parse(jobj["vpnInfo"].ToString());
|
|
//sc.vpnInfo = new VpnInfo();
|
|
//sc.vpnInfo.VpnName = jovpn["VpnName"].ToString();
|
|
//sc.vpnInfo.VpnIP = jovpn["VpnIP"].ToString();
|
|
//sc.vpnInfo.VpnUserName = jovpn["VpnUserName"].ToString();
|
|
//sc.vpnInfo.VpnPsw = jovpn["VpnPsw"].ToString();
|
|
|
|
////server
|
|
//JObject joserver = JObject.Parse(jobj["proServer"].ToString());
|
|
//sc.proServer = new ProcessInfo();
|
|
//sc.proServer.ProName = "server";
|
|
//sc.proServer.ProPath = joserver["ProPath"].ToString();
|
|
//sc.proServer.ProParams = joserver["ProParams"].ToString();
|
|
|
|
////gw.recvftp
|
|
//JObject jorecvftp = JObject.Parse(jobj["proRecv"].ToString());
|
|
//sc.proRecv = new ProcessInfo();
|
|
//sc.proRecv.ProName = "gw.recvftp";
|
|
//sc.proRecv.ProPath = jorecvftp["ProPath"].ToString();
|
|
//sc.proRecv.ProParams = jorecvftp["ProParams"].ToString();
|
|
//sc.proRecv.JsonPath = jorecvftp["JsonPath"].ToString();
|
|
|
|
////gw.apms
|
|
//JObject joapms = JObject.Parse(jobj["proApms"].ToString());
|
|
//sc.proApms = new ProcessInfo();
|
|
//sc.proApms.ProName = "gw.apms";
|
|
//sc.proApms.ProPath = joapms["ProPath"].ToString();
|
|
//sc.proApms.ProParams = joapms["ProParams"].ToString();
|
|
//sc.proApms.JsonPath = joapms["JsonPath"].ToString();
|
|
|
|
////gw.monitor
|
|
//JObject jomonitor = JObject.Parse(jobj["proMonitor"].ToString());
|
|
//sc.proMonitor = new ProcessInfo();
|
|
//sc.proMonitor.ProName = "gw.monitor";
|
|
//sc.proMonitor.ProPath = jomonitor["ProPath"].ToString();
|
|
//sc.proMonitor.ProParams = jomonitor["ProParams"].ToString();
|
|
|
|
////gw.plot
|
|
//JObject joplot = JObject.Parse(jobj["proPlot"].ToString());
|
|
//sc.proPlot = new ProcessInfo();
|
|
//sc.proPlot.ProName = "gw.plot";
|
|
//sc.proPlot.ProPath = joplot["ProPath"].ToString();
|
|
|
|
//reader.Close();
|
|
//sr.Close();
|
|
return sc;
|
|
}
|
|
//catch (Exception)
|
|
//{
|
|
// MessageBox.Show("没有系统配置文件!");
|
|
// return null;
|
|
//}
|
|
}
|
|
public static void WriteSystemConfigFile(string jsonFile, SystemConfig sc)
|
|
{
|
|
string str = JsonConvert.SerializeObject(sc, Formatting.Indented);
|
|
File.WriteAllText(jsonFile, str);
|
|
}
|
|
|
|
public static void UpdateApmsJson(string apmsJsonPath, string savePath)
|
|
{
|
|
StreamReader reader = new StreamReader(apmsJsonPath, Encoding.UTF8);
|
|
string saveStr = reader.ReadToEnd();
|
|
int strInd = saveStr.IndexOf("Main.savepath") - 1;
|
|
string str1 = saveStr.Substring(strInd);
|
|
strInd = str1.IndexOf(",");
|
|
string str2 = str1.Substring(0, strInd);
|
|
strInd = str2.IndexOf(":");
|
|
string strs1 = str2.Substring(0, strInd);
|
|
string strs2 = str2.Substring(strInd + 1);
|
|
savePath = savePath.Replace("\\", "\\\\");
|
|
saveStr = saveStr.Replace(strs2, $"\"{savePath}\"");
|
|
reader.Close();
|
|
File.WriteAllText(apmsJsonPath, saveStr);
|
|
|
|
}
|
|
public static void UpdateRecvJson(string recvJsonPath, string savePath)
|
|
{
|
|
StreamReader reader = new StreamReader(recvJsonPath, Encoding.UTF8);
|
|
string saveStr = reader.ReadToEnd();
|
|
int strInd = saveStr.IndexOf("savepath") - 1;
|
|
string str1 = saveStr.Substring(strInd);
|
|
strInd = str1.IndexOf(",");
|
|
string str2 = str1.Substring(0, strInd);
|
|
strInd = str2.IndexOf(":");
|
|
string strs1 = str2.Substring(0, strInd);
|
|
string strs2 = str2.Substring(strInd + 1);
|
|
savePath = savePath.Replace("\\", "\\\\");
|
|
saveStr = saveStr.Replace(strs2, $"\"{savePath}\"");
|
|
reader.Close();
|
|
File.WriteAllText(recvJsonPath, saveStr);
|
|
}
|
|
|
|
public static string CreateMonitorStartParam(string dataPath, DateTime beginTime)
|
|
{
|
|
string webPath = dataPath.Replace("\\", "/");
|
|
string moniSp = "-sta n1105_station_xyz.csv -port 8086 -rdir " + webPath +
|
|
" -btime " + beginTime.GetDateTimeFormats('s')[0].ToString() + " >outMonitor.txt";
|
|
return moniSp;
|
|
}
|
|
|
|
|
|
public static string[] ReadApmsJson(string apmsJsonPath)
|
|
{
|
|
using (StreamReader sr = File.OpenText(apmsJsonPath))
|
|
{
|
|
|
|
JsonTextReader reader = new JsonTextReader(sr);
|
|
JObject jobj = (JObject)JToken.ReadFrom(reader);
|
|
JObject jordb = JObject.Parse(jobj["channels"].ToString());
|
|
|
|
string sta = jordb["station"].ToString();
|
|
|
|
var staList= sta.Split(",");
|
|
return staList;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|