Description of Wizard.
Exemplo n.º 1
0
 public static void CreateWizard(NewUiaWizardCommand cmdlet)
 {
     if (!cmdlet.ValidateWizardName(cmdlet.Name)) {
         
         cmdlet.WriteVerbose(
             cmdlet,
             "The wizard name you selected is already in use");
         
         cmdlet.WriteError(
             cmdlet,
             "The wizard name you selected is already in use",
             "NameInUse",
             ErrorCategory.InvalidArgument,
             true);
     }
     
     cmdlet.WriteVerbose(cmdlet, "wizard name validated");
     var wzd = new Wizard(cmdlet.Name);
     cmdlet.WriteVerbose(cmdlet, "wizard object created");
     wzd.StartAction = cmdlet.StartAction;
     wzd.StopAction = cmdlet.StopAction;
     wzd.DefaultStepForwardAction = cmdlet.DefaultStepForwardAction;
     wzd.DefaultStepBackwardAction = cmdlet.DefaultStepBackwardAction;
     wzd.DefaultStepCancelAction = cmdlet.DefaultStepCancelAction;
     // 20130319
     //wzd.DefaultStepGetWindowAction = cmdlet.DefaultStepGetWindowAction;
     wzd.GetWindowAction = cmdlet.GetWindowAction;
     cmdlet.WriteVerbose(cmdlet, "the wizard is fulfilled with properties");
     
     cmdlet.WriteObject(cmdlet, wzd);
 }
Exemplo n.º 2
0
        internal override void Execute()
        {
            NewUIAWizardCommand cmdlet =
                (NewUIAWizardCommand)this.Cmdlet;

            //if (!ValidateWizardName(Name)) {
            if (!cmdlet.ValidateWizardName(cmdlet.Name)) {
            //                ErrorRecord err =
            //                    new ErrorRecord(
            //                        new Exception("The wizard name you selected is already in use"),
            //                        "NameInUse",
            //                        ErrorCategory.InvalidArgument,
            //                        this.Name);
            //                err.ErrorDetails =
            //                    new ErrorDetails(
            //                        "The wizard name you selected is already in use");
            //                //ThrowTerminatingError(err);
            //                this.WriteError(this, err, true);

                cmdlet.WriteError(
                    cmdlet,
                    "The wizard name you selected is already in use",
                    "NameInUse",
                    ErrorCategory.InvalidArgument,
                    true);

                // for unit tests
                return;
            }
            //this.WriteVerbose(this, "wizard name validated");
            cmdlet.WriteVerbose(cmdlet, "wizard name validated");
            Wizard wzd = new Wizard(cmdlet.Name);
            //this.WriteVerbose(this, "wizard object created");
            cmdlet.WriteVerbose(cmdlet, "wizard object created");
            if (cmdlet.StartAction != null && cmdlet.StartAction.Length > 0) {
                wzd.StartAction = cmdlet.StartAction;
            }
            //this.WriteObject(this, wzd);
            cmdlet.WriteObject(cmdlet, wzd);
        }
Exemplo n.º 3
0
        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;
                }
            }
        }
Exemplo n.º 4
0
 internal object[] GetStepParameters(Wizard wizard, WizardStep currentStep)
 {
     object[] currentParameters = null;
     switch (currentStep.ToDo) {
         case WizardStepActions.Forward:
             currentParameters = currentStep.StepForwardActionParameters;
             break;
         case WizardStepActions.Backward:
             currentParameters = currentStep.StepBackwardActionParameters;
             break;
         case WizardStepActions.Cancel:
             currentParameters = currentStep.StepCancelActionParameters;
             break;
         case WizardStepActions.Stop:
             wizard.StopImmediately = true;
             currentParameters = wizard.StopActionParameters;
             break;
         default:
             throw new Exception("Invalid value for WizardStepActions on getting steps' parameters");
     }
     return currentParameters;
 }
Exemplo n.º 5
0
 internal void RunCurrentStepParameters(WizardRunCmdletBase cmdlet, Wizard wizard, WizardStep currentStep, object[] currentParameters)
 {
     // 20130606
     //cmdlet.WriteVerbose(cmdlet, "running scriptblocks for the '" + currentStep.Name + "' step");
     cmdlet.WriteInfo(cmdlet, "running scriptblocks for the '" + currentStep.Name + "' step");
     
     if (WizardStepActions.Stop == currentStep.ToDo) {
         
         cmdlet.WriteInfo(cmdlet, "running scriptblocks from the StopAction scriptblock set");
         // 20130819
         // cmdlet.RunWizardStopScriptBlocks(cmdlet, wizard, currentParameters);
         cmdlet.RunWizardStopScriptBlocks(cmdlet, wizard, currentParameters, true);
         // 20130508
         // temporary
         // profiling
         //cmdlet.WriteVerbose(cmdlet, "StopAction has finished, exiting...");
         cmdlet.WriteInfo(cmdlet, "StopAction has finished, exiting...");
         return;
     } else {
         // 20130508
         cmdlet.WriteInfo(cmdlet, "running scriptblocks for step '" + currentStep.Name + "', " + currentStep.ToDo.ToString());
         cmdlet.RunWizardStepScriptBlocks(cmdlet, currentStep, currentStep.ToDo, currentParameters);
         cmdlet.WriteInfo(cmdlet, "Forward, Backward or Cancel scriptblocks have finished");
     }
 }
Exemplo n.º 6
0
        // 20130325

        // these were an action in the Parameters hashtable (the outer hashtable):
        // @{step="Step05PrinterData";action="forward";parameters=@{action="forward";list=@("printer_2","port_2")}}
        #region commented
        //                            try {
//
        //                                switch (dictParameters["ACTION"].ToString().ToUpper()) {
        //                                    case "FORWARD":
        //                                        stepWithParameters.ToDo = WizardStepActions.Forward;
        //                                        break;
        //                                    case "BACKWARD":
        //                                        stepWithParameters.ToDo = WizardStepActions.Backward;
        //                                        break;
        //                                    case "CANCEL":
        //                                        stepWithParameters.ToDo = WizardStepActions.Cancel;
        //                                        break;
        //                                    case "STOP":
        //                                        stepWithParameters.ToDo = WizardStepActions.Stop;
        //                                        break;
        //                                    default:
        //                                        // nothing to do
        //                                        break;
        //                                }
        //                            }
        //                            catch (Exception eActionType) {
//
        //                                cmdlet.WriteVerbose(
        //                                    cmdlet,
        //                                    "The action parameter: " +
        //                                    eActionType.Message);
        //                            }
        #endregion commented

        // these were a hashtable of parameters in the outerhashtable
        // @{step="Step05PrinterData";action="forward";parameters=@{action="forward";list=@("printer_2","port_2")}}
        #region commented
        //                                Hashtable parameters =
        //                                    (Hashtable)dictParameters["PARAMETERS"];
//
        //                                if (null != parameters) {
//
        //                                    switch (parameters["ACTION"].ToString().ToUpper()) {
        //                                        case "FORWARD":
        //                                            stepWithParameters.StepForwardActionParameters = (object[])parameters["LIST"];
        //                                            break;
        //                                        case "BACKWARD":
        //                                            stepWithParameters.StepBackwardActionParameters = (object[])parameters["LIST"];
        //                                            break;
        //                                        case "CANCEL":
        //                                            stepWithParameters.StepCancelActionParameters = (object[])parameters["LIST"];
        //                                            break;
        //                                        default:
        //                                            // nothing to do
        //                                            break;
        //                                    }
//
        //                                } else {
//
        //                                    cmdlet.WriteVerbose(
        //                                        cmdlet,
        //                                        "Parameters: " +
        //                                        "parameters hashtable is null.");
        //                                }
        #endregion commented
        // 20130322
        internal static void PrepareStepParameters(WizardRunCmdletBase cmdlet, Wizard wzd)
        {
            foreach (Dictionary <string, object> dictParameters in cmdlet.ParametersDictionaries)
            {
                WizardStep stepWithParameters     = null;
                string     stepWithParametersName = string.Empty;
                try {
                    stepWithParametersName = dictParameters["STEP"].ToString();

                    if ("0" == stepWithParametersName)
                    {
                        //
                    }
                    else
                    {
                        stepWithParameters = wzd.GetStep(stepWithParametersName);

                        if (null == stepWithParameters)
                        {
                            cmdlet.WriteError(
                                cmdlet,
                                "Failed to get a step with name '" +
                                stepWithParametersName +
                                "' in the Parameters hashtable.",
                                "FailedToGetStep",
                                ErrorCategory.InvalidArgument,
                                true);
                        }
                    }

                    try {
                        switch (dictParameters["ACTION"].ToString().ToUpper())
                        {
                        case "FORWARD":
                            stepWithParameters.StepForwardActionParameters = (object[])dictParameters["PARAMETERS"];
                            break;

                        case "BACKWARD":
                            stepWithParameters.StepBackwardActionParameters = (object[])dictParameters["PARAMETERS"];
                            break;

                        case "CANCEL":
                            stepWithParameters.StepCancelActionParameters = (object[])dictParameters["PARAMETERS"];
                            break;

                        case "STOP":
                            wzd.StopActionParameters = (object[])dictParameters["PARAMETERS"];
                            break;

                        case "START":
                            wzd.StartActionParameters = (object[])dictParameters["PARAMETERS"];
                            break;

                        default:

                            break;
                        }
                    } catch (Exception eParameters) {
                        cmdlet.WriteVerbose(
                            cmdlet,
                            "Parameters: " +
                            eParameters.Message);
                    }
                } catch (Exception eParametersDictionaries) {
                    cmdlet.WriteError(
                        cmdlet,
                        "Failed to parse parameters for step '" +
                        stepWithParametersName +
                        "'. " +
                        eParametersDictionaries.Message,
                        "FailedToParseParameters",
                        ErrorCategory.InvalidArgument,
                        true);
                }
            }
        }
Exemplo n.º 7
0
        protected internal void RunWizardStopScriptBlocks(WizardCmdletBase cmdlet, Wizard wizard, object[] parameters, bool hereMustBeStopAction)
        {
            
            if (hereMustBeStopAction && (null == wizard.StopAction || 0 == wizard.StopAction.Length))
//                cmdlet.WriteVerbose(cmdlet, "there is no any StopAction scriptblock");
                //throw new Exception("There are no StopAction scriptblocks, define at least one");
                cmdlet.WriteError(
                    cmdlet,
                    "There are no StopAction scriptblocks, define at least one",
                    "NoStopActionScriptblocks",
                    ErrorCategory.InvalidArgument,
                    true);
            
            runTwoScriptBlockCollections(
                null,
                wizard.StopAction,
                cmdlet,
                parameters);

        }
Exemplo n.º 8
0
 internal static void PrepareStepDirections(WizardRunCmdletBase cmdlet, Wizard wzd)
 {
     foreach (Dictionary<string, object> dictDirections in cmdlet.DirectionsDictionaries) {
         WizardStep stepWithDirections = null;
         string stepWithDirectionsName = string.Empty;
         try {
             
             stepWithDirectionsName = dictDirections["STEP"].ToString();
             
             if ("0" == stepWithDirectionsName) {
                 //
             } else {
             
                 stepWithDirections = wzd.GetStep(stepWithDirectionsName);
                 
                 if (null == stepWithDirections) {
                     cmdlet.WriteError(
                         cmdlet,
                         "Failed to get a step with name '" +
                         stepWithDirectionsName +
                         "' in the Directions hashtable.",
                         "FailedToGetStep",
                         ErrorCategory.InvalidArgument,
                         true);
                 }
             }
             
             try {
                 switch (dictDirections["ACTION"].ToString().ToUpper()) {
                     case "FORWARD":
                         stepWithDirections.ToDo = WizardStepActions.Forward;
                         break;
                     case "BACKWARD":
                         stepWithDirections.ToDo = WizardStepActions.Backward;
                         break;
                     case "CANCEL":
                         stepWithDirections.ToDo = WizardStepActions.Cancel;
                         break;
                     case "STOP":
                         stepWithDirections.ToDo = WizardStepActions.Stop;
                         break;
                     default:
                         throw new Exception("Invalid value for directions");
                         //stepWithDirections.ToDo = WizardStepActions.Forward;
                         //break;
                 }
                 
             } catch (Exception eActionType) {
                 
                 cmdlet.WriteVerbose(
                     cmdlet,
                     "The action parameter: " +
                     eActionType.Message);
             }
         } catch (Exception eDirectionsDictionaries) {
             cmdlet.WriteError(
                 cmdlet,
                 "Failed to parse directions for step '" +
                 stepWithDirectionsName +
                 "'. " +
                 eDirectionsDictionaries.Message,
                 "FailedToParseDirections",
                 ErrorCategory.InvalidArgument,
                 true);
         }
     }
 }
Exemplo n.º 9
0
        // 20130325

        // these were an action in the Parameters hashtable (the outer hashtable):
        // @{step="Step05PrinterData";action="forward";parameters=@{action="forward";list=@("printer_2","port_2")}}
        #region commented
        //                            try {
//
        //                                switch (dictParameters["ACTION"].ToString().ToUpper()) {
        //                                    case "FORWARD":
        //                                        stepWithParameters.ToDo = WizardStepActions.Forward;
        //                                        break;
        //                                    case "BACKWARD":
        //                                        stepWithParameters.ToDo = WizardStepActions.Backward;
        //                                        break;
        //                                    case "CANCEL":
        //                                        stepWithParameters.ToDo = WizardStepActions.Cancel;
        //                                        break;
        //                                    case "STOP":
        //                                        stepWithParameters.ToDo = WizardStepActions.Stop;
        //                                        break;
        //                                    default:
        //                                        // nothing to do
        //                                        break;
        //                                }
        //                            }
        //                            catch (Exception eActionType) {
//
        //                                cmdlet.WriteVerbose(
        //                                    cmdlet,
        //                                    "The action parameter: " +
        //                                    eActionType.Message);
        //                            }
        #endregion commented

        // these were a hashtable of parameters in the outerhashtable
        // @{step="Step05PrinterData";action="forward";parameters=@{action="forward";list=@("printer_2","port_2")}}
        #region commented
        //                                Hashtable parameters =
        //                                    (Hashtable)dictParameters["PARAMETERS"];
//
        //                                if (null != parameters) {
//
        //                                    switch (parameters["ACTION"].ToString().ToUpper()) {
        //                                        case "FORWARD":
        //                                            stepWithParameters.StepForwardActionParameters = (object[])parameters["LIST"];
        //                                            break;
        //                                        case "BACKWARD":
        //                                            stepWithParameters.StepBackwardActionParameters = (object[])parameters["LIST"];
        //                                            break;
        //                                        case "CANCEL":
        //                                            stepWithParameters.StepCancelActionParameters = (object[])parameters["LIST"];
        //                                            break;
        //                                        default:
        //                                            // nothing to do
        //                                            break;
        //                                    }
//
        //                                } else {
//
        //                                    cmdlet.WriteVerbose(
        //                                        cmdlet,
        //                                        "Parameters: " +
        //                                        "parameters hashtable is null.");
        //                                }
        #endregion commented
        // 20130322
        internal static void PrepareStepParameters(WizardRunCmdletBase cmdlet, Wizard wzd)
        {
            foreach (Dictionary<string, object> dictParameters in cmdlet.ParametersDictionaries) {
                WizardStep stepWithParameters = null;
                string stepWithParametersName = string.Empty;
                try {
                    stepWithParametersName = dictParameters["STEP"].ToString();
                    
                    if ("0" == stepWithParametersName) {
                        //
                    } else {
                        stepWithParameters = wzd.GetStep(stepWithParametersName);
                        
                        if (null == stepWithParameters) {
                            cmdlet.WriteError(
                                cmdlet, 
                                "Failed to get a step with name '" +
                                stepWithParametersName +
                                "' in the Parameters hashtable.",
                                "FailedToGetStep",
                                ErrorCategory.InvalidArgument,
                                true);
                        }
                    }
                    
                    try {
                        switch (dictParameters["ACTION"].ToString().ToUpper()) {
                            case "FORWARD":
                                stepWithParameters.StepForwardActionParameters = (object[])dictParameters["PARAMETERS"];
                                break;
                            case "BACKWARD":
                                stepWithParameters.StepBackwardActionParameters = (object[])dictParameters["PARAMETERS"];
                                break;
                            case "CANCEL":
                                stepWithParameters.StepCancelActionParameters = (object[])dictParameters["PARAMETERS"];
                                break;
                            case "STOP":
                                wzd.StopActionParameters = (object[])dictParameters["PARAMETERS"];
                                break;
                            case "START":
                                wzd.StartActionParameters = (object[])dictParameters["PARAMETERS"];
                                break;
                            default:

                                break;
                        }
                    } catch (Exception eParameters) {

                        cmdlet.WriteVerbose(
                            cmdlet,
                            "Parameters: " +
                            eParameters.Message);
                    }

                } catch (Exception eParametersDictionaries) {

                    cmdlet.WriteError(
                        cmdlet,
                        "Failed to parse parameters for step '" +
                        stepWithParametersName +
                        "'. " +
                        eParametersDictionaries.Message,
                        "FailedToParseParameters",
                        ErrorCategory.InvalidArgument,
                        true);
                }
            }
        }
Exemplo n.º 10
0
 // 20130325
 // 20130329
 // 20130318
 //cmdlet.RunWizardStepScriptBlocks(cmdlet, currentStep, cmdlet.ForwardDirection);
 // 20130321
 //cmdlet.ForwardDirection,
 // 20130321
 //cmdlet.ForwardDirection ? currentStep.StepForwardActionParameters : currentStep.StepBackwardActionParameters);
 internal void RunCurrentStepParameters(WizardRunCmdletBase cmdlet, Wizard wizard, WizardStep currentStep, object[] currentParameters)
 {
     if (WizardStepActions.Stop == currentStep.ToDo) {
         cmdlet.RunWizardStopScriptBlocks(cmdlet, wizard, currentParameters);
         cmdlet.WriteVerbose(cmdlet, "StopAction has finished, exiting...");
         return;
     } else {
         cmdlet.RunWizardStepScriptBlocks(cmdlet, currentStep, currentStep.ToDo, currentParameters);
     }
 }
Exemplo n.º 11
0
        // 20130329
        // running the StopAction script after timeout expired
        internal void InterruptOnTimeoutExpiration(WizardRunCmdletBase cmdlet, Wizard wizard)
        {
            System.DateTime nowDate = System.DateTime.Now;
            if ((nowDate - cmdlet.StartDate).TotalSeconds > (Preferences.Timeout / 1000)) {

                cmdlet.WriteVerbose(
                    cmdlet,
                    "Timout expired. Running the StopAction scriptblock");

                cmdlet.RunWizardStopScriptBlocks(cmdlet, wizard, wizard.StopActionParameters);

                cmdlet.WriteVerbose(
                    cmdlet,
                    "outputting the wizard");

                if (this.Quiet) {
                    cmdlet.WriteObject(cmdlet, false);
                    return;
                } else {
                    cmdlet.WriteError(cmdlet, "Timeout expired", "TimeoutExpired", ErrorCategory.OperationTimeout, true);
                }
            }
        }
Exemplo n.º 12
0
        protected internal void RunWizardInAutomaticMode(WizardRunCmdletBase cmdlet, Wizard wizard)
        {
            cmdlet.StartDate =
                System.DateTime.Now;

            string previousStepName = string.Empty;

            while (cmdlet.RunWizardGetWindowScriptBlocks(cmdlet, wizard, null)) {

                if (null != (CurrentData.CurrentWindow as AutomationElement)) {

                    cmdlet.WriteVerbose(
                        cmdlet,
                        "the window: name = '" +
                        CurrentData.CurrentWindow.Current.Name +
                        "', automationId = '" +
                        CurrentData.CurrentWindow.Current.AutomationId +
                        "', class = '" +
                        CurrentData.CurrentWindow.Current.ClassName +
                        "', processId = " +
                        CurrentData.CurrentWindow.Current.ProcessId.ToString() +
                        ".");

                    cmdlet.WriteInfo(cmdlet, "Getting the active step");

                    // selector of steps' unique controls
                    WizardStep currentStep =
                        wizard.GetActiveStep();

                    // 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...");
                            System.Threading.Thread.Sleep(Preferences.OnSelectWizardStepDelay);
                            continue;
                        }
                        previousStepName = currentStep.Name;

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

                        cmdlet.WriteInfo(cmdlet, "running step '" + currentStep.Name + "'");
                        cmdlet.WriteInfo(cmdlet, "parameters: " + this.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 =
                            System.DateTime.Now;

                    } else {

                        cmdlet.WriteVerbose(
                            cmdlet,
                            "current step is still null");

                        // 20130508
                        // temporary
                        // profiling
                        cmdlet.WriteInfo(cmdlet, "the current step is still null");

                        InterruptOnTimeoutExpiration(cmdlet, wizard);
                        // 20130402
                        break;

                    }
                } else {

                    cmdlet.WriteVerbose(
                        cmdlet,
                        "window is still null");

                    // 20130508
                    // temporary
                    // profiling
                    cmdlet.WriteInfo(cmdlet, "window is still null");

                    // 20130402
                    InterruptOnTimeoutExpiration(cmdlet, wizard);
                    break;
                }
            }
        }
Exemplo n.º 13
0
        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;
                }
            }
        }
Exemplo n.º 14
0
        internal static void PrepareStepDirections(WizardRunCmdletBase cmdlet, Wizard wzd)
        {
            foreach (Dictionary <string, object> dictDirections in cmdlet.DirectionsDictionaries)
            {
                WizardStep stepWithDirections     = null;
                string     stepWithDirectionsName = string.Empty;
                try {
                    stepWithDirectionsName = dictDirections["STEP"].ToString();

                    if ("0" == stepWithDirectionsName)
                    {
                        //
                    }
                    else
                    {
                        stepWithDirections = wzd.GetStep(stepWithDirectionsName);

                        if (null == stepWithDirections)
                        {
                            cmdlet.WriteError(
                                cmdlet,
                                "Failed to get a step with name '" +
                                stepWithDirectionsName +
                                "' in the Directions hashtable.",
                                "FailedToGetStep",
                                ErrorCategory.InvalidArgument,
                                true);
                        }
                    }

                    try {
                        switch (dictDirections["ACTION"].ToString().ToUpper())
                        {
                        case "FORWARD":
                            stepWithDirections.ToDo = WizardStepActions.Forward;
                            break;

                        case "BACKWARD":
                            stepWithDirections.ToDo = WizardStepActions.Backward;
                            break;

                        case "CANCEL":
                            stepWithDirections.ToDo = WizardStepActions.Cancel;
                            break;

                        case "STOP":
                            stepWithDirections.ToDo = WizardStepActions.Stop;
                            break;

                        default:
                            throw new Exception("Invalid value for directions");
                            //stepWithDirections.ToDo = WizardStepActions.Forward;
                            //break;
                        }
                    } catch (Exception eActionType) {
                        cmdlet.WriteVerbose(
                            cmdlet,
                            "The action parameter: " +
                            eActionType.Message);
                    }
                } catch (Exception eDirectionsDictionaries) {
                    cmdlet.WriteError(
                        cmdlet,
                        "Failed to parse directions for step '" +
                        stepWithDirectionsName +
                        "'. " +
                        eDirectionsDictionaries.Message,
                        "FailedToParseDirections",
                        ErrorCategory.InvalidArgument,
                        true);
                }
            }
        }
Exemplo n.º 15
0
 public static bool GetResult_IsStepActive(Hashtable[] searchCriteria, IUiEltCollection elements)
 {
     var step = new WizardStep("stepName", 1) {
         Description = "description",
         SearchCriteria = searchCriteria
     };
     
     var wizard = new Wizard("wizardName");
     
     return wizard.IsStepActive(step, elements);
 }
Exemplo n.º 16
0
 protected internal void RunWizardScriptBlocks(WizardCmdletBase cmdlet, Wizard wizard)
 {
     runTwoScriptBlockCollections(
         null,
         wizard.StartAction,
         cmdlet);
 }
Exemplo n.º 17
0
        protected internal void RunWizardInAutomaticMode(WizardRunCmdletBase cmdlet, Wizard wizard)
        {
            // 20130320
            //CurrentData.CurrentWindow = AutomationElement.RootElement;

            cmdlet.StartDate =
                System.DateTime.Now;

            // 20130327
            string previousStepName = string.Empty;

            // 20130320
            //while ((null != CurrentData.CurrentWindow)) {
            while (cmdlet.RunWizardGetWindowScriptBlocks(cmdlet, wizard, null)) {

                #region commented
                // 20130325
            //			    if (wizard.StopImmediately) {
            //			        break;
            //			    }

                // 20130320
                //CurrentData.CurrentWindow = null;
                // 20130318
                //cmdlet.RunWizardGetWindowScriptBlocks(cmdlet, wizard);
                // 20130320
                //cmdlet.RunWizardGetWindowScriptBlocks(cmdlet, wizard, null);
                #endregion commented

                if (null != (CurrentData.CurrentWindow as AutomationElement)) {

                    cmdlet.WriteVerbose(
                        cmdlet,
                        "the window: name = '" +
                        CurrentData.CurrentWindow.Current.Name +
                        "', automationId = '" +
                        CurrentData.CurrentWindow.Current.AutomationId +
                        "', class = '" +
                        CurrentData.CurrentWindow.Current.ClassName +
                        "', processId = " +
                        CurrentData.CurrentWindow.Current.ProcessId.ToString() +
                        ".");

                    // selector of steps' unique controls
                    WizardStep currentStep =
                        wizard.GetActiveStep();

                    if (null != currentStep) {

                        cmdlet.WriteVerbose(
                            cmdlet,
                            "current step name = '" +
                            currentStep.Name +
                            "'");

                        // 20130327
                        if (previousStepName == currentStep.Name) {

                            InterruptOnTimeoutExpiration(cmdlet, wizard);

                            System.Threading.Thread.Sleep(Preferences.OnSelectWizardStepDelay);
                            continue;
                        }
                        previousStepName = currentStep.Name;

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

                        RunCurrentStepParameters(cmdlet, wizard, currentStep, currentParameters);

                        // 20130325
                        if (wizard.StopImmediately) {

                            break;
                        }

                        #region commented
                        // 20130319 - need moving to an appropriate place
                        //cmdlet.RunWizardStepCancelScriptBlocks(
                        //    cmdlet,
                        //    currentStep,
                        //    currentStep.StepCancelActionParameters);
                        #endregion commented

                        cmdlet.StartDate =
                            System.DateTime.Now;

                    } else {

                        cmdlet.WriteVerbose(
                            cmdlet,
                            "current step is still null");

                        InterruptOnTimeoutExpiration(cmdlet, wizard);
                        // 20130402
                        break;

                    }
                } else {

                    cmdlet.WriteVerbose(
                        cmdlet,
                        "window is still null");

                    // 20130402
                    InterruptOnTimeoutExpiration(cmdlet, wizard);
                    break;
                }
            }
        }
Exemplo n.º 18
0
        // 20130318
        //protected internal void RunWizardGetWindowScriptBlocks(WizardCmdletBase cmdlet, Wizard wizard)
        protected internal bool RunWizardGetWindowScriptBlocks(WizardCmdletBase cmdlet, Wizard wizard, object[] parameters)
        {
            bool result = false;

            // 20130508
            // temporary
            // profiling
            cmdlet.WriteInfo(cmdlet, "running the GetWindowAction scriptblock");
            cmdlet.WriteInfo(cmdlet, "parameters" + parameters);

            try {
                runTwoScriptBlockCollections(
                    null,
                    // 20130319
                    //wizard.DefaultStepGetWindowAction,
                    wizard.GetWindowAction,
                    // 20130318
                    //cmdlet);
                    cmdlet,
                    parameters);

                if (null != CurrentData.CurrentWindow) {
                    result = true;
                }
            }
            catch {}

            // 20130508
            // temporary
            // profiling
            cmdlet.WriteInfo(cmdlet, "the result of the GetWindowAction scriptblock run is " + result.ToString());

            return result;
        }
Exemplo n.º 19
0
        // 20130318
        //protected internal void RunWizardGetWindowScriptBlocks(WizardCmdletBase cmdlet, Wizard wizard)
        protected internal bool RunWizardGetWindowScriptBlocks(WizardCmdletBase cmdlet, Wizard wizard, object[] parameters)
        {
            bool result = false;

            try {
                runTwoScriptBlockCollections(
                    null,
                    // 20130319
                    //wizard.DefaultStepGetWindowAction,
                    wizard.GetWindowAction,
                    // 20130318
                    //cmdlet);
                    cmdlet,
                    parameters);

                if (null != CurrentData.CurrentWindow) {
                    result = true;
                }
            }
            catch {}

            return result;
        }
Exemplo n.º 20
0
 protected internal void RunWizardStartScriptBlocks(WizardCmdletBase cmdlet, Wizard wizard, object[] parameters)
 {
     runTwoScriptBlockCollections(
         null,
         wizard.StartAction,
         cmdlet,
         parameters);
 }
Exemplo n.º 21
0
 // 20130329
 // running the StopAction script after timeout expired
 
 internal bool InterruptOnTimeoutExpiration(WizardRunCmdletBase cmdlet, Wizard wizard)
 {
     // 20130712
     bool interrupt = false;
     
     DateTime nowDate = DateTime.Now;
     if (!((nowDate - cmdlet.StartDate).TotalSeconds > Preferences.Timeout/1000)) return interrupt;
     
     cmdlet.WriteVerbose(
         cmdlet,
         "Timout expired. Running the StopAction scriptblock");
     
     cmdlet.RunWizardStopScriptBlocks(cmdlet, wizard, wizard.StopActionParameters, false);
         
     cmdlet.WriteVerbose(
         cmdlet,
         "outputting the wizard");
         
     if (Quiet) {
         cmdlet.WriteObject(cmdlet, false);
         return interrupt;
     } else {
         cmdlet.WriteError(cmdlet, "Timeout expired", "TimeoutExpired", ErrorCategory.OperationTimeout, true);
     }
     
     interrupt = true;
     
     return interrupt;
 }
Exemplo n.º 22
0
 protected internal bool RunWizardGetWindowScriptBlocks(Wizard wizard, object[] parameters)
 {
     bool result = false;
     
     // 20130508
     // temporary
     // profiling
     // 20140207
     this.WriteInfo(this, "running the GetWindowAction scriptblock");
     this.WriteInfo(this, "parameters" + parameters);
     
     try {
         runTwoScriptBlockCollections(
             null,
             wizard.GetWindowAction,
             this,
             parameters);
             
         result |= null != CurrentData.CurrentWindow;
         /*
         if (null != CurrentData.CurrentWindow) {
             result = true;
         }
         */
     }
     catch {}
     
     // 20130508
     // temporary
     // profiling
     // 20140207
     WriteInfo(this, "the result of the GetWindowAction scriptblock run is " + result.ToString());
     
     return result;
 }
Exemplo n.º 23
0
        public static void InvokeWizard(WizardRunCmdletBase cmdlet)
        {
            cmdlet.WriteVerbose(
                cmdlet,
                "Getting the wizard");
            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
            {
                cmdlet.WriteVerbose(
                    cmdlet,
                    "The wizard has been obtained from the collection");

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

                cmdlet.WriteInfo(cmdlet, "the current wizard is '" + WizardCollection.CurrentWizard.Name + "'");
                #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

                if (null != cmdlet.Directions && 0 < cmdlet.DirectionsDictionaries.Count)
                {
                    cmdlet.WriteVerbose(cmdlet, "Preparing step directions");
                    PrepareStepDirections(cmdlet, wzd);
                }

                // scriptblocks' parameters
                if (null != cmdlet.ParametersDictionaries && 0 < cmdlet.ParametersDictionaries.Count)
                {
                    cmdlet.WriteVerbose(cmdlet, "Preparing step parameters");
                    PrepareStepParameters(cmdlet, wzd);
                }

                // 20130508
                // temporary
                cmdlet.WriteInfo(cmdlet, "running Wizard StartAction scriptblocks");
                cmdlet.WriteInfo(cmdlet, "parameters: " + cmdlet.ConvertObjectArrayToString(wzd.StartActionParameters));

                cmdlet.RunWizardStartScriptBlocks(cmdlet, wzd, wzd.StartActionParameters);

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

                cmdlet.RunWizardInAutomaticMode(cmdlet, wzd);

                if (cmdlet.Quiet)
                {
                    cmdlet.WriteObject(cmdlet, true);
                }
                else
                {
                    cmdlet.WriteObject(cmdlet, wzd);
                }
            }
        }