Example #1
0
    /// <summary>
    /// Checks the declared custom string for presence of the 'testbadword' bad word created by the first code example on this page.
    /// Expects the CreateBadWord method to be run first.
    /// </summary>
    private bool CheckSingleBadWord()
    {
        // Prepare parameters for selection of the checked bad word
        string where = "[WordExpression] = 'testbadword' ";

        // Get the data
        DataSet words = BadWordInfoProvider.GetBadWords(where, null);

        if (!DataHelper.DataSourceIsEmpty(words))
        {
            // Get DataRow with bad word
            DataRow wordDr = words.Tables[0].Rows[0];

            // Get BadWordInfo object
            BadWordInfo badWord = new BadWordInfo(wordDr);

            // String to be checked for presence of the bad word
            string text = "This is a string containing the sample testbadword, which can be created by the first code example on this page.";

            // Hashtable that will contain found bad words
            Hashtable foundWords = new Hashtable();

            // Modify the string according to found bad words and return which action should be performed
            BadWordActionEnum action = BadWordInfoProvider.CheckBadWord(badWord, null, null, ref text, foundWords, 0);

            if (foundWords.Count != 0)
            {
                switch (action)
                {
                case BadWordActionEnum.Deny:
                    // Some additional actions performed here ...
                    break;

                case BadWordActionEnum.RequestModeration:
                    // Some additional actions performed here ...
                    break;

                case BadWordActionEnum.Remove:
                    // Some additional actions performed here ...
                    break;

                case BadWordActionEnum.Replace:
                    // Some additional actions performed here ...
                    break;

                case BadWordActionEnum.ReportAbuse:
                    // Some additional actions performed here ...
                    break;

                case BadWordActionEnum.None:
                    // Some additional actions performed here ...
                    break;
                }

                return(true);
            }

            apiCheckSingleBadWord.ErrorMessage = "Bad word 'testbadword' is not present in the checked string.";
            return(false);
        }

        return(false);
    }