Exemplo n.º 1
0
        public SpamStatus CheckForSpam(SpamFilterPart part)
        {
            var settings = part.TypePartDefinition.Settings.GetModel <SpamFilterPartSettings>();

            // evaluate the text to submit to the spam filters
            var text = _tokenizer.Replace(settings.Pattern, new Dictionary <string, object> {
                { "Content", part.ContentItem }
            });

            var result = CheckForSpam(text, settings.Action);

            // trigger events and rules
            switch (result)
            {
            case SpamStatus.Spam:
                _spamEventHandler.SpamReported(part);
                _rulesManager.TriggerEvent("AntiSpam", "Spam", () => new Dictionary <string, object> {
                    { "Content", part.ContentItem }
                });
                break;

            case SpamStatus.Ham:
                _spamEventHandler.HamReported(part);
                _rulesManager.TriggerEvent("AntiSpam", "Ham", () => new Dictionary <string, object> {
                    { "Content", part.ContentItem }
                });
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            return(result);
        }
Exemplo n.º 2
0
        public SpamStatus CheckForSpam(CommentCheckContext context, SpamFilterAction action, IContent content)
        {
            if (string.IsNullOrWhiteSpace(context.CommentContent))
            {
                return(SpamStatus.Ham);
            }

            var spamFilters = GetSpamFilters().ToList();

            var result = SpamStatus.Ham;

            switch (action)
            {
            case SpamFilterAction.AllOrNothing:
                if (spamFilters.All(x => x.CheckForSpam(context) == SpamStatus.Spam))
                {
                    result = SpamStatus.Spam;
                }

                break;

            case SpamFilterAction.One:
                if (spamFilters.Any(x => x.CheckForSpam(context) == SpamStatus.Spam))
                {
                    result = SpamStatus.Spam;
                }

                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            // trigger events and rules
            switch (result)
            {
            case SpamStatus.Spam:
                _spamEventHandler.SpamReported(content);
                _rulesManager.TriggerEvent("AntiSpam", "Spam", () => new Dictionary <string, object> {
                    { "Content", content }
                });
                break;

            case SpamStatus.Ham:
                _spamEventHandler.HamReported(content);
                _rulesManager.TriggerEvent("AntiSpam", "Ham", () => new Dictionary <string, object> {
                    { "Content", content }
                });
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            return(result);
        }