示例#1
0
        private void UpdateReadBlock(int row)
        {
            int visibleRowCount = dataGridView1.Rows.GetRowCount(DataGridViewElementStates.Displayed);

            if (visibleRowCount == 0)
            {
                visibleRowCount = READ_BLOCK_LINES;
            }

            for (int fileNum = 1; fileNum <= 2; fileNum++)
            {
                _readBlockRows[fileNum - 1]     = NumDiffUtil.ReadBlock(fileNum == 1 ? _filePath1 : _filePath2, GetSeparators(), row, visibleRowCount);
                _readBlockRowIndex[fileNum - 1] = row;
            }
        }
示例#2
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;
        }
示例#3
0
        private void CheckAndClose()
        {
            double d;

            if (!NumDiffUtil.TryParseTollerance(textBoxTollerance.Text, out d))
            {
                MessageBox.Show("Tollerance is not a valid number");
                return;
            }

            NumDiff.Properties.Settings.Default.Tollerance = d;
            NumDiff.Properties.Settings.Default.Separators.Clear();

            if (checkBoxTab.Checked)
            {
                NumDiff.Properties.Settings.Default.Separators.Add("TAB");
            }

            if (checkBoxSpace.Checked)
            {
                NumDiff.Properties.Settings.Default.Separators.Add(" ");
            }

            if (checkBoxComma.Checked)
            {
                NumDiff.Properties.Settings.Default.Separators.Add(",");
            }

            if (checkBoxSemicolon.Checked)
            {
                NumDiff.Properties.Settings.Default.Separators.Add(";");
            }

            NumDiff.Properties.Settings.Default.Save();

            this.DialogResult = DialogResult.OK;
            this.Close();
        }
示例#4
0
        static int Main(string[] args)
        {
            if (args.Length < 2)
            {
                Console.WriteLine("usage: NumDiff <path1> <path2> [options]");
                Console.WriteLine();
                Console.WriteLine("options:");
                Console.WriteLine("-dir: paths refer to two directories)");
                Console.WriteLine("-toll <value>: tollerance value (default: " + DEFAULT_TOLLERANCE + ")");
                Console.WriteLine("-sep <TAB|SPACE|any char>: field separator (default: TAB)");
                Console.WriteLine("-name <column num>: print the row name which is in specified the 0-based column number (default: 1)");
                //Console.WriteLine("-jnd: Just print Number of Differences");
                return(0);
            }

            string path1 = args[0];
            string path2 = args[1];

            double tollerance = DEFAULT_TOLLERANCE;

            if (HasArg(args, "-toll"))
            {
                string val = GetArgPar(args, "-toll", 1);
                if (!NumDiffUtil.TryParseTollerance(val, out tollerance))
                {
                    Console.WriteLine("Tollerance is not a valid number");
                    return(1);
                }
            }

            string[] separators = new string[1];
            separators[0] = DEFAULT_SEPARATOR;
            if (HasArg(args, "-sep"))
            {
                string val = GetArgPar(args, "-sep", 1);
                if (val == "TAB")
                {
                    separators[0] = "\t";
                }
                else if (val == "SPACE")
                {
                    separators[0] = " ";
                }
                else
                {
                    separators[0] = val;
                }
            }

            int nameColumnIndex = 1;

            if (HasArg(args, "-name"))
            {
                string val = GetArgPar(args, "-name", 1);
                if (!int.TryParse(val, out nameColumnIndex))
                {
                    Console.WriteLine("Column number is not a valid number");
                    return(1);
                }
            }

            if (HasArg(args, "-dir"))
            {
                string dir1     = Path.GetDirectoryName(path1);
                string pattern1 = Path.GetFileName(path1);
                if (pattern1 == "")
                {
                    pattern1 = "*.*";
                }

                string dir2     = Path.GetDirectoryName(path2);
                string pattern2 = Path.GetFileName(path2);
                if (pattern2 == "")
                {
                    pattern2 = "*.*";
                }

                string[] files1 = Directory.GetFiles(dir1, pattern1);
                for (int i = 0; i < files1.Count(); i++)
                {
                    string filePath1 = files1[i];
                    string filePath2 = Path.Combine(dir2, Path.GetFileName(filePath1));

                    Console.WriteLine();
                    Console.WriteLine("========================================= " + (i + 1));
                    if (File.Exists(filePath2))
                    {
                        ManageCompareFiles(filePath1, filePath2, nameColumnIndex, tollerance, separators);
                    }
                    else
                    {
                        Console.WriteLine("File does not exists: " + filePath2);
                    }
                }

                // check for files existing only path2
                string[] files2 = Directory.GetFiles(dir2, pattern2);
                for (int i = 0; i < files2.Count(); i++)
                {
                    string filePath2 = files2[i];
                    string filePath1 = Path.Combine(dir1, Path.GetFileName(filePath2));

                    if (!File.Exists(filePath1))
                    {
                        Console.WriteLine();
                        Console.WriteLine("========================================= " + (files1.Count() + i + 1));

                        Console.WriteLine("File does not exists: " + filePath1);
                    }
                }

                return(0);
            }

            ManageCompareFiles(path1, path2, nameColumnIndex, tollerance, separators);

            return(0);
        }
示例#5
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);
        }