private Document Parse(string file) { file = @"..\..\Data\Waybills\" + file; var detector = new WaybillFormatDetector(); var parser = detector.DetectParser(file, new DocumentReceiveLog { Supplier = new Supplier { Id = 105 } }); var doc = new Document(); return(parser.Parse(file, doc)); }
public static Document Parse(string filePath, DocumentReceiveLog log = null) { var detector = new WaybillFormatDetector(); if (!File.Exists(filePath)) { filePath = Path.Combine(@"..\..\Data\Waybills\", filePath); } var parser = detector.DetectParser(filePath, log); var parsers = detector.GetSuitableParsers(filePath, log).ToList(); if (parsers.Count > 1) { throw new Exception($"Для разбора данного формата подходит более одного парсера, {parsers.Implode()}"); } if (parser == null) { return(null); } log = log ?? new DocumentReceiveLog(new Supplier(), new Address { Client = new Client() }); if (log.ClientCode == null) { log.ClientCode = 0; } var document = new Document(log, parser.GetType().Name); var doc = parser.Parse(filePath, document); if (doc != null) { doc.CalculateValues(); } return(doc); }
public void Detect_xml_format() { var parser = detector.DetectParser(@"..\..\Data\Waybills\8041496-001.xml", null); Assert.That(parser, Is.InstanceOf <ProtekXmlParser>()); }