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 TestShutdown() { int shutdownTimeout = 30000; OfficeApplicationHelpers.SetTestSettings(shutdownTimeout, 2000, true, true, true, false, false); List<ApplicationInfo> applications = new List<ApplicationInfo>(); applications.Add(new ApplicationInfo(FileType.WordDocument, true)); applications.Add(new ApplicationInfo(FileType.ExcelSheet, true)); applications.Add(new ApplicationInfo(FileType.PowerPoint, true)); OfficeApplicationHelpers.TerminateProcesses(applications); DateTime timeNow = DateTime.Now; OfficeApplicationCache officeApplicationCache = new OfficeApplicationCache(); ExecuteApplications(officeApplicationCache, applications); officeApplicationCache.ShutDown(); OfficeApplicationHelpers.WaitForApplicationsToTerminate(applications); TimeSpan timeDiff = DateTime.Now.Subtract(timeNow); Assert.Less((int)timeDiff.TotalMilliseconds, shutdownTimeout); }