public void TestHmrcPdfThrasher() { var oLog = new SafeILog(LogManager.GetLogger(typeof(TestRetrieveDataHelper))); var p = new VatReturnPdfThrasher(true, oLog); foreach (string sFilePah in Directory.GetFiles(@"c:\ezbob\test-data\vat-return", "vat*.pdf")) { oLog.Msg("Processing file {0} started...", sFilePah); var smd = new SheafMetaData { BaseFileName = sFilePah, DataType = DataType.VatReturn, FileType = FileType.Pdf, Thrasher = p }; ISeeds s = p.Run(smd, File.ReadAllBytes(sFilePah)); oLog.Msg("Processing file {0} complete.", sFilePah); } // for each } // TestHmrcPdfThrasher
} // constructor public void Run() { FileCache.ErrorMsg = string.Empty; for (int i = 0; i < FileList.Count; i++) { HttpPostedFileBase oFile = FileList[i]; if (oFile == null) { ms_oLog.Debug("File {0}: not found, ignoring.", i); continue; } // if ms_oLog.Debug("File {0}, name: {1}", i, oFile.FileName); if (oFile.ContentLength == 0) { ms_oLog.Debug("File {0}: is empty, ignoring.", i); continue; } // if var oFileContents = new byte[oFile.ContentLength]; int nRead = oFile.InputStream.Read(oFileContents, 0, oFile.ContentLength); if (nRead != oFile.ContentLength) { ms_oLog.Warn("File {0}: failed to read entire file contents, ignoring.", i); continue; } // if string sMimeType = m_oLimitations.DetectFileMimeType(oFileContents, oFile.FileName, oLog: ms_oLog); ms_oLog.Debug("File {0}, name: {1}, MIME type {2}", i, oFile.FileName, sMimeType); if (string.IsNullOrWhiteSpace(sMimeType)) { ms_oLog.Debug("File {0}: has unsupported content type, ignoring.", i); continue; } // if SaveToDisc(CustomerID, OneUploadLimitation.FixFileName(oFile.FileName), oFileContents); var smd = new SheafMetaData { BaseFileName = OneUploadLimitation.FixFileName(oFile.FileName), DataType = DataType.VatReturn, FileType = FileType.Pdf, Thrasher = null }; FileCache.Add(smd, oFileContents); var vrpt = new VatReturnPdfThrasher(false, ms_oLog); ISeeds oResult; try { oResult = vrpt.Run(smd, oFileContents); } catch (Exception e) { ms_oLog.Warn(e, "Failed to parse file {0} named {1}:", i, oFile.FileName); continue; } // try if (oResult == null) { ErrorMsg = m_sErrorMsg + " " + ((VatReturnSeeds)vrpt.Seeds).FatalError; continue; } // if var oSeeds = (VatReturnSeeds)oResult; var di = new DateInterval(oSeeds.DateFrom, oSeeds.DateTo); ms_oLog.Debug("HMRC file cache state before adding file {0}: {1}.", oFile.FileName, FileCache); if (FileCache.Intersects(oSeeds.RegistrationNo, di)) { return; } FileCache.Add(oSeeds.RegistrationNo, di, smd, oResult); ms_oLog.Debug("HMRC file cache state after adding file {0}: {1}.", oFile.FileName, FileCache); } // for } // Run