private XMLRecordFileProcessor getProcessor() { List <String> Containertags = new List <String>(); Containertags.Add(testContainerTag); List <String> IDtags = new List <String>(); IDtags.Add(testIDTag); XMLRecordFileProcessor testProcessor = new XMLRecordFileProcessor(filename, Containertags.ToArray()[0], IDtags.ToArray()); return(testProcessor); }
/// <summary> /// Main function that parses the arguments and creates an instance of <see cref="Core.XMLRecords.Anonymization.AnonymizerXML"/> /// </summary> /// <param name="args">command line arguments</param> public static void Main(string[] args) { int rc = 0; try { //check if the anonymizer file exists if (!File.Exists(anonymizeFile)) { throw new System.ArgumentException(getHelpMessage()); } //check if there are 2 parameters if (args.Length < 2) { throw new System.ArgumentException(getHelpMessage()); } //Add containertags List <String> containerTags = new List <string>(); for (int i = 1; i < args.Length; i++) { containerTags.Add(args[i]); } //Divide the XML files in XML records and write them to a directory with the same name as the XML file without the extension .xml XMLRecordFileProcessor myXMLFile = new XMLRecordFileProcessor(args[0], containerTags.ToArray()); myXMLFile.Process(XMLRecordFileProcessor.ProcessType.Anonymize); rc = 0; //Success } catch (ArgumentException e) { Console.WriteLine(getHelpMessage()); rc = e.GetHashCode(); // alleen om warning weg te krijgen rc = 1; } catch (Exception e) { Console.WriteLine(e); rc = 1; //Error } finally { // Keep the console window open in debug mode. Console.WriteLine(""); Console.WriteLine("Press any key to exit."); Console.ReadKey(); Environment.Exit(rc); } }
/// <summary> /// Main function that parses the arguments and creates an instance of <see cref="Core.XMLRecords.XMLRecordFileProcessor"/> /// </summary> /// <param name="args">command line arguments</param> public static void Main(string[] args) { // The Length property is used to obtain the length of the array. // Notice that Length is a read-only property: // Console.WriteLine("Number of command line parameters = {0}", // args.Length); int rc = 0; try { //check if there are 3 parameters if (args.Length < 3) { throw new System.ArgumentException("3 or more parameters are expected. 1 XML filename, 1 container tag and identifying tags (1 or more)"); } //Store starttime string[] IDTags = new string[args.Length - 2]; for (int i = 2; i < args.Length; i++) { IDTags[i - 2] = args[i]; } //Divide the XML files in XML records and write them to a directory with the same name as the XML file without the extension .xml XMLRecordFileProcessor myXMLFile = new XMLRecordFileProcessor(args[0], args[1], IDTags); myXMLFile.Process(XMLRecordFileProcessor.ProcessType.ToFile); rc = 0; //Success } catch (Exception e) { Console.WriteLine(e); rc = 1; //Error } finally { // Keep the console window open in debug mode. //Console.WriteLine(""); //Console.WriteLine("Press any key to exit."); //Console.ReadKey(); Environment.Exit(rc); } }
public void XMLRecordFileProcessorToFile() { XMLRecordFileProcessor testProcessor = getProcessor(); testProcessor.Process(XMLRecordFileProcessor.ProcessType.ToFile); //check if the corresponding directory exists string dirName = filename.Replace(".xml", ""); Assert.IsTrue(Directory.Exists(dirName)); string[] testFiles = Directory.GetFiles(dirName); Assert.AreEqual(339, testFiles.Length); //Verify if the names contain the containerTag, IDtag and ID values of the XML record string[] Ids = testIDList.Split(','); for (int i = 0; i < testFiles.Length; i++) { Assert.IsTrue(testFiles[i].IndexOf(testContainerTag.Replace(":", "_")) >= 0); Assert.IsTrue(testFiles[i].IndexOf(testIDTag.Replace(":", "_")) >= 0); Assert.IsTrue(testFiles[i].IndexOf(Ids[i]) >= 0); } }
public void XMLRecordFileProcessorToMemory() { XMLRecordFileProcessor testProcessor = getProcessor(); Assert.IsNull(testProcessor.XMLRecordList); Assert.IsNull(testProcessor.getIDList()); Assert.IsNull(testProcessor.getXMLRecord("1")); Assert.AreEqual(-1, testProcessor.IndexOf("1")); testProcessor.Process(XMLRecordFileProcessor.ProcessType.ToMemory); Assert.IsNotNull(testProcessor.XMLRecordList); Assert.IsNotNull(testProcessor.getIDList()); Assert.IsNotNull(testProcessor.getXMLRecord("1")); Assert.AreEqual(109, testProcessor.IndexOf("3")); List <XMLRecord> testList = testProcessor.XMLRecordList; Console.WriteLine("{0} XML records in list!", testList.Count); //check the sorting of the XMLRecordList //build a CSV string of the list string test = TestUtils.List2CSV(testProcessor.getIDList()); Assert.AreEqual(testIDList, test); }
/// <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()); }