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
            {
            }
        }
        public IDiffProgress ProcessDiff(IDiffProgress progress)
        {
            progress.ShowIndeterminatedProgress();

            try
            {
                if (System.IO.File.Exists(_Args.A) == false ||
                    System.IO.File.Exists(_Args.B) == false)
                {
                    return(progress);
                }

                IList <string> a, b;
                int            leadingCharactersToIgnore = 0;

                if (_Args.DiffType == DiffType.File)
                {
                    GetFileLines(_Args.A, _Args.B, out a, out b, out leadingCharactersToIgnore, _Args, progress);
                }
                else
                {
                    GetTextLines(_Args.A, _Args.B, _Args, out a, out b, progress);
                }

                IsBinaryCompare      = leadingCharactersToIgnore > 0;
                IgnoreCase           = IsBinaryCompare ? false : _Args.IgnoreCase;
                IgnoreTextWhitespace = IsBinaryCompare ? false : _Args.IgnoreTextWhitespace;
                TextDiff diff = new TextDiff(_Args.HashType, IgnoreCase, IgnoreTextWhitespace, leadingCharactersToIgnore, !_Args.ShowChangeAsDeleteInsert);

                ListA  = a;
                ListB  = b;
                Script = diff.Execute(a, b);

                progress.ResultData = this;

                return(progress);
            }
            finally
            {
                progress.ProgressDisplayOff();
            }
        }