Ejemplo n.º 1
0
        private HtmlValidatorResult ParseResult(NameValueCollection headers)
        {
            string status = string.Empty;
            int errors = 0;
            int warnings = 0;
            int recursion = 0;

            status = headers["X-W3C-Validator-Status"];
            int.TryParse(headers["X-W3C-Validator-Errors"], out errors);
            int.TryParse(headers["X-W3C-Validator-Warnings"], out warnings);
            int.TryParse(headers["X-W3C-Validator-Recursion"], out recursion);

            HtmlValidatorResult result = new HtmlValidatorResult(status, errors, warnings, recursion);
            return result;
        }
Ejemplo n.º 2
0
        private HtmlValidatorResult FixBrokenHeaders(Stream output, OutputFormat outputFormat, string input, InputFormat inputFormat, IHtmlValidatorSettings settings, string validatorAddress)
        {
            Stream checkStream = mStreamFactory.GetMemoryStream();
            if (outputFormat != OutputFormat.Soap12 || output.CanRead == false)
            {
                if (IsDefaultValidatorAddress(validatorAddress))
                {
                    System.Threading.Thread.Sleep(1000);
                }

                // Headers failed, so we will get the report again in Soap 1.2 format in
                // an in memory stream
                string checkData = GetFormData(input, inputFormat, OutputFormat.Soap12, settings);

                // This time, ignore headers.
                if (inputFormat == InputFormat.Fragment)
                {
                    this.mHttpClient.Post(checkStream, validatorAddress, checkData);
                }
                else
                {
                    this.mHttpClient.Get(checkStream, validatorAddress + "?" + checkData);
                }
            }
            else
            {
                output.Position = 0;
                output.CopyTo(checkStream);
            }

            checkStream.Position = 0;
            var response = mSoapResponseParser.ParseResponse(checkStream);

            var errors = response.Errors.Count();
            var warnings = response.Warnings.Count();
            var status = response.Validity ? "Valid" : "Invalid";
            var recursion = 1;

            var result = new HtmlValidatorResult(status, errors, warnings, recursion);
            return result;
        }