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);
}
}
}