Example #1
0
        private async Task <string> ApplyRule(string pageAddress)
        {
            // ToDo: implement handling of a case when the rule is NULL.
            var rule = _ruleRepository.GetRule(pageAddress);

            var pageContent = await _agent.GetContent($"http://{pageAddress}");

            return(ContentFilter.Apply(pageContent, rule));
        }
        public async Task <IReadOnlyCollection <SpellingError> > Check(string text)
        {
            //используем сервис яндекса для поиска орфографических ошибок в тексте
            //сервис возвращает список слов, в которых допущены ошибки
            const string spellCheckServiceAddress = "http://speller.yandex.net/services/spellservice.json/checkText";

            var json = await _agent.GetContent($"{spellCheckServiceAddress}?text={WebUtility.UrlEncode(text)}");

            return(JsonConvert.DeserializeObject <IReadOnlyCollection <SpellingError> >(json));
        }
Example #3
0
        public async Task <IActionResult> Test(string page, string rule = null)
        {
            if (string.IsNullOrWhiteSpace(page))
            {
                return(BadRequest($"The '{nameof(page)}' parameter is mandatory."));
            }

            if (string.IsNullOrWhiteSpace(rule))
            {
                rule = _ruleRepository.GetRule(page);

                if (rule == null)
                {
                    return(NotFound($"Rule for site '{page}' not found."));
                }
            }

            var pageContent = await _agent.GetContent($"http://{page}");

            var textResult = ContentFilter.Apply(pageContent, rule);

            return(new OkObjectResult(textResult));
        }