Esempio n. 1
0
        /// <summary>
        /// Start Host
        /// </summary>
        /// <param name="startupUri"></param>
        public void StartHost(string startupUri)
        {
            if (monitor != null)
            {
                throw new InvalidOperationException("You must first Close the Host before calling StartHost again.");
            }

            DictionaryStore.StartServer();
            //use a custom startup page
            if (!string.IsNullOrEmpty(startupUri))
            {
                DictionaryStore.Current[UiaDistributedTestcaseHost.StartupUriId] = startupUri;
            }

            monitor = new ApplicationMonitor();
            GetHwndUIHandler handler = new GetHwndUIHandler();

            // register for iexplore and have your app set the title
            monitor.RegisterUIHandler(handler, "iexplore", "RegExp:(Ready)", UIHandlerNotification.TitleChanged);

            //Clear the Click Once cache so the app is always re-activated
            ApplicationDeploymentHelper.CleanClickOnceCache();

            //run the app
            monitor.StartProcess(xbapFileName);

            //wait for the UIHandler to return abort or timeout in 90 seconds
            if (!monitor.WaitForUIHandlerAbort(90000) || handler.topLevelhWnd == IntPtr.Zero)
            {
                throw new TimeoutException("A timeout occured while waiting for the XamlBrowserHost to navigate to the startUpPage");
            }

            //

            monitor.StopMonitoring();

            //Get the remoteHost object
            //


            //if we timedout then let the caller know that the app is not hosting this object
            //if (remoteHost == null)
            //    throw new InvalidOperationException("The launched application did not create a host object in the Harness remote site");

            //set the host hwnd
            hWndHost = handler.topLevelhWnd;
        }