Slow list cycling killing page load

Ice

Member
Joined
Jan 25, 2013
Messages
14
Programming Experience
Beginner
Hi

I have an Illegalcharacter class.
In the class I define a list. Each list item has 3 parts.
A regular expression and 2 boolean values.

I then cycle through a message and apply the IllegalCharacter List to the message.
The problem is it's killing my web page. With it page load is between 17 and 23 secs.
Without it drop to millisecond page loads. I'm not sure how else to do this?

I use the class as follows

C#:
IllegalCharacters.IllegalCharRegPatterns();
sGuestMessage = IllegalCharacters.Filter(sGuestMessage);
sEstMessage = IllegalCharacters.Filter(sEstMessage);
sCancellationPolicy = IllegalCharacters.Filter(sPolicy);

My Illegalcharacter class is as follows

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._%+-]+@+[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,}){7,}\\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\.sleeping-out\.co\.za", "<WWWSLEEPINGOUT>");
        sText = sText.Replace(@"sleeping-out\.co\.za", "<SLEEPINGOUT>");
        sText = sText.Replace(@"sleepingout\.co\.za", "<SLEEPINGOUT>");
        sText = sText.Replace(@"sleeping-out\.com", "<SLEEPINGOUT>");
        sText = sText.Replace(@"sleepingout\.com", "<SLEEPINGOUT>");
        sText = sText.Replace(@"www\.dining-out\.co\.za", "<WWWDININGOUT>");
        sText = sText.Replace(@"dining-out\.co\.za", "<DININGOUT>");
        sText = sText.Replace(@"diningout\.co\.za", "<DININGOUT>");

        return sText;
    }

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

        foreach (RegPatternParameters regPattern in lstIllegalParameters)
        {
            Regex regCompiledPattern = new Regex(regPattern.sRegPattern, RegexOptions.Compiled);
            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("<WWWSLEEPINGOUT>", @"www.sleeping-out.co.za");
        sText = sText.Replace("<SLEEPINGOUT>", @"sleeping-out.co.za");
        sText = sText.Replace("<WWWDININGOUT>", @"www.dining-out.co.za");
        sText = sText.Replace("<DININGOUT>", @"dining-out.co.za");

        return sText;
    }
    /*public static string HighLightWords(string sText)
    {
        sText = ConvertSTDWords(sText);

        foreach (RegPatternParameters regPattern in lstIllegalParameters)
        {
            Regex regCompiledPattern = new Regex(regPattern.sRegPattern, RegexOptions.Compiled);
            if (regPattern.bHide)
            {
                sText = regCompiledPattern.Replace(sText, "<span style='color:red;background-color:yellow;'>$1</span>");
            }
            else
            {
                sText = regCompiledPattern.Replace(sText, "<span style='color:red;'>$1</span>");
            }
        }

        sText = ReturnSTDWords(sText);

        return sText;
    }*/

    /*public static int CharAlert(string sText)
    {
        int iCharAlert = 0;
        sText = ConvertSTDWords(sText);

        foreach (RegPatternParameters regPattern in lstIllegalParameters)
        {
            Regex regCompiledPattern = new Regex(regPattern.sRegPattern, RegexOptions.Compiled);

            if (regCompiledPattern.IsMatch(sText))
            {
                bool bHideMail = regPattern.bHide;
                bool bSendMail = regPattern.bSendMail;

                if ((iCharAlert < 3) && (bSendMail))
                {
                    iCharAlert = 3;
                }
                else if ((iCharAlert < 2) && (bHideMail) && (!bSendMail))
                {
                    iCharAlert = 2;
                }
                else if ((iCharAlert < 1) && (!bHideMail) && (!bSendMail))
                {
                    iCharAlert = 1;
                }
            }

            sText = regCompiledPattern.Replace(sText, " ");
        }

        sText = ReturnSTDWords(sText);
        return iCharAlert;
        
    }*/
}
 
Top Bottom