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