/// <summary> /// AppMonitorLoader Main Method for STi consumption, direct-application-launching version /// </summary> /// <param name="commandline">Arguments to AppMonitor loader, either a config file or original format</param> public static void RunApplication(string commandline) { ProcessStartInfo pInfo = ProcessArgs(commandline); DictionaryStore.StartServer(); ApplicationMonitor appMon = new ApplicationMonitor(); // if we're launching a ClickOnce application, clean the cache // Since this method precludes remote deployment and our enlistment should build properly signed manifests, there's no need to update / resign the manifests. if (pInfo.FileName.ToLowerInvariant().EndsWith(ApplicationDeploymentHelper.STANDALONE_APPLICATION_EXTENSION) || pInfo.FileName.ToLowerInvariant().EndsWith(ApplicationDeploymentHelper.BROWSER_APPLICATION_EXTENSION)) { ApplicationDeploymentHelper.CleanClickOnceCache(); } // shell exec the app appMon.StartProcess(pInfo); // Some Xbap tests exit early unless we add PresentationHost.exe as a monitored process. Has to happen after StartProcess. // Timing is not an issue, since this is simply adding a string to a List, so will execute orders of magnitude faster than actually starting any Xbap. if (pInfo.FileName.ToLowerInvariant().EndsWith(ApplicationDeploymentHelper.BROWSER_APPLICATION_EXTENSION)) { appMon.MonitorProcess("PresentationHost.exe"); } appMon.WaitForUIHandlerAbort(); CloseCurrentVariationIfOneExists(); appMon.Close(); }
/// <summary> /// Sets the system theme to a custom .theme file /// </summary> /// <param name="filename">the path the the .theme file that should be set as the system theme</param> public static void SetCustomTheme(string filename) { //validate input if (filename == null) { throw new ArgumentNullException("filename"); } if (!File.Exists(filename)) { throw new FileNotFoundException("The specified theme file could not be found", filename); } if (Path.GetExtension(filename).ToLowerInvariant() != ".theme") { throw new ArgumentException("The theme file must have a .theme extention.", "filename"); } //Copy the file to another location before setting the theme //The reason for this is that if the custom theme is left after the test //executes the Automation Harness may delete the current theme which //gives and error that prevents the system from restoring the default theme string destFilename = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.InternetCache), Path.GetFileName(filename)); File.Copy(filename, destFilename, true); //Get the active window since the window activation will be lost by lauching the display properties IntPtr activehWnd = GetForegroundWindow(); ApplicationMonitor appMonitor = new ApplicationMonitor(); try { //invoke the theme and handle the dispay config UI appMonitor.RegisterUIHandler(new ChangeThemesUIHandler(), "rundll32", null, UIHandlerNotification.Visible); appMonitor.StartProcess(destFilename); if (!appMonitor.WaitForUIHandlerAbort(60000)) { throw new TimeoutException("The 60 second timeout occured while waiting for themes to change."); } } finally { //Stop the AppMonitor (this will kill rundll32 if it has not exited... hopefuly this wont leave the machine in a bad state if it a timeout occurs appMonitor.Close(); //Restore the active window if (activehWnd != IntPtr.Zero) { SetForegroundWindow(activehWnd); } } }
/// <summary> /// Closes the XamlBrowserHost application /// </summary> public void Close() { if (monitor != null) { //remove the UiaDistributedTestcaseHost from the remote site because we are about to close the host process // remoteHost = null; //Close the host process monitor.Close(); monitor = null; hWndHost = IntPtr.Zero; //give some time for the app to shutdown Thread.Sleep(2000); } }
/// <summary> /// Waits for the ApplicationMonitor to Abort and Closes any remaining /// processes /// </summary> /// <returns>true</returns> protected override bool EndStep() { //Wait for the application to be done appMonitor.WaitForUIHandlerAbort(); appMonitor.Close(); // close the fileHost if one was created within ActivationStep. // Don't close if the filehost is in the context of a FileHostStep if ((fileHost != null) && (SupportFiles.Length > 0)) { fileHost.Close(); } if (hostingPolicyResetter != null) { hostingPolicyResetter.Dispose(); hostingPolicyResetter = null; } return(true); }
/// <summary> /// Change the theme, style, and color scheme to match a defined appearance /// </summary> /// <param name="appearance">the desired defined appearance</param> public static void SetAppearance(DesktopAppearance appearance) { if (appearance == GetAppearance()) { return; } else if ((!new ArrayList(GetAvailableAppearances()).Contains(appearance))) { throw new ArgumentException("The appearance '" + appearance + "' is not currently available.", appearance.ToString()); } string themeName = GetTheme(); string styleFilename = null; // This is only needed if a change in color scheme is required (for Luna and Aero) UIHandler appearanceUIHandler = null; if (appearance == DesktopAppearance.LunaNormalColor || appearance == DesktopAppearance.LunaMetallic || appearance == DesktopAppearance.LunaHomestead) { // First ensure the theme is set to Luna if (themeName.ToLowerInvariant() != LunaString.ToLowerInvariant()) { SetTheme(LunaString); themeName = GetTheme(); if (themeName.ToLowerInvariant() != LunaString.ToLowerInvariant()) { throw new ArgumentException("Failed to change to the theme '" + LunaString + "'.", appearance.ToString()); } } // Build the path for the Luna.msstyles file styleFilename = Path.Combine(themeDirectory, themeName + @"\" + themeName + ".msstyles"); if (!File.Exists(styleFilename)) { throw new ArgumentException("The msstyles file '" + styleFilename + "' does not exist.", appearance.ToString()); } string lunaResourceString = ""; // Get the localized string to select in the color scheme menu if (appearance == DesktopAppearance.LunaMetallic) { lunaResourceString = Microsoft.Test.Loaders.ResourceHelper.GetUnmanagedResourceString(styleFilename, 1001); } else if (appearance == DesktopAppearance.LunaHomestead) { lunaResourceString = Microsoft.Test.Loaders.ResourceHelper.GetUnmanagedResourceString(styleFilename, 1002); } else { lunaResourceString = Microsoft.Test.Loaders.ResourceHelper.GetUnmanagedResourceString(styleFilename, 1000); } // Use the UIHandler for the XP Appearance dialog appearanceUIHandler = new ChangeXPAppearanceUIHandler(lunaResourceString); } else if (appearance == DesktopAppearance.AeroWithoutComposition || appearance == DesktopAppearance.AeroWithComposition) { // First ensure the theme is set to Aero if (themeName.ToLowerInvariant() != AeroString.ToLowerInvariant()) { SetTheme(AeroString); themeName = GetTheme(); if (themeName.ToLowerInvariant() != AeroString.ToLowerInvariant()) { throw new ArgumentException("Failed to change to the theme '" + AeroString + "'.", appearance.ToString()); } } // Build the path to Aero.msstyles styleFilename = Path.Combine(themeDirectory, themeName + @"\" + themeName + ".msstyles"); if (!File.Exists(styleFilename)) { throw new ArgumentException("The msstyles file '" + styleFilename + "' does not exist.", appearance.ToString()); } // Use the UIHandler for the Vista Appearance dialog appearanceUIHandler = new ChangeVistaAppearanceUIHandler(appearance); } else if (appearance == DesktopAppearance.Royale) { // Change the theme to Royale if (themeName.ToLowerInvariant() != RoyaleString.ToLowerInvariant()) { SetTheme(RoyaleString); themeName = GetTheme(); if (themeName.ToLowerInvariant() != RoyaleString.ToLowerInvariant()) { throw new ArgumentException("Failed to change to the theme '" + RoyaleString + "'.", appearance.ToString()); } } } else if (appearance == DesktopAppearance.WindowsClassic) { // Change the theme to Classic if (themeName.ToLowerInvariant() != WindowsClassicString.ToLowerInvariant()) { SetTheme(WindowsClassicString); themeName = GetTheme(); if (themeName.ToLowerInvariant() != WindowsClassicString.ToLowerInvariant()) { throw new ArgumentException("Failed to change to the theme '" + WindowsClassicString + "'.", appearance.ToString()); } } } if (appearanceUIHandler != null) { //Get the active window since the window activation will be lost by lauching the display properties IntPtr activehWnd = GetForegroundWindow(); ApplicationMonitor appMonitor = new ApplicationMonitor(); try { //invoke the msstyles file and handle the dispay config UI appMonitor.RegisterUIHandler(appearanceUIHandler, "rundll32", null, UIHandlerNotification.Visible); appMonitor.StartProcess(styleFilename); if (!appMonitor.WaitForUIHandlerAbort(60000)) { throw new TimeoutException("The 60 second timeout occured while waiting for themes to change."); } } finally { //Stop the AppMonitor (this will kill rundll32 if it has not exited... hopefuly this wont leave the machine in a bad state if it a timeout occurs appMonitor.Close(); //Restore the active window if (activehWnd != IntPtr.Zero) { SetForegroundWindow(activehWnd); } } } if (GetAppearance() != appearance) { throw new Exception("Unable to change appearance."); } }