// TODO this method is currently recursive !!! - consider refuse recursion in order not to get StackOverflow private static Diffs getParent(string parentPath, IDictionary <string, Diffs> nodePaths) { Diffs parent = null; if (nodePaths.ContainsKey(parentPath)) { parent = nodePaths[parentPath]; } if (parent == null) { parent = new Diffs() { ChildDiffs = new List <Diffs>(), FieldName = parentPath }; nodePaths[parentPath] = parent; String parentsParentPath = string.Empty; int index = parentPath.LastIndexOf("."); if (index == -1) { nodePaths[parentsParentPath].ChildDiffs.Add(parent); } else { parentsParentPath = parentPath.Substring(0, index); Diffs parentsParent = getParent(parentsParentPath, nodePaths); parentsParent.ChildDiffs.Add(parent); } } return(parent); }
public bool HasComments() { if (!string.IsNullOrWhiteSpace(GeneralComments)) { return(true); } var hasFileComment = Diffs.Any(r => !string.IsNullOrWhiteSpace(r.Comments)); return(hasFileComment); }
private void UpdateDiffListOnCompareResultRecieved(CompareResult compareResult) { Diffs.Clear(); foreach (var file in compareResult.Files) { Diffs.Add(new CommitFileVm(file)); var commitFile = Diffs.Last(); _backgroundTaskRunner.AddToQueue(async() => await FetchDiffContent(new CommitFile(commitFile.GitHubCommitFile))); } }
internal Patch Copy() { var patchCopy = new Patch ( Start1, Length1, Start2, Length2, Diffs.Select(d => d.Copy()).ToList() ); return(patchCopy); }
/// <summary> /// Increase the context until it is unique, /// but don't let the pattern expand beyond Match_MaxBits.</summary> /// <param name="text">Source text</param> /// <param name="patchMargin"></param> internal void AddContext(string text, short patchMargin = 4) { if (text.Length == 0) { return; } var pattern = text.Substring(Start2, Length1); var padding = 0; // Look for the first and last matches of pattern in text. If two // different matches are found, increase the pattern length. while (text.IndexOf(pattern, StringComparison.Ordinal) != text.LastIndexOf(pattern, StringComparison.Ordinal) && pattern.Length < Constants.MatchMaxBits - patchMargin - patchMargin) { padding += patchMargin; var begin = Math.Max(0, Start2 - padding); pattern = text.Substring(begin, Math.Min(text.Length, Start2 + Length1 + padding) - begin); } // Add one chunk for good luck. padding += patchMargin; // Add the prefix. var begin1 = Math.Max(0, Start2 - padding); var prefix = text.Substring(begin1, Start2 - begin1); if (prefix.Length != 0) { Diffs.Insert(0, Diff.Equal(prefix)); } // Add the suffix. var begin2 = Start2 + Length1; var length = Math.Min(text.Length, Start2 + Length1 + padding) - begin2; var suffix = text.Substring(begin2, length); if (suffix.Length != 0) { Diffs.Add(Diff.Equal(suffix)); } // Roll back the start points. Start1 -= prefix.Length; Start2 -= prefix.Length; // Extend the lengths. Length1 += prefix.Length + suffix.Length; Length2 += prefix.Length + suffix.Length; }
private async Task ReloadComments() { _loadedComments = await _commentsPersist.Load(PullRequestLocator); GeneralComments = _loadedComments.GeneralComments; foreach (var fileComment in _loadedComments.FileComments) { var file = Diffs.SingleOrDefault(r => r.GitHubCommitFile.Filename == fileComment.FileName); if (file == null) { continue; } file.Comments = fileComment.Comments; file.ReviewStatus = fileComment.ReviewStatus; } }
private async Task SaveCommentsWithoutChangeBusyStatus(PullRequestLocator request) { if (request == null || !request.IsValid()) { return; } var commentsContainer = _loadedComments; if (_loadedComments != null) { commentsContainer.AddComments(Diffs.ToList(), GeneralComments); } else { commentsContainer = CommentsContainer.From(Diffs, GeneralComments); } await _commentsPersist.Save(request, commentsContainer); }
public bool Merge(string title, CompareContext context) { if (context == null) { return(false); } if (context.Diffs.Count > 0) { if (!string.IsNullOrEmpty(title)) { Diffs.Add(title); } Diffs.AddRange(context.Diffs); } return(context.Diffs.Count == 0); }
public void Add(Entry e) { long diff = 0; if (Entries.Count == 0) { diff = e.Value;; } else { diff = e.Value - Entries[Entries.Count - 1].Value; } Entries.Add(e); Diffs.Add(diff); BaseLine.Add(e.Value - Entries[0].Value); Sum += diff; Min = Math.Min(Min, e.Value); Max = Math.Max(Max, e.Value); }
public void InitSettings(OpenSettings settings) { if (settings.Method == StartMethod.Open) { _mapsetPath = settings.MapsetPath; var osuFiles = Directory.GetFiles(_mapsetPath, "*.osu", SearchOption.TopDirectoryOnly); foreach (var cur in osuFiles) { Diffs.Add(new DiffVersion { DiffName = OsuParserExtensions.GetDiffName(cur), FileName = cur }); } } if (settings.Method == StartMethod.Create) { InitialCommand.Execute(null); } }
public void AddPaddingAfterLastDiff(string nullPadding) { if (Diffs.Count == 0 || Diffs.Last().Operation != Operation.Equal) { // Add nullPadding equality. Diffs.Add(Diff.Equal(nullPadding)); Length1 += nullPadding.Length; Length2 += nullPadding.Length; } else if (nullPadding.Length > Diffs[Diffs.Count - 1].Text.Length) { // Grow last equality. var lastDiff = Diffs[Diffs.Count - 1]; var extraLength = nullPadding.Length - lastDiff.Text.Length; var text = lastDiff.Text + nullPadding.Substring(0, extraLength); Diffs[Diffs.Count - 1] = lastDiff.Replace(text); Length1 += extraLength; Length2 += extraLength; } }
public void AddPaddingBeforeFirstDiff(string nullPadding) { if (Diffs.Count == 0 || Diffs[0].Operation != Operation.Equal) { // Add nullPadding equality. Diffs.Insert(0, Diff.Equal(nullPadding)); Start1 -= nullPadding.Length; // Should be 0. Start2 -= nullPadding.Length; // Should be 0. Length1 += nullPadding.Length; Length2 += nullPadding.Length; } else if (nullPadding.Length > Diffs[0].Text.Length) { // Grow first equality. var firstDiff = Diffs[0]; var extraLength = nullPadding.Length - firstDiff.Text.Length; Diffs[0] = firstDiff.Replace(nullPadding.Substring(firstDiff.Text.Length) + firstDiff.Text); Start1 -= extraLength; Start2 -= extraLength; Length1 += extraLength; Length2 += extraLength; } }
//private static string ResolveGrantParent(string propertyName) //{ // return ResolveParent(ResolveParent(propertyName)).Equals(propertyName) // ? "" // : ResolveParent(ResolveParent(propertyName)); //} //private static void ClearChildProperties(IList<Diffs> diffs) //{ // diffs.ToList().ForEach(d => // { // d.FieldName = ResolveChild(d.FieldName); // d.ChildDiffs // }); //} private static IEnumerable <Diffs> DiffsFromComparisonResult(ComparisonResult comparisonResult) { //IList<Diffs> result = new List<Diffs>(); //string parentMarker = null; //string parent = null; IList <Diffs> childDiffs = new List <Diffs>(); IDictionary <string, IList <Diffs> > childMapping = new Dictionary <string, IList <Diffs> >(); foreach (Difference difference in comparisonResult.Differences /*.Reverse<Difference>()*/) { if (!childMapping.TryGetValue(ResolveListParentProperty(difference.ParentPropertyName), out childDiffs)) { childDiffs = new List <Diffs>(); childMapping.Add(ResolveListParentProperty(difference.ParentPropertyName), childDiffs); } var diffs = new Diffs { FieldName = ResolveChild(difference.PropertyName), OldValue = difference.Object1Value, NewValue = difference.Object2Value, OperationType = ResolveOperationType(difference.Object1Value, difference.Object2Value) }; childDiffs.Add(diffs); } var enumerator = childMapping.Keys.GetEnumerator(); while (enumerator.MoveNext()) { //ResolveParent(key)//with lastIndexOf delimiter (получить коллекцию от ключ-однаНода) var diff = new Diffs { FieldName = ResolveChild(enumerator.Current), OldValue = "", NewValue = "", OperationType = OperationType.Modified, ChildDiffs = childMapping[enumerator.Current] }; if (!enumerator.Current.Equals("")) { childMapping[ResolveParent(enumerator.Current)].Add(diff); } //childMapping.Remove(enumerator.Current); } //ClearChildProperties(childMapping[""]); return(childMapping[""]); //IEnumerable<Diffs> diffs = Enumerable.Empty<Diffs>(); //if (!result.AreEqual) //{ // Diffs root = new Diffs(); // root.ChildDiffs = new List<Diffs>(); // IDictionary<string, Diffs> nodePaths = new Dictionary<string, Diffs>(); // nodePaths[string.Empty] = root; // foreach (Difference currentDiff in result.Differences) // { // String oldValue = getValue(currentDiff.Object1, currentDiff.Object1Value); // String newValue = getValue(currentDiff.Object2, currentDiff.Object2Value); // Diffs currentChild = new Diffs() // { // FieldName = propertyNameFromPath(currentDiff.PropertyName), // OldValue = oldValue, // NewValue = newValue // }; // Diffs parent = getParent(currentDiff.ParentPropertyName, nodePaths); // parent.ChildDiffs.Add(currentChild); // } // diffs = root.ChildDiffs; //} //return diffs; }
//------------------------------------------------------------------------- StringBuilder CreateHtmlTable(ResultType rt, DataTable dt, string capt) { int delta = rt == ResultType.rtDiff || rt == ResultType.rtIdent ? 2 : 0; // DtDiff and DtIdent have two first no-data columns int colCnt = dt.Columns.Count; StringBuilder sb = new StringBuilder(); sb.AppendLine("<tr><td class=h></tr>"); sb.AppendLine(string.Format("<tr><td class=h colspan={0}>{1}</td></tr>", colCnt - delta + 1, capt)); // heads for (int t = 0; t < 2; t++) { if (rt == ResultType.rtA && t == 1) { continue; } if (rt == ResultType.rtB && t == 0) { continue; } string st = "h1"; if (rt == ResultType.rtA || t == 1) { st = "h2"; } sb.Append("<TR class=" + st + "><TD>" + (rt == ResultType.rtDiff || rt == ResultType.rtIdent ? (t == 0 ? "A" : "B") : "")); for (int c = 0; c < colCnt - delta; c++) { string cls = ""; if (KeyCols.Contains(c)) { cls = " class=k"; } if ((rt == ResultType.rtDiff || rt == ResultType.rtIdent) && MatchCols.Contains(c)) { cls = " class=m"; } if (rt == ResultType.rtDiff && Diffs.Values.SelectMany(v => v).Distinct().Contains(c)) { cls = " class=e"; } sb.Append("<TD" + cls + ">" + ColNames[t][c] .Replace("&", "&").Replace("\"", """).Replace("<", "<").Replace(">", ">")); } sb.AppendLine("</TR>"); } // data for (int r = 0; r < dt.Rows.Count; r++) { int key = rt == ResultType.rtDiff || rt == ResultType.rtIdent ? (int)dt.Rows[r][0] * 10 + (int)dt.Rows[r][1] : -1; sb.Append("<TR" + (r % 2 == 0 || rt == ResultType.rtA || rt == ResultType.rtB ? "" : " class=r") + ">"); if ((rt == ResultType.rtDiff || rt == ResultType.rtIdent) && RepeatRows.ContainsKey(key)) { if (r > 0) { sb.Append("<TD class=e>R" + RepeatRows[key].ToString()); } else { sb.Append(string.Format("<TD class=e><a name=\"{0}\">R{1}</a></td>", rt.ToString(), RepeatRows[key])); } } else { if (r > 0) { sb.Append("<TD>"); } else { sb.Append(string.Format("<TD><a name=\"{0}\"/></td>", rt.ToString())); } } for (int c = delta; c < colCnt; c++) { string cls = ""; if (KeyCols.Contains(c - delta)) { cls = " class=k"; } if (rt == ResultType.rtDiff && Diffs.ContainsKey((int)dt.Rows[r][0]) && Diffs[(int)dt.Rows[r][0]].Contains(c - delta)) { cls = " class=e"; } sb.Append("<TD" + cls + ">" + dt.Rows[r][c].ToString() .Replace("&", "&").Replace("\"", """).Replace("<", "<").Replace(">", ">")); } sb.AppendLine("</TR>"); } // sb.AppendLine("<tr><td class=l><a href=\"#top\">Top</a></td></tr>"); return(sb); }
public IEnumerable <Change> NestedChanges(Func <ValueChange <TChildToken>, IEnumerable <Change> > selector) { Requires.NotNull(selector, nameof(selector)); return(Diffs.SelectMany(selector)); }
public void AddDiff(string diff) { Diffs.Add(diff); }
public Map(string id, int notes, Diffs _diff) { this.Key = id; this.Notes = notes; this.Difficulty = _diff; }