<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using SIM.Sitecore9Installer.Tasks;

namespace SIM.Sitecore9Installer.Validation.Validators
{
  public class HostAvaiableValidator : BaseValidator
  {
    public override string SuccessMessage => "Host response is 200";

    protected override IEnumerable<ValidationResult> GetErrorsForTask(Tasks.Task task, IEnumerable<InstallParam> paramsToValidate)
    {
      foreach (InstallParam p in paramsToValidate)
      {
        WebException error = null;
        HttpWebResponse resp = null;
        try
        {
          resp = this.GetResponse(p.Value);
        }
        catch(WebException ex)
        {
          error = ex;
        }

        if (error != null)
        {
          yield return new ValidationResult(ValidatorState.Error, $"Unable to connect to host {p.Value}", error);
          yield break;
        }

        if (resp.StatusCode != HttpStatusCode.OK)
        {
          yield return new ValidationResult(ValidatorState.Error, $"Host {p.Value} did not return 200.",null);
        }
      }
    }

    protected internal virtual HttpWebResponse GetResponse(string uri)
    {
      HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(uri);
      return (HttpWebResponse)myReq.GetResponse();
    }<commit_msg>#613 Update validation messages in HostAvaiableValidator<commit_after>﻿using System.Collections.Generic;
using System.Net;

namespace SIM.Sitecore9Installer.Validation.Validators
{
  public class HostAvaiableValidator : BaseValidator
  {
    public override string SuccessMessage => null;

    protected override IEnumerable<ValidationResult> GetErrorsForTask(Tasks.Task task, IEnumerable<InstallParam> paramsToValidate)
    {
      foreach (InstallParam p in paramsToValidate)
      {
        WebException error = null;
        HttpWebResponse resp = null;
        try
        {
          resp = this.GetResponse(p.Value);
        }
        catch(WebException ex)
        {
          error = ex;
        }

        if (error != null)
        {
          yield return new ValidationResult(ValidatorState.Error, $"Unable to connect to the following host:\n{p.Value}", error);
          yield break;
        }

        if (resp.StatusCode != HttpStatusCode.OK)
        {
          yield return new ValidationResult(ValidatorState.Error, $"The following host did not return status code 200:\n{p.Value}",null);
        }
        else
        {
          yield return new ValidationResult(ValidatorState.Success, $"The following host returned status code 200:\n{p.Value}", null);
        }
      }
    }

    protected internal virtual HttpWebResponse GetResponse(string uri)
    {
      HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(uri);
      return (HttpWebResponse)myReq.GetResponse();
    }
{'fraction_non_alphanumeric': 0.08558558558558559, 'fraction_numerical': 0.006237006237006237, 'mean_word_length': 2.6823979591836733, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7489529', 'n_tokens_mistral': 778, 'n_tokens_neox': 756, 'n_words': 195}