Exemplo n.º 1
0
        /// <summary>
        /// Start the compare job
        /// </summary>
        private void DoCompare()
        {
            if (_filePath1 == null || _filePath2 == null)
            {
                return;
            }

            System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;

            _cmp = new CompareResults()
            {
                Tollerance = NumDiff.Properties.Settings.Default.Tollerance, Separators = GetSeparators(), FilePath1 = _filePath1, FilePath2 = _filePath2
            };
            if (!NumDiffUtil.ReadCompare(_cmp))
            {
                System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default;

                string errMsg = string.Join("\n", _cmp.Errors);
                MessageBox.Show(errMsg, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            // read first block (it could be optimized)
            UpdateReadBlock(0);

            // set UI data
            SetData(_cmp.GetMaxCountRows(), _cmp.GetMaxCountCols());

            //%toolstrip%
            if (_cmp.Differences.Count == 0)
            {
                toolStripStatusDiffResult.Text = "No difference found";
            }
            else
            {
                toolStripStatusDiffResult.Text = "Differences found: " + _cmp.Differences.Count;
            }

            System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default;
        }
Exemplo n.º 2
0
        private static int ManageCompareFiles(string filePath1, string filePath2, int nameColumnIndex, double tollerance, string[] separators)
        {
            Console.WriteLine("file 1: " + filePath1);
            Console.WriteLine("file 2: " + filePath2);

            CompareResults cmp = new CompareResults()
            {
                Tollerance = tollerance, Separators = separators, ReadHeaders = true, NameColumnIndex = nameColumnIndex, FilePath1 = filePath1, FilePath2 = filePath2
            };

            if (!NumDiffUtil.ReadCompare(cmp))
            {
                string errMsg = string.Join("\n", cmp.Errors);
                Console.WriteLine(errMsg);
                return(2);
            }

            if (cmp.Differences.Count == 0)
            {
                Console.WriteLine("No difference found");
                return(1);
            }

            Console.WriteLine("Differences found: " + cmp.Differences.Count);
            Console.WriteLine();
            Console.WriteLine("============================ differences");

            // sort and group the differences
            var    diffs     = cmp.Differences.OrderBy(x => x.Row).ThenBy(x => x.Col).GroupBy(x => x.Row).ToList();
            string oldHeader = "";

            for (int i = 0; i < diffs.Count; i++)
            {
                string header  = "ROW";
                string values1 = "" + diffs[i].Key;
                string values2 = "" + diffs[i].Key;
                if (nameColumnIndex >= 0)
                {
                    DifferentCell cell = diffs[i].ElementAt(0);
                    header  += "\t" + cmp.Headers[nameColumnIndex];
                    values1 += "\t" + cell.Name;
                    values2 += "\t" + cell.Name;
                }

                for (int j = 0; j < diffs[i].Count(); j++)
                {
                    DifferentCell cell = diffs[i].ElementAt(j);
                    header  += "\t" + cmp.Headers[cell.Col];
                    values1 += "\t" + cell.Value1;
                    values2 += "\t" + cell.Value2;
                }

                if (oldHeader != header)
                {
                    oldHeader = header;
                    Console.WriteLine();
                    Console.WriteLine(header);
                }
                Console.WriteLine(values1);
                Console.WriteLine(values2);
            }

            if (cmp.Errors.Count > 0)
            {
                Console.WriteLine("============================ errors");
                for (int i = 0; i < cmp.Errors.Count; i++)
                {
                    Console.WriteLine(cmp.Errors.ElementAt(i));
                }
            }

            return(0);
        }