Esempio n. 1
0
        /// <summary>
        /// The default constructor.
        /// </summary>
        /// <param name="piranha">The Piranha API</param>
        /// <param name="config">The configuration to use</param>
        /// <param name="httpClientFactory">The factory to use to get http client for requests</param>
        /// <param name="loggerFactory">The factory to use to get a logger</param>
        protected SpamDetectorService(IApi piranha, SpamDetectorConfigService config, IHttpClientFactory httpClientFactory, ILoggerFactory loggerFactory)
        {
            Piranha           = piranha;
            HttpClientFactory = httpClientFactory;
            ConfigModel       = config.Get();

            if (loggerFactory != null)
            {
                Logger = loggerFactory.CreateLogger(this.GetType().FullName);
            }

            if (!ConfigModel.Enabled)
            {
                Logger.LogWarning("Module disabled by configuration: comments will not be reviewed/changed");
            }

            if (string.IsNullOrEmpty(ConfigModel.SpamApiUrl))
            {
                const string msg = "Module not configured properly, mandatory value missing: SpamApiUrl";
                Logger.LogError(msg);
                throw new InvalidOperationException(msg);
            }

            if (string.IsNullOrEmpty(ConfigModel.SiteUrl))
            {
                Logger.LogWarning("Option SiteUrl is missing: results may be wrong");
            }

            if (ConfigModel.IsTest)
            {
                Logger.LogWarning("Option IsTest is true: no live requests will be made");
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Default constructor.
 /// </summary>
 /// <param name="config">Config service</param>
 /// <param name="localizer">Localization service</param>
 public SpamDetectorConfigApiController(SpamDetectorConfigService config, SpamDetectorLocalizer localizer)
 {
     _config    = config;
     _localizer = localizer;
 }
 /// <inheritdoc cref="SpamDetectorService" select="param"/>
 /// <summary>
 /// The Akismet anti-spam service implementation of the <see cref="SpamDetectorService"/> core functionality.
 /// Composes a request to Akismet with as much relevant information as possible provided and
 /// translates a response from Akismet to a review result in form of a <see cref="CommentReview"/>.
 /// </summary>
 public AkismetSpamDetectorService(IApi piranha, SpamDetectorConfigService config, IHttpClientFactory httpClientFactory, ILoggerFactory loggerFactory) : base(piranha, config, httpClientFactory, loggerFactory)
 {
     // Intentionally left empty
 }