internal ScriptBlockAst GetScriptBlockAst() { var scriptContents = ScriptContents; if (_scriptBlock == null) { this.ScriptBlock = ScriptBlock.TryGetCachedScriptBlock(_path, scriptContents); } if (_scriptBlock != null) { return((ScriptBlockAst)_scriptBlock.Ast); } if (_scriptBlockAst == null) { ParseError[] errors; Parser parser = new Parser(); _scriptBlockAst = parser.Parse(_path, ScriptContents, null, out errors, ParseMode.Default); if (errors.Length == 0) { this.ScriptBlock = new ScriptBlock(_scriptBlockAst, isFilter: false); ScriptBlock.CacheScriptBlock(_scriptBlock.Clone(), _path, scriptContents); } } return(_scriptBlockAst); }
public PSModuleInfo(ScriptBlock scriptBlock) { this._context = LocalPipeline.GetExecutionContextFromTLS(); if (this._context == null) { throw new InvalidOperationException(nameof(PSModuleInfo)); } PSModuleInfo.SetDefaultDynamicNameAndPath(this); this._sessionState = new SessionState(this._context.EngineSessionState, true, true); this._sessionState.Internal.Module = this; SessionStateInternal engineSessionState = this._context.EngineSessionState; try { ArrayList resultList = (ArrayList)null; this._context.EngineSessionState = this._sessionState.Internal; this._context.EngineSessionState.SetVariableValue("PSScriptRoot", (object)this._path); scriptBlock = scriptBlock.Clone(true); scriptBlock.SessionState = this._sessionState; if (scriptBlock == null) { throw PSModuleInfo.tracer.NewInvalidOperationException(); } scriptBlock.InvokeWithPipe(false, true, (object)AutomationNull.Value, (object)AutomationNull.Value, (object)AutomationNull.Value, (Pipe)null, ref resultList); } finally { this._context.EngineSessionState = engineSessionState; } }
public PSModuleInfo(ScriptBlock scriptBlock) { this._name = string.Empty; this._path = string.Empty; this._description = string.Empty; this._version = new System.Version(0, 0); this._detectedFunctionExports = new List <string>(); this._detectedWorkflowExports = new List <string>(); this._detectedCmdletExports = new List <string>(); this._compiledExports = new List <CmdletInfo>(); this._fileList = new List <string>(); this._moduleList = new Collection <object>(); this._nestedModules = new List <PSModuleInfo>(); this._scripts = new List <string>(); this._requiredAssemblies = new Collection <string>(); this._requiredModules = new List <PSModuleInfo>(); this._requiredModulesSpecification = new List <ModuleSpecification>(); this._detectedAliasExports = new Dictionary <string, string>(); this._exportedFormatFiles = new ReadOnlyCollection <string>(new List <string>()); this._exportedTypeFiles = new ReadOnlyCollection <string>(new List <string>()); if (scriptBlock == null) { throw PSTraceSource.NewArgumentException("scriptBlock"); } ExecutionContext executionContextFromTLS = LocalPipeline.GetExecutionContextFromTLS(); if (executionContextFromTLS == null) { throw new InvalidOperationException("PSModuleInfo"); } SetDefaultDynamicNameAndPath(this); this._sessionState = new System.Management.Automation.SessionState(executionContextFromTLS, true, true); this._sessionState.Internal.Module = this; SessionStateInternal engineSessionState = executionContextFromTLS.EngineSessionState; try { executionContextFromTLS.EngineSessionState = this._sessionState.Internal; executionContextFromTLS.SetVariable(SpecialVariables.PSScriptRootVarPath, this._path); scriptBlock = scriptBlock.Clone(true); scriptBlock.SessionState = this._sessionState; Pipe outputPipe = new Pipe { NullPipe = true }; scriptBlock.InvokeWithPipe(false, ScriptBlock.ErrorHandlingBehavior.WriteToCurrentErrorPipe, AutomationNull.Value, AutomationNull.Value, AutomationNull.Value, outputPipe, null, new object[0]); } finally { executionContextFromTLS.EngineSessionState = engineSessionState; } }
internal ScriptBlockAst GetScriptBlockAst() { var scriptContents = ScriptContents; if (_scriptBlock == null) { this.ScriptBlock = ScriptBlock.TryGetCachedScriptBlock(_path, scriptContents); } if (_scriptBlock != null) { return((ScriptBlockAst)_scriptBlock.Ast); } if (_scriptBlockAst == null) { ParseError[] errors; Parser parser = new Parser(); // If we are in ConstrainedLanguage mode but the defining language mode is FullLanguage, then we need // to parse the script contents in FullLanguage mode context. Otherwise we will get bogus parsing errors // such as "Configuration or Class keyword not allowed". var context = LocalPipeline.GetExecutionContextFromTLS(); if (context != null && context.LanguageMode == PSLanguageMode.ConstrainedLanguage && DefiningLanguageMode == PSLanguageMode.FullLanguage) { context.LanguageMode = PSLanguageMode.FullLanguage; try { _scriptBlockAst = parser.Parse(_path, ScriptContents, null, out errors, ParseMode.Default); } finally { context.LanguageMode = PSLanguageMode.ConstrainedLanguage; } } else { _scriptBlockAst = parser.Parse(_path, ScriptContents, null, out errors, ParseMode.Default); } if (errors.Length == 0) { this.ScriptBlock = new ScriptBlock(_scriptBlockAst, isFilter: false); ScriptBlock.CacheScriptBlock(_scriptBlock.Clone(), _path, scriptContents); } } return(_scriptBlockAst); }
internal ScriptBlock NewBoundScriptBlock(ScriptBlock scriptBlockToBind, ExecutionContext context) { ScriptBlock block; if ((this._sessionState == null) || (context == null)) { throw PSTraceSource.NewInvalidOperationException("Modules", "InvalidOperationOnBinaryModule", new object[0]); } lock (context.EngineSessionState) { SessionStateInternal engineSessionState = context.EngineSessionState; try { context.EngineSessionState = this._sessionState.Internal; block = scriptBlockToBind.Clone(true); block.SessionState = this._sessionState; } finally { context.EngineSessionState = engineSessionState; } } return(block); }
internal static ScriptBlock Create(Parser parser, string fileName, string fileContents) { var scriptBlock = TryGetCachedScriptBlock(fileName, fileContents); if (scriptBlock != null) { return scriptBlock; } ParseError[] errors; var ast = parser.Parse(fileName, fileContents, null, out errors, ParseMode.Default); if (errors.Length != 0) { throw new ParseException(errors); } var result = new ScriptBlock(ast, isFilter: false); CacheScriptBlock(result, fileName, fileContents); // The value returned will potentially be bound to a session state. We don't want // the cached script block to end up being bound to any session state, so clone // the return value to ensure the cached value has no session state. return result.Clone(); }
public PSModuleInfo(ScriptBlock scriptBlock) { this._name = string.Empty; this._path = string.Empty; this._description = string.Empty; this._version = new System.Version(0, 0); this._detectedFunctionExports = new List<string>(); this._detectedWorkflowExports = new List<string>(); this._detectedCmdletExports = new List<string>(); this._compiledExports = new List<CmdletInfo>(); this._fileList = new List<string>(); this._moduleList = new Collection<object>(); this._nestedModules = new List<PSModuleInfo>(); this._scripts = new List<string>(); this._requiredAssemblies = new Collection<string>(); this._requiredModules = new List<PSModuleInfo>(); this._requiredModulesSpecification = new List<ModuleSpecification>(); this._detectedAliasExports = new Dictionary<string, string>(); this._exportedFormatFiles = new ReadOnlyCollection<string>(new List<string>()); this._exportedTypeFiles = new ReadOnlyCollection<string>(new List<string>()); if (scriptBlock == null) { throw PSTraceSource.NewArgumentException("scriptBlock"); } ExecutionContext executionContextFromTLS = LocalPipeline.GetExecutionContextFromTLS(); if (executionContextFromTLS == null) { throw new InvalidOperationException("PSModuleInfo"); } SetDefaultDynamicNameAndPath(this); this._sessionState = new System.Management.Automation.SessionState(executionContextFromTLS, true, true); this._sessionState.Internal.Module = this; SessionStateInternal engineSessionState = executionContextFromTLS.EngineSessionState; try { executionContextFromTLS.EngineSessionState = this._sessionState.Internal; executionContextFromTLS.SetVariable(SpecialVariables.PSScriptRootVarPath, this._path); scriptBlock = scriptBlock.Clone(true); scriptBlock.SessionState = this._sessionState; Pipe outputPipe = new Pipe { NullPipe = true }; scriptBlock.InvokeWithPipe(false, ScriptBlock.ErrorHandlingBehavior.WriteToCurrentErrorPipe, AutomationNull.Value, AutomationNull.Value, AutomationNull.Value, outputPipe, null, new object[0]); } finally { executionContextFromTLS.EngineSessionState = engineSessionState; } }
internal ScriptBlock NewBoundScriptBlock(ScriptBlock scriptBlockToBind, ExecutionContext context) { ScriptBlock block; if ((this._sessionState == null) || (context == null)) { throw PSTraceSource.NewInvalidOperationException("Modules", "InvalidOperationOnBinaryModule", new object[0]); } lock (context.EngineSessionState) { SessionStateInternal engineSessionState = context.EngineSessionState; try { context.EngineSessionState = this._sessionState.Internal; block = scriptBlockToBind.Clone(true); block.SessionState = this._sessionState; } finally { context.EngineSessionState = engineSessionState; } } return block; }
internal static ScriptBlock Create(Parser parser, string fileName, string fileContents) { ParseError[] parseErrorArray = null; ScriptBlock scriptBlock = ScriptBlock.TryGetCachedScriptBlock(fileName, fileContents); if (scriptBlock == null) { ScriptBlockAst scriptBlockAst = parser.Parse(fileName, fileContents, null, out parseErrorArray); if ((int)parseErrorArray.Length == 0) { ScriptBlock scriptBlock1 = new ScriptBlock(scriptBlockAst, false); ScriptBlock.CacheScriptBlock(scriptBlock1, fileName, fileContents); return scriptBlock1.Clone(false); } else { throw new ParseException(parseErrorArray); } } else { return scriptBlock; } }