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 Page(ProcessedDataPackage pacakge) { RenderData r = (RenderData)pacakge[typeof(RenderData)]; ID = "page_" + pacakge.CollectionID; Title = "MSFast Collection #" + pacakge.CollectionID; StartedDateTime = Converter.EpochToDateTime(pacakge.CollectionStartTime); PageTimings = new PageTimings(pacakge); PageSourceData sd = (PageSourceData)pacakge[typeof(PageSourceData)]; this.PageSourceData = Convert.ToBase64String(Encoding.UTF8.GetBytes(sd.PageSource)); }
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 SourceValidationOccurance(PageSourceData sourceData, int startIndex, int length) : base(sourceData, startIndex, length) { }
public void OnData(string p) { try { if (package == null) { return; } Match match = null; if (score == -1 && (match = RESULTS.Match(p)) != null && match.Success) { this.score = int.Parse(match.Groups[1].Value); return; } if (score != -1 && results == null) { if (SOURCE.IsMatch(p)) { results = new ValidationResults <SourceValidationOccurance>(); } else if (DOWNLOAD.IsMatch(p)) { results = new ValidationResults <DownloadStateOccurance>(); } if (results != null) { results.Score = this.score; } } if (results is ValidationResults <DownloadStateOccurance> && package.ContainsKey(typeof(DownloadData)) && (match = DOWNLOAD.Match(p)) != null && match.Success) { String url = match.Groups[1].Value; DownloadData dd = package[typeof(DownloadData)] as DownloadData; DownloadState ds = null; if (dd != null) { foreach (DownloadState d in dd) { if (String.IsNullOrEmpty(d.URL) == false && d.URL.Equals(url)) { ds = d; break; } } } if (ds != null) { results.Add(new DownloadStateOccurance(ds)); } } else if (results is ValidationResults <SourceValidationOccurance> && (package.ContainsKey(typeof(BrokenSourceData)) || package.ContainsKey(typeof(PageSourceData))) && (match = SOURCE.Match(p)) != null && match.Success) { PageSourceData psd = null; if (package.ContainsKey(typeof(BrokenSourceData))) { psd = (PageSourceData)package[typeof(BrokenSourceData)]; } if (psd == null && package.ContainsKey(typeof(PageSourceData))) { psd = (PageSourceData)package[typeof(PageSourceData)]; } results.Add( new SourceValidationOccurance(psd, int.Parse(match.Groups[1].Value), int.Parse(match.Groups[2].Value)) ); } } catch (Exception e) { if (log.IsErrorEnabled) { log.Error("Error parsing validator output", e); } } }