Beispiel #1
0
        /// <summary>
        /// Append a DiffResult&lt;T&gt; to a list, merging common results.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="diff">The list of DiffResults.</param>
        /// <param name="value">The new value to add to the list.</param>
        /// <param name="owner">The owner (source, target or both) of the value.</param>
        private static void AppendResult <T>(List <DiffResult <T> > diff, T value, DiffOwner owner)
        {
            // If the last entry in the list has the same owner as the new value,
            // just append the new value to the old entry.
            if (diff.Count > 0)
            {
                DiffResult <T> lastResult = diff[diff.Count - 1];
                if (lastResult.Owner == owner)
                {
                    lastResult.Value.Add(value);
                    return;
                }
            }

            // Otherwise, just add a new entry to the list.
            DiffResult <T> result = new DiffResult <T>()
            {
                Owner = owner,
            };

            result.Value.Add(value);
            diff.Add(result);
        }
Beispiel #2
0
        /// <summary>
        /// Prepend a DiffResult&lt;T&gt; to a list, merging common results.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="diff">The list of DiffResults.</param>
        /// <param name="value">The new value to add to the list.</param>
        /// <param name="owner">The owner (source, target or both) of the value.</param>
        private static void PrependResult <T>(List <DiffResult <T> > diff, T value, DiffOwner owner)
        {
            // If the first entry in the list has the same owner as the new value,
            // just prepend the new value to the old entry.
            if (diff.Count > 0)
            {
                DiffResult <T> firstResult = diff[0];
                if (firstResult.Owner == owner)
                {
                    firstResult.Value.Insert(0, value);
                    return;
                }
            }

            // Otherwise, just add a new entry to the start of the list.
            DiffResult <T> result = new DiffResult <T>()
            {
                Owner = owner,
            };

            result.Value.Add(value);

            diff.Insert(0, result);
        }
Beispiel #3
0
        private void UpdateBrowsers(CustomizationComparison comparison, DiffResult <String>[] results)
        {
            if (!ComparisonListView.SelectedItems.Cast <ListViewItem>().Any(i => i.Tag == comparison))
            {
                return;
            }

            SourceBusyPicture.Visible = false;
            TargetBusyPicture.Visible = false;

            StringBuilder sourceBuffer = new StringBuilder();
            StringBuilder targetBuffer = new StringBuilder();

            HtmlTextWriter sourceWriter = new HtmlTextWriter(new StringWriter(sourceBuffer));
            HtmlTextWriter targetWriter = new HtmlTextWriter(new StringWriter(targetBuffer));

            int sourceLineCount = 0;
            int targetLineCount = 0;

            DiffOwner previousOwner = DiffOwner.Both;

            for (int i = 0; i < results.Length; i++)
            {
                DiffResult <String> result = results[i];

                DiffOwner nextOwner      = i + 1 < results.Length ? results[i + 1].Owner : DiffOwner.Both;
                bool      isolatedChange = previousOwner == DiffOwner.Both && nextOwner == DiffOwner.Both;

                switch (result.Owner)
                {
                case DiffOwner.Target:
                    AppendLines(targetWriter, result.Value, isolatedChange ? "missing" : "changed");
                    targetLineCount += result.Value.Count;
                    break;

                case DiffOwner.Source:
                    AppendLines(sourceWriter, result.Value, isolatedChange ? "missing" : "changed");
                    sourceLineCount += result.Value.Count;
                    break;

                case DiffOwner.Both:
                    while (sourceLineCount < targetLineCount)
                    {
                        AppendLine(sourceWriter, " ", "blank");
                        sourceLineCount++;
                    }

                    while (targetLineCount < sourceLineCount)
                    {
                        AppendLine(targetWriter, " ", "blank");
                        targetLineCount++;
                    }

                    AppendLines(sourceWriter, result.Value);
                    AppendLines(targetWriter, result.Value);

                    sourceLineCount += result.Value.Count;
                    targetLineCount += result.Value.Count;
                    break;
                }

                previousOwner = result.Owner;
            }

            sourceWriter.Flush();
            targetWriter.Flush();

            SourceWebBrowser.Document.Body.InnerHtml = sourceBuffer.ToString();
            TargetWebBrowser.Document.Body.InnerHtml = targetBuffer.ToString();

            SourceWebBrowser.Document.Body.ScrollTop = 0;
            TargetWebBrowser.Document.Body.ScrollTop = 0;
        }