public async Task <ICollection <string> > GetErrorsByPageAsync(string page, CancellationToken cancellationToken) { var textErrors = new List <string>(DefaultTextErrorsArrSize); try { var site = new Uri($"{ProtocolConstants.DefaultHttpProtocol}{page}").Host; var htmlDocument = await _httpClientProvider.GetHtmlDocumentByPageAsync(page, cancellationToken); var xPath = _repository.GetAll() .Where(x => x.Site == site) .Select(x => x.Principle) .FirstOrDefault(); if (xPath == null) { return(textErrors); } var text = htmlDocument.DocumentNode .SelectNodes(xPath) .Aggregate(string.Empty, (current, node) => $"{current}{Environment.NewLine}{node.InnerText}"); var errors = await _spellServiceProvider.GetErrorsByTextAsync(text, DefaultTextErrorsArrSize, cancellationToken); textErrors.AddRange(errors.Select(x => x.Word)); } catch (Exception) {} return(textErrors); }
public async Task <GetRuleTestModel> TestAsync(RuleTestModel model, CancellationToken cancellationToken) { var htmlDocument = await _httpClient.GetHtmlDocumentByPageAsync(model.Page, cancellationToken); var rule = model.Rule; var existingRule = _repository.GetAll() .Where(x => x.Site == model.Page) .Select(x => x.Principle) .FirstOrDefault(); var innerText = string.Empty; var result = new GetRuleTestModel { Text = innerText }; if (string.IsNullOrEmpty(rule) && string.IsNullOrEmpty(existingRule)) { return(result); } var temp = htmlDocument.DocumentNode .SelectNodes(rule ?? existingRule); /*var kek*/ innerText = htmlDocument.DocumentNode .SelectNodes(rule ?? existingRule) .Aggregate(innerText, (current, node) => $"{current}{Environment.NewLine}{node?.InnerText}"); result.Text = innerText; return(result); }