public AbstractProcessor(string filePath, string dbConnection, int batchSize) { this.filePath = filePath; this.dbConnection = dbConnection; this.batchSize = batchSize; this.xmlPartitioner = new XmlPartitioner(filePath, batchSize); this.dataAdapter = new DataAdapter(dbConnection); this.xMLSaver = new XMLSaver(AppDomain.CurrentDomain.BaseDirectory, TRANSACTION_NAME + ".xml"); }
public void IsApplicable_Div1OfReqTypeOverflowDiv2_False() { XDocument doc = TestHelper.LoadResourceDocument("IsApplicable05.xml"); XmlPartitioner partitioner = new XmlPartitioner { MinTreshold = 10, MaxTreshold = 25 }; Assert.False(partitioner.IsApplicable(doc)); }
public void NotApplicable_TypeFragments_Unchanged() { XDocument doc = TestHelper.LoadResourceDocument("Sample02.xml"); XmlPartitioner partitioner = new XmlPartitioner { MinTreshold = 10, MaxTreshold = 25 }; bool touched = partitioner.Partition(doc, "sample"); Assert.False(touched); Assert.False(doc.Descendants(XmlPartitioner.TEI + "pb").Any()); }
public void Partition_ApplicableBreakBeforeMin_2() { XDocument doc = TestHelper.LoadResourceDocument("Sample04.xml"); XmlPartitioner partitioner = new XmlPartitioner { MinTreshold = 5, MaxTreshold = 9 }; bool touched = partitioner.Partition(doc, "sample"); Assert.True(touched); List <XElement> breaks = doc.Descendants(XmlPartitioner.TEI + "pb").ToList(); AssertExpectedBreaks(breaks, new[] { "4", "10" }); }
public void Partition_ApplicableN10M25_4() { XDocument doc = TestHelper.LoadResourceDocument("Sample01.xml"); XmlPartitioner partitioner = new XmlPartitioner { MinTreshold = 10, MaxTreshold = 25 }; bool touched = partitioner.Partition(doc, "sample"); Assert.True(touched); List <XElement> breaks = doc.Descendants(XmlPartitioner.TEI + "pb").ToList(); AssertExpectedBreaks(breaks, new[] { "13", "27", "37", "43" }); }
/// <summary> /// Runs this command. /// </summary> public Task Run() { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("PARTITION\n"); Console.ResetColor(); Console.WriteLine( $"Input dir: {_inputDir}\n" + $"Input mask: {_fileMask}\n" + $"Output dir: {_outputDir}\n" + $"Min: {_minTreshold}\n" + $"Max: {_maxTreshold}\n" + $"Recursive: {_recursive}\n"); Log.Logger.Information("PARTITION"); XmlPartitioner partitioner = new XmlPartitioner { MinTreshold = _minTreshold, MaxTreshold = _maxTreshold }; int partitioned = 0, total = 0; if (!Directory.Exists(_outputDir)) { Directory.CreateDirectory(_outputDir); } foreach (string filePath in FileEnumerator.Enumerate( _inputDir, _fileMask, _regexMask, _recursive)) { total++; Console.Write(filePath); XDocument doc = XDocument.Load(filePath, LoadOptions.PreserveWhitespace); bool touched = partitioner.Partition(doc, Path.GetFileNameWithoutExtension(filePath)); string outputPath = Path.Combine(_outputDir, Path.GetFileName(filePath)); if (touched) { partitioned++; Console.WriteLine($" => {outputPath}"); if (!Directory.Exists(_outputDir)) { Directory.CreateDirectory(_outputDir); } doc.Save(outputPath, SaveOptions.OmitDuplicateNamespaces); } else { File.Copy(filePath, outputPath); Console.WriteLine(); } } Console.WriteLine($"Total files: {total}"); Console.WriteLine($"Partitioned files: {partitioned}"); return(Task.CompletedTask); }