LINK BALANCED服务器上的错误

成员
加入
2013年1月25日
消息
14
编程经验
Beginner
你好

我正在通过违法的课程方法运行文本
通过列表运行。我把它置于居住,现在我一直在收到这个错误
System.InvalidOperationException:Collection被修改;枚举操作可能无法执行。在system.collections.generic.List`1.enumerator.movenextrare()在leanthalcharacters.filter(string stext)

我见过人们谈论锁定线程,但我不确定如何实现这一点甚至那个
会工作。

代码在不同的页面上调用如下

C#:
IllegalCharacters.IllegalCharRegPatterns();
Message = IllegalCharacters.Filter(sMessage);

非法特征类的代码是
C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text.RegularExpressions;

/// <summary>
/// Summary description for IllegalCharacters
/// </summary>
public class IllegalCharacters
{
    public static List<RegPatternParameters> lstIllegalParameters = new List<RegPatternParameters>();
    
    public static void IllegalCharRegPatterns()
    {
        //List Layout = RegExp, hide?, send owner email?

        lstIllegalParameters.Add(new RegPatternParameters { sRegPattern = "(\\b[A-Z0-9._%+-][email protected]+[A-Z0-9.-]+\\.+[A-Z]{2,4}\\b)", bHide = true, bSendMail = true });
        lstIllegalParameters.Add(new RegPatternParameters { sRegPattern = "(\\b[A-Z0-9._%+-]+[\\( -]+AT+[\\) -]+[A-Z0-9.-]+\\.+[A-Z]{2,4}\\b)", bHide = false, bSendMail = false });
        lstIllegalParameters.Add(new RegPatternParameters { sRegPattern = "(\\b[A-Z0-9._%+-]+[\\( -]+AT+[\\) -]+[A-Z0-9.-]+[\\( -]+DOT+[\\) -]+[A-Z]{2,4}\\b)", bHide = true, bSendMail = false });
        lstIllegalParameters.Add(new RegPatternParameters { sRegPattern = "(\\b[A-Z0-9._%+-]+[\\( -]+DOT+[\\) -]\\b)", bHide = true, bSendMail = false });
        lstIllegalParameters.Add(new RegPatternParameters { sRegPattern = @"(\\bhttp\\:\\/\\/[A-Z0-9\/_.-]+\\.[A-Z]{2,4}\\b)", bHide = true, bSendMail = true });
        lstIllegalParameters.Add(new RegPatternParameters { sRegPattern = @"(\\bwww\\.[A-Z0-9\/_.-]+\\.[A-Z]{2,4}\\b)", bHide = true, bSendMail = true });
        lstIllegalParameters.Add(new RegPatternParameters { sRegPattern = "(\\b[A-Z0-9.-]+\\.com\\b)", bHide = true, bSendMail = true });
        lstIllegalParameters.Add(new RegPatternParameters { sRegPattern = "(\\b[A-Z0-9.-]+\\.co\\.za\\b)", bHide = true, bSendMail = true });
        lstIllegalParameters.Add(new RegPatternParameters { sRegPattern = "(\\b[A-Z0-9.-]+\\.travel\\b)", bHide = true, bSendMail = true });
        lstIllegalParameters.Add(new RegPatternParameters { sRegPattern = "(\\b[A-Z0-9.-]+\\.net\\b)", bHide = true, bSendMail = true });
        lstIllegalParameters.Add(new RegPatternParameters { sRegPattern = "(\\b[A-Z0-9.-]+\\.org\\b)", bHide = true, bSendMail = true });
        lstIllegalParameters.Add(new RegPatternParameters { sRegPattern = "(\\b([ \\-\\,\\.\\(\\)\\+]?[ \\-\\,\\.\\(\\)\\+]?[ \\-\\,\\.\\(\\)\\+]?\\d{1,}){8,}\\b)", bHide = true, bSendMail = false });
        lstIllegalParameters.Add(new RegPatternParameters { sRegPattern = "(\\b( ||)((zero)|(one)|(two)|(three)|(four)|(five)|(six)|(seven)|(eight)|(nine))( ||)(\\.|\\,|-||)( ||)((zero)|(one)|(two)|(three)|(four)|(five)|(six)|(seven)|(eight)|(nine))( ||)(\\.|\\,|-||)( ||)((zero)|(one)|(two)|(three)|(four)|(five)|(six)|(seven)|(eight)|(nine))( ||)(\\.|\\,|-||)( ||)((zero)|(one)|(two)|(three)|(four)|(five)|(six)|(seven)|(eight)|(nine))( ||)(\\.|\\,|-||)( ||)((zero)|(one)|(two)|(three)|(four)|(five)|(six)|(seven)|(eight)|(nine))\\b)", bHide = true, bSendMail = true });
        lstIllegalParameters.Add(new RegPatternParameters { sRegPattern = "(\\b( ||)((nul)|(een)|(twee)|(drie)|(vier)|(vyf)|(ses)|(sewe)|(agt)|(nege))( ||)(\\.|\\,|-||)( ||)((nul)|(een)|(twee)|(drie)|(vier)|(vyf)|(ses)|(sewe)|(agt)|(nege))( ||)(\\.|\\,|-||)( ||)((nul)|(een)|(twee)|(drie)|(vier)|(vyf)|(ses)|(sewe)|(agt)|(nege))( ||)(\\.|\\,|-||)( ||)((nul)|(een)|(twee)|(drie)|(vier)|(vyf)|(ses)|(sewe)|(agt)|(nege))( ||)(\\.|\\,|-||)( ||)((nul)|(een)|(twee)|(drie)|(vier)|(vyf)|(ses)|(sewe)|(agt)|(nege))\\b)", bHide = true, bSendMail = true });
        lstIllegalParameters.Add(new RegPatternParameters { sRegPattern = "(\\bbooksure\\b)", bHide = true, bSendMail = false });
        lstIllegalParameters.Add(new RegPatternParameters { sRegPattern = "(\\bsearch\\b)", bHide = true, bSendMail = false });
        lstIllegalParameters.Add(new RegPatternParameters { sRegPattern = "(\\bcontact\\b)", bHide = true, bSendMail = false });
        lstIllegalParameters.Add(new RegPatternParameters { sRegPattern = "(\\bnumber\\b)", bHide = false, bSendMail = false });
        lstIllegalParameters.Add(new RegPatternParameters { sRegPattern = "(\\bcell\\b)", bHide = true, bSendMail = false });
        lstIllegalParameters.Add(new RegPatternParameters { sRegPattern = "(\\bmobile\\b)", bHide = true, bSendMail = false });
        lstIllegalParameters.Add(new RegPatternParameters { sRegPattern = "(\\bphone\\b)", bHide = true, bSendMail = false });
        lstIllegalParameters.Add(new RegPatternParameters { sRegPattern = "(\\bselfoonnommer\\b)", bHide = true, bSendMail = false });
        lstIllegalParameters.Add(new RegPatternParameters { sRegPattern = "(\\bkontak\\b)", bHide = true, bSendMail = false });
        lstIllegalParameters.Add(new RegPatternParameters { sRegPattern = "(\\bdirect email\\b)", bHide = true, bSendMail = false });
        lstIllegalParameters.Add(new RegPatternParameters { sRegPattern = "(\\bdirectly\\b)", bHide = true, bSendMail = false });
        lstIllegalParameters.Add(new RegPatternParameters { sRegPattern = "(\\bdirect\\b)", bHide = true, bSendMail = false });
        lstIllegalParameters.Add(new RegPatternParameters { sRegPattern = "(\\bcommission\\b)", bHide = true, bSendMail = false });
        lstIllegalParameters.Add(new RegPatternParameters { sRegPattern = "(\\bcomission\\b)", bHide = true, bSendMail = false });
        lstIllegalParameters.Add(new RegPatternParameters { sRegPattern = "(\\bcommision\\b)", bHide = true, bSendMail = false });
        lstIllegalParameters.Add(new RegPatternParameters { sRegPattern = "(\\bcomision\\b)", bHide = true, bSendMail = false });
        lstIllegalParameters.Add(new RegPatternParameters { sRegPattern = "(\\bemail\\b)", bHide = false, bSendMail = false });
        lstIllegalParameters.Add(new RegPatternParameters { sRegPattern = "(\\bwebmail\\b)", bHide = true, bSendMail = true });
        lstIllegalParameters.Add(new RegPatternParameters { sRegPattern = "(\\bskype\\b)", bHide = true, bSendMail = false });
        lstIllegalParameters.Add(new RegPatternParameters { sRegPattern = "(\\bdirectory enquiries\\b)", bHide = true, bSendMail = false });
        lstIllegalParameters.Add(new RegPatternParameters { sRegPattern = "(\\bfacebook\\b)", bHide = true, bSendMail = true });
        lstIllegalParameters.Add(new RegPatternParameters { sRegPattern = "(\\btwitter\\b)", bHide = true, bSendMail = true });
        lstIllegalParameters.Add(new RegPatternParameters { sRegPattern = "(\\bgesigboek\\b)", bHide = true, bSendMail = true });
        lstIllegalParameters.Add(new RegPatternParameters { sRegPattern = "(\\bgoogle\\b)", bHide = true, bSendMail = true });
        lstIllegalParameters.Add(new RegPatternParameters { sRegPattern = "(\\bgmail\\b)", bHide = true, bSendMail = true });
        lstIllegalParameters.Add(new RegPatternParameters { sRegPattern = "(\\byahoo\\b)", bHide = true, bSendMail = true });
        lstIllegalParameters.Add(new RegPatternParameters { sRegPattern = "(\\bcom\\b)", bHide = true, bSendMail = true });
        lstIllegalParameters.Add(new RegPatternParameters { sRegPattern = "(\\bco\\b)", bHide = true, bSendMail = true });
        lstIllegalParameters.Add(new RegPatternParameters { sRegPattern = "(\\bza\\b)", bHide = true, bSendMail = true });
        lstIllegalParameters.Add(new RegPatternParameters { sRegPattern = "(\\buk\\b)", bHide = true, bSendMail = true });
        lstIllegalParameters.Add(new RegPatternParameters { sRegPattern = "(\\bau\\b)", bHide = true, bSendMail = true });
        lstIllegalParameters.Add(new RegPatternParameters { sRegPattern = "(\\bwww\\b)", bHide = true, bSendMail = true });
        lstIllegalParameters.Add(new RegPatternParameters { sRegPattern = "(\\bfull stop\\b)", bHide = true, bSendMail = false });
        lstIllegalParameters.Add(new RegPatternParameters { sRegPattern = "(\\bsafarinow\\b)", bHide = true, bSendMail = true });
        lstIllegalParameters.Add(new RegPatternParameters { sRegPattern = "(\\bsafari now\\b)", bHide = true, bSendMail = true });
        lstIllegalParameters.Add(new RegPatternParameters { sRegPattern = "(\\bcapestay\\b)", bHide = true, bSendMail = true });
        lstIllegalParameters.Add(new RegPatternParameters { sRegPattern = "(\\bcape stay\\b)", bHide = true, bSendMail = true });
        lstIllegalParameters.Add(new RegPatternParameters { sRegPattern = "(\\bsavenues\\b)", bHide = true, bSendMail = true });
        lstIllegalParameters.Add(new RegPatternParameters { sRegPattern = "(\\bwheretostay\\b)", bHide = true, bSendMail = true });
        lstIllegalParameters.Add(new RegPatternParameters { sRegPattern = "(\\broomsforafrica\\b)", bHide = true, bSendMail = true });
        lstIllegalParameters.Add(new RegPatternParameters { sRegPattern = "(\\brooms for africa\\b)", bHide = true, bSendMail = true });
        lstIllegalParameters.Add(new RegPatternParameters { sRegPattern = "(\\bresafrica\\b)", bHide = true, bSendMail = true });
        lstIllegalParameters.Add(new RegPatternParameters { sRegPattern = "(\\btrip advisor\\b)", bHide = true, bSendMail = true });
        lstIllegalParameters.Add(new RegPatternParameters { sRegPattern = "(\\bfacebook\\b)", bHide = true, bSendMail = true });
        lstIllegalParameters.Add(new RegPatternParameters { sRegPattern = "(\\brennies travel\\b)", bHide = true, bSendMail = false });
        lstIllegalParameters.Add(new RegPatternParameters { sRegPattern = "(\\brennies\\b)", bHide = true, bSendMail = false });
        lstIllegalParameters.Add(new RegPatternParameters { sRegPattern = "(\\binternet\\b)", bHide = false, bSendMail = false });
        lstIllegalParameters.Add(new RegPatternParameters { sRegPattern = "(\\bweb site\\b)", bHide = false, bSendMail = false });
        lstIllegalParameters.Add(new RegPatternParameters { sRegPattern = "(\\bwebsite\\b)", bHide = false, bSendMail = false });
        lstIllegalParameters.Add(new RegPatternParameters { sRegPattern = "(\\bfees\\b)", bHide = false, bSendMail = false });
        lstIllegalParameters.Add(new RegPatternParameters { sRegPattern = "(\\bamadea travel\\b)", bHide = false, bSendMail = false });
        lstIllegalParameters.Add(new RegPatternParameters { sRegPattern = "(\\bbig five promotions\\b)", bHide = false, bSendMail = false });
        lstIllegalParameters.Add(new RegPatternParameters { sRegPattern = "(\\bselfoon\\b)", bHide = true, bSendMail = false });
        lstIllegalParameters.Add(new RegPatternParameters { sRegPattern = "(\\bepos\\b)", bHide = true, bSendMail = false });
        lstIllegalParameters.Add(new RegPatternParameters { sRegPattern = "(\\bdirek\\b)", bHide = true, bSendMail = false });
        lstIllegalParameters.Add(new RegPatternParameters { sRegPattern = "(\\bnavrae\\b)", bHide = true, bSendMail = false });
        lstIllegalParameters.Add(new RegPatternParameters { sRegPattern = "(\\bkommissie\\b)", bHide = true, bSendMail = false });
        lstIllegalParameters.Add(new RegPatternParameters { sRegPattern = "(\\bwebwerf\\b)", bHide = true, bSendMail = false });
        lstIllegalParameters.Add(new RegPatternParameters { sRegPattern = "(\\bweb werf\\b)", bHide = true, bSendMail = false });
        lstIllegalParameters.Add(new RegPatternParameters { sRegPattern = "(\\bfone\\b)", bHide = true, bSendMail = false });
        lstIllegalParameters.Add(new RegPatternParameters { sRegPattern = "(\\bnomber\\b)", bHide = true, bSendMail = false });
    }

    public class RegPatternParameters
    {
        public string sRegPattern { get; set; }
        public bool bHide { get; set; }
        public bool bSendMail { get; set; }
    }

    public static string ConvertSTDWords(string sText)
    {
        //var enquiry = new RegExp("\\b" + iResID.toString(10) + "\\b", "g");
        //TxT = TxT.replace(enquiry, "<ENQUIRY>");

        sText = Regex.Replace(sText, "\\b" + StdVariables.dtNow.Year.ToString() + "\\b", "<CYEAR>");
        sText = Regex.Replace(sText, "\\b" + (StdVariables.dtNow.Year - 1).ToString() + "\\b", "<PYEAR>");
        sText = Regex.Replace(sText, "\\b" + (StdVariables.dtNow.Year + 1).ToString() + "\\b", "<NYEAR>");
        sText = sText.Replace(@"www\.testing-out\.co\.za", "<WWWtestingOUT>");
        sText = sText.Replace(@"testing-out\.co\.za", "<testingOUT>");
        sText = sText.Replace(@"testingout\.co\.za", "<testingOUT>");
        sText = sText.Replace(@"testing-out\.com", "<testingOUT>");
        sText = sText.Replace(@"testingout\.com", "<testingOUT>");
        sText = sText.Replace(@"www\.testingOther-out\.co\.za", "<WWWtestingOtherOUT>");
        sText = sText.Replace(@"testingOther-out\.co\.za", "<testingOtherOUT>");
        sText = sText.Replace(@"testingOtherout\.co\.za", "<testingOtherOUT>");

        return sText;
    }

    public static string Filter(string sText)
    {
        sText = ConvertSTDWords(sText);

        foreach (RegPatternParameters regPattern in lstIllegalParameters)
        {
            Regex regCompiledPattern = new Regex(regPattern.sRegPattern);
            if (regPattern.bHide)
            {
                sText = regCompiledPattern.Replace(sText, " ");
            }
        }

        sText = ReturnSTDWords(sText);

        return sText;
    }

    public static string ReturnSTDWords(string sText)
    {
        //var enquiry = new RegExp(iResID.toString(10), "g");
        //sText = sText.Replace("<ENQUIRY>",iResID.toString(10));

        sText = sText.Replace("<CYEAR>", StdVariables.dtNow.Year.ToString());
        sText = sText.Replace("<PYEAR>", (StdVariables.dtNow.Year - 1).ToString());
        sText = sText.Replace("<NYEAR>", (StdVariables.dtNow.Year + 1).ToString());
        sText = sText.Replace("<WWWSLEEPIT>", @"www.testing-out.co.za");
        sText = sText.Replace("<testingOUT>", @"testing-out.co.za");
        sText = sText.Replace("<WWWtestingOtherOUT>", @"www.testingOther-out.co.za");
        sText = sText.Replace("<testingOtherOUT>", @"testingOther-out.co.za");

        return sText;
    }

}
 

约翰

C#论坛主持人
工作人员
加入
2011年4月23日
消息
1,160
地点
挪威
编程经验
10+
最佳 底部