Ejemplo n.º 1
0
 /// <summary>
 /// Sets the localized error message in profanity check result object
 /// </summary>
 /// <param name="result"></param>
 /// <returns></returns>
 public ProfanityCheckResult LocalizeResult(ProfanityCheckResult result, string culture)
 {
     if (result == null)
     {
         throw new Exception("Null result passed to ProfanityService.LocalizeResult");
     }
     if (culture == null)
     {
         result.ErrorMessage = result.DefaultErrorMessage;
         return(result);
     }
     if (result.HasBadCharacters)
     {
         // leave variable assignment in case we need to step through.
         var badCharacters = _resourcesService.GetString(culture, Lines.ERROR_BAD_CHARACTERS);
         result.ErrorMessage = badCharacters;
     }
     if (result.ProfanityWord != null)
     {
         // leave variable assignment in case we need to step through.
         var errorProfanity = _resourcesService.GetString(culture, Lines.ERROR_PROFANITY);
         result.ErrorMessage = (result.HasBadCharacters ? " " : string.Empty) + errorProfanity + ": " + result.ProfanityWord;
     }
     return(result);
 }
Ejemplo n.º 2
0
        public ProfanityCheckResult CheckProfanity(string input, string culture)
        {
            var result = new ProfanityCheckResult();

            // Check blank first.
            if (string.IsNullOrEmpty(input) || string.IsNullOrWhiteSpace(input))
            {
                result.NoData = true; return(result);
            }
            // Check funny characters
            result.HasBadCharacters = !ProfanityFilter.AllCharactersAllowed(input);
            // Having bad character is enough to not touch cache
            if (result.HasBadCharacters)
            {
                return(LocalizeResult(result, culture));
            }

            // Theoretically this shold never throw exception unless we got some timeout on initialization or something strange.
            var cachedData = GetCachedData();

            result.ProfanityWord = ProfanityFilter.GetProfanity(input, cachedData.Items);

            return(result.HasIssues ? LocalizeResult(result, culture) : result);
        }