예제 #1
0
        public void Check(int id, string val, List <SettingsModel> settings)
        {
            var apiKey            = settings.GetValue <string>(KnownSettings.GoogleApiKey);
            var checkSafeBrowsing = settings.GetValue <bool>(KnownSettings.EnsureSafeLinks);

            // check safebrowsing first to avoid double processing of links
            List <BrokenLinkModel> safeBrowsingResult = checkSafeBrowsing && apiKey.HasValue() ? _safeBrowsingService.Check(val, apiKey) : new List <BrokenLinkModel>();
            List <BrokenLinkModel> brokenLinksResult  = _linksService.Check(val, safeBrowsingResult);

            // then set Failed
            Failed = brokenLinksResult.Any() || safeBrowsingResult.Any();
            // and set Result
            Result = new Dictionary <string, List <BrokenLinkModel> >
            {
                { "safeBrowsing", safeBrowsingResult },
                { "brokenLinks", brokenLinksResult }
            };

            // finally, tally failed tests
            FailedCount  = safeBrowsingResult.Any() ? 1 : 0;
            FailedCount += brokenLinksResult.Any() ? 1 : 0;
        }