예제 #1
0
        /// <summary>
        /// Add any special variables to the session state variable table. This routine
        /// must be called at construction time or if the variable table is reset.
        /// </summary>
        internal void InitializeSessionStateInternalSpecialVariables(bool clearVariablesTable)
        {
            if (clearVariablesTable)
            {
                // Clear the variable table
                GlobalScope.Variables.Clear();

                // Add in the per-scope default variables.
                GlobalScope.AddSessionStateScopeDefaultVariables();
            }

            // Set variable $Error
            PSVariable errorvariable = new PSVariable("Error", new ArrayList(), ScopedItemOptions.Constant);

            GlobalScope.SetVariable(errorvariable.Name, errorvariable, false, false, this, fastPath: true);

            // Set variable $PSDefaultParameterValues
            Collection <Attribute> attributes = new Collection <Attribute>();

            attributes.Add(new ArgumentTypeConverterAttribute(typeof(System.Management.Automation.DefaultParameterDictionary)));
            PSVariable psDefaultParameterValuesVariable = new PSVariable(SpecialVariables.PSDefaultParameterValues,
                                                                         new DefaultParameterDictionary(),
                                                                         ScopedItemOptions.None, attributes,
                                                                         RunspaceInit.PSDefaultParameterValuesDescription);

            GlobalScope.SetVariable(psDefaultParameterValuesVariable.Name, psDefaultParameterValuesVariable, false, false, this, fastPath: true);
        }
예제 #2
0
        public void RemebersTheVaraibleValueAfterModificationInSubScope()
        {
            var sut = new GlobalScope(null, "a");

            sut.SetVariable("a", new String("bottom"), false);

            sut.StartScope();
            sut.SetVariable("a", new String("derived"), true);
            var innerAa =
                sut
                .GetVariable("a", new Runtime(new Processors())).Get(new Runtime(new Processors())) as String;

            Assert.Equal("derived", innerAa.Value);
            sut.EndScope();

            var a = sut.GetVariable("a", new Runtime(new Processors())).Get(new Runtime(new Processors())) as String;

            Assert.Equal("bottom", a.Value);
        }
예제 #3
0
        public void DoesNotTModifyVariableInUpperFromDerivedScope()
        {
            var sut = new GlobalScope(null, "root");

            sut.SetVariable("a", new String("bottom"), false);

            var derived = sut.DeriveFunctionScope();

            derived.SetVariable("a", new String("derived"), true);
            var innerAa = derived.GetVariable("a", new Runtime(new Processors())).Get(new Runtime(new Processors())) as String;

            Assert.Equal("derived", innerAa.Value);


            var a = sut.GetVariable("a", new Runtime(new Processors())).Get(new Runtime(new Processors())) as String;

            Assert.Equal("bottom", a.Value);
        }
예제 #4
0
 public void SetVariable(string variableName, IValue functionParamter, bool coverUpVariable)
 {
     _stack.SetVariable(variableName, functionParamter, coverUpVariable);
 }