Exemplo n.º 1
0
        protected override string getTitle(HtmlNode node)
        {
            var text = node.InnerText.Trim();
            var p    = RegexUtil.MatcheGroups(@"\-[ | ](餌食牝.*)[ | ]\-", text, 1).Trim();

            return(p);
        }
Exemplo n.º 2
0
        /// <internalonly/>
        /// <devdoc>
        ///    EvaluateIsValid method
        /// </devdoc>
        protected override bool EvaluateIsValid()
        {
            // Always succeeds if input is empty or value was not found
            string controlValue = GetControlValidationValue(ControlToValidate);

            Debug.Assert(controlValue != null, "Should have already been checked");
            if (controlValue == null || controlValue.Trim().Length == 0)
            {
                return(true);
            }

            try {
                // we are looking for an exact match, not just a search hit
                // Adding timeout for Regex in case of malicious string causing DoS
                Match m = RegexUtil.Match(controlValue, ValidationExpression, RegexOptions.None, MatchTimeout);

                return(m.Success && m.Index == 0 && m.Length == controlValue.Length);
            }
            catch (ArgumentOutOfRangeException) {
                throw;
            }
            catch {
                Debug.Fail("Regex error should have been caught in property setter.");
                return(true);
            }
        }
Exemplo n.º 3
0
        protected static string GetYearRegexPart()
        {
            // Allow at least 5 years into the future.
            int yearMax = DateTime.Now.Year + (5 + 1);

            return(RegexUtil.RegexForRange(1900, yearMax));
        }
Exemplo n.º 4
0
 //修改服务器端口号
 void btnSysSetServerPortOK_Click(object sender, EventArgs e)
 {
     if (richTextSysSetServerPort.Enabled == true)
     {
         //验证端口号格式是否正确(即是否是小于65535的纯数字)
         if (RegexUtil.RegexCheckNumber(richTextSysSetServerPort.Text))
         {
             int port = int.Parse(richTextSysSetServerPort.Text);
             if ((port > 0) && (port < 65535))
             {
                 richTextSysSetServerPort.Enabled = false;
                 SysConfig.Setting.serverPort     = port;
                 SysConfig.SaveSystemSetting(SysConfig.Setting);                                                 //将系统设置序列化到磁盘
                 //写入服务器端口号修改记录
                 worklog.LogQueue_Enqueue(LogCommand.getButtonClickRecord(BTNPANEL.SysSettingPanel, (int)BtnOfSysSettingPanel.ChangeServerPort, richTextSysSetServerPort.Text));
             }
             else
             {
                 MessageBox.Show("请输入小于65535的端口号");
             }
         }
         else
         {
             MessageBox.Show("请输入有效的端口号");
         }
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// 模板URL自动补全参数
        /// </summary>
        /// <param name="tplUri"></param>
        /// <param name="request"></param>
        /// <returns></returns>
        protected static string mergeTplUri(string tplUri, YopRequest request)
        {
            string uri = tplUri;

            if (tplUri.IndexOf("{") < 0)
            {
                return(uri);
            }
            List <string> dynaParamNames = uriTemplateCache[tplUri];

            if (dynaParamNames == null)
            {
                dynaParamNames = new List <string>();

                dynaParamNames.Add(RegexUtil.GetResResult("\\{([^\\}]+)\\}", tplUri));

                uriTemplateCache.Add(tplUri, dynaParamNames);
            }

            foreach (string dynaParamName in dynaParamNames)
            {
                string value = request.removeParam(dynaParamName);
                Assert.notNull(value, dynaParamName + " must be specified");
                uri = uri.Replace("{" + dynaParamName + "}", value);
            }

            return(uri);
        }
Exemplo n.º 6
0
    void is_regex_contents2_lc()
    {
        var match = RegexUtil.Get1stMatch(G.REGEXCONT2, m_line);

        if (!string.IsNullOrEmpty(match))
        {
            //1 正規表現部分の取得
            var regex = RegexUtil.Get1stMatch(@"\$\/.+\/->#", match); // $/正規表現/->#
            regex = regex.Substring(2);
            regex = regex.Substring(0, regex.Length - 4);

            //マクロ名の取得
            var macroname = RegexUtil.Get1stMatch(@"#.+\$$", match);  // #macro$
            macroname = macroname.TrimEnd('$');

            var macrobuf = G.getMacroValueFunc(macroname);
            if (string.IsNullOrEmpty(macrobuf))
            {
                throw new SystemException("Macro is not defined. : " + macroname);
            }
            var c = create_regex_contents(regex, macrobuf);

            var tmplines = StringUtil.ReplaceWordsInLine(m_line, match, c);
            m_resultlist.AddRange(tmplines);
            m_bContinue = true;
        }
    }
Exemplo n.º 7
0
        public async Task <Pager <IQueryable <UserDepartRoleInfo> > > List(UserInfo userInfo)
        {
            //判断查询参数(组装查询条件)
            Expression <Func <UserDepartRoleInfo, bool> > where_search = LinqUtil.True <UserDepartRoleInfo>();

            if (!string.IsNullOrEmpty(userInfo.name))
            {
                where_search = RegexUtil.Email(userInfo.name) ? where_search.AndAlso(c => c.user_email == userInfo.name)
                    : where_search.AndAlso(c => c.user_phone == userInfo.name);
            }
            if (userInfo.gender != -1)
            {
                where_search = where_search.AndAlso(c => c.user_gender == userInfo.gender);
            }
            if (userInfo.source != -1)
            {
                where_search = where_search.AndAlso(c => c.source_type == userInfo.source);
            }
            if (userInfo.status != -1)
            {
                where_search = where_search.AndAlso(c => c.disable == userInfo.status);
            }

            //根据条件查询用户表,部门表,用户部门表查询出来用户信息
            int total = 0;
            IQueryable <UserDepartRoleInfo> user_dep_role = await userRepository.getLeftJoinDepRole(where_search,
                                                                                                    userInfo.pageindex, userInfo.pagesize, out total);

            return(new Pager <IQueryable <UserDepartRoleInfo> >(total, user_dep_role));
        }
Exemplo n.º 8
0
    void is_contents_1_lc()
    {
#if obs
        if (m_line.Contains(G.CONTENTS1))
        {
            var tmplines = StringUtil.ReplaceWordsInLine(m_line, G.CONTENTS1, m_contents1);
            m_resultlist.AddRange(tmplines);
            m_bContinue = true;
        }
#endif
        var match = RegexUtil.Get1stMatch(G.CONTENTS1PTN, m_line);
        if (!string.IsNullOrEmpty(match))
        {
            var macro = string.Empty;
            if (match.Contains("->@"))
            {
                var index = match.IndexOf("->@");
                if (index >= 0)
                {
                    macro = match.Substring(index + 3).Trim('$');
                }
            }
            var replacevalue = G.get_line_macro_value(macro, m_contents1);
            var tmplines     = StringUtil.ReplaceWordsInLine(m_line, match, replacevalue);
            m_resultlist.AddRange(tmplines);
            m_bContinue = true;
        }
    }
Exemplo n.º 9
0
    void escape_to_char()
    {
        //バッファ内の\xXXを変換
        var res = string.Empty;
        Func <int, string> getstr4 = (i) => {
            if (i < m_src.Length - 4)
            {
                return(m_src.Substring(i, 4));
            }
            return(null);
        };

        for (var index = 0; index < m_src.Length; index++)
        {
            var c = m_src[index];
            if (c == '\\')
            {
                var sample = getstr4(index);
                if (!string.IsNullOrEmpty(sample))
                {
                    if (RegexUtil.IsMatch(@"\\x[0-9a-fA-F]{2}", sample))
                    {
                        var code = Convert.ToInt32(sample.Substring(2), 16);
                        c      = (char)code;
                        index += 3;
                    }
                }
            }
            res += c.ToString();
        }
        m_src = res;
    }
Exemplo n.º 10
0
        // 汎用コンバータ
        public static string Convert(string text, int num, List <string> args, bool bAcceptNullArg = false)
        {
            var src = text;

            for (var loop = 0; loop <= 100; loop++)
            {
                if (loop == 100)
                {
                    throw new SystemException("Unexpected! {710FA2E8-7740-43F9-8A26-703AF71085C6}\n" + src + " #" + num.ToString());
                }

                var match = RegexUtil.Get1stMatch(m_argpattern, src);
                if (!string.IsNullOrEmpty(match))
                {
                    var val = GetArgValue(match, args, bAcceptNullArg);
                    src = src.Replace(match, val);
                    continue;
                }
                match = RegexUtil.Get1stMatch(m_numpattern, src);
                if (!string.IsNullOrEmpty(match))
                {
                    var val = num.ToString();
                    src = src.Replace(match, val);
                    continue;
                }

                break;
            }
            return(src);
        }
Exemplo n.º 11
0
        static void Main(string[] args)
        {
            var doubleList = new List <List <double> >()
            {
                new List <double> {
                    1, 2, 3
                },
                new List <double> {
                    4, 5, 6, 23, 4, 5
                },
                new List <double> {
                    7, 8, 9
                },
            };
            var list = new double[] { 1, 1, 2, 3, 4, 5, 6, 44 }.ToObservable();
            var x = from score in list where score > 8 select score;

            Console.WriteLine(x.ToString());
            var dic = new Dictionary <string, int>()
            {
                { "sss", 1 },
                { "sa", 1 },
                { "s1", 1 },
            };

            foreach (var item in doubleList)
            {
                Console.WriteLine(item.ToListString());
            }
            Console.WriteLine(dic.ToKeyValuePairString());
            Console.WriteLine("Hello World!");
            Console.WriteLine(RegexUtil.IsIdCard("140521********08050018"));
            Console.ReadLine();
        }
Exemplo n.º 12
0
        public static async Task <List <InitRule> > GetInitRules(ApiDbContext context, Guid groupId)
        {
            var             groups    = context.Set <GroupEntity>();
            List <InitRule> initRules = new List <InitRule>();
            var             group     = await groups.Where(g => g.ExternalId == groupId).Select(g => g).FirstOrDefaultAsync();

            if (group == null)
            {
                throw new NotFoundException($"Group '{groupId}' not found");
            }
            List <RuleEntity> orderedRules = group.Rules.OrderBy(r => r.Index).ToList <RuleEntity>();

            foreach (RuleEntity ruleEntity in orderedRules)
            {
                InitRule initRule = new InitRule
                {
                    Pattern         = RegexUtil.ToRegex(ruleEntity.Pattern),
                    SourceType      = ruleEntity.SourceType,
                    DestinationType = ruleEntity.DestinationType
                };
                initRule.Parameters = ruleEntity.Parameters.OrderBy(p => p.Index).Select(p => p.Value).ToList();
                initRules.Add(initRule);
            }
            return(initRules);
        }
Exemplo n.º 13
0
        public void KeepNumberTest()
        {
            var str = RegexUtil.KeepNumber("1qe2vd3k");

            output.WriteLine(str);
            Assert.Equal("123", str);
        }
Exemplo n.º 14
0
        static void Crawler(CrawlerOption crawlerOption)
        {
            if (string.IsNullOrEmpty(crawlerOption.Url))
            {
                WriteLine("url is required");
                return;
            }

            if (RegexUtil.MatchUrl(crawlerOption.Url) == false)
            {
                WriteLine("illegal url");
                return;
            }

            if (crawlerOption.GetHtml == true)
            {
                GetHtmlAsync(crawlerOption.Url);
            }

            if (crawlerOption.GetImage == true)
            {
                GetImageAsync(crawlerOption.Url);
            }

            if (crawlerOption.GetVideo == true)
            {
                GetVideoAsync(crawlerOption.Url);
            }
        }
Exemplo n.º 15
0
 private void ExtractImageWithRegex(object html)
 {
     try
     {
         string          value = "";
         MatchCollection mc    = RegexUtil.Matches(html.ToString(), RegexPattern.TagImgPattern);
         foreach (Match item in mc)
         {
             value = item.Groups["image"].Value;
             if (value.Contains("//") == false)
             {
                 value = baseUrl + value;
             }
             AddToCollection(new UrlStruct()
             {
                 Id = globalIndex, Status = "", Title = "", Url = value
             });
         }
         ShowStatusText($"已抓取到{mc.Count}个图像");
     }
     catch (Exception ex)
     {
         ShowStatusText(ex.Message);
     }
 }
Exemplo n.º 16
0
        public bool ProcessRegex(string target, string regexExpression)
        {
            if (target == null)
            {
                target = String.Empty;
            }

            // Adding timeout for Regex in case of malicious string causing DoS
            Regex regex = RegexUtil.CreateRegex(regexExpression, RegexOptions.ExplicitCapture);
            Match match = regex.Match(target);

            if (match.Success == false)
            {
                return(false);
            }

            string[] groups = regex.GetGroupNames();

            if (groups.Length > 0)
            {
                if (_groups == null)
                {
                    _groups = new Hashtable();
                }

                for (int i = 0; i < groups.Length; i++)
                {
                    _groups[groups[i]] = match.Groups[i].Value;
                }
            }

            return(true);
        }
Exemplo n.º 17
0
        private void ExtractImageWithRegex(string html)
        {
            try
            {
                string          value = "";
                MatchCollection mc    = RegexUtil.Matches(html, RegexPattern.TagImgPattern);

                for (int i = 0; i < mc.Count; i++)
                {
                    value = mc[i].Groups["image"].Value;
                    if (value.Contains("//") == false)
                    {
                        value = BaseUrl + value;
                    }
                    AddToCollection(new UrlStruct()
                    {
                        Id = i + 1, Status = "", Title = "", Url = value
                    });
                }
                ShowStatusText($"已抓取到{imageCollection.Count}个图像");
            }
            catch (Exception ex)
            {
                ShowStatusText(ex.Message);
            }
        }
Exemplo n.º 18
0
        private void btn_Surfing_Click(object sender, RoutedEventArgs e)
        {
            string url             = this.tbox_Url.Text;
            bool   isStartWithHttp = false;

            if (string.IsNullOrEmpty(url))
            {
                ShowStatusText("请输入Url");
                return;
            }

            //判断Url
            if (globalData.CrawlerConfig.UrlConfig.IgnoreUrlCheck == false)
            {
                if (RegexUtil.IsUrl(url, out isStartWithHttp) == false)
                {
                    ShowStatusText("网址输入有误");
                    return;
                }

                if (isStartWithHttp == false)
                {
                    url = "http://" + url;
                }
            }

            Reset();
            Surfing(url);
        }
Exemplo n.º 19
0
        static void Main(string[] args)
        {
            var canlender = new ChineseCalendar(DateTime.Now);

            Console.WriteLine(canlender.WeekDayStr);
            ChineseCalendar c       = new ChineseCalendar(DateTime.Now);
            StringBuilder   dayInfo = new StringBuilder();

            dayInfo.Append("阳历:" + c.DateString + "\r\n");
            dayInfo.Append("农历:" + c.ChineseDateString + "\r\n");
            dayInfo.Append("星期:" + c.WeekDayStr);
            dayInfo.Append("时辰:" + c.ChineseHour + "\r\n");
            dayInfo.Append("属相:" + c.AnimalString + "\r\n");
            dayInfo.Append("节气:" + c.ChineseTwentyFourDay + "\r\n");
            dayInfo.Append("前一个节气:" + c.ChineseTwentyFourPrevDay + "\r\n");
            dayInfo.Append("下一个节气:" + c.ChineseTwentyFourNextDay + "\r\n");
            dayInfo.Append("节日:" + c.DateHoliday + "\r\n");
            dayInfo.Append("干支:" + c.GanZhiDateString + "\r\n");
            dayInfo.Append("星宿:" + c.ChineseConstellation + "\r\n");
            dayInfo.Append("星座:" + c.Constellation + "\r\n");
            Console.WriteLine(dayInfo.ToString());
            Console.WriteLine(RegexUtil.IsEmail("*****@*****.**"));
            Console.WriteLine(RmbUtil.CmycurD("123.45"));
            Console.ReadLine();
        }
Exemplo n.º 20
0
        public object Register(string nickname, string acc, string pwd)
        {
            if (RegexUtil.IsEmail(acc))
            {
                DataTable dt = MemberBll.Instance.GetList("Email='" + acc + "'").Tables[0];
                if (dt.Rows.Count > 0)
                {
                    return(new Dictionary <string, string>()
                    {
                        { "status", "400" }, { "message", "该邮箱已被注册" }
                    });
                }
            }
            else
            {
                DataTable dt = MemberBll.Instance.GetList($"Phone_mob='{acc}'").Tables[0];
                if (dt.Rows.Count > 0)
                {
                    return(new Dictionary <string, string>()
                    {
                        { "status", "403" }, { "message", "该手机号已经注册" }
                    });
                }
            }

            string status = MemberApi.Register(nickname, acc, pwd);

            return(new Dictionary <string, string>()
            {
                { "status", "200" }, { "message", status }
            });
        }
Exemplo n.º 21
0
 public void IsDataTime_Test()
 {
     Assert.False(RegexUtil.IsDataTime("11.32"));
     Assert.False(RegexUtil.IsDataTime(""));
     Assert.True(RegexUtil.IsDataTime("2019-05-23"));
     Assert.True(RegexUtil.IsDataTime("2019-1-3 18:00"));
 }
Exemplo n.º 22
0
        private void btn_Fetch_Click(object sender, RoutedEventArgs e)
        {
            string   url      = this.tbox_Url.Text;
            Encoding encoding = GetChoosedEncoding();

            if (UrlUtil.IsEmpty(url))
            {
                EMessageBox.Show("请输入网址");
                this.tbox_Url.Focus();
                return;
            }

            bool isStartWithHttp = false;

            if (RegexUtil.IsUrl(url, out isStartWithHttp) == false)
            {
                EMessageBox.Show("网址输入错误");
                this.tbox_Url.Focus();
                return;
            }

            ClearControls();

            GetHostIP(url, isStartWithHttp);
            GetHeaderInfo(url, isStartWithHttp);
            GetHtmlSource(url, isStartWithHttp, encoding);
        }
Exemplo n.º 23
0
        /// <summary>
        /// 根据登录名密码获取用户
        /// </summary>
        /// <param name="loginName">登录名</param>
        /// <param name="loginPwd">密码</param>
        /// <param name="isEncrypt">密码是否需要加密</param>
        /// <returns>用户实体</returns>
        public ls_user GetUser(string loginName, string loginPwd, bool isEncrypt)
        {
            ICriteria criteria = db.CreateCriteria(typeof(ls_user));

            if (isEncrypt)                             //如果需要对密码进行加密
            {
                string salt = this.GetSalt(loginName); //获得用户加密盐
                if (string.IsNullOrEmpty(salt))        //如果无法获得用户加密盐
                {
                    return(null);
                }
                loginPwd = DESEncrypt.Encrypt(loginPwd, salt);
            }
            if (RegexUtil.IsMobilePhone(loginName))
            {
                criteria.Add(Expression.Eq("user_mobile", loginName));
            }
            else if (RegexUtil.IsEmail(loginName))
            {
                criteria.Add(Expression.Eq("user_email", loginName));
            }
            else
            {
                criteria.Add(Expression.Eq("user_name", loginName));
            }
            criteria.Add(Expression.Eq("user_password", loginPwd));
            return(criteria.UniqueResult <ls_user>());
        }
Exemplo n.º 24
0
        /// <summary>
        /// 获取用户加密盐
        /// </summary>
        /// <param name="loginName">登录名称</param>
        /// <returns>用户加密盐</returns>
        public string GetSalt(string loginName)
        {
            StringBuilder hql = new StringBuilder();

            hql.Append("select user_salt from ls_user");
            if (RegexUtil.IsMobilePhone(loginName))//如果是手机号
            {
                hql.Append(" where user_mobile=?");
            }
            else if (RegexUtil.IsEmail(loginName))//如果是邮箱
            {
                hql.Append(" where user_email=?");
            }
            else
            {
                hql.Append(" where user_name=?");
            }
            IQuery query = db.CreateQuery(hql.ToString());

            query.SetParameter(0, loginName);
            object obj = query.UniqueResult();

            if (obj == null)
            {
                return("");
            }
            else
            {
                return((string)obj);
            }
        }
Exemplo n.º 25
0
 public void MatchTest()
 {
     Assert.Equal("image/ad1.gif", RegexUtil.Match(
                      @"<img\b[^<>]*?\bsrc[\s\t\r\n]*=[\s\t\r\n]*[""']?[\s\t\r\n]*(?<imgUrl>[^\s\t\r\n""'<>]*)[^<>]*?/?[\s\t\r\n]*>",
                      "<img src=image/ad1.gif width=\"128\" height=\"36\"/><img src='image/ad2.gif' />"
                      ));
 }
Exemplo n.º 26
0
 /*
  *  S_EXEC_REGEX
  *  正規表現の実行
  */
 void S_EXEC_REGEX(bool bFirst)
 {
     //
     if (bFirst)
     {
         if (m_regex[0] == '/' && m_regex[m_regex.Length - 1] == '/')
         {
             m_regex = m_regex.Substring(1);
             m_regex = m_regex.Substring(0, m_regex.Length - 1);
             var match = RegexUtil.Get1stMatch(m_regex, m_val);
             m_bValid = !string.IsNullOrEmpty(match);
         }
         else
         {
             m_bValid = false;
             throw new SystemException("{59858294-6BCF-45B6-B441-076A5A6041D8}\n" + m_line0);
         }
     }
     // branch
     if (m_bValid)
     {
         Goto(S_GET_SIZE);
     }
     else
     {
         Goto(S_REMOVE);
     }
 }
Exemplo n.º 27
0
        private void _init()
        {
            state_list     = new List <string>();
            state_col_list = new List <int>();

            name_list     = new List <string>();
            name_row_list = new List <int>();

            for (var c = 1; c < 10000; c++)
            {
                var state = getChartFunc(STATE_ROW, c);
                if (!string.IsNullOrEmpty(state))
                {
                    if (RegexUtil.Get1stMatch(@"^[a-zA-Z_][a-zA-Z_0-9]*$", state) == state)
                    {
                        state_list.Add(state);
                        state_col_list.Add(c);
                    }
                }
            }

            for (var r = 1; r < 10000; r++)
            {
                var name = getChartFunc(r, NAME_COL);
                if (!string.IsNullOrEmpty(name))
                {
                    name_list.Add(name);
                    name_row_list.Add(r);
                }
            }
        }
Exemplo n.º 28
0
        private void ExtractUrlWithRegex(object html)
        {
            string value = "";
            string url   = "";

            MatchCollection mc = RegexUtil.Matches(html.ToString(), RegexPattern.TagAPattern);

            foreach (Match item in mc)
            {
                value = item.Groups["url"].Value;

                if (value.StartsWith("http://") || value.StartsWith("https://") || value.StartsWith("ftp://"))
                {
                    url = item.Groups["url"].Value;
                }
                else if (value.StartsWith("/"))
                {
                    url = globalBaseUrl + item.Groups["url"].Value;
                }

                AddToCollection(new UrlStruct()
                {
                    Title = "", Id = globalIndex, Status = "", Url = url
                }, globalBaseUrl);
                IncrementCount();
            }

            //对顶级页面抓取的Url进行递归
            if (recursionDepth > StartDepth)
            {
            }
        }
Exemplo n.º 29
0
        public object EmailVerification(string email)
        {
            if (!RegexUtil.IsEmail(email))
            {
                return(new Dictionary <string, string>()
                {
                    { "status", "400" }, { "message", "邮箱不符合规范" }
                });
            }

            DataTable dt = MemberBll.Instance.GetList("Email='" + email + "'").Tables[0];

            if (dt.Rows.Count > 0)
            {
                return(new Dictionary <string, string>()
                {
                    { "status", "403" }, { "message", "该邮箱已被注册" }
                });
            }
            else
            {
                return(new Dictionary <string, string>()
                {
                    { "status", "200" }, { "message", "该邮箱未被注册" }
                });
            }
        }
Exemplo n.º 30
0
        static void Main(string[] args)
        {
            Console.WriteLine("Validando WTF! as a regular expression!");
            var isValid = RegexUtil.IsRegexPatternValid("WTF!");

            Console.WriteLine($"Is Valid={isValid}");
        }
Exemplo n.º 31
0
 /// <summary>
 /// 静态实例化单体模式
 /// 保证应用程序操作某一全局对象,让其保持一致而产生的对象
 /// </summary>
 /// <returns></returns>
 public static RegexUtil GetInstance()
 {
     if (RegexUtil.instance == null)
     {
         RegexUtil.instance = new RegexUtil();
     }
     return RegexUtil.instance;
 }