internal CommandProcessorBase CreateScriptProcessorForMiniShell( ExternalScriptInfo scriptInfo, bool useLocalScope) { CommandDiscovery.VerifyPSVersion(scriptInfo); if (string.IsNullOrEmpty(scriptInfo.RequiresApplicationID)) { if (scriptInfo.RequiresPSSnapIns != null && scriptInfo.RequiresPSSnapIns.Count > 0) { Collection <string> psSnapinNames = this.GetPSSnapinNames(scriptInfo.RequiresPSSnapIns); ScriptRequiresException requiresException = new ScriptRequiresException(scriptInfo.Name, psSnapinNames, "ScriptRequiresMissingPSSnapIns"); CommandDiscovery.tracer.TraceException((Exception)requiresException); throw requiresException; } return(CommandDiscovery.CreateCommandProcessorForScript(scriptInfo, this._context, useLocalScope)); } if (string.Equals(this._context.ShellID, scriptInfo.RequiresApplicationID, StringComparison.OrdinalIgnoreCase)) { return(CommandDiscovery.CreateCommandProcessorForScript(scriptInfo, this._context, useLocalScope)); } string pathFromRegistry = CommandDiscovery.GetShellPathFromRegistry(scriptInfo.RequiresApplicationID); ScriptRequiresException requiresException1 = new ScriptRequiresException(scriptInfo.Name, scriptInfo.ApplicationIDLineNumber, scriptInfo.RequiresApplicationID, pathFromRegistry, "ScriptRequiresUnmatchedShellId"); CommandDiscovery.tracer.TraceException((Exception)requiresException1); throw requiresException1; }
internal static void VerifyPSVersion(ExternalScriptInfo scriptInfo) { Version requiresPsVersion = scriptInfo.RequiresPSVersion; if (requiresPsVersion != (Version)null && !Utils.IsVersionSupported(requiresPsVersion)) { ScriptRequiresException requiresException = new ScriptRequiresException(scriptInfo.Name, scriptInfo.PSVersionLineNumber, requiresPsVersion, PSVersionInfo.PSVersion.ToString(), "ScriptRequiresUnmatchedPSVersion"); CommandDiscovery.tracer.TraceException((Exception)requiresException); throw requiresException; } }
internal ScriptRequiresException( string commandName, Collection <string> missingPSSnapIns, string errorId) : base(ScriptRequiresException.BuildMessage(commandName, missingPSSnapIns)) { this._commandName = commandName; this._missingPSSnapIns = new ReadOnlyCollection <string>((IList <string>)missingPSSnapIns); this.SetErrorId(errorId); this.SetTargetObject((object)commandName); this.SetErrorCategory(ErrorCategory.ResourceUnavailable); }
internal ScriptRequiresException( string commandName, uint lineNumber, Version requiresPSVersion, string currentPSVersion, string errorId) : base(ScriptRequiresException.BuildMessage(commandName, lineNumber, requiresPSVersion.ToString(), currentPSVersion, false)) { this._commandName = commandName; this._requiresPSVersion = requiresPSVersion; this.SetErrorId(errorId); this.SetTargetObject((object)commandName); this.SetErrorCategory(ErrorCategory.ResourceUnavailable); }
internal ScriptRequiresException( string commandName, uint lineNumber, string requiresShellId, string requiresShellPath, string errorId) : base(ScriptRequiresException.BuildMessage(commandName, lineNumber, requiresShellId, requiresShellPath, true)) { this._commandName = commandName; this._requiresShellId = requiresShellId; this._requiresShellPath = requiresShellPath; this.SetErrorId(errorId); this.SetTargetObject((object)commandName); this.SetErrorCategory(ErrorCategory.ResourceUnavailable); }
private CommandProcessorBase CreateScriptProcessorForSingleShell( ExternalScriptInfo scriptInfo, RunspaceConfigForSingleShell ssRunConfig, bool useLocalScope) { CommandDiscovery.VerifyPSVersion(scriptInfo); Collection <PSSnapInNameVersionPair> requiresPsSnapIns = scriptInfo.RequiresPSSnapIns; if (requiresPsSnapIns != null) { Collection <string> missingPSSnapIns = (Collection <string>)null; foreach (PSSnapInNameVersionPair PSSnapin in requiresPsSnapIns) { Collection <PSSnapInInfo> psSnapIn = ssRunConfig.ConsoleInfo.GetPSSnapIn(PSSnapin.PSSnapInName, false); if (psSnapIn == null || psSnapIn.Count == 0) { if (missingPSSnapIns == null) { missingPSSnapIns = new Collection <string>(); } missingPSSnapIns.Add(CommandDiscovery.BuildPSSnapInDisplayName(PSSnapin)); } else if (PSSnapin.Version != (Version)null && !CommandDiscovery.AreInstalledRequiresVersionsCompatible(PSSnapin.Version, psSnapIn[0].Version)) { if (missingPSSnapIns == null) { missingPSSnapIns = new Collection <string>(); } missingPSSnapIns.Add(CommandDiscovery.BuildPSSnapInDisplayName(PSSnapin)); } } if (missingPSSnapIns != null) { ScriptRequiresException requiresException = new ScriptRequiresException(scriptInfo.Name, missingPSSnapIns, "ScriptRequiresMissingPSSnapIns"); CommandDiscovery.tracer.TraceException((Exception)requiresException); throw requiresException; } } else if (!string.IsNullOrEmpty(scriptInfo.RequiresApplicationID)) { CommandDiscovery.GetShellPathFromRegistry(scriptInfo.RequiresApplicationID); ScriptRequiresException requiresException = new ScriptRequiresException(scriptInfo.Name, scriptInfo.ApplicationIDLineNumber, string.Empty, string.Empty, "RequiresShellIDInvalidForSingleShell"); CommandDiscovery.tracer.TraceException((Exception)requiresException); throw requiresException; } return(CommandDiscovery.CreateCommandProcessorForScript(scriptInfo, this._context, useLocalScope)); }
private CommandProcessorBase CreateScriptProcessorForSingleShell(ExternalScriptInfo scriptInfo, ExecutionContext context, bool useLocalScope, SessionStateInternal sessionState) { VerifyPSVersion(scriptInfo); this.VerifyRequiredModules(scriptInfo); IEnumerable<PSSnapInSpecification> requiresPSSnapIns = scriptInfo.RequiresPSSnapIns; if ((requiresPSSnapIns != null) && requiresPSSnapIns.Any<PSSnapInSpecification>()) { Collection<string> requiresMissingPSSnapIns = null; VerifyRequiredSnapins(requiresPSSnapIns, context, out requiresMissingPSSnapIns); if (requiresMissingPSSnapIns != null) { ScriptRequiresException exception = new ScriptRequiresException(scriptInfo.Name, requiresMissingPSSnapIns, "ScriptRequiresMissingPSSnapIns", true); throw exception; } } else if (!string.IsNullOrEmpty(scriptInfo.RequiresApplicationID)) { GetShellPathFromRegistry(scriptInfo.RequiresApplicationID); ScriptRequiresException exception2 = new ScriptRequiresException(scriptInfo.Name, string.Empty, string.Empty, "RequiresShellIDInvalidForSingleShell"); throw exception2; } return CreateCommandProcessorForScript(scriptInfo, this._context, useLocalScope, sessionState); }
internal CommandProcessorBase CreateScriptProcessorForMiniShell(ExternalScriptInfo scriptInfo, bool useLocalScope, SessionStateInternal sessionState) { VerifyPSVersion(scriptInfo); this.VerifyRequiredModules(scriptInfo); if (string.IsNullOrEmpty(scriptInfo.RequiresApplicationID)) { if ((scriptInfo.RequiresPSSnapIns != null) && scriptInfo.RequiresPSSnapIns.Any<PSSnapInSpecification>()) { Collection<string> pSSnapinNames = GetPSSnapinNames(scriptInfo.RequiresPSSnapIns); ScriptRequiresException exception = new ScriptRequiresException(scriptInfo.Name, pSSnapinNames, "ScriptRequiresMissingPSSnapIns", true); throw exception; } return CreateCommandProcessorForScript(scriptInfo, this._context, useLocalScope, sessionState); } if (string.Equals(this._context.ShellID, scriptInfo.RequiresApplicationID, StringComparison.OrdinalIgnoreCase)) { return CreateCommandProcessorForScript(scriptInfo, this._context, useLocalScope, sessionState); } string shellPathFromRegistry = GetShellPathFromRegistry(scriptInfo.RequiresApplicationID); ScriptRequiresException exception2 = new ScriptRequiresException(scriptInfo.Name, scriptInfo.RequiresApplicationID, shellPathFromRegistry, "ScriptRequiresUnmatchedShellId"); throw exception2; }
private void VerifyRequiredModules(ExternalScriptInfo scriptInfo) { if (scriptInfo.RequiresModules != null) { foreach (ModuleSpecification specification in scriptInfo.RequiresModules) { ErrorRecord error = null; ModuleCmdletBase.LoadRequiredModule(this.Context, null, specification, null, ModuleCmdletBase.ManifestProcessingFlags.LoadElements | ModuleCmdletBase.ManifestProcessingFlags.WriteErrors, out error); if (error != null) { ScriptRequiresException exception = new ScriptRequiresException(scriptInfo.Name, new Collection<string> { specification.Name }, "ScriptRequiresMissingModules", false, error); throw exception; } } } }
internal static void VerifyPSVersion(ExternalScriptInfo scriptInfo) { Version requiresPSVersion = scriptInfo.RequiresPSVersion; if ((requiresPSVersion != null) && !Utils.IsPSVersionSupported(requiresPSVersion)) { ScriptRequiresException exception = new ScriptRequiresException(scriptInfo.Name, requiresPSVersion, PSVersionInfo.PSVersion.ToString(), "ScriptRequiresUnmatchedPSVersion"); throw exception; } }