Example #1
0
        public void XMLRecordfactoryMethodSuccesfulInstantiation()
        {
            fillTestIDList();
            XMLRecord testRec = XMLRecord.XMLRecordFactory(testIDList, "<XML>Not really XML</XML>", XMLDecl, "<nsTag xmlns:hpg=\"some namespace\">", "</endNSTag>");
            // Test IDs
            int i = 0;

            foreach (string ID in testRec.getIDList())
            {
                i++;
                Assert.AreEqual(ID, i.ToString());
            }
            //TestXMLRecord??
            //test XMLDecl
            testRec.MustBeValidatable = true;
            TestRegEx(true, testRec.getXMLRecord(), XMLDeclTestPattern);

            //namespaceTag
            TestRegEx(true, testRec.NamespaceTag, nsTagTestPattern);

            //namespace end tag
            TestRegEx(true, testRec.EndNamespaceTag, nsEndTagTestPattern);

            Assert.IsTrue(!testRec.SearchOnly);
        }
Example #2
0
        public void XMLRecordSearchConstructor()
        {
            XMLRecord testRec = new XMLRecord(testID);
            int       i       = 0;

            foreach (string ID in testRec.getIDList())
            {
                i++;
                Assert.AreEqual(ID, i.ToString());
            }
            Assert.IsTrue(testRec.SearchOnly);
            Assert.IsTrue(testRec.getXMLRecord().Length == 0);
            Assert.IsTrue(testRec.getID() == testID);
        }
Example #3
0
        public void XMLRecordfactoryMethodAllArgsAreNull()
        {
            fillTestIDList();
            int i = 0;

            for (int c = 0; c < testIDs.Length; c++)
            {
                try
                {
                    XMLRecord testRec = null;
                    i++;
                    switch (i + 1)
                    {
                    case 1:
                        testRec = XMLRecord.XMLRecordFactory(null, null, null, null, null);
                        break;

                    case 2:
                        testRec = XMLRecord.XMLRecordFactory(testIDList, null, null, null, null);
                        break;

                    case 3:
                        testRec = XMLRecord.XMLRecordFactory(testIDList, "<XML>Not really XML</XML>", null, null, null);
                        break;

                    case 4:
                        testRec = XMLRecord.XMLRecordFactory(testIDList, "<XML>Not really XML</XML>", XMLDecl, null, null);
                        break;

                    case 5:
                        testRec = XMLRecord.XMLRecordFactory(testIDList, "<XML>Not really XML</XML>", XMLDecl, "nsTag", null);
                        break;
                    }
                }
                catch (Exception e)
                {
                    Assert.IsInstanceOfType(e, typeof(ArgumentException));
                    Assert.AreEqual(errMsgs[i], e.Message);
                }
            }
        }
Example #4
0
        public void XMLrecordMustBevalidatable()
        {
            try
            {
                List <String> Containertags = new List <String>();
                Containertags.Add("hyp:Schuldenaar");
                List <String> IDtags = new List <String>();
                IDtags.Add("hyp:PartijId");
                XMLRecordFileIterator myXMLFile = XMLRecordFileIterator.GetXMLRecordFileIterator(filename, Containertags, IDtags);

                int       i       = 0;
                XMLRecord testRec = null;
                foreach (XMLRecord myRec in myXMLFile)
                {
                    testRec = myRec;
                    i++;
                    if (i == 12)
                    {
                        break;
                    }
                }

                TestRegEx(false, testRec.getXMLRecord(), XMLDeclTestPattern);
                Console.WriteLine(testRec.getXMLRecord());
                Console.WriteLine("--------------------------------------------------------");
                testRec.MustBeValidatable = true;
                TestRegEx(true, testRec.getXMLRecord(), XMLDeclTestPattern);
                Console.WriteLine(testRec.getXMLRecord());
                Console.WriteLine("--------------------------------------------------------");
            }
            catch (Exception e)
            {
                Console.WriteLine("--------------------------------------------------------");
                Console.WriteLine(e.Message);
                //System.Diagnostics.Debug.Print(e.Message);
                Assert.IsInstanceOfType(e, typeof(ArgumentException));
            }
        }
Example #5
0
        public void XMLRecordBehaviorInList()
        {
            List <XMLRecord> testList = new List <XMLRecord>();

            string[] testArray = new string[5];
            int      c         = 0;

            testArray[c] = testID; c++;
            testArray[c] = "4,5,6,7"; c++;
            testArray[c] = "2,3,4"; c++;
            testArray[c] = "3,4,5,6,7,8"; c++;
            testArray[c] = "3,,,,7,8"; c++;

            for (int i = 0; i < testArray.Length; i++)
            {
                testList.Add(new XMLRecord(testArray[i]));
            }


            // test Sort
            testList.Sort();
            c = 0;
            int[] sortorder = { 0, 2, 4, 3, 1 };
            foreach (XMLRecord testRec in testList)
            {
                Console.WriteLine(testRec.getID());
                Assert.AreEqual(testArray[sortorder[c]], testRec.getID());
                c++;
            }

            //test indexOf, contains, BinarySearch
            XMLRecord searchRec = new XMLRecord(testArray[2]);

            Assert.IsTrue(testList.IndexOf(searchRec) == 1);
            Assert.IsTrue(testList.Contains(searchRec));
            Assert.IsTrue(testList.BinarySearch(searchRec) == 1);
        }
Example #6
0
        /// <summary>
        /// Compares the two files stored in members _file1 and _file2
        /// </summary>
        /// <param name="filePrefix">Used for making the file with the comparison Results</param>
        /// <returns>the filename of the file with the comparison results</returns>
        public string compare(string filePrefix)
        {
            // Console.WriteLine(_file1);
            // Console.WriteLine(_file2);
            // Console.WriteLine(_containerTag);
            // Console.WriteLine(_identifyingTag);

            //Process the XML files and make XML recordlists of them
            DateTime start        = DateTime.Now;
            DateTime startCompare = start;
            XMLRecordFileProcessor firstXMLFile = new XMLRecordFileProcessor(_file1, _containerTag, _identifyingTags);

            firstXMLFile.Process(XMLRecordFileProcessor.ProcessType.ToMemory);
            DateTime stop     = DateTime.Now;
            TimeSpan duration = stop.Subtract(start);

            if (_perf)
            {
                Console.WriteLine("Duration of processing file {0}: {1:g}", _file1, duration);
            }

            start = DateTime.Now;
            XMLRecordFileProcessor secondXMLFile = new XMLRecordFileProcessor(_file2, _containerTag, _identifyingTags);

            secondXMLFile.Process(XMLRecordFileProcessor.ProcessType.ToMemory);
            stop     = DateTime.Now;
            duration = stop.Subtract(start);
            if (_perf)
            {
                Console.WriteLine("Duration of processing file {0}: {1:g}", _file2, duration);
            }

            //Make a unique list of IDs from both files
            start = DateTime.Now;
            List <string> allIDs = new List <string>();

            foreach (string ID in firstXMLFile.getIDList())
            {
                allIDs.Add(ID);
            }

            foreach (string ID in secondXMLFile.getIDList())
            {
                if (allIDs.IndexOf(ID) < 0)
                {
                    allIDs.Add(ID);
                }
            }
            stop     = DateTime.Now;
            duration = stop.Subtract(start);
            if (_perf)
            {
                Console.WriteLine("Duration of making a unique list of IDs: {0:g}", duration);
            }

            start = DateTime.Now;
            allIDs.Sort();
            stop     = DateTime.Now;
            duration = stop.Subtract(start);
            if (_perf)
            {
                Console.WriteLine("Duration of sorting the unique list of IDs: {0:g}", duration);
            }

            StringBuilder filename = new StringBuilder("");
            bool          found1   = false;
            bool          found2   = false;

            if (filePrefix.Length > 0)
            {
                filename.AppendFormat("{0}_", filePrefix);
            }
            filename.Append("Compare summary.txt");

            start = DateTime.Now;
            TimeSpan[] durations = new TimeSpan[5];
            //Initialiseer timespans
            for (int i = 0; i < durations.Length; i++)
            {
                durations[i] = new TimeSpan(0);
            }

            using (System.IO.StreamWriter file = new System.IO.StreamWriter(filename.ToString()))
            {
                foreach (string ID in allIDs)
                {
                    start         = DateTime.Now;
                    found1        = (firstXMLFile.getIDList().IndexOf(ID) >= 0);
                    found2        = (secondXMLFile.getIDList().IndexOf(ID) >= 0);
                    stop          = DateTime.Now;
                    durations[0] += stop.Subtract(start);

                    start = DateTime.Now;
                    StringBuilder msg = new StringBuilder("");
                    msg.AppendFormat("{0} => ", _containerTag);
                    string[] idTagnames = getIDTags().Split(',');
                    string[] idvalues   = ID.Split(',');
                    for (int i = 0; i < idTagnames.Length; i++)
                    {
                        string tag   = "";
                        string value = "";
                        if (i < idTagnames.Length)
                        {
                            tag = idTagnames[i];
                        }
                        if (i < idvalues.Length)
                        {
                            value = idvalues[i];
                        }
                        //clean values
                        if (tag == null)
                        {
                            tag = "";
                        }
                        if (value == null)
                        {
                            value = "";
                        }

                        //Neem waarde op als gevuld
                        if (value.Length > 0)
                        {
                            msg.AppendFormat("{0}:{1}\t", tag, value);
                        }
                    }

                    if (found1 && !found2)
                    {
                        msg.AppendFormat("Only present in file 1:'{0}'", firstXMLFile.getFilename());
                    }
                    if (!found1 && found2)
                    {
                        msg.AppendFormat("Only present in file 2:'{0}'", secondXMLFile.getFilename());
                    }
                    stop          = DateTime.Now;
                    durations[1] += stop.Subtract(start);


                    start = DateTime.Now;
                    if (found1 && found2)
                    {
                        msg.AppendFormat("Present in file '{0}' and file '{1}' => ", firstXMLFile.getFilename(), secondXMLFile.getFilename());
                        //Haal XMLRecords op
                        XMLRecord XMLRecord1 = firstXMLFile.getXMLRecord(ID);
                        XMLRecord1.MustBeValidatable = true;
                        XmlDocument doc1 = new XmlDocument();
                        doc1.LoadXml(XMLRecord1.getXMLRecord());

                        XMLRecord XMLRecord2 = secondXMLFile.getXMLRecord(ID);
                        XMLRecord2.MustBeValidatable = true;
                        XmlDocument doc2 = new XmlDocument();
                        doc2.LoadXml(XMLRecord2.getXMLRecord());


                        bool equal = false;
                        // if (XMLRecord1 != null && XMLRecord2 != null) equal = XMLRecord1.getXMLRecord().Equals(XMLRecord2.getXMLRecord());
                        // if (equal) msg.AppendFormat("Contents are identical (binary compare)");
                        // else msg.AppendFormat("Contents are different (binary compare)");
                        XmlDiff myDiff = new XmlDiff(XmlDiffOptions.IgnoreComments | XmlDiffOptions.IgnorePI | XmlDiffOptions.IgnoreXmlDecl | XmlDiffOptions.IgnorePrefixes | XmlDiffOptions.IgnoreNamespaces |
                                                     XmlDiffOptions.IgnoreChildOrder | XmlDiffOptions.IgnoreWhitespace | XmlDiffOptions.IgnoreDtd);
                        myDiff.Algorithm = XmlDiffAlgorithm.Precise;
                        //XMLRecord1.Write("XML1.xml",firstXMLFile.getNamespaceTag(), firstXMLFile.getEndNamespaceTag());
                        //// XMLRecord1.Write("XML2.xml",firstXMLFile.getNamespaceTag(), firstXMLFile.getEndNamespaceTag());
                        //XMLRecord2.Write("XML2.xml",secondXMLFile.getNamespaceTag(), secondXMLFile.getEndNamespaceTag());

                        try {
                            if (XMLRecord1 != null && XMLRecord2 != null)
                            {
                                equal = myDiff.Compare(doc1, doc2);
                            }
                            if (equal)
                            {
                                msg.AppendFormat(" Contents are identical (XML compare)");
                            }
                            else
                            {
                                msg.AppendFormat(" Contents are different (XML compare)");
                            }
                        }
                        catch (Exception e)
                        {
                            msg.Append(" XML compare failed.");
                            StringBuilder sb = new StringBuilder(getIDTags());
                            sb.AppendFormat("{0}_file1_exception.xml", XMLRecord1.getID());
                            string filename_tmp = XMLRecordFileProcessor.cleanFilename(sb.ToString());
                            XMLRecord1.MustBeValidatable = true;
                            XMLRecord1.Write(filename_tmp);
                            msg.AppendFormat("\r\n{0} {1} opgeslagen in bestand {2}", _identifyingTags, XMLRecord1.getID(), filename_tmp);
                            // Console.WriteLine(XMLRecordFile.cleanFilename(sb.ToString()));

                            sb.Clear();
                            sb.Append(getIDTags());
                            sb.AppendFormat("{0}_file2_exception.xml", XMLRecord2.getID());
                            // Console.WriteLine(XMLRecordFile.cleanFilename(sb.ToString()));
                            filename_tmp = XMLRecordFileProcessor.cleanFilename(sb.ToString());
                            XMLRecord2.MustBeValidatable = true;
                            XMLRecord2.Write(filename_tmp);
                            msg.AppendFormat("\r\n{0} {1} opgeslagen in bestand {2}", _identifyingTags, XMLRecord2.getID(), filename_tmp);

                            msg.AppendFormat("\r\nError message:\r\n{0}", e.ToString());
                            file.WriteLine(msg.ToString());
                        }
                    }
                    file.WriteLine(msg.ToString());
                    stop          = DateTime.Now;
                    durations[2] += stop.Subtract(start);
                }
            }
            //performance output
            if (_perf)
            {
                Console.WriteLine("Duration of searching both lists of XMLRecords: {0:g}", durations[0]);
            }
            if (_perf)
            {
                Console.WriteLine("Message preparation and checking if IDS are in both lists: {0:g}", durations[1]);
            }
            if (_perf)
            {
                Console.WriteLine("Comparing of two files XML1.xml and XML2.xml: {0:g}", durations[2]);
            }

            stop     = DateTime.Now;
            duration = stop.Subtract(startCompare);
            Console.WriteLine("Duration of compare: {0:g}", duration);

            return(filename.ToString());
        }