Пример #1
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);
        }
Пример #2
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);
         }
     }
 }
Пример #3
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);
                }
            }
        }
Пример #4
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);
                }
            }
        }
Пример #5
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;
 }
Пример #6
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);
                }
            }
        }
Пример #7
0
        public static void InvokeWizard(WizardRunCmdletBase cmdlet)
        {
            Wizard wzd = cmdlet.GetWizard(cmdlet.Name);

            if (null == wzd) {

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

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

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

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

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

                    PrepareStepDirections(cmdlet, wzd);
                }

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

                    PrepareStepParameters(cmdlet, wzd);
                }

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

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

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

                cmdlet.RunWizardInAutomaticMode(cmdlet, wzd);

                if (cmdlet.Quiet) {
                    cmdlet.WriteObject(cmdlet, true);
                } else {
                    cmdlet.WriteObject(cmdlet, wzd);
                }
            }
        }
Пример #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);
                }
            }
        }
Пример #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);
                }
            }
        }
Пример #10
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);
                }
            }
        }