private void ExecuteUsingOfficeOpenXml(TempFileForActions tempFile, CleanActionPropertySet elementsToClean) { try { m_elementsToClean = GetElementsNotRemovedByDomClean(GetListOfEnabledElementsToClean(elementsToClean)); using (BinaryData bData = new BinaryData(tempFile.GetMemoryStream())) { using (XlsxDocumentReader reader = new XlsxDocumentReader(bData)) { using (Stream str = GetOutputStream()) { reader.CleanTo(str, m_elementsToClean); File.Copy(InterimTempFileName, tempFile.TempFile, true); } } } } catch (System.Exception ex) { Logger.LogError(ex); throw; } finally { CleanUp(); } }
public override void RemoveMetadata(TempFileForActions tempFile, CleanActionPropertySet cleanProperties) { try { m_elementsToClean = GetListOfEnabledElementsToClean(cleanProperties); List<Exclusion> listExclusion = GetListOfExcludedElements(cleanProperties); using (BinaryData bData = new BinaryData(tempFile.GetMemoryStream())) { using (XlsxDocumentReader reader = new XlsxDocumentReader(bData)) { using (Stream str = GetOutputStream()) { reader.CleanTo(str, m_elementsToClean, listExclusion); File.Copy(InterimTempFileName, tempFile.TempFile, true); } } } } catch (System.Exception ex) { Logger.LogError("ExcelX cleaning failed"); Logger.LogError(ex); } finally { CleanUp(); } }
/// <summary> /// Original incarnation of lightspeed clean method. Left for comparison. There is at least one document that gets corrupted by the /// lightspeed clean user action as opposed to the method below. see Rally DE8912 in Professional & Deltaview project. /// </summary> /// <param name="listContentTypes"></param> private void DoLightSpeedClean(List<ContentType> listContentTypes) { System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch(); watch.Start(); switch (m_ft) { case Workshare.Policy.FileType.WordDocument: using (WordDocumentReader Word2003Reader1 = new WordDocumentReader(m_sFileForBinClean, true)) { Word2003Reader1.Clean(listContentTypes); } break; case Workshare.Policy.FileType.ExcelSheet: using (ExcelDocumentReader Excel2003Reader1 = new ExcelDocumentReader(m_sFileForBinClean, true)) { Excel2003Reader1.Clean(listContentTypes); } break; case Workshare.Policy.FileType.PowerPoint: using (Workshare.FCS.Lite.PptDocumentReader Ppt2003Reader1 = new PptDocumentReader(m_sFileForBinClean, true)) { Ppt2003Reader1.Clean(listContentTypes); } break; case Workshare.Policy.FileType.WordDocumentX: case Workshare.Policy.FileType.WordDocumentMacroX: case Workshare.Policy.FileType.WordDocumentTemplateX: case Workshare.Policy.FileType.WordDocumentMacroTemplateX: { string outFileName = System.IO.Path.GetTempFileName(); using (DocxDocumentReader Word2007Reader1 = new DocxDocumentReader(m_sFileForBinClean)) { using (Stream outStr = File.Open(outFileName, FileMode.Create)) { Word2007Reader1.CleanTo(outStr, listContentTypes); } } File.Copy(outFileName, m_sFileForBinClean, true); File.Delete(outFileName); break; } case Workshare.Policy.FileType.ExcelSheetX: case Workshare.Policy.FileType.ExcelSheetMacroX: case Workshare.Policy.FileType.ExcelSheetTemplateX: case Workshare.Policy.FileType.ExcelSheetMacroTemplateX: { string outFileName = System.IO.Path.GetTempFileName(); using (XlsxDocumentReader Excel2007Reader1 = new XlsxDocumentReader(m_sFileForBinClean)) { using (Stream outStr = File.Open(outFileName, FileMode.Create)) { Excel2007Reader1.CleanTo(outStr, listContentTypes); } } File.Copy(outFileName, m_sFileForBinClean, true); File.Delete(outFileName); break; } case Workshare.Policy.FileType.PowerPointX: case Workshare.Policy.FileType.PowerPointMacroX: case Workshare.Policy.FileType.PowerPointTemplateX: case Workshare.Policy.FileType.PowerPointMacroTemplateX: case Workshare.Policy.FileType.PowerPointShowX: case Workshare.Policy.FileType.PowerPointMacroShowX: { string outFileName = System.IO.Path.GetTempFileName(); using (PptxDocumentReader Ppt2007Reader1 = new PptxDocumentReader(m_sFileForBinClean)) { using (Stream outStr = File.Open(outFileName, FileMode.Create)) { Ppt2007Reader1.CleanTo(outStr, listContentTypes); } } File.Copy(outFileName, m_sFileForBinClean, true); File.Delete(outFileName); break; } default: break; } watch.Stop(); m_binCleanTime = watch.Elapsed.TotalSeconds; }