/// <summary> /// Execute BeginProcessing part of command. It sets up the overall scope /// object for this command and runs the begin clause of the script block if /// it isn't empty. /// </summary> /// <exception cref="PipelineStoppedException"> /// a terminating error occurred, or the pipeline was otherwise stopped /// </exception> internal override void DoBegin() { if (!RanBeginAlready) { RanBeginAlready = true; ScriptBlock.LogScriptBlockStart(_scriptBlock, Context.CurrentRunspace.InstanceId); // Even if there is no begin, we need to set up the execution scope for this script... SetCurrentScopeToExecutionScope(); CommandProcessorBase oldCurrentCommandProcessor = Context.CurrentCommandProcessor; try { Context.CurrentCommandProcessor = this; if (_scriptBlock.HasBeginBlock) { RunClause(_runOptimizedCode ? _scriptBlock.BeginBlock : _scriptBlock.UnoptimizedBeginBlock, AutomationNull.Value, _input); } } finally { Context.CurrentCommandProcessor = oldCurrentCommandProcessor; RestorePreviousScope(); } } }