/// <summary>
/// In a script block, we only provide the pipeline as the automatic $input variable, but call it only once
/// </summary>
public override void ProcessRecords()
{
// TODO: provide the automatic $input variable
// TODO: currently we don't support "cmdlet scripts", i.e. functions that behave like cmdlets.
// TODO: Investigate the usage of different function blocks properly before implementing them
//set the execution context of the runspace to the new context for execution in it
SwitchToOwnScope();
try
{
_scriptBlockInfo.ScriptBlock.Ast.Visit(new ExecutionVisitor(ExecutionContext, CommandRuntime, false));
}
catch (ExitException e)
{
if (_fromFile)
{
_exitCode = e.ExitCode;
ExecutionContext.SetVariable("global:LASTEXITCODE", e.ExitCode);
}
else
{
throw;
}
}
finally //make sure we switch back to the original execution context, no matter what happened
{
RestoreOriginalScope();
}
}