public override ValidationResults <SourceValidationOccurance> ValidateData(ProcessedDataPackage package) { ValidationResults <SourceValidationOccurance> results = new ValidationResults <SourceValidationOccurance>(); results.Score = -1; PageSourceData data = package.GetData <PageSourceData>(); if (data == null || String.IsNullOrEmpty(data.PageSource)) { return(results); } MatchCollection mc = regex.Matches(data.PageSource); int i = 0; foreach (Match m in mc) { String ma = m.ToString(); results.Add(new SourceValidationOccurance(data, m.Index, m.Length)); i++; } if (results.Count == 0) { results.Score = 100; } else { results.Score = 0; } return(results); }
public override ValidationResults <SourceValidationOccurance> ValidateData(ProcessedDataPackage package) { ValidationResults <SourceValidationOccurance> results = new ValidationResults <SourceValidationOccurance>(); results.Score = -1; PageSourceData data = package.GetData <PageSourceData>(); if (data == null || String.IsNullOrEmpty(data.PageSource)) { return(results); } using (StringReader reader = new StringReader(data.PageSource)) { XmlReaderSettings settings = new XmlReaderSettings(); settings.ProhibitDtd = false; settings.ValidationType = ValidationType.DTD; settings.ValidationEventHandler += new System.Xml.Schema.ValidationEventHandler( delegate(object sender, System.Xml.Schema.ValidationEventArgs e) { int position = GetIndex(data.PageSource, e.Exception.LineNumber, e.Exception.LinePosition); int length = data.PageSource.Length - position > DISPLAYBUFFER ? DISPLAYBUFFER : data.PageSource.Length - position; SourceValidationOccurance p = new SourceValidationOccurance(data, position, length); p.Comment = e.Exception.Message; results.Add(p); }); settings.XmlResolver = new XHTMLXmlResolver(); using (XmlReader xmlReader = XmlReader.Create(reader, settings)) { try { while (xmlReader.Read()) { } } catch (System.Xml.XmlException ex) { int position = GetIndex(data.PageSource, ex.LineNumber, ex.LinePosition); int length = data.PageSource.Length - position > DISPLAYBUFFER ? DISPLAYBUFFER : data.PageSource.Length - position; SourceValidationOccurance p = new SourceValidationOccurance(data, position, length); p.Comment = ex.Message; results.Add(p); } catch (Exception ex) { Console.WriteLine(ex); } } } results.Score = (results.Count == 0 ? 100 : 0); return(results); }
public override ValidationResults <SourceValidationOccurance> ValidateData(ProcessedDataPackage package) { ValidationResults <SourceValidationOccurance> results = new ValidationResults <SourceValidationOccurance>(); results.Score = -1; PageSourceData data = package.GetData <PageSourceData>(); if (data == null || String.IsNullOrEmpty(data.PageSource)) { return(results); } int headIndex = 0; results.Score = 100; Match headMatch = head.Match(data.PageSource); if (headMatch != null && headMatch.Success) { headIndex = headMatch.Index; } MatchCollection mc = linkinsidesideofhead.Matches(data.PageSource); int i = 0; foreach (Match m in mc) { if (m.Index < headIndex) { String ma = m.ToString(); results.Add(new SourceValidationOccurance(data, m.Index, m.Length)); i++; } } results.ResultsExplenation = String.Format(message, results.Count); int c = 0; for (int xx = 0; xx < grades.Length; xx++) { if (grades[xx] < results.Count) { c++; } else { break; } } results.Score -= c * 10; return(results); }
public override ValidationResults <String> ValidateData(ProcessedDataPackage package) { ValidationResults <String> results = new ValidationResults <String>(); results.Score = -1; DownloadData data = package.GetData <DownloadData>(); if (data == null || data.Count == 0) { return(results); } results.Score = 100; foreach (DownloadState ds in data) { try{ Uri u = new Uri(ds.URL); if (results.Contains(u.Host.Trim().ToLower()) == false) { results.Add(u.Host); } } catch { } } results.ResultsExplenation = message; int c = 0; for (int xx = 0; xx < grades.Length; xx++) { if (grades[xx] < results.Count) { c++; } else { break; } } results.Score -= c * 10; return(results); }
public override ValidationResults <SourceValidationOccurance> ValidateData(ProcessedDataPackage package) { ValidationResults <SourceValidationOccurance> results = new ValidationResults <SourceValidationOccurance>(); results.Score = -1; PageSourceData data = package.GetData <PageSourceData>(); if (data == null || String.IsNullOrEmpty(data.PageSource)) { return(results); } String buffer = data.PageSource; var res = Regex.Match(buffer, "(?<=__VIEWSTATE\" value=\")(?<val>.*?)(?=\")").Groups["val"]; if (res.Success == false) { results.Score = 100; return(results); } SourceValidationOccurance occurrence = new SourceValidationOccurance(data, res.Index, res.Length); results.Add(occurrence); if (res.Length > errorThreshold) { results.Score = 45; } else if (res.Length > warningThreshold) { results.Score = 65; } else if (res.Length > barelyPassedThreshold) { results.Score = 85; } else { results.Score = 100; } return(results); }
public override ValidationResults <DownloadStateOccurance> ValidateData(ProcessedDataPackage package) { ValidationResults <DownloadStateOccurance> results = new ValidationResults <DownloadStateOccurance>(); results.Score = -1; DownloadData data = package.GetData <DownloadData>(); if (data == null || data.Count == 0) { return(results); } results.Score = 100; foreach (DownloadState ds in data) { if (regex.IsMatch(ds.URL) == false) { results.Add(new DownloadStateOccurance(ds)); } } results.Score -= Math.Min(results.Count, 4) * 10; if (results.Count > 0) { if (results.Count == 1) { results.ResultsExplenation = message_single; } else { results.ResultsExplenation = String.Format(message_more, results.Count); } } return(results); }
public override ValidationResults <DownloadStateOccurance> ValidateData(ProcessedDataPackage package) { ValidationResults <DownloadStateOccurance> results = new ValidationResults <DownloadStateOccurance>(); results.Score = -1; DownloadData data = package.GetData <DownloadData>(); ResponseBodyDumpFilesInfo rbdfi = new ResponseBodyDumpFilesInfo(package); if (data == null || data.Count == 0) { return(results); } results.Score = 100; String bodyBuffer = null; StreamReader sr = null; MatchCollection m = null; int count = 0; Stream stream = null; foreach (DownloadState ds in data) { if (ds.URLType != URLType.CSS) { continue; } try { stream = rbdfi.Open(FileAccess.Read, ds.FileGUID); if (stream != null) { sr = new StreamReader(stream); if (sr != null) { bodyBuffer = sr.ReadToEnd(); sr.Close(); sr.Dispose(); m = regex.Matches(bodyBuffer); if (m.Count > 0) { count += m.Count; results.Add(new DownloadStateOccurance(ds)); } } } } catch { } } results.ResultsExplenation = String.Format(message, count); int c = 0; for (int xx = 0; xx < grades.Length; xx++) { if (grades[xx] < count) { c++; } else { break; } } results.Score -= c * 10; return(results); }
public override ValidationResults <DownloadStateOccurance> ValidateData(ProcessedDataPackage package) { ValidationResults <DownloadStateOccurance> results = new ValidationResults <DownloadStateOccurance>(); results.Score = -1; DownloadData data = package.GetData <DownloadData>(); if (data == null || data.Count == 0) { return(results); } results.Score = 100; List <DownloadState> list = GetAllDownloadsFor(URLType.JS, data); String expl = ""; if (list.Count > 0) { foreach (DownloadState ds in list) { DownloadStateOccurance downloadDataValidatorOccurance = new DownloadStateOccurance(ds); results.Add(downloadDataValidatorOccurance); } expl += String.Format(js_message, list.Count); int m = 0; for (int i = 0; i < js_grades.Length; i++) { if (js_grades[i] < list.Count) { m++; } else { break; } } results.Score -= m * 10; } list = GetAllDownloadsFor(URLType.CSS, data); if (list.Count > 0) { foreach (DownloadState ds in list) { DownloadStateOccurance downloadDataValidatorOccurance = new DownloadStateOccurance(ds); results.Add(downloadDataValidatorOccurance); } expl += String.Format(css_message, list.Count); int m = 0; for (int i = 0; i < css_grades.Length; i++) { if (css_grades[i] < list.Count) { m++; } else { break; } } results.Score -= m * 10; } results.ResultsExplenation = expl; return(results); }
public override ValidationResults <DownloadStateOccurance> ValidateData(ProcessedDataPackage package) { ValidationResults <DownloadStateOccurance> results = new ValidationResults <DownloadStateOccurance>(); results.Score = -1; DownloadData data = package.GetData <DownloadData>(); ResponseHeaderDumpFilesInfo rbdfi = new ResponseHeaderDumpFilesInfo(package); if (data == null || data.Count == 0) { return(results); } results.Score = 100; String headerBuffer = null; StreamReader sr = null; DateTime now = DateTime.Now.AddDays(2); Stream stream = null; foreach (DownloadState ds in data) { try { stream = rbdfi.Open(FileAccess.Read, ds.FileGUID); if (stream != null) { sr = new StreamReader(stream); if (sr != null) { headerBuffer = sr.ReadToEnd(); sr.Close(); sr.Dispose(); if (regexContentType.IsMatch(headerBuffer) == false) { continue; } if (regexContentEncoding.IsMatch(headerBuffer) == false) { results.Add(new DownloadStateOccurance(ds)); } } } } catch { } } results.Score -= Math.Min(results.Count, 4) * 10; if (results.Count > 0) { if (results.Count == 1) { results.ResultsExplenation = message_single; } else { results.ResultsExplenation = String.Format(message_more, results.Count); } } return(results); }
public override ValidationResults <DownloadStateOccurance> ValidateData(ProcessedDataPackage package) { ValidationResults <DownloadStateOccurance> results = new ValidationResults <DownloadStateOccurance>(); results.Score = -1; DownloadData data = package.GetData <DownloadData>(); ResponseHeaderDumpFilesInfo rbdfi = new ResponseHeaderDumpFilesInfo(package); if (data == null || data.Count == 0) { return(results); } results.Score = 100; String headerBuffer = null; StreamReader sr = null; Match m = null; DateTime now = DateTime.Now.AddDays(2); Stream stream = null; foreach (DownloadState ds in data) { try { stream = rbdfi.Open(FileAccess.Read, ds.FileGUID); if (stream != null) { sr = new StreamReader(stream); if (sr != null) { headerBuffer = sr.ReadToEnd(); sr.Close(); sr.Dispose(); m = regex.Match(headerBuffer); if (m.Success == false || m.Groups.Count <= 1 || String.IsNullOrEmpty(m.Groups[1].ToString())) { DownloadStateOccurance dso = new DownloadStateOccurance(ds); dso.Comment = "(no expires)"; results.Add(dso); } else { try { if (m.Groups[1].ToString() == "-1") { DownloadStateOccurance dso = new DownloadStateOccurance(ds); dso.Comment = "(-1)"; results.Add(dso); } else { DateTime dt = DateTime.Parse(m.Groups[1].ToString()); if (dt < now) { DownloadStateOccurance dso = new DownloadStateOccurance(ds); dso.Comment = String.Format("({0})", dt.Date); results.Add(dso); } } } catch { } } } } } catch { } } results.Score -= Math.Min(results.Count, 4) * 10; if (results.Count > 0) { if (results.Count == 1) { results.ResultsExplenation = message_single; } else { results.ResultsExplenation = String.Format(message_more, results.Count); } } return(results); }