/// <summary>
        /// If the window is a dialog and visible, it will be passed to
        /// the registered dialog handlers. I none if these can handle
        /// it, it will be closed if <see cref="CloseUnhandledDialogs"/>
        /// is <c>true</c>.
        /// </summary>
        /// <param name="window">The window.</param>
        public void HandleWindow(Window window)
        {
            if (!window.IsDialog())
            {
                return;
            }
            if (!HasDialogSameProcessNameAsBrowserWindow(window))
            {
                return;
            }
            if (!window.Visible)
            {
                return;
            }
            int topProcessID = window.ToplevelWindow.ProcessID;

            if ((TopWindow.ProcessID != topProcessID) && (MainWindow.ProcessID != topProcessID))
            {
                return;
            }

            // This is needed otherwise the window Style will return a "wrong" result.
            WaitUntilVisibleOrTimeOut(window);

            // Lock the thread and see if a handler will handle
            // this dialog window
            lock (this)
            {
                foreach (var dialogHandler in _handlers)
                {
                    try
                    {
                        if (dialogHandler.CanHandleDialog(window, MainWindow.Hwnd))
                        {
                            if (dialogHandler.HandleDialog(window))
                            {
                                return;
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        LastException = e;

                        Logger.LogAction((LogFunction log) => { log("Exception was thrown while DialogWatcher called HandleDialog: {0}", e.ToString()); });
                    }
                }

                // If no handler handled the dialog, see if the dialog
                // should be closed automatically.
                if (!CloseUnhandledDialogs)
                {
                    return;
                }

                Logger.LogAction((LogFunction log) => { log("Auto closing dialog with title: '{0}', text: {1}, style: ", window.Title, window.Message, window.StyleInHex); });
                window.ForceClose();
            }
        }
示例#2
0
        /// <summary>
        /// If the window is a dialog and visible, it will be passed to
        /// the registered dialog handlers. I none if these can handle
        /// it, it will be closed if <see cref="CloseUnhandledDialogs"/>
        /// is <c>true</c>.
        /// </summary>
        /// <param name="window">The window.</param>
        public void HandleWindow(Window window)
        {
            if (window.IsDialog())
            {
                WaitUntilVisibleOrTimeOut(window);

                // Lock the thread and see if a handler will handle
                // this dialog window
                lock (this)
                {
                    foreach (IDialogHandler dialogHandler in handlers)
                    {
                        try
                        {
                            if (dialogHandler.HandleDialog(window))
                            {
                                return;
                            }
                        }
                        catch (Exception e)
                        {
                            lastException = e;

                            Logger.LogAction("Exception was thrown while DialogWatcher called HandleDialog:");
                            Logger.LogAction(e.ToString());
                        }
                    }

                    // If no handler handled the dialog, see if the dialog
                    // should be closed automatically.
                    if (CloseUnhandledDialogs)
                    {
                        Logger.LogAction("Auto closing dialog with title '{0}'.", window.Title);
                        window.ForceClose();
                    }
                }
            }
        }
示例#3
0
        /// <summary>
        /// If the window is a dialog and visible, it will be passed to
        /// the registered dialog handlers. I none if these can handle
        /// it, it will be closed if <see cref="CloseUnhandledDialogs"/>
        /// is <c>true</c>.
        /// </summary>
        /// <param name="window">The window.</param>
        public void HandleWindow(Window window)
        {
            if (!window.IsDialog())
            {
                return;
            }
            if (Process.GetProcessById(window.ProcessID).ProcessName != "iexplore")
            {
                return;
            }
            if (string.IsNullOrWhiteSpace(window.Title))
            {
                return;
            }

            if (Count > 0)
            {
                // This is needed otherwise the window Style will return a "wrong" result.
                if (CloseUnhandledDialogs)
                {
                    WaitUntilVisibleOrTimeOut(window);
                }

                //Logger.LogDebug("Find dialog " + window.Title);
                // Lock the thread and see if a handler will handle
                // this dialog window
                lock (this)
                {
                    foreach (var dialogHandler in _handlers)
                    {
                        //Logger.LogDebug(dialogHandler.GetType().Name);
                        try
                        {
                            if (dialogHandler.CanHandleDialog(window, MainWindowHwnd))
                            {
                                Logger.LogAction("Handle dialog");
                                if (dialogHandler.HandleDialog(window))
                                {
                                    return;
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            LastException = e;

                            Logger.LogAction("Exception was thrown while DialogWatcher called HandleDialog:");
                            Logger.LogAction(e.ToString());
                        }
                    }
                }
            }

            // If no handler handled the dialog, see if the dialog
            // should be closed automatically.
            if (!CloseUnhandledDialogs)
            {
                return;
            }

            Logger.LogAction("Auto closing dialog with title '{0}'.", window.Title);
            window.ForceClose();
        }
示例#4
0
		/// <summary>
		/// If the window is a dialog and visible, it will be passed to
		/// the registered dialog handlers. I none if these can handle
		/// it, it will be closed if <see cref="CloseUnhandledDialogs"/>
		/// is <c>true</c>.
		/// </summary>
		/// <param name="window">The window.</param>
		public void HandleWindow(Window window)
		{
			if (window.IsDialog())
			{
				WaitUntilVisibleOrTimeOut(window);

				// Lock the thread and see if a handler will handle
				// this dialog window
				lock (this)
				{
					foreach (IDialogHandler dialogHandler in handlers)
					{
						try
						{
							if (dialogHandler.HandleDialog(window)) return;
						}
						catch (Exception e)
						{
							lastException = e;

							Logger.LogAction("Exception was thrown while DialogWatcher called HandleDialog:");
							Logger.LogAction(e.ToString());
						}
					}

					// If no handler handled the dialog, see if the dialog
					// should be closed automatically.
					if (CloseUnhandledDialogs)
					{
						Logger.LogAction("Auto closing dialog with title '{0}'.", window.Title);
						window.ForceClose();
					}
				}
			}
		}