private void ExecuteApplications(OfficeApplicationCache officeApplicationCache, List<ApplicationInfo> applications)
		{
			foreach (ApplicationInfo application in applications)
			{
				officeApplicationCache.Create(application.FileType);

				if (application.ShouldRun)
				{
					OfficeApplicationHelpers.WaitForProcessToStartup(application.Name);
					Assert.IsTrue(OfficeApplicationHelpers.IsProcessRunning(application.Name), string.Format("{0} should be running after a create", application.Name));
				}
				else
				{
					Assert.IsFalse(OfficeApplicationHelpers.IsProcessRunning(application.Name), string.Format("{0} should NOT be running after a create", application.Name));
				}
			}
			officeApplicationCache.StartTimeout();
		}
		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 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);
		}
		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 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 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();
			}
		}
		public void TestOpenPowerPointDocument()
		{
			OfficeApplicationHelpers.SetTestSettings(1000, 2000, false, false, false, false, false);

			OfficeApplicationCache officeApplicationCache = new OfficeApplicationCache();
			object officeDocument = officeApplicationCache.OpenDocument(CopyFile(Path.Combine(m_testPath, "test.ppt")), false);
			Assert.IsNotNull(officeDocument);
			try
			{
				
				if (IsPowerPointVersion11orGreater())
				{
					Assert.IsInstanceOf(typeof(PowerPoint11.Presentation), officeDocument);

				}
				else                
					Assert.IsInstanceOf(typeof(PowerPoint.Presentation), officeDocument);
			}
			finally
			{
				Marshal.ReleaseComObject(officeDocument);
			}
			officeApplicationCache.StartTimeout();
		}
		public void TestOpenExcelDocument()
		{
			OfficeApplicationHelpers.SetTestSettings(1000, 2000, false, false, false, false, false);

			OfficeApplicationCache officeApplicationCache = new OfficeApplicationCache();
			object officeDocument = officeApplicationCache.OpenDocument(m_testPath + "test.xls", false);
			Assert.IsNotNull(officeDocument);
			try
			{
				Assert.IsInstanceOf(typeof(Excel.Workbook), officeDocument);
			}
			finally
			{
				Marshal.ReleaseComObject(officeDocument);
			}
			officeApplicationCache.StartTimeout();
		}
		public void TestCreateNoOfficeInstance()
		{
			OfficeApplicationHelpers.SetTestSettings(1000, 0, false, false, false, false, false);

			List<ApplicationInfo> applications = new List<ApplicationInfo>();
			applications.Add(new ApplicationInfo(FileType.WordDocument, false));
			applications.Add(new ApplicationInfo(FileType.ExcelSheet, false));
			applications.Add(new ApplicationInfo(FileType.PowerPoint, false));

			OfficeApplicationHelpers.TerminateProcesses(applications);

			OfficeApplicationCache officeApplicationCache = new OfficeApplicationCache();
			ExecuteApplications(officeApplicationCache, applications);
		}