Exemple #1
0
        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 Collection <PSObject> InvokeScript(SessionState sessionState, ScriptBlock scriptBlock, params object[] args)
        {
            Collection <PSObject> collection;

            if (scriptBlock == null)
            {
                throw PSTraceSource.NewArgumentNullException("scriptBlock");
            }
            if (sessionState == null)
            {
                throw PSTraceSource.NewArgumentNullException("sessionState");
            }
            SessionStateInternal engineSessionState = this._context.EngineSessionState;

            try
            {
                this._context.EngineSessionState = sessionState.Internal;
                collection = this.InvokeScript(scriptBlock, false, PipelineResultTypes.None, null, args);
            }
            finally
            {
                this._context.EngineSessionState = engineSessionState;
            }
            return(collection);
        }
Exemple #3
0
 private void InitializeCommon(AutomationEngine engine, PSHost hostInterface)
 {
     this._engine = engine;
     if (!_assemblyEventHandlerSet)
     {
         lock (lockObject)
         {
             if (!_assemblyEventHandlerSet)
             {
                 AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(ExecutionContext.PowerShellAssemblyResolveHandler);
                 _assemblyEventHandlerSet = true;
             }
         }
     }
     this._debugger          = new System.Management.Automation.Debugger(this);
     this.eventManager       = new PSLocalEventManager(this);
     this.transactionManager = new PSTransactionManager();
     this.myHostInterface    = hostInterface as System.Management.Automation.Internal.Host.InternalHost;
     if (this.myHostInterface == null)
     {
         this.myHostInterface = new System.Management.Automation.Internal.Host.InternalHost(hostInterface, this);
     }
     this._assemblyCache        = new Dictionary <string, Assembly>();
     this._topLevelSessionState = this._engineSessionState = new SessionStateInternal(this);
     if (this._authorizationManager == null)
     {
         this._authorizationManager = new System.Management.Automation.AuthorizationManager(null);
     }
     this._modules = new ModuleIntrinsics(this);
 }
Exemple #4
0
        internal static PSReference GetVariableAsRef(VariablePath variablePath, ExecutionContext executionContext, Type staticType)
        {
            Diagnostics.Assert(variablePath.IsVariable, "calller to verify varpath is a variable.");

            SessionStateInternal sessionState = executionContext.EngineSessionState;
            CommandOrigin        origin       = sessionState.CurrentScope.ScopeOrigin;

            SessionStateScope scope;
            PSVariable        var = sessionState.GetVariableItem(variablePath, out scope, origin);

            if (var == null)
            {
                throw InterpreterError.NewInterpreterException(variablePath, typeof(RuntimeException), null,
                                                               "NonExistingVariableReference",
                                                               ParserStrings.NonExistingVariableReference);
            }

            object value = var.Value;

            if (staticType == null && value != null)
            {
                value = PSObject.Base(value);
                if (value != null)
                {
                    staticType = value.GetType();
                }
            }
            if (staticType == null)
            {
                var declaredType = var.Attributes.OfType <ArgumentTypeConverterAttribute>().FirstOrDefault();
                staticType = declaredType != null ? declaredType.TargetType : typeof(LanguagePrimitives.Null);
            }

            return(PSReference.CreateInstance(var, staticType));
        }
Exemple #5
0
        /// <summary>
        /// </summary>
        /// <param name="sessionState"></param>
        /// <param name="scriptBlock"></param>
        /// <param name="args"></param>
        /// <returns></returns>
        public Collection <PSObject> InvokeScript(
            SessionState sessionState, ScriptBlock scriptBlock, params object[] args)
        {
            if (scriptBlock == null)
            {
                throw PSTraceSource.NewArgumentNullException(nameof(scriptBlock));
            }

            if (sessionState == null)
            {
                throw PSTraceSource.NewArgumentNullException(nameof(sessionState));
            }

            SessionStateInternal _oldSessionState = _context.EngineSessionState;

            try
            {
                _context.EngineSessionState = sessionState.Internal;
                return(InvokeScript(
                           sb: scriptBlock,
                           useNewScope: false,
                           writeToPipeline: PipelineResultTypes.None,
                           input: null,
                           args: args));
            }
            finally
            {
                _context.EngineSessionState = _oldSessionState;
            }
        }
Exemple #6
0
 public FunctionScopeItemSearcher(
     SessionStateInternal sessionState,
     VariablePath lookupPath,
     CommandOrigin origin) : base(sessionState, lookupPath)
 {
     _origin = origin;
 }
Exemple #7
0
        internal static object GetVariableValue(VariablePath variablePath, ExecutionContext executionContext, VariableExpressionAst varAst)
        {
            if (!variablePath.IsVariable)
            {
                CmdletProviderContext contextOut;
                SessionStateScope     scopeOut;
                SessionStateInternal  ss = executionContext.EngineSessionState;
                return(ss.GetVariableValueFromProvider(variablePath, out contextOut, out scopeOut, ss.CurrentScope.ScopeOrigin));
            }

            SessionStateInternal sessionState = executionContext.EngineSessionState;
            CommandOrigin        origin       = sessionState.CurrentScope.ScopeOrigin;

            SessionStateScope scope;
            PSVariable        var = sessionState.GetVariableItem(variablePath, out scope, origin);

            if (var != null)
            {
                return(var.Value);
            }

            if (sessionState.ExecutionContext._debuggingMode > 0)
            {
                sessionState.ExecutionContext.Debugger.CheckVariableRead(variablePath.UnqualifiedPath);
            }

            if (ThrowStrictModeUndefinedVariable(executionContext, varAst))
            {
                throw InterpreterError.NewInterpreterException(variablePath.UserPath, typeof(RuntimeException),
                                                               varAst.Extent, "VariableIsUndefined", ParserStrings.VariableIsUndefined, variablePath.UserPath);
            }

            return(null);
        }
Exemple #8
0
 private void InvokeAction(EventAction nextAction)
 {
     lock (this.actionProcessingLock)
     {
         this.processingAction = nextAction;
         SessionStateInternal engineSessionState = this.context.EngineSessionState;
         this.context.EngineSessionState = nextAction.Sender.Action.ScriptBlock.SessionStateInternal;
         Runspace defaultRunspace = Runspace.DefaultRunspace;
         try
         {
             Runspace.DefaultRunspace = this.context.CurrentRunspace;
             nextAction.Sender.Action.Invoke(nextAction.Sender, nextAction.Args);
         }
         catch (Exception ex)
         {
             CommandProcessorBase.CheckForSevereException(ex);
             if (!(ex is PipelineStoppedException))
             {
                 return;
             }
             this.AddAction(nextAction);
         }
         finally
         {
             Runspace.DefaultRunspace        = defaultRunspace;
             this.context.EngineSessionState = engineSessionState;
             this.processingAction           = (EventAction)null;
         }
     }
 }
Exemple #9
0
        private static PSReference GetVariableAsRef(VariablePath variablePath, ExecutionContext executionContext, Type staticType)
        {
            SessionStateScope    scope;
            SessionStateInternal engineSessionState = executionContext.EngineSessionState;
            CommandOrigin        scopeOrigin        = engineSessionState.CurrentScope.ScopeOrigin;
            PSVariable           variable           = engineSessionState.GetVariableItem(variablePath, out scope, scopeOrigin);

            if (variable == null)
            {
                throw InterpreterError.NewInterpreterException(variablePath, typeof(RuntimeException), null, "NonExistingVariableReference", ParserStrings.NonExistingVariableReference, new object[0]);
            }
            object obj2 = variable.Value;

            if ((staticType == null) && (obj2 != null))
            {
                obj2 = PSObject.Base(obj2);
                if (obj2 != null)
                {
                    staticType = obj2.GetType();
                }
            }
            if (staticType == null)
            {
                ArgumentTypeConverterAttribute attribute = variable.Attributes.OfType <ArgumentTypeConverterAttribute>().FirstOrDefault <ArgumentTypeConverterAttribute>();
                staticType = (attribute != null) ? attribute.TargetType : typeof(LanguagePrimitives.Null);
            }
            return(PSReference.CreateInstance(variable, staticType));
        }
Exemple #10
0
 internal SecurityDescriptorCmdletProviderIntrinsics(Cmdlet cmdlet)
 {
     using (SecurityDescriptorCmdletProviderIntrinsics.tracer.TraceConstructor((object)this))
     {
         this.cmdlet       = cmdlet != null ? cmdlet : throw SecurityDescriptorCmdletProviderIntrinsics.tracer.NewArgumentNullException(nameof(cmdlet));
         this.sessionState = cmdlet.Context.EngineSessionState;
     }
 }
Exemple #11
0
 internal DriveManagementIntrinsics(SessionStateInternal sessionState)
 {
     if (sessionState == null)
     {
         throw PSTraceSource.NewArgumentNullException("sessionState");
     }
     this.sessionState = sessionState;
 }
 protected ScriptCommandProcessorBase(ScriptBlock scriptBlock, ExecutionContext context, bool useLocalScope, CommandOrigin origin, SessionStateInternal sessionState)
 {
     this._dontUseScopeCommandOrigin = false;
     base.CommandInfo = new ScriptInfo(string.Empty, scriptBlock, context);
     base._fromScriptFile = false;
     this.CommonInitialization(scriptBlock, context, useLocalScope, sessionState);
     base.Command.CommandOriginInternal = origin;
 }
 internal SecurityDescriptorCmdletProviderIntrinsics(SessionStateInternal sessionState)
 {
     if (sessionState == null)
     {
         throw PSTraceSource.NewArgumentNullException("sessionState");
     }
     this.sessionState = sessionState;
 }
 internal ChildItemCmdletProviderIntrinsics(SessionStateInternal sessionState)
 {
     if (sessionState == null)
     {
         throw PSTraceSource.NewArgumentNullException("sessionState");
     }
     this.sessionState = sessionState;
 }
 internal ItemCmdletProviderIntrinsics(SessionStateInternal sessionState)
 {
     if (sessionState == null)
     {
         throw PSTraceSource.NewArgumentNullException("sessionState");
     }
     this.sessionState = sessionState;
 }
Exemple #16
0
 internal PathIntrinsics(SessionStateInternal sessionState)
 {
     if (sessionState == null)
     {
         throw PSTraceSource.NewArgumentNullException("sessionState");
     }
     this.sessionState = sessionState;
 }
Exemple #17
0
 internal SessionState(SessionStateInternal sessionState)
 {
     if (sessionState == null)
     {
         throw PSTraceSource.NewArgumentNullException("sessionState");
     }
     this.sessionState = sessionState;
 }
 internal PSVariableIntrinsics(SessionStateInternal sessionState)
 {
     if (sessionState == null)
     {
         throw PSTraceSource.NewArgumentException("sessionState");
     }
     this.sessionState = sessionState;
 }
Exemple #19
0
 /// <summary>
 /// This is the constructor for script as cmdlet. 
 /// </summary>
 /// <param name="scriptCommandInfo">
 /// The information about the cmdlet.
 /// </param>
 /// <param name="context">
 /// PowerShell engine execution context for this command.
 /// </param>
 /// <param name="useLocalScope"></param>
 /// <param name="sessionState"></param>
 /// <param name="fromScriptFile">True when the script to be executed came from a file (as opposed to a function, or interactive input)</param>
 internal CommandProcessor(IScriptCommandInfo scriptCommandInfo, ExecutionContext context, bool useLocalScope, bool fromScriptFile, SessionStateInternal sessionState)
     : base(scriptCommandInfo as CommandInfo)
 {
     this._context = context;
     this._useLocalScope = useLocalScope;
     this._fromScriptFile = fromScriptFile;
     this.CommandSessionState = sessionState;
     Init(scriptCommandInfo);
 }
        /// <summary>
        /// Constructs a Drive management facade.
        /// </summary>
        /// <param name="sessionState">
        /// The instance of session state that facade wraps.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="sessionState"/> is null.
        /// </exception>
        internal DriveManagementIntrinsics(SessionStateInternal sessionState)
        {
            if (sessionState is null)
            {
                throw PSTraceSource.NewArgumentNullException(nameof(sessionState));
            }

            _sessionState = sessionState;
        }
Exemple #21
0
        private ScriptBlock CreateBoundScriptBlock(ScriptBlock scriptAction)
        {
            ScriptBlock          block                = this.context.Modules.CreateBoundScriptBlock(this.context, scriptAction, true);
            PSVariable           variable             = new PSVariable("script:Error", new ArrayList(), ScopedItemOptions.Constant);
            SessionStateInternal sessionStateInternal = block.SessionStateInternal;

            sessionStateInternal.GetScopeByID("script").SetVariable(variable.Name, variable, false, true, sessionStateInternal, CommandOrigin.Internal, false);
            return(block);
        }
        /// <summary>
        /// Constructs a facade over the "real" session state API.
        /// </summary>
        /// <param name="sessionState">
        /// An instance of the sessionState.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="sessionState"/> is null.
        /// </exception>
        internal ContentCmdletProviderIntrinsics(SessionStateInternal sessionState)
        {
            if (sessionState is null)
            {
                throw PSTraceSource.NewArgumentNullException(nameof(sessionState));
            }

            _sessionState = sessionState;
        }
Exemple #23
0
        /// <summary>
        /// The internal constructor for this object. It should be the only one that gets called.
        /// </summary>
        /// <param name="sessionState">
        /// An instance of SessionState that the APIs should work against.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="sessionState"/> is null.
        /// </exception>
        internal SessionState(SessionStateInternal sessionState)
        {
            if (sessionState is null)
            {
                throw PSTraceSource.NewArgumentNullException(nameof(sessionState));
            }

            _sessionState = sessionState;
        }
Exemple #24
0
        /// <summary>
        /// Constructs a facade for the specified session.
        /// </summary>
        /// <param name="sessionState">
        /// The session for which the facade wraps.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="sessionState"/> is null.
        /// </exception>
        internal PSVariableIntrinsics(SessionStateInternal sessionState)
        {
            if (sessionState is null)
            {
                throw PSTraceSource.NewArgumentException(nameof(sessionState));
            }

            _sessionState = sessionState;
        }
Exemple #25
0
        } // DriveManagementIntrinsics private


        /// <summary>
        /// Constructs a Drive management facade
        /// </summary>
        /// 
        /// <param name="sessionState">
        /// The instance of session state that facade wraps.
        /// </param>
        /// 
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="sessionState"/> is null.
        /// </exception>
        /// 
        internal DriveManagementIntrinsics(SessionStateInternal sessionState)
        {
            if (sessionState == null)
            {
                throw PSTraceSource.NewArgumentNullException("sessionState");
            }

            _sessionState = sessionState;
        } // DriveManagementIntrinsics internal
 internal ItemCmdletProviderIntrinsics(Cmdlet cmdlet)
 {
     if (cmdlet == null)
     {
         throw PSTraceSource.NewArgumentNullException("cmdlet");
     }
     this.cmdlet       = cmdlet;
     this.sessionState = cmdlet.Context.EngineSessionState;
 }
Exemple #27
0
        } // PSVariableInterfaces private

        /// <summary>
        /// Constructs a facade for the specified session.
        /// </summary>
        /// 
        /// <param name="sessionState">
        /// The session for which the facade wraps.
        /// </param>
        /// 
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="sessionState"/> is null.
        /// </exception>
        /// 
        internal PSVariableIntrinsics(SessionStateInternal sessionState)
        {
            if (sessionState == null)
            {
                throw PSTraceSource.NewArgumentException("sessionState");
            }

            _sessionState = sessionState;
        } // PSVariableInterfaces internal
        } // ContentCmdletProviderIntrinsics internal

        /// <summary>
        /// Constructs a facade over the "real" session state API
        /// </summary>
        ///
        /// <param name="sessionState">
        /// An instance of the sessionState.
        /// </param>
        ///
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="sessionState"/> is null.
        /// </exception>
        /// 
        internal ContentCmdletProviderIntrinsics(SessionStateInternal sessionState)
        {
            if (sessionState == null)
            {
                throw PSTraceSource.NewArgumentNullException("sessionState");
            }

            _sessionState = sessionState;
        } // ContentCmdletProviderIntrinsics internal
        /// <summary>
        /// The facade for managing providers.
        /// </summary>
        /// <param name="sessionState">
        /// The session to which this is a facade.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="sessionState"/> is null.
        /// </exception>
        internal CmdletProviderManagementIntrinsics(SessionStateInternal sessionState)
        {
            if (sessionState == null)
            {
                throw PSTraceSource.NewArgumentNullException("sessionState");
            }

            _sessionState = sessionState;
        }
 internal ChildItemCmdletProviderIntrinsics(Cmdlet cmdlet)
 {
     if (cmdlet == null)
     {
         throw PSTraceSource.NewArgumentNullException("cmdlet");
     }
     this.cmdlet = cmdlet;
     this.sessionState = cmdlet.Context.EngineSessionState;
 }
        /// <summary>
        /// Initializes a new instance of the SecurityDescriptorCmdletProviderIntrinsics
        /// class, using the sessionState parameter to obtain access to the SessionState APIs.
        /// </summary>
        /// <param name="sessionState">
        /// An instance of the real session state class.
        /// </param>
        internal SecurityDescriptorCmdletProviderIntrinsics(SessionStateInternal sessionState)
        {
            if (sessionState == null)
            {
                throw PSTraceSource.NewArgumentNullException(nameof(sessionState));
            }

            _sessionState = sessionState;
        }
Exemple #32
0
 public SessionState()
 {
     ExecutionContext executionContextFromTLS = LocalPipeline.GetExecutionContextFromTLS();
     if (executionContextFromTLS == null)
     {
         throw new InvalidOperationException("ExecutionContext");
     }
     this.sessionState = new SessionStateInternal(executionContextFromTLS);
     this.sessionState.PublicSessionState = this;
 }
        protected ScriptCommandProcessorBase(IScriptCommandInfo commandInfo, ExecutionContext context, bool useLocalScope, SessionStateInternal sessionState)
            : base((CommandInfo)commandInfo)
        {
            Diagnostics.Assert(commandInfo != null, "commandInfo cannot be null");
            Diagnostics.Assert(commandInfo.ScriptBlock != null, "scriptblock cannot be null");

            this._fromScriptFile = (this.CommandInfo is ExternalScriptInfo || this.CommandInfo is ScriptInfo);
            this._dontUseScopeCommandOrigin = true;

            CommonInitialization(commandInfo.ScriptBlock, context, useLocalScope, CommandOrigin.Internal, sessionState);
        }
Exemple #34
0
        internal SessionState(SessionStateInternal parent, bool createAsChild, bool linkToGlobal)
        {
            ExecutionContext executionContextFromTls = LocalPipeline.GetExecutionContextFromTLS();

            if (executionContextFromTls == null)
            {
                throw new InvalidOperationException("ExecutionContext");
            }
            this.sessionState = !createAsChild ? new SessionStateInternal(executionContextFromTls) : new SessionStateInternal(parent, linkToGlobal, executionContextFromTls);
            this.sessionState.PublicSessionState = this;
        }
Exemple #35
0
        internal SessionStateInternal(SessionStateInternal parent, bool linkToGlobal, ExecutionContext context)
        {
            if (context == null)
            {
                throw PSTraceSource.NewArgumentNullException(nameof(context));
            }

            ExecutionContext = context;

            // Create the working directory stack. This
            // is used for the pushd and popd commands

            _workingLocationStack = new Dictionary <string, Stack <PathInfo> >(StringComparer.OrdinalIgnoreCase);

            // Conservative choice to limit the Set-Location history in order to limit memory impact in case of a regression.
            const int locationHistoryLimit = 20;

            _setLocationHistory = new HistoryStack <PathInfo>(locationHistoryLimit);

            GlobalScope   = new SessionStateScope(null);
            ModuleScope   = GlobalScope;
            _currentScope = GlobalScope;

            InitializeSessionStateInternalSpecialVariables(false);

            // Create the push the global scope on as
            // the starting script scope.  That way, if you dot-source a script
            // that uses variables qualified by script: it works.
            GlobalScope.ScriptScope = GlobalScope;

            if (parent != null)
            {
                GlobalScope.Parent = parent.GlobalScope;

                // Copy the drives and providers from the parent...
                CopyProviders(parent);
                // During loading of core modules, providers are not populated.
                // We set the drive information later
                if (Providers != null && Providers.Count > 0)
                {
                    CurrentDrive = parent.CurrentDrive;
                }

                // Link it to the global scope...
                if (linkToGlobal)
                {
                    GlobalScope = parent.GlobalScope;
                }
            }
            else
            {
                _currentScope.LocalsTuple = MutableTuple.MakeTuple(Compiler.DottedLocalsTupleType, Compiler.DottedLocalsNameIndexMap);
            }
        }
		private ProviderInfo GetProvider()
        {
            ExecutionContext executionContext = GetExecutionContext();
            SessionStateInternal sessionState = new SessionStateInternal(executionContext);
			
			SessionStateProviderEntry providerEntry = new SessionStateProviderEntry("FileSystem",typeof(FileSystemProvider), null);
			sessionState.AddSessionStateEntry(providerEntry);
            ProviderInfo matchingProvider = sessionState.ProviderList.ToList()[0];

            return matchingProvider;
        }
Exemple #37
0
        public SessionState()
        {
            ExecutionContext executionContextFromTLS = LocalPipeline.GetExecutionContextFromTLS();

            if (executionContextFromTLS == null)
            {
                throw new InvalidOperationException("ExecutionContext");
            }
            this.sessionState = new SessionStateInternal(executionContextFromTLS);
            this.sessionState.PublicSessionState = this;
        }
Exemple #38
0
 internal ProviderIntrinsics(SessionStateInternal sessionState)
 {
     using (ProviderIntrinsics.tracer.TraceConstructor((object)this))
     {
         this.item               = sessionState != null ? new ItemCmdletProviderIntrinsics(sessionState) : throw ProviderIntrinsics.tracer.NewArgumentNullException(nameof(sessionState));
         this.childItem          = new ChildItemCmdletProviderIntrinsics(sessionState);
         this.content            = new ContentCmdletProviderIntrinsics(sessionState);
         this.property           = new PropertyCmdletProviderIntrinsics(sessionState);
         this.securityDescriptor = new SecurityDescriptorCmdletProviderIntrinsics(sessionState);
     }
 }
Exemple #39
0
 internal void SetCurrentScopeToExecutionScope()
 {
     if (this._commandSessionState == null)
     {
         this._commandSessionState = this.Context.EngineSessionState;
     }
     this._previousScope = this._commandSessionState.CurrentScope;
     this._previousCommandSessionState      = this.Context.EngineSessionState;
     this.Context.EngineSessionState        = this._commandSessionState;
     this._commandSessionState.CurrentScope = this.CommandScope;
     this.OnSetCurrentScope();
 }
Exemple #40
0
 internal ProviderIntrinsics(SessionStateInternal sessionState)
 {
     if (sessionState == null)
     {
         throw PSTraceSource.NewArgumentNullException("sessionState");
     }
     this.item = new ItemCmdletProviderIntrinsics(sessionState);
     this.childItem = new ChildItemCmdletProviderIntrinsics(sessionState);
     this.content = new ContentCmdletProviderIntrinsics(sessionState);
     this.property = new PropertyCmdletProviderIntrinsics(sessionState);
     this.securityDescriptor = new SecurityDescriptorCmdletProviderIntrinsics(sessionState);
 }
 internal ProviderIntrinsics(SessionStateInternal sessionState)
 {
     if (sessionState == null)
     {
         throw PSTraceSource.NewArgumentNullException("sessionState");
     }
     this.item               = new ItemCmdletProviderIntrinsics(sessionState);
     this.childItem          = new ChildItemCmdletProviderIntrinsics(sessionState);
     this.content            = new ContentCmdletProviderIntrinsics(sessionState);
     this.property           = new PropertyCmdletProviderIntrinsics(sessionState);
     this.securityDescriptor = new SecurityDescriptorCmdletProviderIntrinsics(sessionState);
 }
Exemple #42
0
        private static object SetVariableValue(VariablePath variablePath, object value, ExecutionContext executionContext, AttributeBaseAst[] attributeAsts)
        {
            SessionStateScope    scope;
            SessionStateInternal engineSessionState = executionContext.EngineSessionState;
            CommandOrigin        scopeOrigin        = engineSessionState.CurrentScope.ScopeOrigin;

            if (!variablePath.IsVariable)
            {
                engineSessionState.SetVariable(variablePath, value, true, scopeOrigin);
                return(value);
            }
            if (executionContext.PSDebugTraceLevel > 0)
            {
                executionContext.Debugger.TraceVariableSet(variablePath.UnqualifiedPath, value);
            }
            if (variablePath.IsUnscopedVariable)
            {
                variablePath = variablePath.CloneAndSetLocal();
            }
            PSVariable newValue = engineSessionState.GetVariableItem(variablePath, out scope, scopeOrigin);

            if (newValue == null)
            {
                Collection <Attribute> attributes = (attributeAsts == null) ? new Collection <Attribute>() : GetAttributeCollection(attributeAsts);
                newValue = new PSVariable(variablePath.UnqualifiedPath, value, ScopedItemOptions.None, attributes);
                engineSessionState.SetVariable(variablePath, newValue, false, scopeOrigin);
                if (executionContext._debuggingMode > 0)
                {
                    executionContext.Debugger.CheckVariableWrite(variablePath.UnqualifiedPath);
                }
                return(value);
            }
            if (attributeAsts != null)
            {
                newValue.Attributes.Clear();
                Collection <Attribute> attributeCollection = GetAttributeCollection(attributeAsts);
                value = PSVariable.TransformValue(attributeCollection, value);
                if (!PSVariable.IsValidValue(attributeCollection, value))
                {
                    ValidationMetadataException exception = new ValidationMetadataException("ValidateSetFailure", null, Metadata.InvalidValueFailure, new object[] { newValue.Name, (value != null) ? value.ToString() : "" });
                    throw exception;
                }
                newValue.SetValueRaw(value, true);
                newValue.AddParameterAttributesNoChecks(attributeCollection);
                if (executionContext._debuggingMode > 0)
                {
                    executionContext.Debugger.CheckVariableWrite(variablePath.UnqualifiedPath);
                }
                return(value);
            }
            newValue.Value = value;
            return(value);
        }
Exemple #43
0
 public void TestDrives()
 {
     CultureInfo currentCulture = CultureInfo.CurrentCulture;
     PSHost hostInterface =  new DefaultHost(currentCulture,currentCulture);
     RunspaceConfiguration runspaceConfiguration =  RunspaceConfiguration.Create();
     InitialSessionState iss = InitialSessionState.CreateDefault2();
     AutomationEngine engine = new AutomationEngine(hostInterface, runspaceConfiguration, iss);
     ExecutionContext executionContext = new ExecutionContext(engine, hostInterface, iss);
     SessionStateInternal sessionState = new SessionStateInternal(executionContext);
     Collection<PSDriveInfo> drives = sessionState.Drives(null);
     Assert.NotNull(drives);
 }
        /// <summary>
        /// Constructs a facade over the "real" session state API.
        /// </summary>
        /// <param name="sessionState">
        /// An instance of the cmdlet.
        /// </param>
        internal ProviderIntrinsics(SessionStateInternal sessionState)
        {
            if (sessionState == null)
            {
                throw PSTraceSource.NewArgumentNullException(nameof(sessionState));
            }

            Item               = new ItemCmdletProviderIntrinsics(sessionState);
            ChildItem          = new ChildItemCmdletProviderIntrinsics(sessionState);
            Content            = new ContentCmdletProviderIntrinsics(sessionState);
            Property           = new PropertyCmdletProviderIntrinsics(sessionState);
            SecurityDescriptor = new SecurityDescriptorCmdletProviderIntrinsics(sessionState);
        }
Exemple #45
0
        internal SessionStateInternal(SessionStateInternal parent, bool linkToGlobal, ExecutionContext context)
        {
            if (context == null)
            {
                throw PSTraceSource.NewArgumentNullException("context");
            }
            ExecutionContext = context;

            // Create the working directory stack. This
            // is used for the pushd and popd commands

            _workingLocationStack = new Dictionary<String, Stack<PathInfo>>(StringComparer.OrdinalIgnoreCase);

            GlobalScope = new SessionStateScope(null);
            ModuleScope = GlobalScope;
            _currentScope = GlobalScope;

            InitializeSessionStateInternalSpecialVariables(false);

            // Create the push the global scope on as
            // the starting script scope.  That way, if you dot-source a script
            // that uses variables qualified by script: it works.
            GlobalScope.ScriptScope = GlobalScope;


            if (parent != null)
            {
                GlobalScope.Parent = parent.GlobalScope;

                // Copy the drives and providers from the parent...
                CopyProviders(parent);
                // During loading of core modules, providers are not populated.
                // We set the drive information later
                if (Providers != null && Providers.Count > 0)
                {
                    CurrentDrive = parent.CurrentDrive;
                }

                // Link it to the global scope...
                if (linkToGlobal)
                {
                    GlobalScope = parent.GlobalScope;
                }
            }
            else
            {
                _currentScope.LocalsTuple = MutableTuple.MakeTuple(Compiler.DottedLocalsTupleType, Compiler.DottedLocalsNameIndexMap);
            }
        }
Exemple #46
0
        /// <summary>
        /// The internal constructor for this object. It should be the only one that gets called.
        /// </summary>
        ///
        /// <param name="sessionState">
        /// An instance of SessionState that the APIs should work against.
        /// </param>
        ///
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="sessionState"/> is null.
        /// </exception>
        /// 
        internal SessionState(SessionStateInternal sessionState)
        {
            if (sessionState == null)
            {
                throw PSTraceSource.NewArgumentNullException("sessionState");
            }

            _sessionState = sessionState;

#if RELATIONSHIP_SUPPORTED
    // 2004/11/24-JeffJon - Relationships have been removed from the Exchange release

            this.relationship = new RelationshipProviderManagementIntrinsics (sessionState);
#endif
        } // SessionState
Exemple #47
0
        } // SessionState

        /// <summary>
        /// The internal constructor for this object. It should be the only one that gets called.
        /// </summary>
        ///
        /// <param name="context">
        /// An instance of ExecutionContext whose EngineSessionState represents the parent session state.
        /// </param>
        /// <param name="createAsChild">
        /// True if the session state should be created as a child session state.
        /// </param>
        /// <param name="linkToGlobal">
        /// True if the session state should be linked to the global scope.
        /// </param>
        ///
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="context"/> is null.
        /// </exception>
        internal SessionState(ExecutionContext context, bool createAsChild, bool linkToGlobal)
        {
            if (context == null)
                throw new InvalidOperationException("ExecutionContext");

            if (createAsChild)
            {
                _sessionState = new SessionStateInternal(context.EngineSessionState, linkToGlobal, context);
            }
            else
            {
                _sessionState = new SessionStateInternal(context);
            }

            _sessionState.PublicSessionState = this;
        } // SessionState
 protected void CommonInitialization(ScriptBlock scriptBlock, ExecutionContext context, bool useLocalScope, SessionStateInternal sessionState)
 {
     base.CommandSessionState = sessionState;
     base._context = context;
     this._rethrowExitException = base.Context.ScriptCommandProcessorShouldRethrowExit;
     base._context.ScriptCommandProcessorShouldRethrowExit = false;
     ScriptCommand thisCommand = new ScriptCommand {
         CommandInfo = base.CommandInfo
     };
     base.Command = thisCommand;
     base.Command.commandRuntime = base.commandRuntime = new MshCommandRuntime(base.Context, base.CommandInfo, thisCommand);
     base.CommandScope = useLocalScope ? base.CommandSessionState.NewScope(base.FromScriptFile) : base.CommandSessionState.CurrentScope;
     base.UseLocalScope = useLocalScope;
     this._scriptBlock = scriptBlock;
     if (!base.UseLocalScope && !this._rethrowExitException)
     {
         CommandProcessorBase.ValidateCompatibleLanguageMode(this._scriptBlock, context.LanguageMode, base.Command.MyInvocation);
     }
 }
Exemple #49
0
 internal SessionStateInternal(SessionStateInternal parent, bool linkToGlobal, System.Management.Automation.ExecutionContext context)
 {
     this.ModuleTableKeys = new List<string>();
     this._moduleTable = new Dictionary<string, PSModuleInfo>(StringComparer.OrdinalIgnoreCase);
     this._scripts = new List<string>(new string[] { "*" });
     this._applications = new List<string>(new string[] { "*" });
     this._exportedCmdlets = new List<CmdletInfo>();
     this._exportedAliases = new List<AliasInfo>();
     this._exportedFunctions = new List<FunctionInfo>();
     this._exportedWorkflows = new List<WorkflowInfo>();
     this.defaultStackName = "default";
     this._providers = new Dictionary<string, List<ProviderInfo>>(100, StringComparer.OrdinalIgnoreCase);
     this._providersCurrentWorkingDrive = new Dictionary<ProviderInfo, PSDriveInfo>();
     this._exportedVariables = new List<PSVariable>();
     if (context == null)
     {
         throw PSTraceSource.NewArgumentNullException("context");
     }
     this._context = context;
     this.workingLocationStack = new Dictionary<string, Stack<PathInfo>>(StringComparer.OrdinalIgnoreCase);
     this._globalScope = new SessionStateScope(null);
     this._moduleScope = this._globalScope;
     this.currentScope = this._globalScope;
     this.InitializeSessionStateInternalSpecialVariables(false);
     this._globalScope.ScriptScope = this._globalScope;
     if (parent != null)
     {
         this._globalScope.Parent = parent.GlobalScope;
         this.CopyProviders(parent);
         if ((this.Providers != null) && (this.Providers.Count > 0))
         {
             this.CurrentDrive = parent.CurrentDrive;
         }
         if (linkToGlobal)
         {
             this._globalScope = parent.GlobalScope;
         }
     }
     else
     {
         this.currentScope.LocalsTuple = MutableTuple.MakeTuple(Compiler.DottedLocalsTupleType, Compiler.DottedLocalsNameIndexMap);
     }
 }
        } // ProviderIntrinsics internal

        /// <summary>
        /// Constructs a facade over the "real" session state API
        /// </summary>
        ///
        /// <param name="sessionState">
        /// An instance of the cmdlet.
        /// </param>
        ///
        internal ProviderIntrinsics(SessionStateInternal sessionState)
        {
            if (sessionState == null)
            {
                throw PSTraceSource.NewArgumentNullException("sessionState");
            }

            Item = new ItemCmdletProviderIntrinsics(sessionState);
            ChildItem = new ChildItemCmdletProviderIntrinsics(sessionState);
            Content = new ContentCmdletProviderIntrinsics(sessionState);
            Property = new PropertyCmdletProviderIntrinsics(sessionState);
#if SUPPORTS_IMULTIVALUEPROPERTYCMDLETPROVIDER
            this.propertyValue = new PropertyValueCmdletProviderIntrinsics(sessionState);
#endif
            SecurityDescriptor = new SecurityDescriptorCmdletProviderIntrinsics(sessionState);

#if RELATIONSHIP_SUPPORTED
    // 2004/11/24-JeffJon - Relationships have been removed from the Exchange release
            this.relationship = new RelationshipProviderIntrinsics(sessionState);
#endif
        } // ProviderIntrinsics internal
Exemple #51
0
 private static CommandProcessorBase CreateCommandProcessorForScript(ScriptInfo scriptInfo, ExecutionContext context, bool useNewScope, SessionStateInternal sessionState)
 {
     sessionState = sessionState ?? (scriptInfo.ScriptBlock.SessionStateInternal ?? context.EngineSessionState);
     CommandProcessorBase base2 = GetScriptAsCmdletProcessor(scriptInfo, context, useNewScope, true, sessionState);
     if (base2 != null)
     {
         return base2;
     }
     return new DlrScriptCommandProcessor(scriptInfo, context, useNewScope, sessionState);
 }
 internal DlrScriptCommandProcessor(ScriptBlock scriptBlock, ExecutionContext context, bool useNewScope, CommandOrigin origin, SessionStateInternal sessionState) : base(scriptBlock, context, useNewScope, origin, sessionState)
 {
     this._input = new ArrayList();
     this.Init();
 }
Exemple #53
0
 internal PSVariable SetVariable(string name, object value, bool asValue, bool force, SessionStateInternal sessionState, CommandOrigin origin = CommandOrigin.Internal, bool fastPath = false)
 {
     PSVariable variable;
     PSVariable variable2 = value as PSVariable;
     if (fastPath)
     {
         if (this.Parent != null)
         {
             throw new NotImplementedException("fastPath");
         }
         variable = new PSVariable(name, variable2.Value, variable2.Options, variable2.Attributes) {
             Description = variable2.Description
         };
         this.GetPrivateVariables()[name] = variable;
         return variable;
     }
     bool flag = this.TryGetVariable(name, origin, true, out variable);
     if (!asValue && (variable2 != null))
     {
         if (flag)
         {
             if (((variable == null) || variable.IsConstant) || (!force && variable.IsReadOnly))
             {
                 SessionStateUnauthorizedAccessException exception = new SessionStateUnauthorizedAccessException(name, SessionStateCategory.Variable, "VariableNotWritable", SessionStateStrings.VariableNotWritable);
                 throw exception;
             }
             if ((variable is LocalVariable) && (variable2.Attributes.Any<Attribute>() || (variable2.Options != variable.Options)))
             {
                 SessionStateUnauthorizedAccessException exception2 = new SessionStateUnauthorizedAccessException(name, SessionStateCategory.Variable, "VariableNotWritableRare", SessionStateStrings.VariableNotWritableRare);
                 throw exception2;
             }
             if (variable.IsReadOnly && force)
             {
                 this._variables.Remove(name);
                 flag = false;
                 variable = new PSVariable(name, variable2.Value, variable2.Options, variable2.Attributes) {
                     Description = variable2.Description
                 };
             }
             else
             {
                 variable.Attributes.Clear();
                 variable.Value = variable2.Value;
                 variable.Options = variable2.Options;
                 variable.Description = variable2.Description;
                 foreach (Attribute attribute in variable2.Attributes)
                 {
                     variable.Attributes.Add(attribute);
                 }
             }
         }
         else
         {
             variable = variable2;
         }
     }
     else if (variable != null)
     {
         variable.Value = value;
     }
     else
     {
         variable = (this.LocalsTuple != null) ? (this.LocalsTuple.TrySetVariable(name, value)) ?? new PSVariable(name, value) : new PSVariable(name, value);
     }
     if (!flag && (this._variables.Count > (this.VariableCapacity.FastValue - 1)))
     {
         SessionStateOverflowException exception3 = new SessionStateOverflowException(name, SessionStateCategory.Variable, "VariableOverflow", SessionStateStrings.VariableOverflow, new object[] { this.VariableCapacity.FastValue });
         throw exception3;
     }
     if (System.Management.Automation.ExecutionContext.HasEverUsedConstrainedLanguage)
     {
         System.Management.Automation.ExecutionContext executionContextFromTLS = LocalPipeline.GetExecutionContextFromTLS();
         if (((executionContextFromTLS != null) && (executionContextFromTLS.LanguageMode == PSLanguageMode.ConstrainedLanguage)) && ((variable.Options & ScopedItemOptions.AllScope) == ScopedItemOptions.AllScope))
         {
             /* TODO: Review how to  get around this: */ /* throw new PSNotSupportedException(); */
         }
     }
     this._variables[name] = variable;
     variable.SessionState = sessionState;
     return variable;
 }
Exemple #54
0
 internal PSVariable NewVariable(PSVariable newVariable, bool force, SessionStateInternal sessionState)
 {
     PSVariable variable;
     bool flag = this.TryGetVariable(newVariable.Name, this.ScopeOrigin, true, out variable);
     if (flag)
     {
         if (((variable == null) || variable.IsConstant) || (!force && variable.IsReadOnly))
         {
             SessionStateUnauthorizedAccessException exception = new SessionStateUnauthorizedAccessException(newVariable.Name, SessionStateCategory.Variable, "VariableNotWritable", SessionStateStrings.VariableNotWritable);
             throw exception;
         }
         if (variable is LocalVariable)
         {
             SessionStateUnauthorizedAccessException exception2 = new SessionStateUnauthorizedAccessException(newVariable.Name, SessionStateCategory.Variable, "VariableNotWritableRare", SessionStateStrings.VariableNotWritableRare);
             throw exception2;
         }
         if (!object.ReferenceEquals(newVariable, variable))
         {
             variable.WasRemoved = true;
             variable = newVariable;
         }
     }
     else
     {
         variable = newVariable;
     }
     if (!flag && (this._variables.Count > (this.VariableCapacity.FastValue - 1)))
     {
         SessionStateOverflowException exception3 = new SessionStateOverflowException(newVariable.Name, SessionStateCategory.Variable, "VariableOverflow", SessionStateStrings.VariableOverflow, new object[] { this.VariableCapacity.FastValue });
         throw exception3;
     }
     if (System.Management.Automation.ExecutionContext.HasEverUsedConstrainedLanguage)
     {
         System.Management.Automation.ExecutionContext executionContextFromTLS = LocalPipeline.GetExecutionContextFromTLS();
         if (((executionContextFromTLS != null) && (executionContextFromTLS.LanguageMode == PSLanguageMode.ConstrainedLanguage)) && ((variable.Options & ScopedItemOptions.AllScope) == ScopedItemOptions.AllScope))
         {
             throw new PSNotSupportedException();
         }
     }
     this._variables[variable.Name] = variable;
     variable.SessionState = sessionState;
     return variable;
 }
Exemple #55
0
        internal CommandProcessorBase LookupCommandProcessor(CommandInfo commandInfo, CommandOrigin commandOrigin, bool? useLocalScope, SessionStateInternal sessionState)
        {
            CommandProcessorBase base2 = null;
            FunctionInfo info3;
            CommandNotFoundException exception6;
            HashSet<string> set = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
            while (((commandInfo.CommandType == CommandTypes.Alias) && !set.Contains(commandInfo.Name)) && ((commandOrigin == CommandOrigin.Internal) || (commandInfo.Visibility == SessionStateEntryVisibility.Public)))
            {
                set.Add(commandInfo.Name);
                AliasInfo info = (AliasInfo) commandInfo;
                commandInfo = info.ResolvedCommand;
                if (commandInfo == null)
                {
                    commandInfo = LookupCommandInfo(info.Definition, commandOrigin, this._context);
                }
                if (commandInfo == null)
                {
                    CommandNotFoundException exception = new CommandNotFoundException(info.Name, null, "AliasNotResolvedException", DiscoveryExceptions.AliasNotResolvedException, new object[] { info.UnresolvedCommandName });
                    throw exception;
                }
                PSSQMAPI.IncrementData(CommandTypes.Alias);
            }
            ShouldRun(this._context, this._context.EngineHostInterface, commandInfo, commandOrigin);
            CommandTypes commandType = commandInfo.CommandType;
            if (commandType <= CommandTypes.ExternalScript)
            {
                switch (commandType)
                {
                    case CommandTypes.Function:
                    case CommandTypes.Filter:
                        goto Label_01E3;

                    case CommandTypes.Cmdlet:
                        base2 = new CommandProcessor((CmdletInfo) commandInfo, this._context);
                        goto Label_0260;

                    case CommandTypes.ExternalScript:
                    {
                        ExternalScriptInfo scriptInfo = (ExternalScriptInfo) commandInfo;
                        scriptInfo.SignatureChecked = true;
                        try
                        {
                            if (!this._context.IsSingleShell)
                            {
                                bool? nullable = useLocalScope;
                                base2 = this.CreateScriptProcessorForMiniShell(scriptInfo, nullable.HasValue ? nullable.GetValueOrDefault() : true, sessionState);
                            }
                            else
                            {
                                bool? nullable2 = useLocalScope;
                                base2 = this.CreateScriptProcessorForSingleShell(scriptInfo, this._context, nullable2.HasValue ? nullable2.GetValueOrDefault() : true, sessionState);
                            }
                            goto Label_0260;
                        }
                        catch (ScriptRequiresSyntaxException exception2)
                        {
                            CommandNotFoundException exception3 = new CommandNotFoundException(exception2.Message, exception2);
                            throw exception3;
                        }
                        catch (PSArgumentException exception4)
                        {
                            CommandNotFoundException exception5 = new CommandNotFoundException(commandInfo.Name, exception4, "ScriptRequiresInvalidFormat", DiscoveryExceptions.ScriptRequiresInvalidFormat, new object[0]);
                            throw exception5;
                        }
                        goto Label_01E3;
                    }
                }
                goto Label_023F;
            }
            if (commandType != CommandTypes.Application)
            {
                if (commandType == CommandTypes.Script)
                {
                    bool? nullable4 = useLocalScope;
                    base2 = CreateCommandProcessorForScript((ScriptInfo) commandInfo, this._context, nullable4.HasValue ? nullable4.GetValueOrDefault() : true, sessionState);
                    goto Label_0260;
                }
                if (commandType == CommandTypes.Workflow)
                {
                    goto Label_01E3;
                }
                goto Label_023F;
            }
            base2 = new NativeCommandProcessor((ApplicationInfo) commandInfo, this._context);
            goto Label_0260;
        Label_01E3:
            info3 = (FunctionInfo) commandInfo;
            bool? nullable3 = useLocalScope;
            base2 = CreateCommandProcessorForScript(info3, this._context, nullable3.HasValue ? nullable3.GetValueOrDefault() : true, sessionState);
            goto Label_0260;
        Label_023F:
            exception6 = new CommandNotFoundException(commandInfo.Name, null, "CommandNotFoundException", DiscoveryExceptions.CommandNotFoundException, new object[0]);
            throw exception6;
        Label_0260:
            PSSQMAPI.IncrementData(commandInfo.CommandType);
            base2.Command.CommandOriginInternal = commandOrigin;
            base2.Command.MyInvocation.InvocationName = commandInfo.Name;
            return base2;
        }
Exemple #56
0
 private static CommandProcessorBase GetScriptAsCmdletProcessor(IScriptCommandInfo scriptCommandInfo, ExecutionContext context, bool useNewScope, bool fromScriptFile, SessionStateInternal sessionState)
 {
     if ((scriptCommandInfo.ScriptBlock == null) || !scriptCommandInfo.ScriptBlock.UsesCmdletBinding)
     {
         return null;
     }
     sessionState = sessionState ?? (scriptCommandInfo.ScriptBlock.SessionStateInternal ?? context.EngineSessionState);
     return new CommandProcessor(scriptCommandInfo, context, useNewScope, fromScriptFile, sessionState);
 }
Exemple #57
0
 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);
 }
Exemple #58
0
 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;
 }
 internal DlrScriptCommandProcessor(ScriptInfo scriptInfo, ExecutionContext context, bool useNewScope, SessionStateInternal sessionState) : base(scriptInfo, context, useNewScope, sessionState)
 {
     this._input = new ArrayList();
     this.Init();
 }
Exemple #60
0
 internal static CommandProcessorBase CreateCommandProcessorForScript(ScriptBlock scriptblock, ExecutionContext context, bool useNewScope, SessionStateInternal sessionState)
 {
     sessionState = sessionState ?? (scriptblock.SessionStateInternal ?? context.EngineSessionState);
     if (scriptblock.UsesCmdletBinding)
     {
         FunctionInfo scriptCommandInfo = new FunctionInfo("", scriptblock, context);
         return GetScriptAsCmdletProcessor(scriptCommandInfo, context, useNewScope, false, sessionState);
     }
     return new DlrScriptCommandProcessor(scriptblock, context, useNewScope, CommandOrigin.Internal, sessionState);
 }