public static bool Save(string id, string host, string httpPort, string name, string key) { var validate = new Validate(); validate.AddCmd(new ValidateCmd(name, "名称未输入")); validate.AddCmd(new ValidateCmd(host, "主机地址未输入")); validate.AddCmd(new ValidateCmd(httpPort, "http端口未输入")); validate.AddCmd(new ValidateCmd("主机地址格式不正确", () => Validate.IsHost(host))); validate.AddCmd(new ValidateCmd("http端口格式不正确", () => Validate.IsInteger(httpPort))); if (!validate.Execute()) { return(false); } if (!string.IsNullOrEmpty(id)) { ListenServerData.Delete(id); } var success = ListenServerData.AddServer(name, host, int.Parse(httpPort), key); if (!success) { MsgBox.Alert("添加失败,主机和端口已存在"); return(false); } else { return(true); } }
public void Refresh() { UpdateStatusTaskManager.Execute(this, UpdateStatusTaskType.Server, () => { var serverData = ListenServerData.GetServerList(); serverData.Columns.Add(new DataColumn("StatusColor", typeof(string))); foreach (DataRow row in serverData.Rows) { var host = row ["Host"].ToString(); var port = row ["HttpPort"].ToString(); var serverItem = new ListenServerItem(); serverItem.Host = host; serverItem.HttpPort = port; var url = serverItem.HttpUrl; var result = HttpHelper.CheckHttp(url); if (result.Item1) { row ["Status"] = "正常"; row ["StatusColor"] = Common.DEFAULT_TEXT_COLOR; } else { row ["Status"] = "异常"; row ["StatusColor"] = "Red"; } } var dataView = serverData.DefaultView; if (serverData.Rows.Count > 0) { dataView.Sort = "Status desc"; } Dispatcher.Invoke((Action) delegate { listView.DataContext = dataView.ToTable(); }); }); }
public ServerProperty(string id) { this.serverId = id; this.serverItem = ListenServerData.GetServerItem(serverId); this.dataSource = new DataSource(serverItem); InitializeComponent(); }
private void Button_Click_2(object sender, RoutedEventArgs e) { var id = GetSelectedItemID(); if (string.IsNullOrEmpty(id)) { return; } MessageBoxResult confirmToDel = MsgBox.Comfirn("确认要删除所选行吗?"); if (confirmToDel == MessageBoxResult.Yes) { ListenServerData.Delete(id); Refresh(); } }
private void listView_SelectionChanged(object sender, MouseButtonEventArgs e) { var id = GetSelectedItemID(); if (string.IsNullOrEmpty(id)) { return; } var serverItem = ListenServerData.GetServerItem(id); var serverManager = new ServerManager(serverItem); serverManager.Closed += delegate { this.Show(); }; serverManager.Owner = this; serverManager.Show(); this.Hide(); }