添加项目文件。

master
mzhifa 1 year ago
parent ca51d89f9a
commit d343d24795

@ -0,0 +1,149 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
using System.IO;
using StartServerWPF.Modules.Main.Model;
namespace StartServerWPF.Modules.Main
{
public static class JsonParser
{
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);
//using (StreamWriter sw = new StreamWriter(jsonFile))
//{
// JsonSerializer js = new JsonSerializer();
// JsonWriter jw = new JsonTextWriter(sw);
// js.Serialize(jw, sc);
// jw.Close();
// sw.Close();
//}
}
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;
}
}
}

@ -0,0 +1,22 @@
using Prism.Ioc;
using Prism.Modularity;
using Prism.Regions;
using StartServerWPF.Modules.Main.ViewModels;
using StartServerWPF.Modules.Main.Views;
namespace StartServerWPF.Modules.Main
{
public class MainModule : IModule
{
public void OnInitialized(IContainerProvider containerProvider)
{
var iRegion= containerProvider.Resolve<IRegionManager>();
iRegion.RegisterViewWithRegion("MainContentRegion", typeof(MainView));
}
public void RegisterTypes(IContainerRegistry containerRegistry)
{
containerRegistry.RegisterDialog<SetParamDialog>();
}
}
}

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StartServerWPF.Modules.Main.Model
{
public class ApmsConfig
{
private string station;
public string Station
{
get { return station; }
set { station = value; }
}
private string mainlog_level;
public string Mainlog_level
{
get { return mainlog_level; }
set { mainlog_level = value; }
}
}
}

@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StartServerWPF.Modules.Main.Model
{
public class SystemConfig
{
/// <summary>
/// 远程数据库
/// </summary>
public RemoteDataBase remoteDb { get; set; }
/// <summary>
/// Vpn信息
/// </summary>
public VpnInfo vpnInfo;
/// <summary>
/// server程序
/// </summary>
public ProcessInfo proServer { get; set; }
/// <summary>
/// Recv程序
/// </summary>
public ProcessInfo proRecv { get; set; }
/// <summary>
/// Apms(定位程序)程序
/// </summary>
public ProcessInfo proApms { get; set; }
/// <summary>
/// Monitor(网页显示)程序
/// </summary>
public ProcessInfo proMonitor { get; set; }
/// <summary>
/// 波形显示程序
/// </summary>
public ProcessInfo proPlot { get; set; }
}
}

@ -0,0 +1,48 @@
using Prism.Mvvm;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StartServerWPF.Modules.Main.Model
{
/// <summary>
/// VPN信息类
/// </summary>
public class VpnInfo : BindableBase
{
private string vpnName;
private string vpnIP;
private string vpnUserName;
private string vpnPsw;
private string systemLogPath;
private string dataSavePath;
/// <summary>
/// VPN名称
/// </summary>
public string VpnName { get => vpnName; set => SetProperty(ref vpnName, value); }
/// <summary>
/// VPNIP
/// </summary>
public string VpnIP { get => vpnIP; set => SetProperty(ref vpnIP, value); }
/// <summary>
/// VPN用户名
/// </summary>
public string VpnUserName { get => vpnUserName; set => SetProperty(ref vpnUserName, value); }
/// <summary>
/// VPN密码
/// </summary>
public string VpnPsw { get => vpnPsw; set => SetProperty(ref vpnPsw, value); }
/// <summary>
/// 系统日志路径
/// </summary>
public string SystemLogPath { get => systemLogPath; set => SetProperty(ref systemLogPath, value); }
/// <summary>
/// 数据存储路径
/// </summary>
public string DataSavePath { get => dataSavePath; set => SetProperty(ref dataSavePath, value); }
}
}

@ -0,0 +1,83 @@
using System;
namespace StartServerWPF.Modules.Main
{
public class MsEvent
{
public int ID { get; set; }
public DateTime OriginTime { get; set; }
public double ShowX { get; set; }
public double ShowY { get; set; }
public double ShowZ { get; set; }
public double X { get; set; }
public double Y { get; set; }
public double Z { get; set; }
/// <summary>
/// 震级
/// </summary>
public double ML { get; set; }
/// <summary>
/// 定位台站数量
/// </summary>
public int NFP { get; set; }
/// <summary>
/// 计算震级的台站数量
/// </summary>
public int NFM { get; set; }
/// <summary>
/// 残差
/// </summary>
public double Residual { get; set; }
/// <summary>
/// 文件路径
/// </summary>
public string FilePath { get; set; }
public MsEvent()
{
}
public MsEvent(string str)
{
string[] evtS = str.Trim(' ').Split(new char[] { ' ' });
OriginTime = DateTime.Parse(evtS[0]);
X = double.Parse(evtS[2]);
Y = double.Parse(evtS[1]);
Z = double.Parse(evtS[3]);
int off = 0;
if (evtS.Length == 7)
{
ML = -10;
}
else
{
ML = double.Parse(evtS[5]);
off = 2;
}
NFP = int.Parse(evtS[4 + off]);
NFM = int.Parse(evtS[5 + off]);
Residual = double.Parse(evtS[6 + off]);
}
//public DateTime JsonDataFormatConvert(string jdf)
//{
// DateTime cd;
// string[] strs = jdf.Trim().Split(new char[] { 'T' });
// cd=new DateTime()
//}
public override string ToString()
{
string MLSTR = "";
if (ML != -10)
{
MLSTR = "ML" + " ";
}
string str = OriginTime.ToString("yyyy-MM-dd HH:mm:ss:fff") + " " +
Y.ToString() + " " +
X.ToString() + " " +
Z.ToString() + " " +
MLSTR +
ML.ToString() + " " + NFP.ToString() + " " + NFM.ToString() + " " +
Residual.ToString();
return str;
}
}
}

@ -0,0 +1,100 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MySql.Data.MySqlClient;
namespace StartServerWPF.Modules.Main
{
public class MySqlHelper
{
public RemoteDataBase rdb;
public MySqlConnection conn;
public string ConnectionString;
public MySqlHelper(string serverAddress, string serverPort,
string userName, string passWord,
string dataBase, string tableName)
{
rdb = new RemoteDataBase();
rdb.ServerAddress = serverAddress;
rdb.ServerPort = serverPort;
rdb.UserName = userName;
rdb.Password = passWord;
rdb.DataBase = dataBase;
rdb.TableName = tableName;
ConnectionString = "server=" + rdb.ServerAddress + ";port=" + rdb.ServerPort +
";user=" + rdb.UserName + ";password=" + rdb.Password + "; database=" + rdb.DataBase + ";";
conn = new MySqlConnection(ConnectionString);
}
public MySqlHelper(RemoteDataBase remotedb)
{
rdb = remotedb;
ConnectionString = "server=" + rdb.ServerAddress + ";port=" + rdb.ServerPort +
";user=" + rdb.UserName + ";password=" + rdb.Password + "; database=" + rdb.DataBase + ";";
conn = new MySqlConnection(ConnectionString);
}
public int MySqlExcute(string cmdStr)
{
conn.Open();
MySqlCommand mcmd = new MySqlCommand(cmdStr, conn);
int rtn = mcmd.ExecuteNonQuery();
conn.Close();
return rtn;
}
public bool InsertEvent(MsEvent msEvent)
{
conn.Open();
//检查是否有重复记录
string timeStr = msEvent.OriginTime.ToString("yyyy-MM-ddTHH:mm:ss.fff");
string checkExist = "select COUNT('ETime') from " + rdb.TableName + " where ETime='" + timeStr + "'";
//Console.WriteLine(timeStr);
MySqlCommand mcmd = new MySqlCommand(checkExist, conn);
int rtn = Convert.ToInt32(mcmd.ExecuteScalar());
//0=没有,则新增记录
if (rtn == 0)
{
string insStr = "insert into " + rdb.TableName + "(ETime,X,Y,Z,ML,LocSta,MLSta,Rms)" +
"values('" +
msEvent.OriginTime.ToString("yyyy-MM-ddTHH:mm:ss.fff") + "','" +
msEvent.X.ToString() + "','" +
msEvent.Y.ToString() + "','" +
msEvent.Z.ToString() + "','" +
msEvent.ML.ToString() + "','" +
msEvent.NFP.ToString() + "','" +
msEvent.NFM.ToString() + "','" +
msEvent.Residual.ToString() + "')";
mcmd = new MySqlCommand(insStr, conn);
int insertRow = mcmd.ExecuteNonQuery();
if (insertRow > 0)
{
conn.Close();
return true;
}
else
{
conn.Close();
return false;
}
}
else
{
conn.Close();
return false;
}
}
public DataSet MySqlSelect(string cmdStr)
{
conn.Open();
MySqlCommand mcmd = new MySqlCommand(cmdStr, conn);
MySqlDataAdapter msda = new MySqlDataAdapter(mcmd);
DataSet ds = new DataSet();
msda.Fill(ds, rdb.TableName);
//int rtn = mcmd.ExecuteNonQuery();
conn.Close();
return ds;
}
}
}

@ -0,0 +1,85 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
namespace StartServerWPF.Modules.Main
{
public class ProcessInfo
{
private string proName;
/// <summary>
/// 程序路径
/// </summary>
[JsonProperty]
public string ProName
{
get { return proName; }
set { proName = value; }
}
private string proPath;
/// <summary>
/// 程序路径
/// </summary>
[JsonProperty]
public string ProPath
{
get { return proPath; }
set { proPath = value; }
}
private string proParams;
/// <summary>
/// 启动参数
/// </summary>
[JsonProperty]
public string ProParams
{
get { return proParams; }
set { proParams = value; }
}
/// <summary>
/// 配置文件路径
/// </summary>
[JsonProperty]
public string JsonPath { get; set; }
private int pid;
public int Pid
{
get { return pid; }
set { pid = value; }
}
private string operationStr = "open";
/// <summary>
/// 操作,open=打开;edit=编辑;find=搜寻
/// </summary>
public string OperationStr
{
get { return operationStr; }
set { operationStr = value; }
}
private int showState = 0;
/// <summary>
///Deafult:0
///HIDE 0 隐藏窗体并激活其它窗体;
///SHOWNORMAL 1 激活并显示一个窗体,假设窗体是最小化或最大化, 将其还原到其原始大小和位置 (同 RESTORE
///SHOWMINIMIZED 2 激活窗体并最小化;
///SHOWMAXIMIZED 3 激活窗体并最大化;
///SHOWMINNOACTIVATE 4 以近期的大小和位置显示窗体,当前活动窗体保持活动;
///SHOW 5 激活窗体并显示其当前大小和位置中;
///MINIMIZE 6 最小化指定窗体并激活系统列表中顶层窗体;
///SHOWMINNOACTIVE 7 以最小化模式显示窗体,当前活动窗体保持活动;
///SHOWN 8 以近期的状态显示窗体,当前活动窗体保持活动
///RESTORE 9 激活窗体并显示,假设窗体是最小化或最大化, 还原到其原始大小和位置 同SHOWNORMAL
/// </summary>
public int ShowState
{
get { return showState; }
set { showState = value; }
}
}
}

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StartServerWPF.Modules.Main
{
public class RemoteDataBase
{
public string ServerAddress { get; set; }
public string ServerPort { get; set; }
public string UserName { get; set; }
public string Password { get; set; }
public string DataBase { get; set; }
public string TableName { get; set; }
}
}

@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework>
<UseWPF>true</UseWPF>
<UseWindowsForms>True</UseWindowsForms>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.39" />
<PackageReference Include="MySql.Data" Version="8.0.33" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Prism.Wpf" Version="8.1.97" />
</ItemGroup>
<ItemGroup>
<Reference Include="DotRas">
<HintPath>..\StartServerWPF\DotRas.dll</HintPath>
</Reference>
</ItemGroup>
</Project>

@ -0,0 +1,173 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using DotRas;
namespace StartServerWPF.Modules.Main
{
public class VPNHelper
{
public RasDialer dialer;
public RasHandle handle;
public RasConnection connect;
//public RasPhoneBook allUsersPhoneBook;
// VPN地址
public string IPToPing { get; set; }
// VPN名称
public string VPNName { get; set; }
// VPN用户名
public string UserName { get; set; }
// VPN密码
public string PassWord { get; set; }
public VPNHelper(string vpnName, string vpnIP, string userName, string passWord)
{
VPNName = vpnName;
IPToPing = vpnIP;
UserName = userName;
PassWord = passWord;
dialer = new RasDialer();
dialer.EntryName = vpnName;
dialer.PhoneBookPath = RasPhoneBook.GetPhoneBookPath(RasPhoneBookType.AllUsers);
}
public VPNHelper()
{
}
/// <summary>
/// 尝试连接VPN
/// </summary>
/// <returns></returns>
public string ConnectVPN(string vpnName, string userName, string passWord)
{
try
{
dialer.EntryName = vpnName;
// Set the credentials the dialer should use.
dialer.Credentials = new NetworkCredential(userName, passWord);
// NOTE: The entry MUST be in the phone book before the connection can be dialed.
// Begin dialing the connection; this will raise events from the dialer instance.
handle = dialer.DialAsync();
return "VPN连接成功";
// Enable the disconnect button for use later.
//this.DisconnectButton.Enabled = true;
}
catch (Exception ex)
{
return ex.ToString();
//this.StatusTextBox.AppendText(ex.ToString());
}
}
/// <summary>
/// 尝试断开连接(默认VPN)
/// </summary>
/// <returns></returns>
[Obsolete]
public void DisConnectVPN(string vpnName)
{
if (dialer.IsBusy)
{
// The connection attempt has not been completed, cancel the attempt.
dialer.DialAsyncCancel();
}
else
{
// The connection attempt has completed, attempt to find the connection in the active connections.
RasConnection connection = RasConnection.GetActiveConnectionByName(vpnName, dialer.PhoneBookPath);
if (connection != null)
{
// The connection has been found, disconnect it.
connection.HangUp();
}
}
}
/// <summary>
/// 创建或更新一个VPN连接(指定VPN名称及IP)
/// </summary>
[Obsolete]
public void CreateOrUpdateVPN(string updateVPNname, string updateVPNip)
{
RasDialer dialer = new RasDialer();
RasPhoneBook allUsersPhoneBook = new RasPhoneBook();
allUsersPhoneBook.Open();
// 如果已经该名称的VPN已经存在则更新这个VPN服务器地址
if (allUsersPhoneBook.Entries.Contains(updateVPNname))
{
allUsersPhoneBook.Entries[updateVPNname].PhoneNumber = updateVPNip;
// 不管当前VPN是否连接服务器地址的更新总能成功如果正在连接则需要VPN重启后才能起作用
allUsersPhoneBook.Entries[updateVPNname].Update();
}
// 创建一个新VPN
else
{
RasEntry entry = RasEntry.CreateVpnEntry(updateVPNname,
updateVPNip, RasVpnStrategy.PptpFirst, RasDevice.GetDeviceByName("(PPTP)", RasDeviceType.Vpn));
allUsersPhoneBook.Entries.Add(entry);
dialer.EntryName = updateVPNname;
dialer.PhoneBookPath = RasPhoneBook.GetPhoneBookPath(RasPhoneBookType.AllUsers);
}
}
[Obsolete]
public bool CheckVpnStatus(string vpnName)
{
RasConnection connection = RasConnection.GetActiveConnectionByName(vpnName, dialer.PhoneBookPath);
return connection != null ? true : false;
}
/// <summary>
/// 删除指定名称的VPN
/// 如果VPN正在运行一样会在电话本里删除但是不会断开连接所以最好是先断开连接再进行删除操作
/// </summary>
/// <param name="delVpnName"></param>
[Obsolete]
public void TryDeleteVPN(string delVpnName)
{
RasDialer dialer = new RasDialer();
RasPhoneBook allUsersPhoneBook = new RasPhoneBook();
allUsersPhoneBook.Open();
if (allUsersPhoneBook.Entries.Contains(delVpnName))
{
allUsersPhoneBook.Entries.Remove(delVpnName);
}
}
/// <summary>
/// 获取VPN IP,如果无172地址则未连接VPN
/// </summary>
public string GetLocalIp()
{
// 获取本地的IP地址
string AddressIP = string.Empty;
foreach (IPAddress _IPAddress in Dns.GetHostEntry(Dns.GetHostName()).AddressList)
{
if (_IPAddress.AddressFamily.ToString() == "InterNetwork")
{
AddressIP = _IPAddress.ToString();
if (AddressIP.Contains("172.16"))
{
return AddressIP;
}
}
}
return AddressIP;
}
}
}

@ -0,0 +1,695 @@
using Prism.Commands;
using Prism.Mvvm;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows;
using System.Collections.ObjectModel;
using StartServerWPF.Modules.Main.Model;
namespace StartServerWPF.Modules.Main.ViewModels
{
public class MainViewModel : BindableBase
{
public MainViewModel(IDialogService dialogService)
{
Message = "View A from your Prism Module";
Console.WriteLine(System.Environment.CurrentDirectory + "\\" + systemConfigPath);
sc = JsonParser.ReadSystemJsonFile(systemConfigPath);
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(sc.proApms.ProPath + "apms.json", sc.vpnInfo.DataSavePath);
JsonParser.UpdateRecvJson(sc.proRecv.ProPath + "gw.recvftp.json", sc.vpnInfo.DataSavePath);
sc.proMonitor.ProParams = JsonParser.CreateMonitorStartParam(sc.vpnInfo.DataSavePath, MoniStartTime);
StartTime = DateTime.Now;
// labelStartTime.Text = "启动时间:" + StartTime.ToString();
remDb = new MySqlHelper(sc.remoteDb);
Console.WriteLine(System.Environment.CurrentDirectory);
Console.WriteLine(sc.remoteDb.ServerAddress + "\t" + sc.remoteDb.ServerPort
+ "\t" + sc.remoteDb.UserName + "\t" + sc.remoteDb.Password);
this._dialogService = dialogService;
}
#region 属性
private string _message;
public string Message
{
get { return _message; }
set { SetProperty(ref _message, value); }
}
private DateTime startTime;
private DateTime moniStartTime;
public DateTime StartTime { get => startTime; set => startTime = value; }
public DateTime MoniStartTime { get => moniStartTime; set => moniStartTime = value; }
private string runTime;
public string RunTime
{
get { return runTime; }
set { runTime = value; }
}
private string vPNStatus;
public string VPNStatus
{
get { return vPNStatus; }
set { vPNStatus = value; }
}
private string vpnIP;
public string VpnIP
{
get { return vpnIP; }
set { vpnIP = value; }
}
private ObservableCollection<string> reciveDataSource=new ObservableCollection<string>();
public ObservableCollection<string> ReciveDataSource
{
get { return reciveDataSource; }
set { reciveDataSource = value; }
}
private ObservableCollection<int> intervalTimesSource=new ObservableCollection<int>();
public ObservableCollection<int> IntervalTimesSource
{
get { return intervalTimesSource; }
set { intervalTimesSource = value; }
}
private int selectedIndex;
public int SelectedIndex
{
get { return selectedIndex; }
set { selectedIndex = value; }
}
private bool isEnabledStart;
public bool IsEnabledStart
{
get { return isEnabledStart; }
set { isEnabledStart = value; }
}
private int proMonInterval = 10;
public int ProMonInterval { get => proMonInterval;
set => proMonInterval = value;
}
#endregion
#region 事件
public DelegateCommand LoadedCommand => new(Loaded);
public DelegateCommand UnloadedCommand => new(Unloaded);
public DelegateCommand ConnectVPNCommand => new(ConnectVPN);
public DelegateCommand DisConnectVPNCommand => new(DisConnectVPN);
public DelegateCommand GetVPNStatusCommand => new(GetVPNStatus);
public DelegateCommand SetVPNParaCommand => new(SetVPNPara);
public DelegateCommand DisplayLogCommand => new(DisplayLog);
public DelegateCommand OneKeyStartCommand => new(OneKeyStart);
public DelegateCommand OneKeyStopCommand => new(OneKeyStop);
public DelegateCommand DisplayRealWavesCommand => new(DisplayRealWaves);
public DelegateCommand QueryDataCommand => new(QueryData);
public DelegateCommand InsertDataCommand => new(InsertData);
private void Loaded()
{
IntilVPN();
SetControlstatus();
}
private void Unloaded()
{
KillProcess(sc.proServer);
KillProcess(sc.proRecv);
KillProcess(sc.proApms);
KillProcess(sc.proMonitor);
string logStr = DateTime.Now.ToString("s") + "\t程序关闭";
WriteSerLog(sc.vpnInfo.SystemLogPath + systemLogFileName, logStr);
//switch (kserindex)
//{
// case -1:
// Console.WriteLine(serProcInfo.ProName + "结束失败");
// break;
// case 0:
// Console.WriteLine(serProcInfo.ProName + "结束成功");
// break;
// case 1:
// Console.WriteLine(serProcInfo.ProName + "程序未启动");
// break;
//}
//int krecindex = KillProcess(recvProcInfo);
//switch (krecindex)
//{
// case -1:
// Console.WriteLine(recvProcInfo.ProName + "结束失败");
// break;
// case 0:
// Console.WriteLine(recvProcInfo.ProName + "结束成功");
// break;
// case 1:
// Console.WriteLine(recvProcInfo.ProName + "程序未启动");
// break;
//}
}
private void ConnectVPN()
{
vpn.CreateOrUpdateVPN(sc.vpnInfo.VpnName, sc.vpnInfo.VpnIP);
vpn.ConnectVPN(sc.vpnInfo.VpnName, sc.vpnInfo.VpnUserName, sc.vpnInfo.VpnPsw);
Thread.Sleep(1000);
string logStr = DateTime.Now.ToString("s") + "\tVPN手动连接";
WriteSerLog(sc.vpnInfo.SystemLogPath + systemLogFileName, logStr);
SetControlstatus();
}
private void DisConnectVPN()
{
if (MessageBox.Show("是否断开VPN连接", "提示", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes)
{
vpn.DisConnectVPN(sc.vpnInfo.VpnName);
Thread.Sleep(500);
SetControlstatus();
Thread.Sleep(100);
string logStr = DateTime.Now.ToString("s") + "\tVPN手动断开";
WriteSerLog(sc.vpnInfo.SystemLogPath + systemLogFileName, logStr);
}
}
private void GetVPNStatus()
{
if (vpn.CheckVpnStatus(sc.vpnInfo.VpnName))
{
MessageBox.Show("VPN已经连接!");
}
else
{
MessageBox.Show("VPN未连接!");
}
}
private void SetVPNPara()
{
//FormSetParam fvi = new FormSetParam();
//fvi.fm = this;
//fvi.ShowDialog();
DialogParameters param = new DialogParameters();
param.Add("type", 1);// 编辑
param.Add("model", sc.vpnInfo);
_dialogService.ShowDialog(
"SetParamDialog",
param,
new Action<IDialogResult>(result =>
{
if (result != null && result.Result == ButtonResult.OK)
{
MessageBox.Show("数据已保存", "提示");
}
}));
}
private void DisplayLog()
{
Process.Start("explorer.exe", sc.vpnInfo.SystemLogPath);
}
private void OneKeyStart()
{
StartTime = DateTime.Now;
sc.proServer.Pid = StartProcess(sc.proServer);
StartTime = DateTime.Now;
if (sc.proServer.Pid < 32)
{
ReciveDataSource.Add("服务器程序启动失败:" + StartTime.ToString());
}
Thread.Sleep(10);
sc.proRecv.Pid = StartProcess(sc.proRecv);
if (sc.proRecv.Pid < 32)
{
ReciveDataSource.Add("接收数据程序启动失败:" + StartTime.ToString());
}
Thread.Sleep(10);
sc.proApms.Pid = StartProcess(sc.proApms);
if (sc.proApms.Pid < 32)
{
ReciveDataSource.Add("自动识别程序启动失败:" + StartTime.ToString());
}
Thread.Sleep(10);
sc.proMonitor.Pid = StartProcess(sc.proMonitor);
Console.WriteLine(sc.proMonitor.Pid);
if (sc.proMonitor.Pid < 32)
{
ReciveDataSource.Add("网页服务程序启动失败:" + StartTime.ToString());
}
Thread.Sleep(10);
// labelStartTime.Text = "启动时间:" + StartTime.ToString();
RunTime = "运行时间:" + DateDiff(DateTime.Now, StartTime);
string logStr = StartTime.ToString("s") + "\t服务器程序启动";
WriteSerLog(sc.vpnInfo.SystemLogPath + systemLogFileName, logStr);
// progressBar1.Style = ProgressBarStyle.Marquee;
IsEnabledStart = false;
// btnSetParams.Enabled = false;
timer1.Interval = ProMonInterval * 1000;
timer1.Start();
ReciveDataSource.Clear();
}
private void OneKeyStop()
{
int kserindex = KillProcess(sc.proServer);
if (kserindex > -1)
{
ReciveDataSource.Add(sc.proServer.ProName + "结束成功");
}
else
{
ReciveDataSource.Add(sc.proServer.ProName + "结束失败");
}
int krecindex = KillProcess(sc.proRecv);
if (kserindex > -1)
{
ReciveDataSource.Add(sc.proRecv.ProName + "结束成功");
}
else
{
ReciveDataSource.Add(sc.proRecv.ProName + "结束失败");
}
int kampsindex = KillProcess(sc.proApms);
if (kampsindex > -1)
{
ReciveDataSource.Add(sc.proApms.ProName + "结束成功");
}
else
{
ReciveDataSource.Add(sc.proApms.ProName + "结束失败");
}
int kmonitorindex = KillProcess(sc.proMonitor);
if (kmonitorindex > -1)
{
ReciveDataSource.Add(sc.proMonitor.ProName + "结束成功");
}
else
{
ReciveDataSource.Add(sc.proMonitor.ProName + "结束失败");
}
ReciveDataSource.Add("服务停止于:" + DateTime.Now.ToString());
timer1.Stop();
// progressBar1.Style = ProgressBarStyle.Continuous;
string logStr = DateTime.Now.ToString("s") + "\t服务器程序关闭";
WriteSerLog(sc.vpnInfo.SystemLogPath + systemLogFileName, logStr);
// labelStartTime.Text = "启动时间:";
StartTime = new DateTime();
RunTime = "运行时间:";
isEnabledStart = true;
// buttonOneKeyStart.Enabled = true;
// btnSetParams.Enabled = true;
}
private void DisplayRealWaves()
{
StartProcess(sc.proPlot);
}
private void QueryData()
{
string str = "2021-05-09T00:15:34.530406 -0.60000 -0.07969 0.6000 ML -3.05 14 13 0.048 ";
MsEvent me = new MsEvent(str);
// dataGridView1.DataSource = remDb.MySqlSelect("select ETime,X,Y,Z,ML,LocSta,MLSta,Rms from " + sc.remoteDb.TableName).Tables[sc.remoteDb.TableName];
}
private void InsertData()
{
string str = "2021-05-09T00:15:34.900406 -0.60000 -0.07969 0.6000 ML -3.05 14 13 0.048 ";
MsEvent me = new MsEvent(str);
bool insStat = remDb.InsertEvent(me);
if (insStat)
{
Console.WriteLine("新增成功");
}
else
{
Console.WriteLine("已有该记录");
}
// dataGridView1.DataSource = remDb.MySqlSelect("select ETime,X,Y,Z,ML,LocSta,MLSta,Rms from " + sc.remoteDb.TableName).Tables[sc.remoteDb.TableName];
}
//private void button1_Click(object sender, EventArgs e)
//{
// vpn.ConnectVPN(sc.vpnInfo.VpnName, sc.vpnInfo.VpnUserName, sc.vpnInfo.VpnPsw);
// Thread.Sleep(1000);
// string logStr = DateTime.Now.ToString("s") + "\tVPN手动连接";
// WriteSerLog(sc.SystemLogPath + systemLogFileName, logStr);
// SetControlstatus();
//}
//private void button1_Click_1(object sender, EventArgs e)
//{
// JsonParser.WriteSystemConfigFile("SystemConfig.json", sc);
//}
//private void button2_Click(object sender, EventArgs e)
//{
// ProcessStartInfo processStartInfo = new ProcessStartInfo(@"F:\Project\2021\河南理工\余吾预警项目\郑老师程序\v20210415\All\server.exe", "service.conf");
// processStartInfo.WindowStyle = ProcessWindowStyle.Normal;
// Process proc = Process.Start(processStartInfo);
// ProcessStartInfo processStartInfoRec = new ProcessStartInfo(@"F:\Project\2021\河南理工\余吾预警项目\郑老师程序\v20210415\All\gw.recvftp.exe", "-cfg gw.recvftp.json >outRecv.txt");
// processStartInfoRec.WindowStyle = ProcessWindowStyle.Normal;
// Process procRec = Process.Start(processStartInfoRec);
//}
#endregion
private void ConnectVpn()
{
// 系统路径 C:\windows\system32\
string WinDir = Environment.GetFolderPath(Environment.SpecialFolder.SystemX86) + @"";
Console.WriteLine(WinDir);
// rasdial.exe
string RasDialFileName = "rasdial.exe";
// VPN路径 C:\windows\system32\rasdial.exe
string VPNPROCESS = WinDir + "\\" + RasDialFileName;
// VPN地址
//string IPToPing = "49.232.209.49";
// VPN名称
string VPNName = "余吾手动";
// VPN用户名
string UserName = "lzvpn";
// VPN密码
string PassWord = "Lz123456789";
string args = string.Format("{0} {1} {2}", VPNName, UserName, PassWord);
ProcessStartInfo myProcess = new ProcessStartInfo(VPNPROCESS, args);
myProcess.CreateNoWindow = true;
myProcess.UseShellExecute = false;
Process.Start(myProcess);
}
private void IntilVPN()
{
vpn = new VPNHelper(sc.vpnInfo.VpnName, sc.vpnInfo.VpnIP, sc.vpnInfo.VpnUserName, sc.vpnInfo.VpnPsw);
}
[DllImport("shell32.dll")]
public static extern int ShellExecute(IntPtr hwnd, StringBuilder lpszOp, StringBuilder lpszFile, StringBuilder lpszParams, StringBuilder lpszDir, int FsShowCmd);
public string proPath;
public string zyProPath = @"\serverprogram";
public string systemConfigPath = "SystemConfig.json";
public string systemLogFileName;
public int showState = 0;
public string serverVision = "20210629";
public VPNHelper vpn;
public bool vpnStatus = false;
public SystemConfig sc;
MySqlHelper remDb;
private System.Timers.Timer timer1=new System.Timers.Timer();
private readonly IDialogService _dialogService;
public void InitializeParams()
{
timer1.Interval = ProMonInterval * 1000;
this.Message = "服务器版本:" + serverVision;
IntervalTimesSource.Add(5);
IntervalTimesSource.Add(10);
IntervalTimesSource.Add(15);
IntervalTimesSource.Add(20);
IntervalTimesSource.Add(30);
IntervalTimesSource.Add(60);
SelectedIndex = 1;
systemLogFileName = "SerLog_" + DateTime.Now.ToString("yyyyMMdd") + ".txt";
string logStr = DateTime.Now.ToString("s") + "\t程序启动";
WriteSerLog(sc.vpnInfo.SystemLogPath + systemLogFileName, logStr);
//CheckIp();
}
#region 方法
/// <summary>
/// 启动进程
/// </summary>
/// <param name="proInfo"></param>
/// <returns>进程启动返回值</returns>
private int StartProcess(ProcessInfo proInfo)
{
int seInd = ShellExecute(IntPtr.Zero, new StringBuilder("open"), new StringBuilder(proInfo.ProName + ".exe")
, new StringBuilder(proInfo.ProParams), new StringBuilder(proInfo.ProPath), proInfo.ShowState);
return seInd;
}
/// <summary>
/// 结束进程
/// </summary>
/// <param name="processInfo"></param>
/// <returns>0=成功;1=未找到进程;-1=失败</returns>
private 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;
}
}
/// <summary>
/// 查找进程
/// </summary>
/// <param name="processInfo"></param>
/// <returns>0=正在运行;1=未运行;-1=系统错误</returns>
private int FindProcess(ProcessInfo processInfo)
{
int ri = 0;
try
{
Process[] localByName = Process.GetProcessesByName(processInfo.ProName);
if (localByName.Length == 0)
{
ri = 1;
return ri;
}
return ri;
}
catch (Exception)
{
return -1;
}
}
private string DateDiff(DateTime DateTime1, DateTime DateTime2)
{
string dateDiff = null;
TimeSpan ts1 = new TimeSpan(DateTime1.Ticks);
TimeSpan ts2 = new
TimeSpan(DateTime2.Ticks);
TimeSpan ts = ts1.Subtract(ts2).Duration();
if (ts.Days > 0)
{
dateDiff += ts.Days.ToString() + "天";
}
if (ts.Hours > 0)
{
dateDiff += ts.Hours.ToString() + "小时";
}
if (ts.Minutes > 0)
{
dateDiff += ts.Minutes.ToString() + "分钟";
}
dateDiff += ts.Seconds.ToString() + "秒";
return dateDiff;
}
private void timer1_Tick(object sender, EventArgs e)
{
ReciveDataSource.Clear();
ReciveDataSource.Add(DateTime.Now.ToString());
int sfp = FindProcess(sc.proServer);
if (sfp == 0)
{
ReciveDataSource.Add("服务器程序运行正常");
}
else
{
ReciveDataSource.Add("服务器程序未运行");
Thread.Sleep(2);
StartProcess(sc.proServer);
Thread.Sleep(20);
ReciveDataSource.Add("服务器程序重启成功");
string logStr = DateTime.Now.ToString("s") + "\t服务器程序" + sc.proServer.ProName + "重启";
WriteSerLog(sc.vpnInfo.SystemLogPath + systemLogFileName, logStr);
}
sfp = FindProcess(sc.proRecv);
if (sfp == 0)
{
ReciveDataSource.Add("接收数据程序运行正常");
}
else
{
ReciveDataSource.Add("接收数据程序未运行");
Thread.Sleep(2);
StartProcess(sc.proRecv);
Thread.Sleep(20);
ReciveDataSource.Add("接收数据程序重启成功");
string logStr = DateTime.Now.ToString("s") + "\t接收数据程序" + sc.proRecv.ProName + "重启";
WriteSerLog(sc.vpnInfo.SystemLogPath + systemLogFileName, logStr);
}
sfp = FindProcess(sc.proApms);
if (sfp == 0)
{
ReciveDataSource.Add("自动识别程序运行正常");
}
else
{
ReciveDataSource.Add("自动识别程序未运行");
Thread.Sleep(2);
StartProcess(sc.proApms);
Thread.Sleep(20);
ReciveDataSource.Add("自动识别程序重启成功");
string logStr = DateTime.Now.ToString("s") + "\t自动识别程序" + sc.proApms.ProName + "重启";
WriteSerLog(sc.vpnInfo.SystemLogPath + systemLogFileName, logStr);
}
sfp = FindProcess(sc.proMonitor);
if (sfp == 0)
{
ReciveDataSource.Add("网页服务程序运行正常");
}
else
{
ReciveDataSource.Add("网页服务程序未运行");
Thread.Sleep(2);
StartProcess(sc.proMonitor);
Thread.Sleep(20);
ReciveDataSource.Add("网页服务程序重启成功");
string logStr = DateTime.Now.ToString("s") + "\t网页服务程序" + sc.proMonitor.ProName + "重启";
WriteSerLog(sc.vpnInfo.SystemLogPath + systemLogFileName, logStr);
}
RunTime = "运行时间:" + DateDiff(DateTime.Now, StartTime);
vpnStatus = vpn.CheckVpnStatus(sc.vpnInfo.VpnName);
if (!vpnStatus)
{
vpn.ConnectVPN(sc.vpnInfo.VpnName, sc.vpnInfo.VpnUserName, sc.vpnInfo.VpnPsw);
Thread.Sleep(1000);
string logStr = DateTime.Now.ToString("s") + "\tVPN断开重连";
WriteSerLog(sc.vpnInfo.SystemLogPath + systemLogFileName, logStr);
}
}
public void GetLocalIp()
{
///获取本地的IP地址
string AddressIP = string.Empty;
foreach (IPAddress _IPAddress in Dns.GetHostEntry(Dns.GetHostName()).AddressList)
{
if (_IPAddress.AddressFamily.ToString() == "InterNetwork")
{
AddressIP = _IPAddress.ToString();
if (AddressIP.Contains("172.16"))
{
sc.vpnInfo.VpnIP = AddressIP;
}
}
}
//return AddressIP;
}
public void SetControlstatus()
{
vpnStatus = vpn.CheckVpnStatus(sc.vpnInfo.VpnName);
if (vpnStatus)
{
//gbServerControl.Enabled = true;
// buttonConnectVPN.Enabled = false;
// buttonDisconnectVPN.Enabled = true;
// labelVPNstatus.ForeColor = Color.Blue;
VPNStatus = "VPN已连接";
VpnIP = "本机IP" + vpn.GetLocalIp();
}
else
{
// gbServerControl.Enabled = false;
// buttonConnectVPN.Enabled = true;
// buttonDisconnectVPN.Enabled = false;
// labelVPNstatus.ForeColor = Color.Red;
VPNStatus = "VPN未连接";
}
}
public void WriteSerLog(string fn, string logstr)
{
StreamWriter sw = new StreamWriter(fn, true, Encoding.Default);
sw.WriteLine(logstr);
sw.Close();
}
#endregion
}
}

@ -0,0 +1,115 @@
using Prism.Commands;
using Prism.Mvvm;
using Prism.Services.Dialogs;
using StartServerWPF.Modules.Main.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
namespace StartServerWPF.Modules.Main.ViewModels
{
public class SetParamDialogViewModel : BindableBase, IDialogAware
{
public SetParamDialogViewModel()
{
}
private string _title = "参数设置";
public string Title => _title;
public event Action<IDialogResult> RequestClose;
public bool CanCloseDialog()
{
return true;
}
public void OnDialogClosed() { }
public void OnDialogOpened(IDialogParameters parameters)
{
// _title = "编辑" + _title;
var _type = parameters.GetValue<int>("type");
// _title = (_type == 0 ? "新增" : "修改") + _title;
MainModel = parameters.GetValue<VpnInfo>("model");
}
private VpnInfo _mainModel = new VpnInfo();
public VpnInfo MainModel
{
get => _mainModel;
set { SetProperty(ref _mainModel, value); }
}
public DelegateCommand FilePathSaveCommand=> new(()=>
{
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;
}
});
public DelegateCommand LogPathSaveCommand=> new(() =>
{
System.Windows.Forms.FolderBrowserDialog fbd = new System.Windows.Forms.FolderBrowserDialog();
fbd.SelectedPath = System.Environment.CurrentDirectory + "\\" + MainModel.SystemLogPath;
fbd.ShowNewFolderButton = true;
if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
//if (fbd.SelectedPath != textBoxLogPath.Text)
//{
// textBoxLogPath.Text = fbd.SelectedPath;
//}
MainModel.SystemLogPath = fbd.SelectedPath;
}
});
public ICommand ConfirmCommand
{
get => new DelegateCommand(() =>
{
// 确认操作
// 数据校验关键字段不能为空、年龄做数字区间的校验、做UserName的唯一检查自定义特性检查
if (string.IsNullOrEmpty(MainModel.VpnName) || string.IsNullOrEmpty(MainModel.VpnIP))
{
MessageBox.Show("内容不能为空", "提示", System.Windows.MessageBoxButton.OK);
return;
}
if (MessageBox.Show("确认修改?", "参数设置", MessageBoxButton.OKCancel,
MessageBoxImage.Exclamation) == MessageBoxResult.OK)
{
//if (updateSysConfig)
//{
// JsonParser.WriteSystemConfigFile(fm.systemConfigPath, fsc);
//}
//if (updateJson)
//{
// JsonParser.UpdateRecvJson(fm.sc.proRecv.ProPath + fm.sc.proRecv.JsonPath, fm.sc.DataSavePath);
// JsonParser.UpdateApmsJson(fm.sc.proApms.ProPath + fm.sc.proApms.JsonPath, fm.sc.DataSavePath);
//}
//var device = _deviceInfoModel.deviceInfoModelList.Where(device => device.Index == MainModel.Index).FirstOrDefault();
//if (device != null)
//{
// _deviceInfoModel.deviceInfoModelList.Remove(device);
// _deviceInfoModel.deviceInfoModelList.Add(MainModel);
// _deviceInfoModel.Save();
//}
RequestClose?.Invoke(new DialogResult(ButtonResult.OK));
}
});
}
public ICommand CancelCommand
{
get => new DelegateCommand(() =>
{
RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel));
});
}
}
}

@ -0,0 +1,95 @@
<UserControl x:Class="StartServerWPF.Modules.Main.Views.MainView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:StartServerWPF.Modules.Main.Views"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
mc:Ignorable="d"
d:DesignHeight="600" d:DesignWidth="800"
xmlns:prism="http://prismlibrary.com/"
prism:ViewModelLocator.AutoWireViewModel="True" >
<i:Interaction.Triggers>
<i:EventTrigger EventName="Loaded">
<i:InvokeCommandAction Command="{Binding Path=LoadedCommand}"/>
</i:EventTrigger>
<i:EventTrigger EventName="Unloaded">
<i:InvokeCommandAction Command="{Binding Path=UnloadedCommand}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="300"/>
<ColumnDefinition Width="23*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="52*"/>
<RowDefinition Height="75*"/>
<RowDefinition Height="112*"/>
<RowDefinition Height="30"/>
</Grid.RowDefinitions>
<GroupBox Header="网络控制">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="2*"/>
</Grid.ColumnDefinitions>
<RadioButton GroupName="con" x:Name="rtnConnect" Content="连接" Command="{Binding ConnectVPNCommand}" Grid.Row="0" VerticalAlignment="Center"/>
<RadioButton GroupName="con" Content="断开连接" Grid.Column="1" Command="{Binding DisConnectVPNCommand}" VerticalAlignment="Center" IsChecked="True"/>
<StackPanel Grid.Column="2" Orientation="Horizontal" VerticalAlignment="Center">
<Button Content="检查状态" Command="{Binding GetVPNStatusCommand}"/>
<TextBlock Text="{Binding VPNStatus}"/>
</StackPanel>
<Button Content="参数设置" Grid.Row="1" Command="{Binding SetVPNParaCommand}" VerticalAlignment="Center"/>
<Button Content="运行日志" Grid.Row="1" Grid.Column="1" Command="{Binding DisplayLogCommand}" VerticalAlignment="Center"/>
<TextBlock Grid.Row="1" Grid.Column="2" VerticalAlignment="Center">
<Run Text="本机IP:"/>
<Run Text="{Binding VpnIP}"/>
</TextBlock>
</Grid>
</GroupBox>
<GroupBox IsEnabled="{Binding ElementName=rtnConnect,Path=IsChecked}" Grid.Row="1" Header="服务器控制">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="2*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
</Grid.RowDefinitions>
<Button x:Name="btnStart" Content="一键启动" Command="{Binding OneKeyStartCommand}" IsEnabled="{Binding IsEnabledStart}" Grid.Column="0" VerticalAlignment="Center"/>
<Button Content="全部关闭" Command="{Binding OneKeyStopCommand}" Grid.Column="1" VerticalAlignment="Center"/>
<Button Content="实时波形" Command="{Binding DisplayRealWavesCommand}" Grid.Column="2" VerticalAlignment="Center" HorizontalAlignment="Right"/>
<TextBlock Grid.Row="1" VerticalAlignment="Center" Grid.ColumnSpan="2">
<Run Text="启动时间:"/>
<Run Text="{Binding StartTime}"/>
</TextBlock>
<TextBlock Grid.Row="2" Grid.ColumnSpan="2" VerticalAlignment="Center">
<Run Text="运行时间:"/>
<Run Text="{Binding RunTime}"/>
</TextBlock>
<DockPanel Grid.Row="2" Grid.Column="2" >
<ComboBox DockPanel.Dock="Right" ItemsSource="{Binding IntervalTimesSource}" SelectedIndex="{Binding selectedIndex}" Text="{Binding ProMonInterval}" VerticalAlignment="Center"/>
<TextBlock Text="监隔间隔(s):" DockPanel.Dock="Right" VerticalAlignment="Center"/>
</DockPanel>
</Grid>
</GroupBox>
<ListBox Grid.Row="2" ItemsSource="{Binding ReciveDataSource}">
</ListBox>
<ProgressBar Grid.Row="3"/>
<DataGrid Grid.Column="1" Grid.RowSpan="3" ItemsSource="{Binding DataGridSource}">
</DataGrid>
<StackPanel Grid.Row="3" Grid.Column="1" Orientation="Horizontal" VerticalAlignment="Center">
<Button Content="查询" Command="{Binding QueryDataCommand}"/>
<Button Content="新增" Command="{Binding InsertDataCommand}"/>
</StackPanel>
</Grid>
</UserControl>

@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace StartServerWPF.Modules.Main.Views
{
/// <summary>
/// Interaction logic for ViewA.xaml
/// </summary>
public partial class MainView : UserControl
{
public MainView()
{
InitializeComponent();
}
}
}

@ -0,0 +1,84 @@
<UserControl x:Class="StartServerWPF.Modules.Main.Views.SetParamDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:prism="http://prismlibrary.com/"
prism:ViewModelLocator.AutoWireViewModel="True"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="500">
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
<prism:Dialog.WindowStyle>
<Style TargetType="Window">
<Setter Property="Width" Value="500"/>
<Setter Property="Height" Value="300"/>
</Style>
</prism:Dialog.WindowStyle>
<Grid Margin="10">
<Grid.RowDefinitions>
<RowDefinition Height="30"/>
<RowDefinition Height="10*"/>
<RowDefinition Height="10*"/>
<RowDefinition Height="5*"/>
<RowDefinition Height="5*"/>
</Grid.RowDefinitions>
<TextBlock Text="{Binding Title}" FontSize="20" VerticalAlignment="Center" Foreground="#888" Margin="10,0,10,0"/>
<Grid Grid.Row="1" VerticalAlignment="Center">
<Grid.RowDefinitions>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="2*"/>
</Grid.ColumnDefinitions>
<TextBlock Text="VPN名称" Grid.Row="0" Grid.Column="0"/>
<TextBox Text="{Binding MainModel.VpnName}" Grid.Row="0" Grid.Column="1" Margin="0,0,10,0"/>
<TextBlock Text="IP地址" Grid.Row="0" Grid.Column="2"/>
<TextBox Text="{Binding MainModel.VpnIP}" Grid.Row="0" Grid.Column="3"/>
<TextBlock Text="用户名:" Grid.Row="1" Grid.Column="0" />
<TextBox Text="{Binding MainModel.VpnPsw}" Grid.Row="1" Grid.Column="1" Margin="0,0,10,0"/>
<TextBlock Text="密码:" Grid.ColumnSpan="2" Grid.Row="1" Grid.Column="2" />
<TextBox Text="{Binding MainModel.VpnPsw}" Grid.Row="1" Grid.Column="3" />
</Grid>
<Grid Grid.Row="2" VerticalAlignment="Center">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="5*"/>
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
</Grid.RowDefinitions>
<TextBlock Text="存储路径:" Grid.Row="0" Grid.Column="0"/>
<TextBox Text="{Binding MainModel.DataSavePath}" IsReadOnly="True" Grid.Row="0" Grid.Column="1"/>
<Button Content="设置路径" Command="{Binding FilePathSaveCommand}" Grid.Row="0" Grid.Column="2"/>
<TextBlock Text="日志路径:" Grid.Row="1" Grid.Column="0" />
<TextBox Text="{Binding MainModel.SystemLogPath}" IsReadOnly="True" Grid.Row="1" Grid.Column="1"/>
<Button Content="设置路径" Command="{Binding LogPathSaveCommand}" Grid.Row="1" Grid.Column="2"/>
</Grid>
<StackPanel Grid.Row="3" Orientation="Horizontal" VerticalAlignment="Center">
<TextBlock Text="监控日期:"/>
<TextBox />
</StackPanel>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Grid.Row="4" >
<Button Content="确认" Width="100" Height="30" Margin="5,0"
Background="#FF0ABEFF"
Command="{Binding ConfirmCommand}"/>
<Button Content="取消" Width="100" Height="30"
Background="#DDD" Foreground="#666"
Command="{Binding CancelCommand}"/>
</StackPanel>
</Grid>
</UserControl>

@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace StartServerWPF.Modules.Main.Views
{
/// <summary>
/// ModifyDeviceView.xaml 的交互逻辑
/// </summary>
public partial class SetParamDialog : UserControl
{
public SetParamDialog()
{
InitializeComponent();
}
}
}

@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.3.32819.101
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StartServerWPF.Modules.Main", "StartServerWPF.Modules.Main\StartServerWPF.Modules.Main.csproj", "{D9A5C84C-296A-458E-9CCB-BCD95959F88B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StartServerWPF", "StartServerWPF\StartServerWPF.csproj", "{7585A28B-9A36-4B10-9033-0214C93F68F5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{D9A5C84C-296A-458E-9CCB-BCD95959F88B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D9A5C84C-296A-458E-9CCB-BCD95959F88B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D9A5C84C-296A-458E-9CCB-BCD95959F88B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D9A5C84C-296A-458E-9CCB-BCD95959F88B}.Release|Any CPU.Build.0 = Release|Any CPU
{7585A28B-9A36-4B10-9033-0214C93F68F5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7585A28B-9A36-4B10-9033-0214C93F68F5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7585A28B-9A36-4B10-9033-0214C93F68F5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7585A28B-9A36-4B10-9033-0214C93F68F5}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {4C2B8513-F88D-45FB-84AE-09A4F061099D}
EndGlobalSection
EndGlobal

@ -0,0 +1,9 @@
<prism:PrismApplication x:Class="StartServerWPF.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:StartServerWPF"
xmlns:prism="http://prismlibrary.com/" >
<Application.Resources>
</Application.Resources>
</prism:PrismApplication>

@ -0,0 +1,30 @@
using Prism.Ioc;
using Prism.Modularity;
using StartServerWPF.Modules.Main;
using StartServerWPF.Views;
using System.Windows;
namespace StartServerWPF
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App
{
protected override Window CreateShell()
{
return Container.Resolve<MainWindow>();
}
protected override void RegisterTypes(IContainerRegistry containerRegistry)
{
}
protected override void ConfigureModuleCatalog(IModuleCatalog moduleCatalog)
{
moduleCatalog.AddModule<MainModule>();
base.ConfigureModuleCatalog(moduleCatalog);
}
}
}

Binary file not shown.

@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<UseWPF>true</UseWPF>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Prism.DryIoc" Version="8.1.97" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\StartServerWPF.Modules.Main\StartServerWPF.Modules.Main.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="SystemConfig.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

@ -0,0 +1,63 @@
{
"remoteDb":{
"ServerAddress": "txgydatabase.mysql.rds.aliyuncs.com",
"ServerPort": "3306",
"UserName": "tayrds_db",
"Password": "txgy1929",
"DataBase": "txgymeisdb",
"TableName": "event"
},
"vpnInfo": {
"VpnName": "YUWU-VPN-BySM",
"VpnIP": "49.232.209.49",
"VpnUserName": "lzvpn",
"VpnPsw": "Lz123456789"
},
"SystemLogPath": "Systemlog\\",
"DataSavePath": "G:\\DATA\\",
"proServer": {
"ProName": "server",
"ProPath": "serverprogram\\server\\",
"ProParams": "service.conf",
"JsonPath": null,
"Pid": 0,
"OperationStr": "open",
"ShowState": 0
},
"proRecv": {
"ProName": "gw.recvftp",
"ProPath": "serverprogram\\recvftp\\",
"ProParams": "-cfg gw.recvftp.json >outRecv.txt",
"JsonPath": "gw.recvftp.json",
"Pid": 0,
"OperationStr": "open",
"ShowState": 0
},
"proApms": {
"ProName": "gw.apms",
"ProPath": "serverprogram\\apms\\",
"ProParams": "-cfg apms.json >outApms.txt",
"JsonPath": "apms.json",
"Pid": 0,
"OperationStr": "open",
"ShowState": 0
},
"proMonitor": {
"ProName": "gw.monitor",
"ProPath": "serverprogram\\monitor\\",
"ProParams": "-sta n1105_station_xyz.csv -port 8086 -rdir G:/DATA/ -btime 2021-03-15T00:00:00 >outMonitor.txt",
"JsonPath": null,
"Pid": 0,
"OperationStr": "open",
"ShowState": 0
},
"proPlot": {
"ProName": "gw.plot",
"ProPath": "serverprogram\\plot\\",
"ProParams": null,
"JsonPath": null,
"Pid": 0,
"OperationStr": "open",
"ShowState": 0
}
}

@ -0,0 +1,19 @@
using Prism.Mvvm;
namespace StartServerWPF.ViewModels
{
public class MainWindowViewModel : BindableBase
{
private string _title = "Prism Application";
public string Title
{
get { return _title; }
set { SetProperty(ref _title, value); }
}
public MainWindowViewModel()
{
}
}
}

@ -0,0 +1,10 @@
<Window x:Class="StartServerWPF.Views.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:prism="http://prismlibrary.com/"
prism:ViewModelLocator.AutoWireViewModel="True"
Title="{Binding Title}" Height="350" Width="525" >
<Grid>
<ContentControl prism:RegionManager.RegionName="MainContentRegion" />
</Grid>
</Window>

@ -0,0 +1,15 @@
using System.Windows;
namespace StartServerWPF.Views
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
}
}
Loading…
Cancel
Save