diff --git a/StartServerWPF.Modules.Main/JsonParser.cs b/StartServerWPF.Modules.Main/JsonParser.cs new file mode 100644 index 0000000..58fda2a --- /dev/null +++ b/StartServerWPF.Modules.Main/JsonParser.cs @@ -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(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; + } + } +} diff --git a/StartServerWPF.Modules.Main/MainModule.cs b/StartServerWPF.Modules.Main/MainModule.cs new file mode 100644 index 0000000..2d22d89 --- /dev/null +++ b/StartServerWPF.Modules.Main/MainModule.cs @@ -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(); + iRegion.RegisterViewWithRegion("MainContentRegion", typeof(MainView)); + } + + public void RegisterTypes(IContainerRegistry containerRegistry) + { + containerRegistry.RegisterDialog(); + } + } +} \ No newline at end of file diff --git a/StartServerWPF.Modules.Main/Model/ApmsConfig.cs b/StartServerWPF.Modules.Main/Model/ApmsConfig.cs new file mode 100644 index 0000000..19b3672 --- /dev/null +++ b/StartServerWPF.Modules.Main/Model/ApmsConfig.cs @@ -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; } + } + + } +} diff --git a/StartServerWPF.Modules.Main/Model/SystemConfig.cs b/StartServerWPF.Modules.Main/Model/SystemConfig.cs new file mode 100644 index 0000000..0c9eeab --- /dev/null +++ b/StartServerWPF.Modules.Main/Model/SystemConfig.cs @@ -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 + { + + /// + /// 远程数据库 + /// + public RemoteDataBase remoteDb { get; set; } + /// + /// Vpn信息 + /// + public VpnInfo vpnInfo; + /// + /// server程序 + /// + public ProcessInfo proServer { get; set; } + /// + /// Recv程序 + /// + public ProcessInfo proRecv { get; set; } + /// + /// Apms(定位程序)程序 + /// + public ProcessInfo proApms { get; set; } + /// + /// Monitor(网页显示)程序 + /// + public ProcessInfo proMonitor { get; set; } + /// + /// 波形显示程序 + /// + public ProcessInfo proPlot { get; set; } + } +} diff --git a/StartServerWPF.Modules.Main/Model/VpnInfo.cs b/StartServerWPF.Modules.Main/Model/VpnInfo.cs new file mode 100644 index 0000000..627078b --- /dev/null +++ b/StartServerWPF.Modules.Main/Model/VpnInfo.cs @@ -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 +{ + /// + /// VPN信息类 + /// + public class VpnInfo : BindableBase + { + private string vpnName; + private string vpnIP; + private string vpnUserName; + private string vpnPsw; + private string systemLogPath; + private string dataSavePath; + + /// + /// VPN名称 + /// + public string VpnName { get => vpnName; set => SetProperty(ref vpnName, value); } + /// + /// VPNIP + /// + public string VpnIP { get => vpnIP; set => SetProperty(ref vpnIP, value); } + /// + /// VPN用户名 + /// + public string VpnUserName { get => vpnUserName; set => SetProperty(ref vpnUserName, value); } + /// + /// VPN密码 + /// + public string VpnPsw { get => vpnPsw; set => SetProperty(ref vpnPsw, value); } + + /// + /// 系统日志路径 + /// + public string SystemLogPath { get => systemLogPath; set => SetProperty(ref systemLogPath, value); } + /// + /// 数据存储路径 + /// + public string DataSavePath { get => dataSavePath; set => SetProperty(ref dataSavePath, value); } + } +} diff --git a/StartServerWPF.Modules.Main/MsEvent.cs b/StartServerWPF.Modules.Main/MsEvent.cs new file mode 100644 index 0000000..9348237 --- /dev/null +++ b/StartServerWPF.Modules.Main/MsEvent.cs @@ -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; } + /// + /// 震级 + /// + public double ML { get; set; } + /// + /// 定位台站数量 + /// + public int NFP { get; set; } + /// + /// 计算震级的台站数量 + /// + public int NFM { get; set; } + /// + /// 残差 + /// + public double Residual { get; set; } + /// + /// 文件路径 + /// + 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; + } + } +} diff --git a/StartServerWPF.Modules.Main/MySqlHelper.cs b/StartServerWPF.Modules.Main/MySqlHelper.cs new file mode 100644 index 0000000..63172c9 --- /dev/null +++ b/StartServerWPF.Modules.Main/MySqlHelper.cs @@ -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; + } + + } +} diff --git a/StartServerWPF.Modules.Main/ProcessInfo.cs b/StartServerWPF.Modules.Main/ProcessInfo.cs new file mode 100644 index 0000000..76b2906 --- /dev/null +++ b/StartServerWPF.Modules.Main/ProcessInfo.cs @@ -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; + /// + /// 程序路径 + /// + [JsonProperty] + public string ProName + { + get { return proName; } + set { proName = value; } + } + private string proPath; + /// + /// 程序路径 + /// + [JsonProperty] + public string ProPath + { + get { return proPath; } + set { proPath = value; } + } + private string proParams; + + /// + /// 启动参数 + /// + [JsonProperty] + public string ProParams + { + get { return proParams; } + set { proParams = value; } + } + + /// + /// 配置文件路径 + /// + [JsonProperty] + public string JsonPath { get; set; } + + private int pid; + public int Pid + { + get { return pid; } + set { pid = value; } + } + private string operationStr = "open"; + /// + /// 操作,open=打开;edit=编辑;find=搜寻 + /// + public string OperationStr + { + get { return operationStr; } + set { operationStr = value; } + } + private int showState = 0; + /// + ///Deafult:0 + ///HIDE 0 隐藏窗体并激活其它窗体; + ///SHOWNORMAL 1 激活并显示一个窗体,假设窗体是最小化或最大化, 将其还原到其原始大小和位置 (同 RESTORE); + ///SHOWMINIMIZED 2 激活窗体并最小化; + ///SHOWMAXIMIZED 3 激活窗体并最大化; + ///SHOWMINNOACTIVATE 4 以近期的大小和位置显示窗体,当前活动窗体保持活动; + ///SHOW 5 激活窗体并显示其当前大小和位置中; + ///MINIMIZE 6 最小化指定窗体并激活系统列表中顶层窗体; + ///SHOWMINNOACTIVE 7 以最小化模式显示窗体,当前活动窗体保持活动; + ///SHOWN 8 以近期的状态显示窗体,当前活动窗体保持活动 + ///RESTORE 9 激活窗体并显示,假设窗体是最小化或最大化, 还原到其原始大小和位置 (同SHOWNORMAL) + /// + public int ShowState + { + get { return showState; } + set { showState = value; } + } + } +} diff --git a/StartServerWPF.Modules.Main/RemoteDataBase.cs b/StartServerWPF.Modules.Main/RemoteDataBase.cs new file mode 100644 index 0000000..1f2b60c --- /dev/null +++ b/StartServerWPF.Modules.Main/RemoteDataBase.cs @@ -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; } + } +} diff --git a/StartServerWPF.Modules.Main/StartServerWPF.Modules.Main.csproj b/StartServerWPF.Modules.Main/StartServerWPF.Modules.Main.csproj new file mode 100644 index 0000000..70b599b --- /dev/null +++ b/StartServerWPF.Modules.Main/StartServerWPF.Modules.Main.csproj @@ -0,0 +1,18 @@ + + + net6.0-windows + true + True + + + + + + + + + + ..\StartServerWPF\DotRas.dll + + + \ No newline at end of file diff --git a/StartServerWPF.Modules.Main/VPNHelper.cs b/StartServerWPF.Modules.Main/VPNHelper.cs new file mode 100644 index 0000000..bd80726 --- /dev/null +++ b/StartServerWPF.Modules.Main/VPNHelper.cs @@ -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() + { + + } + + /// + /// 尝试连接VPN + /// + /// + 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()); + } + } + + + /// + /// 尝试断开连接(默认VPN) + /// + /// + [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(); + + } + } + } + + /// + /// 创建或更新一个VPN连接(指定VPN名称,及IP) + /// + [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; + } + /// + /// 删除指定名称的VPN + /// 如果VPN正在运行,一样会在电话本里删除,但是不会断开连接,所以,最好是先断开连接,再进行删除操作 + /// + /// + [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); + } + } + /// + /// 获取VPN IP,如果无172地址,则未连接VPN + /// + 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; + } + + } +} diff --git a/StartServerWPF.Modules.Main/ViewModels/MainViewModel.cs b/StartServerWPF.Modules.Main/ViewModels/MainViewModel.cs new file mode 100644 index 0000000..9bc8c1b --- /dev/null +++ b/StartServerWPF.Modules.Main/ViewModels/MainViewModel.cs @@ -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 reciveDataSource=new ObservableCollection(); + + public ObservableCollection ReciveDataSource + { + get { return reciveDataSource; } + set { reciveDataSource = value; } + } + private ObservableCollection intervalTimesSource=new ObservableCollection(); + + public ObservableCollection 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(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 方法 + /// + /// 启动进程 + /// + /// + /// 进程启动返回值 + 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; + } + /// + /// 结束进程 + /// + /// + /// 0=成功;1=未找到进程;-1=失败 + 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; + } + } + /// + /// 查找进程 + /// + /// + /// 0=正在运行;1=未运行;-1=系统错误 + 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 + } + + + +} diff --git a/StartServerWPF.Modules.Main/ViewModels/SetParamDialogViewModel.cs b/StartServerWPF.Modules.Main/ViewModels/SetParamDialogViewModel.cs new file mode 100644 index 0000000..245a167 --- /dev/null +++ b/StartServerWPF.Modules.Main/ViewModels/SetParamDialogViewModel.cs @@ -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 RequestClose; + + public bool CanCloseDialog() + { + return true; + } + + public void OnDialogClosed() { } + + public void OnDialogOpened(IDialogParameters parameters) + { + // _title = "编辑" + _title; + var _type = parameters.GetValue("type"); + // _title = (_type == 0 ? "新增" : "修改") + _title; + MainModel = parameters.GetValue("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)); + }); + } + + } +} diff --git a/StartServerWPF.Modules.Main/Views/MainView.xaml b/StartServerWPF.Modules.Main/Views/MainView.xaml new file mode 100644 index 0000000..02775b3 --- /dev/null +++ b/StartServerWPF.Modules.Main/Views/MainView.xaml @@ -0,0 +1,95 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +