public override void Execute(WorkItem workItem) { try { switch (workItem.Extension) { case "doc": ExecuteWithWord(workItem); break; case "ppt": ExecuteWithPowerpoint(workItem); break; case "xls": ExecuteWithExcel(workItem); break; default: throw new Exception("File extension not expected : " + workItem.Extension); } } catch (Exception e) { workItem.FailureMode = FailureMode.DocumentCorruption; throw e; } }
public override void Execute(WorkItem workItem) { try { m_workItem = workItem; DocumentText dtCheck; switch (workItem.Extension) { case "doc": WordDocumentReader wrdRdr = new WordDocumentReader(workItem.BaseFileName); try { dtCheck = wrdRdr.Read(); } catch (Exception) { return; // failed to discover source document } CompareDiscoveryForDoc(workItem.BaseFileName, workItem.DiscoveredText, dtCheck); break; case "ppt": PptDocumentReader pptRdr = new PptDocumentReader(workItem.BaseFileName); try { dtCheck = pptRdr.Read(); } catch (Exception) { return; // failed to discover source document } CompareDiscoveryForPpt(workItem.BaseFileName, workItem.DiscoveredText, dtCheck); break; case "xls": ExcelDocumentReader xlsRdr = new ExcelDocumentReader(workItem.BaseFileName); try { dtCheck = xlsRdr.Read(); } catch (Exception) { return; // failed to discover source document } CompareDiscoveryForXls(workItem.BaseFileName, workItem.DiscoveredText, dtCheck); break; default: throw new Exception("File extension not expected : " + workItem.Extension); } } catch (Exception e) { workItem.FailureMode = FailureMode.DiscoveryMismatch; throw e; } }
public override void Execute(WorkItem workItem) { try { switch (workItem.Extension) { case "doc": using (DocxDocumentReader reader = new DocxDocumentReader(workItem.ConvertedFileName)) { workItem.discoveryTimer.Start(); DocumentText results = reader.Read(); workItem.DiscoveredText = results; workItem.FileSize += new FileInfo(workItem.ConvertedFileName).Length; } break; case "ppt": using (PptxDocumentReader reader = new PptxDocumentReader(workItem.ConvertedFileName)) { workItem.discoveryTimer.Start(); DocumentText results = reader.Read(); workItem.DiscoveredText = results; workItem.FileSize += new FileInfo(workItem.ConvertedFileName).Length; } break; case "xls": using (XlsxDocumentReader reader = new XlsxDocumentReader(workItem.ConvertedFileName)) { workItem.discoveryTimer.Start(); DocumentText results = reader.Read(); workItem.DiscoveredText = results; workItem.FileSize += new FileInfo(workItem.ConvertedFileName).Length; } break; default: throw new Exception("File extension not expected : " + workItem.Extension); } } catch (Exception e) { workItem.FailureMode = FailureMode.DiscoveryFailed; workItem.ShouldAbort = true; throw e; } finally { workItem.discoveryTimer.Stop(); } }
private void ExecuteWithExcel(WorkItem workItem) { try { ExcelUtils.CheckFileValid(workItem.CleanedFileName); } catch (Exception e) { if (e.Message.StartsWith("The remote procedure call failed")) { ExcelUtils.DiscardExcelApp(); } if (e.Message.StartsWith("The RPC server is unavailable")) { ExcelUtils.DiscardExcelApp(); } throw e; } }
public abstract void Execute(WorkItem workItem);
public override void Execute(WorkItem workItem) { try { switch (workItem.Extension) { case "doc": using (DocxDocumentReader reader = new DocxDocumentReader(workItem.CleanedFileName)) { DocumentText results = reader.Read(); //workItem.FileSize += new FileInfo(workItem.ConvertedFileName).Length; foreach (IAbstractTextType tt in results.GetTextTypes()) { if (tt.GetContentType() == ContentType.WorkshareProperty) continue; // We explicitly never clean these if (tt.GetChildCount() > 0 && (tt.GetContentType() != ContentType.Paragraph)) { workItem.Info = DumpTextType(tt); workItem.ContentType = tt.GetContentType(); throw new Exception("Unexpected content type found in cleaned doc"); } } } break; case "ppt": using (PptxDocumentReader reader = new PptxDocumentReader(workItem.CleanedFileName)) { DocumentText results = reader.Read(); //workItem.FileSize += new FileInfo(workItem.ConvertedFileName).Length; foreach (IAbstractTextType tt in results.GetTextTypes()) { if (tt.GetContentType() == ContentType.TextBox) continue; if (tt.GetContentType() == ContentType.Paragraph) continue; if (tt.GetChildCount() > 0 ) { workItem.Info = DumpTextType(tt); workItem.ContentType = tt.GetContentType(); throw new Exception("Unexpected content type found in cleaned ppt"); } } } break; case "xls": using (XlsxDocumentReader reader = new XlsxDocumentReader(workItem.CleanedFileName)) { DocumentText results = reader.Read(); //workItem.FileSize += new FileInfo(workItem.ConvertedFileName).Length; foreach (IAbstractTextType tt in results.GetTextTypes()) { if (tt.GetContentType() == ContentType.RoutingSlip) continue; if (tt.GetChildCount() > 0 && (tt.GetContentType() != ContentType.CellText)) { workItem.Info = DumpTextType(tt); workItem.ContentType = tt.GetContentType(); throw new Exception("Unexpected content type found in cleaned xls"); } } } break; default: throw new Exception("File extension not expected : " + workItem.Extension); } } catch (Exception e) { workItem.FailureMode = FailureMode.ThingsNotCleaned; throw e; } }