Exemple #1
0
        /// <summary>Compare to files or string contents and return result via progress object.</summary>
        /// <param name="progress"></param>
        /// <param name="dataSource"></param>
        /// <returns></returns>
        public IDiffProgress ProcessDiff(IDiffProgress progress, IDataSource dataSource)
        {
            try
            {
                DiffBinaryTextResults result = null;

                if (_Args.DiffType == DiffType.File)
                {
                    var fileA = dataSource.CreateFile(_Args.A);
                    var fileB = dataSource.CreateFile(_Args.B);

                    result = GetFileLines(fileA, fileB, _Args, progress);
                }
                else
                {
                    // DiffType in-memory text content
                    result = GetTextLines(TextContentA, TextContentB, _Args, progress);
                }

                if (result.IsComparedAs == CompareType.Text || result.IsComparedAs == CompareType.Xml)
                {
                    // Render Text or XML lines from in-memory text content
                    if (_Args.DiffType == DiffType.File)
                    {
                        result = GetTextLines(result, _Args, progress);
                    }

                    // Assumption: Binary cannot be edit and RAW data cannot be stored in string
                    //             Therefore, binary lines are rendered only once directly from file
                    TextOriginalA = result.A.TextContent;
                    TextContentA  = result.A.TextContent;
                    TextEncodingA = result.A.TextEncoding;

                    TextOriginalB = result.B.TextContent;
                    TextContentB  = result.B.TextContent;
                    TextEncodingB = result.B.TextEncoding;
                }

                ListA = result.A.Lines;
                ListB = result.B.Lines;

                IsComparedAs         = result.IsComparedAs;
                IgnoreCase           = result.IgnoreCase;
                IgnoreTextWhitespace = result.IgnoreTextWhitespace;

                TextDiff diff = new TextDiff(_Args.HashType, IgnoreCase, IgnoreTextWhitespace,
                                             result.LeadingCharactersToIgnore, !_Args.ShowChangeAsDeleteInsert);

                Script = diff.Execute(ListA, ListB, progress);

                progress.ResultData = this;

                return(progress);
            }
            finally
            {
            }
        }
Exemple #2
0
        private DiffBinaryTextResults GetTextLines(DiffBinaryTextResults src
                                                   , TextBinaryDiffArgs args
                                                   , IDiffProgress progress)
        {
            IList <string> a = null, b = null;

            bool isAuto = args.CompareType == CompareType.Auto;

            if (args.CompareType == CompareType.Xml || isAuto)
            {
                a = TryGetXmlText(DiffUtility.GetXmlTextLinesFromXml, "the left side text", src.A.TextContent, !isAuto, args, progress);

                // If A failed to parse with Auto, then there's no reason to try B.
                if (a != null)
                {
                    b = TryGetXmlText(DiffUtility.GetXmlTextLinesFromXml, "the right side text", src.B.TextContent, !isAuto, args, progress);
                }

                // If we get here and the compare type was XML, then both
                // inputs parsed correctly, and both lists should be non-null.
                // If we get here and the compare type was Auto, then one
                // or both lists may be null, so we'll fallthrough to the text
                // handling logic.
            }

            if (a == null || b == null)
            {
                a = DiffUtility.GetStringTextLines(src.A.TextContent, progress);
                b = DiffUtility.GetStringTextLines(src.B.TextContent, progress);
            }
            else
            {
                src.IsComparedAs = CompareType.Xml;
            }

            src.A.Lines = a;
            src.B.Lines = b;

            return(src);
        }
Exemple #3
0
        private DiffBinaryTextResults GetTextLines(string textA, string textB
                                                   , TextBinaryDiffArgs args
                                                   , IDiffProgress progress)
        {
            FileContentInfo af = null, bf = null;

            bool isAuto = args.CompareType == CompareType.Auto;

            if (args.CompareType == CompareType.Xml || isAuto)
            {
                af = TryGetXmlText(DiffUtility.GetXmlTextFromXml, "the left side text", textA, !isAuto, args, progress);

                // If A failed to parse with Auto, then there's no reason to try B.
                if (af != null)
                {
                    bf = TryGetXmlText(DiffUtility.GetXmlTextFromXml, "the right side text", textB, !isAuto, args, progress);
                }

                // If we get here and the compare type was XML, then both
                // inputs parsed correctly, and both lists should be non-null.
                // If we get here and the compare type was Auto, then one
                // or both lists may be null, so we'll fallthrough to the text
                // handling logic.
            }

            if (af == null || bf == null)
            {
                af = new FileContentInfo();
                bf = new FileContentInfo();

                af.Lines = DiffUtility.GetStringTextLines(textA, progress);
                bf.Lines = DiffUtility.GetStringTextLines(textB, progress);
            }

            af.TextContent = textA;
            bf.TextContent = textB;
            DiffBinaryTextResults result = new DiffBinaryTextResults(CompareType.Text, af, bf);

            return(result);
        }