UIAutomation.WizardRunCmdletBase.RunWizardInAutomaticMode C# (CSharp) Метод

RunWizardInAutomaticMode() защищенный Метод

protected RunWizardInAutomaticMode ( WizardRunCmdletBase cmdlet, Wizard wizard ) : void
cmdlet WizardRunCmdletBase
wizard Wizard
Результат void
        protected internal void RunWizardInAutomaticMode(WizardRunCmdletBase cmdlet, Wizard wizard)
        {
            cmdlet.StartDate =
                DateTime.Now;
            
            string previousStepName = string.Empty;
            
            // 20140314
            // while (cmdlet.RunWizardGetWindowScriptBlocks(wizard, null)) {
            while (cmdlet.RunWizardGetWindowScriptBlocks(wizard, null) && !wizard.StopImmediately) {
                
                if (null != CurrentData.CurrentWindow) {
                    
                    cmdlet.WriteInfo(cmdlet, "Getting the active step");
                    
                    // selector of steps' unique controls
                    WizardStep currentStep = null;
                    try {
                        currentStep = wizard.GetActiveStep();
                    } catch (Exception) {
                        continue;
                    }
                    
                    // 20130506
                    //WizardCollection.CurrentWizard = wizard;

                    if (null != currentStep) {
                        
                        cmdlet.WriteVerbose(
                            cmdlet,
                            "current step name = '" +
                            currentStep.Name +
                            "'");
                        
                        cmdlet.WriteInfo(cmdlet, "the active step is '" + currentStep.Name + "'");
                        
                        // 20130327
                        if (previousStepName == currentStep.Name) {
                            
                            InterruptOnTimeoutExpiration(cmdlet, wizard);
                            
                            // 20130508
                            cmdlet.WriteInfo(cmdlet, "the same step, sleeping...");
                            Thread.Sleep(Preferences.OnSelectWizardStepDelay);
                            continue;
                        }
                        previousStepName = currentStep.Name;

                        object[] currentParameters = GetStepParameters(wizard, currentStep);

                        cmdlet.WriteInfo(cmdlet, "running step '" + currentStep.Name + "'");
                        cmdlet.WriteInfo(cmdlet, "parameters: " + ConvertObjectArrayToString(currentParameters));
                        RunCurrentStepParameters(cmdlet, wizard, currentStep, currentParameters);

                        // 20130325
                        if (wizard.StopImmediately) {

                            cmdlet.WriteInfo(cmdlet, "stopping the wizard");
                            break;
                        }
                        
                        #region commented
                        // 20130319 - need moving to an appropriate place
                        //cmdlet.RunWizardStepCancelScriptBlocks(
                        //    cmdlet,
                        //    currentStep,
                        //    currentStep.StepCancelActionParameters);
                        #endregion commented
                        
                        cmdlet.StartDate =
                            DateTime.Now;
                        
                    } else {
                        
                        cmdlet.WriteVerbose(
                            cmdlet,
                            "current step is still null");
                        
                        // 20130508
                        // temporary
                        // profiling
                        cmdlet.WriteInfo(cmdlet, "the current step is still null");

                        // 20130712
                        //InterruptOnTimeoutExpiration(cmdlet, wizard);
                        bool interrupt1 = InterruptOnTimeoutExpiration(cmdlet, wizard);
                        // 20130402
                        // 20130712
                        //break;
                        if (interrupt1) {
                            break;
                        }
                        
                    }
                } else {

                    cmdlet.WriteVerbose(
                        cmdlet,
                        "window is still null");
                    
                    // 20130508
                    // temporary
                    // profiling
                    cmdlet.WriteInfo(cmdlet, "window is still null");
                    
                    // 20130402
                    // 20130712
                    //InterruptOnTimeoutExpiration(cmdlet, wizard);
                    bool interrupt2 = InterruptOnTimeoutExpiration(cmdlet, wizard);
                    if (interrupt2) {
                        break;
                    }
                    // 20130712
                    //break;
                }
            }
        }

Usage Example

Пример #1
0
        public static void InvokeWizard(WizardRunCmdletBase cmdlet)
        {
            Wizard wzd = cmdlet.GetWizard(cmdlet.Name);

            if (null == wzd) {

                cmdlet.WriteError(cmdlet, "Couldn't get the wizard you asked for", "NoSuchWizard", ErrorCategory.InvalidArgument, true);
            } else {

                // publish the wizard as a global variable
                WizardCollection.CurrentWizard = wzd;

            #region commented
            //                try {
            //
            //                    System.Management.Automation.Runspaces.Runspace.DefaultRunspace.SessionStateProxy.GetVariable(".SessionStateProxy.PSVariable.Set(
            //                        "Wizard",
            //                        wzd);
            //
            ////                    testRunSpace.SessionStateProxy.SetVariable(
            ////                        variableName,
            ////                        variableValue);
            ////                    result = true;
            //                }
            //                catch (Exception eWizardVariable) {
            //
            //                    cmdlet.WriteError(
            //                        cmdlet,
            //                        eWizardVariable.Message,
            //                        "VariablePublishingFailed",
            //                        ErrorCategory.InvalidOperation,
            //                        true);
            //                }
            #endregion commented

                // 20130322
                //wzd.Automatic = cmdlet.Automatic;
                //wzd.ForwardDirection = cmdlet.ForwardDirection;

                // 20130322
                if (null != cmdlet.Directions && 0 < cmdlet.DirectionsDictionaries.Count) {

                    PrepareStepDirections(cmdlet, wzd);
                }

                // scriptblocks' parameters
                if (null != cmdlet.ParametersDictionaries && 0 < cmdlet.ParametersDictionaries.Count) {

                    PrepareStepParameters(cmdlet, wzd);
                }

                cmdlet.WriteVerbose(cmdlet, "running Wizard StartAction scriptblocks");

                // 20130318
                //cmdlet.RunWizardStartScriptBlocks(cmdlet, wzd);
                // 20130325
                //cmdlet.RunWizardStartScriptBlocks(cmdlet, wzd, null);
                cmdlet.RunWizardStartScriptBlocks(cmdlet, wzd, wzd.StartActionParameters);

                cmdlet.WriteVerbose(cmdlet, "running Wizard in the automated mode");

                cmdlet.RunWizardInAutomaticMode(cmdlet, wzd);

                if (cmdlet.Quiet) {
                    cmdlet.WriteObject(cmdlet, true);
                } else {
                    cmdlet.WriteObject(cmdlet, wzd);
                }
            }
        }
All Usage Examples Of UIAutomation.WizardRunCmdletBase::RunWizardInAutomaticMode