コード例 #1
0
ファイル: WizardHelper.cs プロジェクト: MatkoHanus/STUPS
        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);
            }
        }
コード例 #2
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);
            }
        }