public bool Execute() { m_bAbortFlag = false; try { CallbackSteppingMessage("Initialising"); KillOfficeApps(); m_ft = Workshare.ApplicationControllers.OfficeApplicationCache.GetFileTypeBasedOnFilename(m_sInputFile, false); m_cache = Workshare.ApplicationControllers.OfficeApplicationCache.Instance; appLaunchTime.Reset(); appLaunchTime.Start(); try { m_cache.GetHostApplication(m_ft); // otherwise the Shutdown will not release the office app instance } catch (Exception e) { if (e.Message.Contains("controller")) return false; throw; } appLaunchTime.Stop(); TakeWorkingCopiesOfDataDataFile(); CallbackSteppingMessage("Discover Original"); m_dtReadOnlyDiscover = DiscoverDocument(m_sInputFile); m_dtDiscoverAfterApiClean = m_dtReadOnlyDiscover; // if the Api clean fails, we treat it as nothing cleaned if (m_advancedOptions.DoBinaryClean) { CallbackSteppingMessage("LightSpeed Redacting"); List<ContentType> listContentTypes = GetListOfAllContentTypes(); DoLightSpeedCleanEx(listContentTypes); m_LightSpeedCleaningWorked = true; CallbackSteppingMessage("Discover LightSpeed Redacted Version"); m_dtDiscoverAfterBinClean = DiscoverDocument(m_sFileForBinClean); } if (m_advancedOptions.DoDomClean) { CallbackSteppingMessage("API Cleaning"); DoAPIClean(); CallbackSteppingMessage("Discover API Cleaned Version"); m_dtDiscoverAfterApiClean = DiscoverDocument(m_sFileForApiClean); } if (m_advancedOptions.DoValidation) { CallbackSteppingMessage("Checking LightSpeed Redacted Doc for Corruption"); ValidateNotCorrupt(m_sFileForBinClean); } CallbackSteppingMessage("Completed"); return true; } finally { appCloseTime.Reset(); if (m_cache != null) { appCloseTime.Start(); m_cache.ShutDown(); appCloseTime.Stop(); } } }
public void TestRecoverInvalidHostApplicationForPowerPoint() { OfficeApplicationHelpers.SetTestSettings(1000, 2000, false, false, true, false, false); OfficeApplicationCache officeApplicationCache = new OfficeApplicationCache(); FileType fileType = OfficeApplicationCache.GetFileTypeBasedOnFilename(CopyFile(Path.Combine(m_testPath, "test.ppt")), true); object application = officeApplicationCache.GetHostApplication(fileType); Assert.IsNotNull(application); // User kills all word processes foreach (Process process in Process.GetProcessesByName("powerpnt")) { process.Kill(); } application = officeApplicationCache.GetHostApplication(fileType); Assert.IsNotNull(application); try { Assert.IsInstanceOf(typeof(PowerPoint._Application), application); PowerPoint._Application pptApplication = application as PowerPoint._Application; string version = pptApplication.Version; Assert.IsFalse(string.IsNullOrEmpty(version)); } finally { officeApplicationCache.StartTimeout(); } }
public void TestGetHostApplicationForPowerPoint() { OfficeApplicationHelpers.SetTestSettings(1000, 2000, false, false, true, false, false); OfficeApplicationCache officeApplicationCache = new OfficeApplicationCache(); FileType fileType = OfficeApplicationCache.GetFileTypeBasedOnFilename(CopyFile(Path.Combine(m_testPath, "test.ppt")), true); object application = officeApplicationCache.GetHostApplication(fileType); Assert.IsNotNull(application); try { Assert.IsInstanceOf(typeof(PowerPoint._Application), application); } finally { officeApplicationCache.StartTimeout(); } }
public void TestRecoverInvalidHostApplicationForExcel() { OfficeApplicationHelpers.SetTestSettings(1000, 2000, false, true, false, false, false); OfficeApplicationCache officeApplicationCache = new OfficeApplicationCache(); FileType fileType = OfficeApplicationCache.GetFileTypeBasedOnFilename(m_testPath + "test.xls", true); object application = officeApplicationCache.GetHostApplication(fileType); Assert.IsNotNull(application); // User kills all word processes foreach (Process process in Process.GetProcessesByName("excel")) { process.Kill(); } application = officeApplicationCache.GetHostApplication(fileType); Assert.IsNotNull(application); try { Assert.IsInstanceOf(typeof(Excel._Application), application); Excel._Application excelApplication = application as Excel._Application; string version = excelApplication.Version; Assert.IsFalse(string.IsNullOrEmpty(version)); } finally { officeApplicationCache.StartTimeout(); } }
public void TestGetHostApplicationForExcel() { OfficeApplicationHelpers.SetTestSettings(1000, 2000, false, true, false, false, false); OfficeApplicationCache officeApplicationCache = new OfficeApplicationCache(); FileType fileType = OfficeApplicationCache.GetFileTypeBasedOnFilename(m_testPath + "test.xls", true); object application = officeApplicationCache.GetHostApplication(fileType); Assert.IsNotNull(application); try { Assert.IsInstanceOf(typeof(Excel._Application), application); } finally { officeApplicationCache.StartTimeout(); } }
public void TestRecoverInvalidHostApplicationForWord() { OfficeApplicationHelpers.SetTestSettings(1000, 2000, true, false, false, false, false); OfficeApplicationCache officeApplicationCache = new OfficeApplicationCache(); FileType fileType = OfficeApplicationCache.GetFileTypeBasedOnFilename(m_testPath + "test.doc", true); object application = officeApplicationCache.GetHostApplication(fileType); Assert.IsNotNull(application); // User kills all word processes foreach (Process process in Process.GetProcessesByName("winword")) { process.Kill(); } System.Threading.Thread.Sleep(50); Process[] p = Process.GetProcessesByName("winword"); int timeout = 100; while ((timeout-- > 0) && (p != null) && (p.Length != 0)) { System.Threading.Thread.Sleep(50); p = Process.GetProcessesByName("winword"); } OfficeApplicationHelpers.WaitForAllWordInstancesToExit(1000); application = officeApplicationCache.GetHostApplication(fileType); Assert.IsNotNull(application); try { Assert.IsInstanceOf(typeof(Word._Application), application); Word._Application wordApplication = application as Word._Application; string version = wordApplication.Version; Assert.IsFalse(string.IsNullOrEmpty(version)); } finally { officeApplicationCache.StartTimeout(); } }