private void LoadEditData(int ID) { IpSetting info = IpSettingHelper.SelectListByAll().Where(p => p.IPCID == ID).FirstOrDefault(); if (info.IsNull() || info.IPCID.IsNull()) { return; } this.txtWebName.Text = info.WebName.ToString(); this.txtIPUrl.Text = info.IPUrl.ToString(); this.txtIPRegex.Text = info.IPRegex.ToString(); this.txtDataEncode.Text = info.DataEncode.ToString(); }
/// <summary> /// 获取外网IP地址 多线程 有一个线程取到数据后其它线程都停止 /// </summary> /// <returns></returns> public static string GetIpFast() { string ip = string.Empty; ThreadEx ex = new ThreadEx(); IList <IpSetting> list = IpSettingHelper.SelectListByAll(); list.Do((p, i) => { ex.QueueWorkItem(new System.Threading.WaitCallback(o => { IpSetting setting = (IpSetting)o; try { string data = string.Empty; string name = setting.DataEncode.IfNullOrEmpty("utf-8"); Encoding coding = Encoding.GetEncoding(name); data = GetRemoteHtmlCode(setting.IPUrl, coding); if (!data.Trim().IsNullEmpty()) { if (setting.IPRegex.IsNullEmpty()) //允许正则为空 { if (!data.IsNullEmpty()) { ip = data; ex.SetAll(); } } else { string begin = setting.IPRegex.Substring(0, setting.IPRegex.IndexOf("(")).Replace("\\", ""); string end = setting.IPRegex.Substring(setting.IPRegex.IndexOf(")") + 1).Replace("\\", ""); if (!begin.IsNullEmpty() && !end.IsNullEmpty()) { string _ip = data.GetMatchingValues(setting.IPRegex, begin, end).Join(","); if (!_ip.IsNullEmpty()) { ip = _ip; ex.SetAll(); } } } } } catch { } }), p); }); ex.WaitAllComplete(); return(ip); }
private void btnDel_Click(object sender, EventArgs e) { if (this.listView1.SelectedItems.Count > 0 && this.listView1.SelectedItems[0].Tag != null) { if (MessageBox.Show("确认要删除选中的记录吗?", " 系统提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { int id = this.listView1.SelectedItems[0].Tag.ToString().ToInt(0); if (id < 1) { return; } IpSettingHelper.DeleteByID(id); IpSettingHelper.ClearCacheAll(); loadData(); } } else { MessageBox.Show("请选择你要删除的记录!", " 系统提示"); } }
public void loadData() { frmMain.Instance.ShowStatusText("正在数据...."); this.listView1.Items.Clear(); this.listView1.BeginUpdate(); IpSettingHelper.SelectListByAll().OrderBy(p => p.IPCID).Do((p, i) => { ListViewItem item = new ListViewItem((i + 1).ToString()); item.Tag = p.IPCID.Value; item.ToolTipText = p.IPCID.ToString(); item.SubItems.Add(p.WebName.ToString()); item.SubItems.Add(p.IPUrl.ToString()); item.SubItems.Add(p.IPRegex.ToString()); item.SubItems.Add(p.DataEncode.ToString()); if (i % 2 == 0) { item.BackColor = Color.FromArgb(247, 247, 247); } this.listView1.Items.Add(item); }); this.listView1.EndUpdate(); frmMain.Instance.ShowStatusText("数据加载完成!"); }
private void button1_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(this.txtWebName.Text)) { MessageBox.Show("网址名称不能为空", "系统提示"); return; } if (string.IsNullOrEmpty(this.txtIPUrl.Text)) { MessageBox.Show("网址地址不能为空", "系统提示"); return; } DialogResult = System.Windows.Forms.DialogResult.OK; IpSetting info = new IpSetting(); info.WebName = this.txtWebName.Text; info.IPUrl = this.txtIPUrl.Text; info.IPRegex = this.txtIPRegex.Text; info.DataEncode = this.txtDataEncode.Text; if (this.id != 0) { info.IPCID = this.id; IpSettingHelper.Update(info); IpSettingHelper.ClearCacheAll(); } else { IpSettingHelper.Insert(info); IpSettingHelper.ClearCacheAll(); } MessageBox.Show("保存数据成功!", " 系统提示"); this.Close(); }
public static void TestIPStart(Action <string> msg, Pub.Class.Action done) { IList <IpSetting> list = IpSettingHelper.SelectListByAll(); if (list.Count == 0) { msg("请设置需要获取IP的网址!"); return; } msg("共有{0}个获取IP的网址!".FormatWith(list.Count)); if (!ex.IsNull()) { ex.SetAll(); } ex = new ThreadEx(); list.Do((p, i) => { ex.QueueWorkItem(new System.Threading.WaitCallback(o => { IpSetting setting = (IpSetting)o; string ip = string.Empty; try { string data = string.Empty; string name = setting.DataEncode.IfNullOrEmpty("utf-8"); Encoding coding = Encoding.GetEncoding(name); data = GetRemoteHtmlCode(setting.IPUrl, coding); if (data.Trim().IsNullEmpty()) { msg("{0},error - 请检查网址{1}是否正确!".FormatWith(i + 1, setting.IPUrl)); } else { if (setting.IPRegex.IsNullEmpty()) //允许正则为空 { if (data.IsNullEmpty()) { msg("{0},error - 网址{1}无法匹配IP:{2}".FormatWith(i + 1, setting.IPUrl, data)); } else { msg("{0},ok - 网址{1}获取的IP是:{2}".FormatWith(i + 1, setting.IPUrl, data)); } } else { string begin = setting.IPRegex.Substring(0, setting.IPRegex.IndexOf("(")).Replace("\\", ""); string end = setting.IPRegex.Substring(setting.IPRegex.IndexOf(")") + 1).Replace("\\", ""); if (begin.IsNullEmpty() || end.IsNullEmpty()) { msg("{0},error - 请检查网址{1}的正则是否正确:{2}".FormatWith(i + 1, setting.IPUrl, setting.IPRegex)); } else { ip = data.GetMatchingValues(setting.IPRegex, begin, end).Join(","); if (ip.IsNullEmpty()) { msg("{0},error - 网址{1}无法匹配IP:{2}".FormatWith(i + 1, setting.IPUrl, data)); } else { msg("{0},ok - 网址{1}获取的IP是:{2}".FormatWith(i + 1, setting.IPUrl, ip)); } } } } } catch (Exception e) { msg("{0},error - 获取网址{1}数据出错:{2}".FormatWith(i + 1, setting.IPUrl, e.Message)); return; } }), p); }); ex.WaitAllComplete(); done(); }