static void Main(string[] args)
        {
            // Load first document
            TextExtractor document1 = new TextExtractor();

            document1.RegistrationName = "demo";
            document1.RegistrationKey  = "demo";
            document1.LoadDocumentFromFile(@".\comparison1.pdf");

            // Load second  document
            TextExtractor document2 = new TextExtractor();

            document2.RegistrationName = "demo";
            document2.RegistrationKey  = "demo";
            document2.LoadDocumentFromFile(@".\comparison2.pdf");

            // Compare documents
            TextComparer comparer = new TextComparer();

            comparer.RegistrationName = "demo";
            comparer.RegistrationKey  = "demo";
            comparer.Compare(document1, document2);

            // Generate report
            comparer.GenerateHtmlReport(@".\report.html");

            document1.Dispose();
            document2.Dispose();

            // Open the report in default browser
            ProcessStartInfo processStartInfo = new ProcessStartInfo(@".\report.html");

            processStartInfo.UseShellExecute = true;
            Process.Start(processStartInfo);
        }
Esempio n. 2
0
        public void Compare_StringAndValue_True()
        {
            var comparer = new TextComparer();
            var result   = comparer.Compare("string", "(value)");

            Assert.That(result.AreEqual, Is.True);
        }
Esempio n. 3
0
        public void Compare_NullAndAny_True()
        {
            var comparer = new TextComparer();
            var result   = comparer.Compare(null, "(any)");

            Assert.That(result.AreEqual, Is.True);
        }
Esempio n. 4
0
        public void Compare_NullAndString_False()
        {
            var comparer = new TextComparer();
            var result   = comparer.Compare(null, "string");

            Assert.That(result.AreEqual, Is.False);
        }
Esempio n. 5
0
        static void Main(string[] args)
        {
            // Load first document
            TextExtractor document1 = new TextExtractor();

            document1.RegistrationName = "demo";
            document1.RegistrationKey  = "demo";
            document1.LoadDocumentFromFile("comparison1.pdf");

            // Load second  document
            TextExtractor document2 = new TextExtractor();

            document2.RegistrationName = "demo";
            document2.RegistrationKey  = "demo";
            document2.LoadDocumentFromFile("comparison2.pdf");

            // Compare documents
            TextComparer comparer = new TextComparer();

            comparer.RegistrationName = "demo";
            comparer.RegistrationKey  = "demo";
            comparer.Compare(document1, document2);

            // Generate report
            comparer.GenerateHtmlReport("report.html");

            // Open the report in browser
            System.Diagnostics.Process.Start("report.html");
        }
Esempio n. 6
0
        public void Compare_NullAndValue_False()
        {
            var comparer = new TextComparer();
            var result   = comparer.Compare(null, "(value)");

            Assert.That(result.AreEqual, Is.False);
        }
Esempio n. 7
0
        public void Compare_TwoSpacesAndBlankPlaceHolder_True()
        {
            var comparer = new TextComparer();
            var result   = comparer.Compare("  ", "(blank)");

            Assert.That(result.AreEqual, Is.True);
        }
Esempio n. 8
0
        public void Compare_StringAndSubstring_False()
        {
            var comparer = new TextComparer();
            var result   = comparer.Compare("string", "str");

            Assert.That(result.AreEqual, Is.False);
        }
Esempio n. 9
0
        public void Compare_StringAndSameStringUppercase_False()
        {
            var comparer = new TextComparer();
            var result   = comparer.Compare("string", "STRING");

            Assert.That(result.AreEqual, Is.False);
        }
Esempio n. 10
0
        public void Compare_1AndEmptyPlaceHolder_False()
        {
            var comparer = new TextComparer();
            var result   = comparer.Compare(1, "(empty)");

            Assert.That(result.AreEqual, Is.False);
        }
Esempio n. 11
0
        public void Compare_EmptyAndEmptyPlaceHolder_True()
        {
            var comparer = new TextComparer();
            var result   = comparer.Compare(string.Empty, "(empty)");

            Assert.That(result.AreEqual, Is.True);
        }
Esempio n. 12
0
        public void Compare_NullAndNullPlaceHolder_True()
        {
            var comparer = new TextComparer();
            var result   = comparer.Compare(null, "(null)");

            Assert.That(result.AreEqual, Is.True);
        }
Esempio n. 13
0
        public void Compare_IgnoreCase_true(string def)
        {
            var tolerance = new TextToleranceFactory().Instantiate(def);
            var comparer  = new TextComparer();
            var result    = comparer.Compare("Seddryck", "seddryck", tolerance);

            Assert.That(result.AreEqual, Is.True);
        }
Esempio n. 14
0
        public void Compare_LargeDifference_False(string def)
        {
            var tolerance = new TextToleranceFactory().Instantiate(def);
            var comparer  = new TextComparer();
            var result    = comparer.Compare("Seddryck", "Undefined", tolerance);

            Assert.That(result.AreEqual, Is.False);
        }
Esempio n. 15
0
        protected override bool ApplyWithReference(object reference, object x)
        {
            var cpr = new TextComparer();

            return(cpr.Compare(x, reference).AreEqual);
        }
Esempio n. 16
0
        public bool Compare(object x, object y)
        {
            var cpr = new TextComparer();

            return(cpr.Compare(x, y).AreEqual);
        }
Esempio n. 17
0
        private void CompareValues(List <CompareHelper> keyMatchingRows, List <DataRow> nonMatchingValueRows)
        {
            if (Settings.KeysDef != ResultSetComparisonSettings.KeysChoice.All)
            {
                foreach (var rxHelper in keyMatchingRows)
                {
                    var ryHelper = yDict[rxHelper.Keys];

                    //if (ryHelper.ValuesHashed == rxHelper.ValuesHashed)
                    //{
                    //    // quick shortcut. If the hash of the values matches, then there is no further need to test
                    //    continue;
                    //}

                    var rx = rxHelper.DataRowObj;
                    var ry = ryHelper.DataRowObj;

                    var isRowOnError = false;

                    for (int i = 0; i < rx.Table.Columns.Count; i++)
                    {
                        if (Settings.GetColumnRole(i) == ColumnRole.Value)
                        {
                            //Any management
                            if (rx[i].ToString() != "(any)" && ry[i].ToString() != "(any)")
                            {
                                //Null management
                                if (rx.IsNull(i) || ry.IsNull(i))
                                {
                                    if ((!rx.IsNull(i) && rx[i].ToString() != "(blank)") || (!ry.IsNull(i) && ry[i].ToString() != "(blank)"))
                                    {
                                        ry.SetColumnError(i, ry.IsNull(i) ? rx[i].ToString() : "(null)");
                                        if (!isRowOnError)
                                        {
                                            isRowOnError = true;
                                            nonMatchingValueRows.Add(ry);
                                        }
                                    }
                                }
                                //(value) management
                                else if (rx[i].ToString() == "(value)" || ry[i].ToString() == "(value)")
                                {
                                    if (rx.IsNull(i) || ry.IsNull(i))
                                    {
                                        ry.SetColumnError(i, rx[i].ToString());
                                        if (!isRowOnError)
                                        {
                                            isRowOnError = true;
                                            nonMatchingValueRows.Add(ry);
                                        }
                                    }
                                }
                                //Not Null management
                                else
                                {
                                    ComparerResult result = null;

                                    //Numeric
                                    if (Settings.GetColumnType(i) == ColumnType.Numeric)
                                    {
                                        //Convert to decimal
                                        if (Settings.IsRounding(i))
                                        {
                                            result = numericComparer.Compare(rx[i], ry[i], Settings.GetRounding(i));
                                        }
                                        else
                                        {
                                            result = numericComparer.Compare(rx[i], ry[i], Settings.GetTolerance(i));
                                        }
                                    }
                                    //Date and Time
                                    else if (Settings.GetColumnType(i) == ColumnType.DateTime)
                                    {
                                        //Convert to dateTime
                                        if (Settings.IsRounding(i))
                                        {
                                            result = dateTimeComparer.Compare(rx[i], ry[i], Settings.GetRounding(i));
                                        }
                                        else
                                        {
                                            result = dateTimeComparer.Compare(rx[i], ry[i], Settings.GetTolerance(i));
                                        }
                                    }
                                    //Boolean
                                    else if (Settings.GetColumnType(i) == ColumnType.Boolean)
                                    {
                                        //Convert to bool
                                        result = booleanComparer.Compare(rx[i], ry[i]);
                                    }
                                    //Text
                                    else
                                    {
                                        result = textComparer.Compare(rx[i], ry[i]);
                                    }

                                    //If are not equal then we need to set the message in the ColumnError.
                                    if (!result.AreEqual)
                                    {
                                        ry.SetColumnError(i, result.Message);
                                        if (!isRowOnError)
                                        {
                                            isRowOnError = true;
                                            nonMatchingValueRows.Add(ry);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Esempio n. 18
0
        public override bool Apply(object x)
        {
            var cpr = new TextComparer();

            return(cpr.Compare(x, Reference).AreEqual);
        }
        protected ResultSetCompareResult doCompare(DataTable x, DataTable y)
        {
            var chrono = DateTime.Now;

            var columnsCount = Math.Max(y.Columns.Count, x.Columns.Count);

            if (Settings == null)
            {
                BuildDefaultSettings(columnsCount);
            }
            else
            {
                Settings.ApplyTo(columnsCount);
            }

            Settings.ConsoleDisplay();
            WriteSettingsToDataTableProperties(y, Settings);
            WriteSettingsToDataTableProperties(x, Settings);

            CheckSettingsAndDataTable(y, Settings);
            CheckSettingsAndDataTable(x, Settings);

            CheckSettingsAndFirstRow(y, Settings);
            CheckSettingsAndFirstRow(x, Settings);

            var keyComparer = new DataRowKeysComparer(Settings, x.Columns.Count);

            CalculateHashValues(x, xDict, keyComparer, false);
            CalculateHashValues(y, yDict, keyComparer, true);

            chrono = DateTime.Now;
            List <CompareHelper> missingRows;

            {
                var missingRowKeys = xDict.Keys.Except(yDict.Keys);
                missingRows = new List <CompareHelper>(missingRowKeys.Count());
                foreach (Int64 i in missingRowKeys)
                {
                    missingRows.Add(xDict[i]);
                }
            }
            Trace.WriteLineIf(NBiTraceSwitch.TraceInfo, string.Format("Missing rows: {0} [{1}]", missingRows.Count(), DateTime.Now.Subtract(chrono).ToString(@"d\d\.hh\h\:mm\m\:ss\s\ \+fff\m\s")));

            chrono = DateTime.Now;
            List <CompareHelper> unexpectedRows;

            {
                var unexpectedRowKeys = yDict.Keys.Except(xDict.Keys);
                unexpectedRows = new List <CompareHelper>(unexpectedRowKeys.Count());
                foreach (Int64 i in unexpectedRowKeys)
                {
                    unexpectedRows.Add(yDict[i]);
                }
            }
            Trace.WriteLineIf(NBiTraceSwitch.TraceInfo, string.Format("Unexpected rows: {0} [{1}]", unexpectedRows.Count(), DateTime.Now.Subtract(chrono).ToString(@"d\d\.hh\h\:mm\m\:ss\s\ \+fff\m\s")));

            chrono = DateTime.Now;
            List <CompareHelper> keyMatchingRows;

            {
                var keyMatchingRowKeys = xDict.Keys.Intersect(yDict.Keys);
                keyMatchingRows = new List <CompareHelper>(keyMatchingRowKeys.Count());
                foreach (Int64 i in keyMatchingRowKeys)
                {
                    keyMatchingRows.Add(xDict[i]);
                }
            }
            Trace.WriteLineIf(NBiTraceSwitch.TraceInfo, string.Format("Rows with a matching key and not duplicated: {0}  [{1}]", keyMatchingRows.Count(), DateTime.Now.Subtract(chrono).ToString(@"d\d\.hh\h\:mm\m\:ss\s\ \+fff\m\s")));

            chrono = DateTime.Now;
            var nonMatchingValueRows = new List <DataRow>();

            // If all of the columns make up the key, then we already know which rows match and which don't.
            //  So there is no need to continue testing
            if (Settings.KeysDef != ResultSetComparisonSettings.KeysChoice.All)
            {
                foreach (var rxHelper in keyMatchingRows)
                {
                    var ryHelper = yDict[rxHelper.KeysHashed];

                    //if (ryHelper.ValuesHashed == rxHelper.ValuesHashed)
                    //{
                    //    // quick shortcut. If the hash of the values matches, then there is no further need to test
                    //    continue;
                    //}

                    var rx = rxHelper.DataRowObj;
                    var ry = ryHelper.DataRowObj;

                    for (int i = 0; i < rx.Table.Columns.Count; i++)
                    {
                        if (Settings.IsValue(i))
                        {
                            //Null management
                            if (rx.IsNull(i) || ry.IsNull(i))
                            {
                                if (!rx.IsNull(i) || !ry.IsNull(i))
                                {
                                    ry.SetColumnError(i, ry.IsNull(i) ? rx[i].ToString() : "(null)");
                                    if (!nonMatchingValueRows.Contains(ry))
                                    {
                                        nonMatchingValueRows.Add(ry);
                                    }
                                }
                            }
                            //(value) management
                            else if (rx[i].ToString() == "(value)" || ry[i].ToString() == "(value)")
                            {
                                if (rx.IsNull(i) || ry.IsNull(i))
                                {
                                    ry.SetColumnError(i, rx[i].ToString());
                                    if (!nonMatchingValueRows.Contains(ry))
                                    {
                                        nonMatchingValueRows.Add(ry);
                                    }
                                }
                            }
                            //Not Null management
                            else
                            {
                                ComparerResult result = null;

                                //Numeric
                                if (Settings.IsNumeric(i))
                                {
                                    //Convert to decimal
                                    if (Settings.IsRounding(i))
                                    {
                                        result = numericComparer.Compare(rx[i], ry[i], Settings.GetRounding(i));
                                    }
                                    else
                                    {
                                        result = numericComparer.Compare(rx[i], ry[i], Settings.GetTolerance(i));
                                    }
                                }
                                //Date and Time
                                else if (Settings.IsDateTime(i))
                                {
                                    //Convert to dateTime
                                    if (Settings.IsRounding(i))
                                    {
                                        result = dateTimeComparer.Compare(rx[i], ry[i], Settings.GetRounding(i));
                                    }
                                    else
                                    {
                                        result = dateTimeComparer.Compare(rx[i], ry[i], Settings.GetTolerance(i));
                                    }
                                }
                                //Boolean
                                else if (Settings.IsBoolean(i))
                                {
                                    //Convert to bool
                                    result = booleanComparer.Compare(rx[i], ry[i]);
                                }
                                //Text
                                else
                                {
                                    result = textComparer.Compare(rx[i], ry[i]);
                                }

                                //If are not equal then we need to set the message in the ColumnError.
                                if (!result.AreEqual)
                                {
                                    ry.SetColumnError(i, result.Message);
                                    if (!nonMatchingValueRows.Contains(ry))
                                    {
                                        nonMatchingValueRows.Add(ry);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            Trace.WriteLineIf(NBiTraceSwitch.TraceInfo, string.Format("Rows with a matching key but without matching value: {0} [{1}]", nonMatchingValueRows.Count(), DateTime.Now.Subtract(chrono).ToString(@"d\d\.hh\h\:mm\m\:ss\s\ \+fff\m\s")));

            var duplicatedRows = new List <DataRow>(); // Dummy place holder

            return(ResultSetCompareResult.Build(
                       missingRows.Select(a => a.DataRowObj).ToList(),
                       unexpectedRows.Select(a => a.DataRowObj).ToList(),
                       duplicatedRows,
                       keyMatchingRows.Select(a => a.DataRowObj).ToList(),
                       nonMatchingValueRows
                       ));
        }
Esempio n. 20
0
        private IEnumerable <DataRow> CompareValues(DataRow rx, DataRow ry)
        {
            var nonMatchingValueRows = new List <DataRow>();
            var isRowOnError         = false;

            for (int i = 0; i < rx.Table.Columns.Count; i++)
            {
                if (Settings.GetColumnRole(i) == ColumnRole.Value)
                {
                    //Null management
                    if (rx.IsNull(i) || ry.IsNull(i))
                    {
                        if (!rx.IsNull(i) || !ry.IsNull(i))
                        {
                            ry.SetColumnError(i, ry.IsNull(i) ? rx[i].ToString() : "(null)");
                            if (!isRowOnError)
                            {
                                isRowOnError = true;
                                nonMatchingValueRows.Add(ry);
                            }
                        }
                    }
                    //(value) management
                    else if (rx[i].ToString() == "(value)" || ry[i].ToString() == "(value)")
                    {
                        if (rx.IsNull(i) || ry.IsNull(i))
                        {
                            ry.SetColumnError(i, rx[i].ToString());
                            if (!isRowOnError)
                            {
                                isRowOnError = true;
                                nonMatchingValueRows.Add(ry);
                            }
                        }
                    }
                    //Not Null management
                    else
                    {
                        ComparerResult result = null;

                        //Numeric
                        if (Settings.GetColumnType(i) == ColumnType.Numeric)
                        {
                            //Convert to decimal
                            if (Settings.IsRounding(i))
                            {
                                result = numericComparer.Compare(rx[i], ry[i], Settings.GetRounding(i));
                            }
                            else
                            {
                                result = numericComparer.Compare(rx[i], ry[i], Settings.GetTolerance(i));
                            }
                        }
                        //Date and Time
                        else if (Settings.GetColumnType(i) == ColumnType.DateTime)
                        {
                            //Convert to dateTime
                            if (Settings.IsRounding(i))
                            {
                                result = dateTimeComparer.Compare(rx[i], ry[i], Settings.GetRounding(i));
                            }
                            else
                            {
                                result = dateTimeComparer.Compare(rx[i], ry[i], Settings.GetTolerance(i));
                            }
                        }
                        //Boolean
                        else if (Settings.GetColumnType(i) == ColumnType.Boolean)
                        {
                            //Convert to bool
                            result = booleanComparer.Compare(rx[i], ry[i]);
                        }
                        //Text
                        else
                        {
                            result = textComparer.Compare(rx[i], ry[i]);
                        }

                        //If are not equal then we need to set the message in the ColumnError.
                        if (!result.AreEqual)
                        {
                            ry.SetColumnError(i, result.Message);
                            if (!isRowOnError)
                            {
                                isRowOnError = true;
                                nonMatchingValueRows.Add(ry);
                            }
                        }
                    }
                }
            }
            return(nonMatchingValueRows);
        }