示例#1
0
        public SpamStatus CheckForSpam(string text, SpamFilterAction action)
        {
            var spamFilters = GetSpamFilters().ToList();

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

                return(SpamStatus.Ham);

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

                return(SpamStatus.Ham);

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
示例#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);
        }
示例#3
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;
        }
示例#4
0
        public SpamStatus CheckForSpam(string text, SpamFilterAction action) {
            var spamFilters = GetSpamFilters().ToList();

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

                    return SpamStatus.Ham;
                case SpamFilterAction.One:
                    if (spamFilters.Any(x => x.CheckForSpam(text) == SpamStatus.Spam)) {
                        return SpamStatus.Spam;
                    }

                    return SpamStatus.Ham;
                default:
                    throw new ArgumentOutOfRangeException();
            }
        }