Description of WizardStep.
Example #1
0
        public WizardStep GetActiveStep()
        {
            StopImmediately = false;

            WizardStep resultStep = null;

            // load controls from the wizard's window
            var allWizardControls =
                (CurrentData.CurrentWindow as ISupportsExtendedModel).Descendants.PerformFindAll();

            foreach (WizardStep step in Steps)
            {
                if (StopImmediately)
                {
                    resultStep = step;
                    break;
                }

                if (IsStepActive(step, allWizardControls))
                {
                    resultStep = step;
                    ActiveStep = step;
                    break;
                }
            }

            // 20130515
            // moving the current step to the end of the step collection
            try {
                int currentIndex = Steps.IndexOf(resultStep);

                if (0 <= currentIndex && (Steps.Count - 1) != currentIndex)
                {
                    Steps.Insert(Steps.Count, resultStep);
                    // cmdletCtrl.WriteInfo(cmdletCtrl, "inserted after the last step");
                    Steps.RemoveAt(currentIndex);
                    // cmdletCtrl.WriteInfo(cmdletCtrl, "deleted from the previous position");
                }
                else
                {
                    // cmdletCtrl.WriteInfo(cmdletCtrl, "there was no manipulation with wizard steps' order");
                }
            }
            catch (Exception) {
                // cmdletCtrl.WriteInfo(cmdletCtrl, eMovingToTheEnd.Message);
            }

            return(resultStep);
        }
Example #2
0
        public static void AddWizardStep(WizardStepCmdletBase cmdlet)
        {
            if (null != cmdlet.InputObject && null != cmdlet.InputObject)
            {
                WizardStep probeTheSameStep = cmdlet.InputObject.GetStep(cmdlet.Name);
                if (null != probeTheSameStep)
                {
                    cmdlet.WriteError(
                        cmdlet,
                        "A step with the name provided already exists",
                        "StepAlreadyExists",
                        ErrorCategory.InvalidArgument,
                        true);
                }

                // WizardStep step = new WizardStep(cmdlet.Name, cmdlet.Order)
                var step = new WizardStep(cmdlet.Name, cmdlet.Order)
                {
                    SearchCriteria     = cmdlet.SearchCriteria,
                    StepForwardAction  = cmdlet.StepForwardAction,
                    StepBackwardAction = cmdlet.StepBackwardAction,
                    StepCancelAction   = cmdlet.StepCancelAction,
                    Description        = cmdlet.Description,
                    Parent             = cmdlet.InputObject
                };
                // 20130319
                //step.StepGetWindowAction = cmdlet.StepGetWindowAction;

                cmdlet.WriteVerbose(cmdlet, "adding the step");
                cmdlet.InputObject.Steps.Add(step);

                // 20130508
                cmdlet.WriteInfo(cmdlet, step.Name + " has been added");

                if (cmdlet.PassThru)
                {
                    cmdlet.WriteObject(cmdlet, cmdlet.InputObject);
                }
                else
                {
                    cmdlet.WriteObject(cmdlet, true);
                }
            }
            else
            {
                cmdlet.WriteError(cmdlet, "The wizard object you provided is not valid", "WrongWizardObject", ErrorCategory.InvalidArgument, true);
            }
        }
Example #3
0
        public static void AddWizardStep(WizardStepCmdletBase cmdlet)
        {
            if (null != cmdlet.InputObject && null != cmdlet.InputObject) {
                
                WizardStep probeTheSameStep = cmdlet.InputObject.GetStep(cmdlet.Name);
                if (null != probeTheSameStep) {
                    
                    cmdlet.WriteError(
                        cmdlet,
                        "A step with the name provided already exists",
                        "StepAlreadyExists",
                        ErrorCategory.InvalidArgument,
                        true);
                }
                
                // WizardStep step = new WizardStep(cmdlet.Name, cmdlet.Order)
                var step = new WizardStep(cmdlet.Name, cmdlet.Order)
                {
                    SearchCriteria = cmdlet.SearchCriteria,
                    StepForwardAction = cmdlet.StepForwardAction,
                    StepBackwardAction = cmdlet.StepBackwardAction,
                    StepCancelAction = cmdlet.StepCancelAction,
                    Description = cmdlet.Description,
                    Parent = cmdlet.InputObject
                };
                // 20130319
                //step.StepGetWindowAction = cmdlet.StepGetWindowAction;
                
                cmdlet.WriteVerbose(cmdlet, "adding the step");
                cmdlet.InputObject.Steps.Add(step);
                
                // 20130508
                cmdlet.WriteInfo(cmdlet, step.Name + " has been added");

                if (cmdlet.PassThru) {

                    cmdlet.WriteObject(cmdlet, cmdlet.InputObject);
                } else {

                    cmdlet.WriteObject(cmdlet, true);
                }
            } else {

                cmdlet.WriteError(cmdlet, "The wizard object you provided is not valid", "WrongWizardObject", ErrorCategory.InvalidArgument, true);
            }
        }
Example #4
0
 protected internal void RunWizardStepScriptBlocks(
     WizardCmdletBase cmdlet,
     WizardStep wizardStep,
     bool forward)
 {
     if (forward) {
         runTwoScriptBlockCollections(
             null,
             wizardStep.StepForwardAction,
             cmdlet);
     } else {
         runTwoScriptBlockCollections(
             null,
             wizardStep.StepBackwardAction,
             cmdlet);
     }
 }
Example #5
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);
 }
Example #6
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;
 }
Example #7
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");
     }
 }
Example #8
0
        protected internal void RunWizardStepScriptBlocks(
            WizardCmdletBase cmdlet,
            WizardStep wizardStep,
            // 20130318
            //bool forward)
            // 20130321
            //bool forward,
            WizardStepActions whatToRun,
            object[] parameters)
        {
            switch (whatToRun) {
                case WizardStepActions.Forward:
                    cmdlet.WriteVerbose(
                        cmdlet,
                        "ForwardAction scriptblocks");

                    runTwoScriptBlockCollections(
                        wizardStep.Parent.DefaultStepForwardAction,
                        wizardStep.StepForwardAction,
                        cmdlet,
                        parameters);
                    break;
                case WizardStepActions.Backward:
                    cmdlet.WriteVerbose(
                        cmdlet,
                        "BackwardAction scriptblocks");

                    runTwoScriptBlockCollections(
                        wizardStep.Parent.DefaultStepBackwardAction,
                        wizardStep.StepBackwardAction,
                        cmdlet,
                        parameters);
                    break;
                case WizardStepActions.Cancel:
                    cmdlet.WriteVerbose(
                        cmdlet,
                        "CancelAction scriptblocks");

                    runTwoScriptBlockCollections(
                        wizardStep.Parent.DefaultStepCancelAction,
                        wizardStep.StepCancelAction,
                        cmdlet,
                        parameters);
                    break;
            //                case WizardStepActions.Stop:
            //                    cmdlet.WriteVerbose(
            //                        cmdlet,
            //                        "StopAction scriptblocks");
            //
            //                    runTwoScriptBlockCollections(
            //                        null,
            //                        wizardStep.Parent.StopAction,
            //                        cmdlet,
            //                        parameters);
            //                    break;
                default:
                    throw new Exception("Invalid value for WizardStepActions");
            }

            // 20130321
            #region commented
            //            if (forward) {
            //
            //                cmdlet.WriteVerbose(
            //                    cmdlet,
            //                    "ForwardAction scriptblocks");
            //
            //                runTwoScriptBlockCollections(
            //        			// 20130317
            //                    //null,
            //                    wizardStep.Parent.DefaultStepForwardAction,
            //                    wizardStep.StepForwardAction,
            //                    // 20130318
            //                    //cmdlet);
            //                    cmdlet,
            //                    parameters);
            //
            //            } else {
            //
            //                cmdlet.WriteVerbose(
            //                    cmdlet,
            //                    "BackwardAction scriptblocks");
            //
            //                runTwoScriptBlockCollections(
            //        			// 20130317
            //                    //null,
            //                    wizardStep.Parent.DefaultStepBackwardAction,
            //                    wizardStep.StepBackwardAction,
            //                    // 20130318
            //                    //cmdlet);
            //                    cmdlet,
            //                    parameters);
            //
            //            }
            #endregion commented

            cmdlet.WriteVerbose(
                cmdlet,
                "Scriptblocks finished");
        }
Example #9
0
 internal bool IsStepActive(WizardStep step, IUiEltCollection elements)
 {
     bool result = false;
     
     if (null == step) return result;
     if (null == step.SearchCriteria || 0 == step.SearchCriteria.Count()) return result;
     var searchCriteria = step.SearchCriteria.Where(hashtable => null != hashtable);
     if (null == searchCriteria || 0 == searchCriteria.Count()) return result;
     if (null == elements || 0 == elements.Count) return result;
     
     if (searchCriteria.All(criterion =>   
                            elements.ToArray().Any(elt => ControlSearcher.TestControlWithAllSearchCriteria(new Hashtable[] { criterion }, elt))
                           )) {
         result = true;
     }
     
     return result;
 }
Example #10
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);
                }
            }
        }
Example #11
0
        protected internal void RunWizardStepScriptBlocks(
            WizardCmdletBase cmdlet,
            WizardStep wizardStep,
            WizardStepActions whatToRun,
            object[] parameters)
        {
            switch (whatToRun)
            {
            case WizardStepActions.Forward:
//                    cmdlet.WriteVerbose(
//                        cmdlet,
//                        "ForwardAction scriptblocks");

                runTwoScriptBlockCollections(
                    wizardStep.Parent.DefaultStepForwardAction,
                    wizardStep.StepForwardAction,
                    cmdlet,
                    parameters);
                break;

            case WizardStepActions.Backward:
//                    cmdlet.WriteVerbose(
//                        cmdlet,
//                        "BackwardAction scriptblocks");

                runTwoScriptBlockCollections(
                    wizardStep.Parent.DefaultStepBackwardAction,
                    wizardStep.StepBackwardAction,
                    cmdlet,
                    parameters);
                break;

            case WizardStepActions.Cancel:
//                    cmdlet.WriteVerbose(
//                        cmdlet,
//                        "CancelAction scriptblocks");

                runTwoScriptBlockCollections(
                    wizardStep.Parent.DefaultStepCancelAction,
                    wizardStep.StepCancelAction,
                    cmdlet,
                    parameters);
                break;

//                case WizardStepActions.Stop:
//                    cmdlet.WriteVerbose(
//                        cmdlet,
//                        "StopAction scriptblocks");
//
//                    runTwoScriptBlockCollections(
//                        null,
//                        wizardStep.Parent.StopAction,
//                        cmdlet,
//                        parameters);
//                    break;
            default:
                throw new Exception("Invalid value for WizardStepActions on running scriptblocks");
            }

            cmdlet.WriteVerbose(
                cmdlet,
                "Scriptblocks finished");
        }
Example #12
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;
                }
            }
        }
Example #13
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");
            }
        }
Example #14
0
        public static void StepWizardStep(StepUiaWizardCommand cmdlet)
        {
            // getting the step the user ordered to run
            if (cmdlet.InputObject != null && null != cmdlet.InputObject)
            {
                WizardStep stepToRun = null;

                cmdlet.WriteVerbose(cmdlet, "searching for a step");

                foreach (WizardStep step in cmdlet.InputObject.Steps)
                {
                    cmdlet.WriteVerbose(cmdlet, "found step: " + step.Name);

                    if (step.Name != cmdlet.Name)
                    {
                        continue;
                    }

                    cmdlet.WriteVerbose(cmdlet, "found the step we've been searching for");
                    stepToRun = step;
                    break;

                    /*
                     * if (step.Name == cmdlet.Name) {
                     *  //WriteVerbose(this, "found the step we've been searching for");
                     *  cmdlet.WriteVerbose(cmdlet, "found the step we've been searching for");
                     *  stepToRun = step;
                     *  break;
                     * }
                     */
                }
                if (stepToRun == null)
                {
                    //                    ErrorRecord err =
                    //                        new ErrorRecord(
                    //                            new Exception("Couldn't find the step"),
                    //                            "StepNotFound",
                    //                            ErrorCategory.InvalidArgument,
                    //                            stepToRun.Name);
                    //                    err.ErrorDetails =
                    //                        new ErrorDetails(
                    //                            "Failed to find the step");
                    //                    WriteError(this, err, true);

                    cmdlet.WriteError(
                        cmdlet,
                        "Couldn't find the step",
                        "StepNotFound",
                        ErrorCategory.InvalidArgument,
                        true);
                }

                bool result = false;
                do
                {
                    cmdlet.WriteVerbose(cmdlet, "checking controls' properties");

                    // if there is no SearchCriteria, for example, there's at least one @{}
                    if (stepToRun.SearchCriteria.Length == 0 ||
                        Regex.IsMatch(
                            stepToRun.SearchCriteria.ToString(),
                            @"[\@][\{]\s+?[\}]"))
                    {
                        result = true;
                    }
                    else
                    {
                        result =
                            //testControlByPropertiesFromHashtable(
                            cmdlet.TestControlByPropertiesFromHashtable(
                                // 20130315
                                null,
                                stepToRun.SearchCriteria,
                                //this.Timeout);
                                cmdlet.Timeout);
                    }
                    if (result)
                    {
                        cmdlet.WriteVerbose(cmdlet, "there are no SearchCriteria");
                        cmdlet.WriteVerbose(cmdlet, "thus, control state is confirmed");
                    }
                    else
                    {
                        cmdlet.WriteVerbose(cmdlet, "control state is not yet confirmed. Checking the timeout");
                        cmdlet.SleepAndRunScriptBlocks(cmdlet);
                        // wait until timeout expires or the state will be confirmed as valid
                        DateTime nowDate =
                            DateTime.Now;

                        if ((nowDate - cmdlet.StartDate).TotalSeconds > cmdlet.Timeout / 1000)
                        {
                            //WriteObject(this, false);
                            //result = true;
                            //return;
                            //                            WriteVerbose(this, "the timeout has already expired");
                            //                            ErrorRecord err =
                            //                                new ErrorRecord(
                            //                                    new Exception("Timeout expired"),
                            //                                    "TimeoutExpired",
                            //                                    ErrorCategory.OperationTimeout,
                            //                                    this.InputObject);
                            //                            err.ErrorDetails =
                            //                                new ErrorDetails(
                            //                                    "Timeout expired");
                            //                            WriteError(this, err, true);

                            cmdlet.WriteError(
                                cmdlet,
                                "Timeout expired",
                                "TimeoutExpired",
                                ErrorCategory.OperationTimeout,
                                true);
                        }
                    }
                } while (!result);

                //WriteVerbose(this, "running script blocks");
                // 20130319
                //cmdlet.WriteVerbose(cmdlet, "running ForwardAction, BackwardAction, CancelAction scriptblocks");
                cmdlet.WriteVerbose(cmdlet, "running ForwardAction or BackwardAction scriptblocks");
                //RunWizardStepScriptBlocks(this, stepToRun, Forward);
                // 20130318
                //cmdlet.RunWizardStepScriptBlocks(cmdlet, stepToRun, cmdlet.Forward);
                // 20130321
                //cmdlet.RunWizardStepScriptBlocks(cmdlet, stepToRun, cmdlet.Forward, null);
                cmdlet.RunWizardStepScriptBlocks(cmdlet, stepToRun, stepToRun.ToDo, null);

                //if (PassThru) {
                if (cmdlet.PassThru)
                {
                    //WriteObject(this, InputObject);
                    cmdlet.WriteObject(cmdlet, cmdlet.InputObject);
                }
                else
                {
                    //WriteObject(this, true);
                    cmdlet.WriteObject(cmdlet, true);
                }
            }
            else
            {
                //                ErrorRecord err =
                //                    new ErrorRecord(
                //                        new Exception("The wizard object you provided is not valid"),
                //                        "WrongWizardObject",
                //                        ErrorCategory.InvalidArgument,
                //                        InputObject);
                //                err.ErrorDetails =
                //                    new ErrorDetails(
                //                        "The wizard object you provided is not valid");
                //                WriteError(this, err, true);

                cmdlet.WriteError(
                    cmdlet,
                    "The wizard object you provided is not valid",
                    "WrongWizardObject",
                    ErrorCategory.InvalidArgument,
                    true);
            }
        }
Example #15
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);
     }
 }
Example #16
0
        protected internal void RunWizardStepScriptBlocks(
            WizardCmdletBase cmdlet,
            WizardStep wizardStep,
            WizardStepActions whatToRun,
            object[] parameters)
        {

            switch (whatToRun) {
                case WizardStepActions.Forward:
//                    cmdlet.WriteVerbose(
//                        cmdlet,
//                        "ForwardAction scriptblocks");
    
                    runTwoScriptBlockCollections(
                        wizardStep.Parent.DefaultStepForwardAction,
                        wizardStep.StepForwardAction,
                        cmdlet,
                        parameters);
                    break;
                case WizardStepActions.Backward:
//                    cmdlet.WriteVerbose(
//                        cmdlet,
//                        "BackwardAction scriptblocks");
                    
                    runTwoScriptBlockCollections(
                        wizardStep.Parent.DefaultStepBackwardAction,
                        wizardStep.StepBackwardAction,
                        cmdlet,
                        parameters);
                    break;
                case WizardStepActions.Cancel:
//                    cmdlet.WriteVerbose(
//                        cmdlet,
//                        "CancelAction scriptblocks");
                    
                    runTwoScriptBlockCollections(
                        wizardStep.Parent.DefaultStepCancelAction,
                        wizardStep.StepCancelAction,
                        cmdlet,
                        parameters);
                    break;
//                case WizardStepActions.Stop:
//                    cmdlet.WriteVerbose(
//                        cmdlet,
//                        "StopAction scriptblocks");
//                    
//                    runTwoScriptBlockCollections(
//                        null,
//                        wizardStep.Parent.StopAction,
//                        cmdlet,
//                        parameters);
//                    break;
                default:
                    throw new Exception("Invalid value for WizardStepActions on running scriptblocks");
            }
            
            cmdlet.WriteVerbose(
                cmdlet,
                "Scriptblocks finished");
        }
Example #17
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);
                }
            }
        }