Description of GetWindowCmdletBase.
Inheritance: GetCmdletBase
Exemplo n.º 1
0
        private void CheckTimeout(GetWindowCmdletBase cmdlet,
                                  ICollection aeWindowList,
                                  bool fromCmdlet)
        {
            cmdlet.WriteVerbose(cmdlet, "OnSleep scriptblocks");
            SleepAndRunScriptBlocks(this);
            DateTime nowDate = DateTime.Now;

            WriteVerbose(this, "process: " +
                         cmdlet.ProcessName +
                         ", name: " +
                         cmdlet.Name +
                         ", seconds: " + (nowDate - StartDate).TotalSeconds);
            try {
                if ((null == aeWindowList || aeWindowList.Count <= 0) &&
                    !((nowDate - StartDate).TotalSeconds > Timeout / 1000))
                {
                    return;
                }
                if (null == aeWindowList)
                {
                    Wait = false;
                    var eReturn =
                        // Exception eReturn =
                        new Exception(
                            CmdletName(this) + ": timeout expired for process: " +
                            cmdlet.ProcessName + ", title: " + cmdlet.Name);
                    throw(eReturn);
                } // else{ // OK
                  // }

                Wait &= cmdlet.WaitNoWindow;

                /*
                 * if (!cmdlet.WaitNoWindow) {
                 *  Wait = false;
                 * }
                 */
                // break;
            } catch (Exception eEvaluatingWindowOrMeasuringTimeout) {
                WriteDebug(this, "exception: " +
                           eEvaluatingWindowOrMeasuringTimeout.Message);

                cmdlet.WriteError(
                    cmdlet,
                    "An error raised during checking the timeout. " +
                    eEvaluatingWindowOrMeasuringTimeout.Message,
                    "CheckingTimeout",
                    ErrorCategory.InvalidOperation,
                    true);
            }
        }
Exemplo n.º 2
0
 private void CheckTimeout(GetWindowCmdletBase cmdlet,
                           ICollection aeWindowList,
                           bool fromCmdlet)
 {
     cmdlet.WriteVerbose(cmdlet, "OnSleep scriptblocks");
     SleepAndRunScriptBlocks(this);
     DateTime nowDate = DateTime.Now;
     WriteVerbose(this, "process: " +
                  cmdlet.ProcessName +
                  ", name: " +
                  cmdlet.Name +
                  ", seconds: " + (nowDate - StartDate).TotalSeconds);
     try {
         if ((null == aeWindowList || aeWindowList.Count <= 0) &&
             !((nowDate - StartDate).TotalSeconds > Timeout/1000)) return;
         if (null == aeWindowList) {
             Wait = false;
             var eReturn =
             // Exception eReturn =
                 new Exception(
                     CmdletName(this) + ": timeout expired for process: " +
                     cmdlet.ProcessName + ", title: " + cmdlet.Name);
             throw(eReturn);
         } // else{ // OK
         // }
             
         Wait &= cmdlet.WaitNoWindow;
         /*
         if (!cmdlet.WaitNoWindow) {
             Wait = false;
         }
         */
         // break;
         
     } catch (Exception eEvaluatingWindowOrMeasuringTimeout) {
         WriteDebug(this, "exception: " +
                    eEvaluatingWindowOrMeasuringTimeout.Message);
         
         cmdlet.WriteError(
             cmdlet,
             "An error raised during checking the timeout. " +
             eEvaluatingWindowOrMeasuringTimeout.Message,
             "CheckingTimeout",
             ErrorCategory.InvalidOperation,
             true);
     }
 }
Exemplo n.º 3
0
        // 20120123
        // private void checkTimeout(ref System.Windows.Automation.AutomationElement aeWindow,
        private void checkTimeout(GetWindowCmdletBase cmdlet,
                                  //System.Windows.Automation.AutomationElement aeWindow,
                                  ArrayList aeWindowList,
                                  bool fromCmdlet)
        {
            // RunOnRefreshScriptBlocks(this);
            // System.Threading.Thread.Sleep(Preferences.SleepInterval);
            // RunScriptBlocks(this);
            SleepAndRunScriptBlocks(this);
            System.DateTime nowDate = System.DateTime.Now;
            WriteVerbose(this, "process: " +
                         // processName +
                         cmdlet.ProcessName +
                         ", name: " +
                         cmdlet.Name +
                         ", seconds: " + (nowDate - StartDate).TotalSeconds);
            try {
                // 20120824
                //if ((aeWindow != null && (int)aeWindow.Current.ProcessId > 0) ||
                if ((null != aeWindowList && //(int)((AutomationElement)aeWindowList[0]).Current.ProcessId > 0) ||
                     aeWindowList.Count > 0) ||
                    (nowDate - StartDate).TotalSeconds > this.Timeout / 1000)
                {
                    // 20120824
                    //if (aeWindow == null) {
                    if (null == aeWindowList) {
                        //                        ErrorRecord err =
                        //                            new ErrorRecord(
                        //                                new Exception(),
                        //                                "ControlIsNull",
                        //                                ErrorCategory.OperationTimeout,
                        //                                aeWindow);
                        //                        err.ErrorDetails =
                        //                            new ErrorDetails(
                        //                                CmdletName(this) + ": timeout expired for process: " +
                        //                                cmdlet.ProcessName + ", title: " + cmdlet.Name);
                        //                        WriteError(this, err, false);
                        //                        //WriteError(this, err, true); //// 20120306
                        //return;
                        this.Wait = false;
                        Exception eReturn =
                            new Exception(
                                CmdletName(this) + ": timeout expired for process: " +
                                cmdlet.ProcessName + ", title: " + cmdlet.Name);
                        throw(eReturn);
                    }else{
            //                        WriteVerbose(this, "got the window: " +
            //                                     // 20120824
            //                                     //aeWindow.Current.Name);
            //                                     ((AutomationElement)aeWindowList[0]).Current.Name);
                    }

                    // 20130529
                    //this.Wait = false;
                    if (!cmdlet.WaitNoWindow) {
                        this.Wait = false;
                    }
                    // break;
                }
            } catch (Exception eEvaluatingWindowOrMeasuringTimeout) {
                // try { WriteDebug(CmdletName(this) + ": exception: " +
                // eEvaluatingWindowOrMeasuringTimeout.Message); } catch { }
                WriteDebug(this, "exception: " +
                           eEvaluatingWindowOrMeasuringTimeout.Message);

                // 20121001
                //UIAHelper.GetScreenshotOfAutomationElement(this, CmdletName(this) + "_Timeout", true, 0, 0, 0, 0, string.Empty, System.Drawing.Imaging.ImageFormat.Jpeg);
                cmdlet.WriteError(
                    cmdlet,
                    "An error raised during checking the timeout. " +
                    eEvaluatingWindowOrMeasuringTimeout.Message,
                    "CheckingTimeout",
                    ErrorCategory.InvalidOperation,
                    true);
            }
        }
Exemplo n.º 4
0
        internal ArrayList GetWindow(
            GetWindowCmdletBase cmdlet,
            // 20130513
            bool win32,
            Process[] processes,
            string[] processNames,
            int[] processIds,
            string[] windowNames,
            string automationId,
            string className,
            bool testMode)
        {
            ArrayList aeWndCollection =
                new ArrayList();

            cmdlet.WriteVerbose(cmdlet, "getting the root element");
            rootElement =
                System.Windows.Automation.AutomationElement.RootElement;
            if (rootElement == null)
            {
                cmdlet.WriteVerbose(cmdlet, "rootElement == null");
                return aeWndCollection;
            }
            else
            {
                cmdlet.WriteVerbose(cmdlet, "rootElement: " + rootElement.Current);
            }

            // 20130529
            bool wasFound = false;
            do {

                // 20130513
                //if (null != processes && processes.Length > 0) {
                if (win32) {

                    cmdlet.WriteVerbose(cmdlet, "getting a window via Win32 API");
                    aeWndCollection = getWindowCollectionViaWin32(cmdlet.First, cmdlet.Recurse, cmdlet.Name, cmdlet.AutomationId, cmdlet.Class);

                } else if (null != processes && processes.Length > 0) {
                    cmdlet.WriteVerbose(cmdlet, "getting a window by process");
                    aeWndCollection = getWindowCollectionFromProcess(processes, cmdlet.First, cmdlet.Recurse, cmdlet.Name, cmdlet.AutomationId, cmdlet.Class);

                } else if (null != processIds && processIds.Length > 0) {

                    cmdlet.WriteVerbose(cmdlet, "getting a window by PID");
                    aeWndCollection = getWindowCollectionByPID(processIds, cmdlet.First, cmdlet.Recurse, cmdlet.Name, cmdlet.AutomationId, cmdlet.Class);

                } else if (null != processNames && processNames.Length > 0) {

                    cmdlet.WriteVerbose(cmdlet, "getting a window by name");
                    aeWndCollection = getWindowCollectionByProcessName(processNames, cmdlet.First, cmdlet.Recurse, cmdlet.Name, cmdlet.AutomationId, cmdlet.Class);

                } else if ((null != windowNames && windowNames.Length > 0) ||
                           (null != automationId && 0 < automationId.Length) ||
                           (null != className && 0 < className.Length)) {

                    cmdlet.WriteVerbose(cmdlet, "getting a window by name, automationId, className");
                    aeWndCollection = getWindowCollectionByName(windowNames, automationId, className, cmdlet.Recurse);
                }

                // 20130228
                // filtering result window collection by SearchCriteria
                if (null != aeWndCollection && 0 < aeWndCollection.Count) {

                    cmdlet.WriteVerbose(cmdlet, "one or several windows were found by name, process name, process id or process object");

                    if (null != cmdlet.SearchCriteria && 0 < cmdlet.SearchCriteria.Length) {

                        cmdlet.WriteVerbose(cmdlet, "processing SearchCriteria");

                        aeWndCollection =
                            cmdlet.getFiltredElementsCollection(
                                cmdlet,
                                aeWndCollection);
                    }
                }

                // filtering result window collection by having a control(s) with properties as from WithControl
                if (null != aeWndCollection && 0 < aeWndCollection.Count) {

                    cmdlet.WriteVerbose(cmdlet, "one or several windows were not excluded by SearchCriteria");

                    if (null != cmdlet.WithControl && 0 < cmdlet.WithControl.Length) {

                        cmdlet.WriteVerbose(cmdlet, "processing WithControl");

                        ArrayList filteredWindows =
                            new ArrayList();

                        foreach (AutomationElement window in aeWndCollection) {

                            cmdlet.WriteVerbose(cmdlet, "searching for control(s) for every window, one by one");

                            GetControlCmdletBase cmdletCtrl =
                                new GetControlCmdletBase();
                            //cmdletCtrl.InputObject = (AutomationElement[])aeWndCollection.ToArray();
                            cmdletCtrl.InputObject =
                                // 20130316
                                //(AutomationElement[])aeWndCollection.ToArray(typeof(AutomationElement));
                                new AutomationElement[]{ window };
                            cmdletCtrl.SearchCriteria = cmdlet.WithControl;
                            cmdletCtrl.Timeout = 0;

                            cmdlet.WriteVerbose(cmdlet, "searching for one or more controls");

                            // 20130301
                            try {

                                ArrayList controlsList =
                                    GetControl(cmdletCtrl);

                                cmdlet.WriteVerbose(cmdlet, "after the search");

                                if (null != controlsList && 0 < controlsList.Count) {

                                    cmdlet.WriteVerbose(cmdlet, "ths list of controls that are on the window is not empty");

                                    filteredWindows.Add(window);
                                }

                            // 20130301
                            }

                            catch (Exception eWindowIsGone) {

                                // forcing to a next loop
                                aeWndCollection.Clear();
                                break;

                            }
                        }

                        aeWndCollection = filteredWindows;
                    }
                }

                // 20130529
                if (cmdlet.WaitNoWindow && wasFound && (null == aeWndCollection || 0 == aeWndCollection.Count)) {

                    cmdlet.Wait = false;
                }

                if (cmdlet.WaitNoWindow && !wasFound && null != aeWndCollection && 0 != aeWndCollection.Count) {

                    wasFound = true;
                    aeWndCollection = null;
                }

                if (null != aeWndCollection && aeWndCollection.Count > 0) {

                    cmdlet.WriteVerbose(cmdlet, "aeWndCollection != null");

                }
                // 20120123
                // checkTimeout(ref aeWnd, true);
                // 20120824
                //checkTimeout(cmdlet, aeWnd, true);
                checkTimeout(cmdlet, aeWndCollection, true);

                System.Threading.Thread.Sleep(Preferences.OnSleepDelay);

            } while (cmdlet.Wait);
            try {

                if (null != aeWndCollection && (int)((AutomationElement)aeWndCollection[0]).Current.ProcessId > 0) {

                    cmdlet.WriteVerbose(cmdlet, "" + aeWndCollection.ToString());
                    cmdlet.WriteVerbose(cmdlet,
                                        "aeWnd.Current.GetType() = " +
                                        ((AutomationElement)aeWndCollection[0]).GetType().Name);

                } // 20120127

                CurrentData.CurrentWindow = (AutomationElement)aeWndCollection[aeWndCollection.Count -1];
                // 20120824
                //return aeWnd;
                //return aeWndCollection;
            } catch (Exception eEvaluatingWindowAndWritingToPipeline) {

                //WriteDebug(cmdlet, "exception: " +
                cmdlet.WriteVerbose(
                    cmdlet,
                    "exception: " +
                    eEvaluatingWindowAndWritingToPipeline.Message);

                cmdlet.WriteVerbose(this, "<<<< ==  ==  writing/nullifying CurrentWindow  ==  == >>>>>");

                CurrentData.CurrentWindow = null;

            }

            return aeWndCollection;
        }