/// <summary> /// Text diffs the first line /// </summary> /// <param name="result"></param> /// <param name="firstText"></param> /// <param name="secondText"></param> /// <param name="firstBasePos">The starting position for the first text relative to the entire request/response text</param> /// <param name="secondBasePos">The starting position for the second text relative to the entire request/response text</param> private RequestsDifferResult DiffFirstLine(RequestsDifferResult result, string firstText, string secondText, int firstBasePos, int secondBasePos) { //extract the request lines and diff them int nlIndex = firstText.IndexOf('\n'); string firstLine = String.Empty; if (nlIndex > -1) { firstLine = firstText.Substring(0, nlIndex); } nlIndex = secondText.IndexOf('\n'); string secondLine = String.Empty; if (nlIndex > -1) { secondLine = secondText.Substring(0, nlIndex); } //do the diff WordsDiffer lineDiffer = new WordsDiffer(); lineDiffer.AddTask(firstLine, firstBasePos); lineDiffer.AddTask(secondLine, secondBasePos); lineDiffer.DoDiff(); result = AppendDiffs(result, lineDiffer); return(result); }
/// <summary> /// Check if the values match and outputs a set of granular differences /// </summary> /// <param name="diffObject"></param> /// <param name="diffsForSelf"></param> /// <param name="diffsForArgument"></param> /// <returns></returns> public bool ValueMatches(IDiffObject diffObject, out IDiffObjectsCollection diffsForSelf, out IDiffObjectsCollection diffsForArgument, out IDiffObjectsCollection commonElements) { HeaderDiffObject otherObject = diffObject as HeaderDiffObject; diffsForSelf = null; diffsForArgument = null; commonElements = null; bool matches = false; if (otherObject != null) { matches = _headerLineHash == otherObject.HeaderLineHash; //if the values are different but the headers are the same if (!matches && String.Compare(_name, otherObject.Name, true) == 0) { WordsDiffer valuesDiffer = new WordsDiffer(); valuesDiffer.AddTask(_values); valuesDiffer.AddTask(otherObject.Values); valuesDiffer.Properties.Sorted = true; valuesDiffer.Properties.CaseInSensitiveSort = true; double diffRatio = valuesDiffer.DoDiff(0, 1); diffsForSelf = valuesDiffer.GetResultingDifferences(0); diffsForArgument = valuesDiffer.GetResultingDifferences(1); commonElements = valuesDiffer.GetResultingCommonElements(0); matches = diffRatio >= _valuesMinSimilarity; } } return(matches); }
/// <summary> /// Diffs the POST data /// </summary> /// <param name="firstRequest"></param> /// <param name="secondRequest"></param> /// <returns></returns> private RequestsDifferResult DiffPostData(RequestsDifferResult result, string firstRequest, string secondRequest) { int firstPostStart = firstRequest.IndexOf("\r\n\r\n"); if (firstPostStart == -1) { //try without \r firstPostStart = firstRequest.IndexOf("\n\n"); if (firstPostStart != -1) { firstPostStart += 2; } } else { firstPostStart += 4; } int secondPostStart = secondRequest.IndexOf("\r\n\r\n"); if (secondPostStart == -1) { //try without \r secondPostStart = secondRequest.IndexOf("\n\n"); if (secondPostStart != -1) { secondPostStart += 2; } } else { secondPostStart += 4; } string firstPost = String.Empty; string secondPost = String.Empty; //construct the post data if (firstPostStart > -1) { firstPost = firstRequest.Substring(firstPostStart, firstRequest.Length - firstPostStart); } if (secondPostStart > -1) { secondPost = secondRequest.Substring(secondPostStart, secondRequest.Length - secondPostStart); } //create a word differ WordsDiffer wordsDiffer = new WordsDiffer(); wordsDiffer.Properties.Sorted = true; wordsDiffer.Properties.CaseInSensitiveSort = true; wordsDiffer.AddTask(firstPost, firstPostStart); wordsDiffer.AddTask(secondPost, secondPostStart); wordsDiffer.DoDiff(); result = AppendDiffs(result, wordsDiffer); return(result); }