コード例 #1
0
        /// <summary>
        /// 获取IP配置修改记录
        /// </summary>
        /// <param name="ipSetting">获取IP配置实体类</param>
        /// <param name="where">修改时附加条件,统一的前面要加链接符(and、or等等)</param>
        /// <param name="delCache">修改成功后清理的CACHE key,支持正则</param>
        /// <param name="dbkey">存在数据库连接池中的连接key,为空时使用ConnString连接</param>
        /// <returns>修改是否成功</returns>
        public static bool Update(IpSetting ipSetting, string dbkey = "", Where where = null, string[] delCache = null)
        {
            if (ipSetting.IPCID.IsNull())
            {
                return(false);
            }
            int value = new SQL().Database(dbkey).Update(IpSetting._)
                        .SetP(IpSetting._WebName, ipSetting.WebName)
                        .SetP(IpSetting._IPUrl, ipSetting.IPUrl)
                        .SetP(IpSetting._IPRegex, ipSetting.IPRegex)
                        .SetP(IpSetting._DataEncode, ipSetting.DataEncode)
                        .Where(new Where()
                               .AndP(IpSetting._IPCID, ipSetting.IPCID, Operator.Equal, true)
                               ).Where(where).ToExec();

            if (value <= 0)
            {
                return(false);
            }
            if (delCache.IsNull())
            {
                return(true);
            }
            Cache2.Remove("TH.Mailer.IpSettingCache_", delCache);
            return(true);
        }
コード例 #2
0
        /// <summary>
        /// 获取IP配置添加记录
        /// </summary>
        /// <param name="ipSetting">获取IP配置实体类</param>
        /// <param name="delCache">添加成功后清理的CACHE key,支持正则</param>
        /// <param name="dbkey">存在数据库连接池中的连接key,为空时使用ConnString连接</param>
        /// <returns>返回添加成功后的ID</returns>
        public static Int64 Insert(IpSetting ipSetting, string dbkey = "", string[] delCache = null)
        {
            object obj = new SQL().Database(dbkey).Insert(IpSetting._)
                         .ValueP(IpSetting._IPCID, ipSetting.IPCID)
                         .ValueP(IpSetting._WebName, ipSetting.WebName)
                         .ValueP(IpSetting._IPUrl, ipSetting.IPUrl)
                         .ValueP(IpSetting._IPRegex, ipSetting.IPRegex)
                         .ValueP(IpSetting._DataEncode, ipSetting.DataEncode)
                         .ToExec();

            if (obj.ToInt() != 1)
            {
                return(0);
            }
            obj = new SQL().Database(dbkey).From(IpSetting._).Max("IPCID").ToScalar();
            if (obj.IsAllNull())
            {
                return(0);
            }
            Int64 value = obj.ToString().ToBigInt();

            if (delCache.IsNull())
            {
                return(value);
            }
            Cache2.Remove("TH.Mailer.IpSettingCache_", delCache);
            return(value);
        }
コード例 #3
0
        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();
        }
コード例 #4
0
        /// <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);
        }
コード例 #5
0
        /// <summary>
        /// 获取IP配置修改多条记录
        /// </summary>
        /// <param name="iPCIDList">获取IP配置编号列表,用“,”号分隔</param>
        /// <param name="ipSetting">获取IP配置实体类</param>
        /// <param name="where">修改时附加条件,统一的前面要加链接符(and、or等等)</param>
        /// <param name="delCache">修改成功后清理的CACHE key,支持正则</param>
        /// <param name="dbkey">存在数据库连接池中的连接key,为空时使用ConnString连接</param>
        /// <returns>修改是否成功</returns>
        public static bool UpdateByIDList(IEnumerable <Int64> iPCIDList, IpSetting ipSetting, string dbkey = "", Where where = null, string[] delCache = null)
        {
            int value = new SQL().Database(dbkey).Update(IpSetting._)
                        .SetP(IpSetting._WebName, ipSetting.WebName)
                        .SetP(IpSetting._IPUrl, ipSetting.IPUrl)
                        .SetP(IpSetting._IPRegex, ipSetting.IPRegex)
                        .SetP(IpSetting._DataEncode, ipSetting.DataEncode)
                        .Where(new Where()
                               .And(IpSetting._IPCID, "(" + iPCIDList.Join(",") + ")", Operator.In)
                               ).Where(where).ToExec();

            if (value <= 0)
            {
                return(false);
            }
            if (delCache.IsNull())
            {
                return(true);
            }
            Cache2.Remove("TH.Mailer.IpSettingCache_", delCache);
            return(true);
        }
コード例 #6
0
        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();
        }
コード例 #7
0
 /// <summary>
 /// 获取IP配置添加记录
 /// </summary>
 /// <param name="ipSetting">获取IP配置实体类</param>
 /// <returns>返回添加成功后的ID</returns>
 public static Int64 Insert(IpSetting ipSetting, string dbkey)
 {
     return(Insert(ipSetting, dbkey, null));
 }
コード例 #8
0
 /// <summary>
 /// 获取IP配置修改多条记录
 /// </summary>
 /// <param name="iPCIDList">获取IP配置编号列表,用“,”号分隔</param>
 /// <param name="ipSetting">获取IP配置实体类</param>
 /// <returns>修改是否成功</returns>
 public static bool UpdateByIDList(IEnumerable <Int64> iPCIDList, IpSetting ipSetting, string dbkey)
 {
     return(UpdateByIDList(iPCIDList, ipSetting, dbkey, null, null));
 }
コード例 #9
0
 /// <summary>
 /// 获取IP配置修改记录
 /// </summary>
 /// <param name="ipSetting">获取IP配置实体类</param>
 /// <returns>修改是否成功</returns>
 public static bool Update(IpSetting ipSetting, string dbkey)
 {
     return(Update(ipSetting, dbkey, null, null));
 }
コード例 #10
0
        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();
        }