当前位置: 首页>>代码示例>>C#>>正文


C# ExecutionContext.SetVariable方法代码示例

本文整理汇总了C#中ExecutionContext.SetVariable方法的典型用法代码示例。如果您正苦于以下问题:C# ExecutionContext.SetVariable方法的具体用法?C# ExecutionContext.SetVariable怎么用?C# ExecutionContext.SetVariable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ExecutionContext的用法示例。


在下文中一共展示了ExecutionContext.SetVariable方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Execute

        public override string Execute(ExecutionContext context)
        {
            string varValue = ExecuteChildren(context);

            context.SetVariable(Variable, varValue.Trim(Environment.NewLine.ToCharArray()));

            return "";
        }
开发者ID:strager,项目名称:osq2osb,代码行数:8,代码来源:LetNode.cs

示例2: LoadConfigFile

 internal static Hashtable LoadConfigFile(ExecutionContext context, ExternalScriptInfo scriptInfo)
 {
     object obj2;
     object variableValue = context.GetVariableValue(SpecialVariables.PSScriptRootVarPath);
     object newValue = context.GetVariableValue(SpecialVariables.PSCommandPathVarPath);
     try
     {
         context.SetVariable(SpecialVariables.PSScriptRootVarPath, Path.GetDirectoryName(scriptInfo.Definition));
         context.SetVariable(SpecialVariables.PSCommandPathVarPath, scriptInfo.Definition);
         obj2 = PSObject.Base(scriptInfo.ScriptBlock.InvokeReturnAsIs(new object[0]));
     }
     finally
     {
         context.SetVariable(SpecialVariables.PSScriptRootVarPath, variableValue);
         context.SetVariable(SpecialVariables.PSCommandPathVarPath, newValue);
     }
     return (obj2 as Hashtable);
 }
开发者ID:nickchal,项目名称:pash,代码行数:18,代码来源:DISCUtils.cs

示例3: ConditionSatisfiedRegex

 internal static bool ConditionSatisfiedRegex(bool caseSensitive, object condition, IScriptExtent errorPosition, string str, ExecutionContext context)
 {
     string str2;
     bool success;
     RegexOptions options = caseSensitive ? RegexOptions.None : RegexOptions.IgnoreCase;
     try
     {
         Match match;
         Regex regex = condition as Regex;
         if ((regex != null) && (((regex.Options & RegexOptions.IgnoreCase) != RegexOptions.None) != caseSensitive))
         {
             match = regex.Match(str);
         }
         else
         {
             str2 = PSObject.ToStringParser(context, condition);
             match = Regex.Match(str, str2, options);
             if (match.Success && (match.Groups.Count > 0))
             {
                 regex = new Regex(str2, options);
             }
         }
         if (match.Success)
         {
             GroupCollection groups = match.Groups;
             if (groups.Count > 0)
             {
                 Hashtable newValue = new Hashtable(StringComparer.CurrentCultureIgnoreCase);
                 foreach (string str3 in regex.GetGroupNames())
                 {
                     Group group = groups[str3];
                     if (group.Success)
                     {
                         int num;
                         if (int.TryParse(str3, out num))
                         {
                             newValue.Add(num, group.ToString());
                         }
                         else
                         {
                             newValue.Add(str3, group.ToString());
                         }
                     }
                 }
                 context.SetVariable(SpecialVariables.MatchesVarPath, newValue);
             }
         }
         success = match.Success;
     }
     catch (ArgumentException exception)
     {
         str2 = PSObject.ToStringParser(context, condition);
         throw InterpreterError.NewInterpreterExceptionWithInnerException(str2, typeof(RuntimeException), errorPosition, "InvalidRegularExpression", ParserStrings.InvalidRegularExpression, exception, new object[] { str2 });
     }
     return success;
 }
开发者ID:nickchal,项目名称:pash,代码行数:56,代码来源:SwitchOps.cs

示例4: Execute

        public override string Execute(ExecutionContext context)
        {
            var output = new StringBuilder();

            object expr = Values.Evaluate(context);

            object[] values = expr as object[] ?? new object[] { expr };

            foreach(var value in values) {
                context.SetVariable(Variable, value);

                output.Append(ExecuteChildren(context));
            }

            return output.ToString();
        }
开发者ID:peppy,项目名称:osq2osb,代码行数:16,代码来源:EachNode.cs

示例5: Evaluation

        public void Evaluation()
        {
            string input = "x${test - 42}.2";
            string expected = "x42.2";

            var context = new ExecutionContext();
            context.SetVariable("test", 84);

            var output = new StringBuilder();

            using(var reader = new LocatedTextReaderWrapper(input)) {
                var parser = new Parser(reader);

                foreach(var node in parser.ReadNodes()) {
                    output.Append(node.Execute(context));
                }

                Assert.AreEqual(expected, output.ToString());
            }
        }
开发者ID:peppy,项目名称:osq2osb,代码行数:20,代码来源:ParserTests.cs

示例6: Execute

        public override string Execute(ExecutionContext context)
        {
            var output = new StringBuilder();

            double counter = Convert.ToDouble(Start.Evaluate(context), Parser.DefaultCulture);

            while(true) {
                context.SetVariable(Variable, counter);

                output.Append(ExecuteChildren(context));

                counter = Convert.ToDouble(context.GetVariable(Variable), Parser.DefaultCulture);
                counter += Step == null ? 1.0 : Convert.ToDouble(Step.Evaluate(context), Parser.DefaultCulture);

                if(counter >= Convert.ToDouble(End.Evaluate(context), Parser.DefaultCulture)) {
                    break;
                }
            }

            return output.ToString();
        }
开发者ID:peppy,项目名称:osq2osb,代码行数:21,代码来源:ForNode.cs

示例7: SetPSBoundParametersVariable

 internal void SetPSBoundParametersVariable(ExecutionContext context)
 {
     context.SetVariable(SpecialVariables.PSBoundParametersVarPath, this._dictionary);
 }
开发者ID:nickchal,项目名称:pash,代码行数:4,代码来源:CommandLineParameters.cs

示例8: EvaluatePowerShellDataFile


//.........这里部分代码省略.........
                                     bool skipPathValidation)
        {
            if (!skipPathValidation && string.IsNullOrEmpty(parameterName)) { throw PSTraceSource.NewArgumentNullException("parameterName"); }
            if (string.IsNullOrEmpty(psDataFilePath)) { throw PSTraceSource.NewArgumentNullException("psDataFilePath"); }
            if (context == null) { throw PSTraceSource.NewArgumentNullException("context"); }

            string resolvedPath;
            if (skipPathValidation)
            {
                resolvedPath = psDataFilePath;
            }
            else
            {
                #region "ValidatePowerShellDataFilePath"

                bool isPathValid = true;

                // File extension needs to be .psd1
                string pathExt = Path.GetExtension(psDataFilePath);
                if (string.IsNullOrEmpty(pathExt) ||
                    !StringLiterals.PowerShellDataFileExtension.Equals(pathExt, StringComparison.OrdinalIgnoreCase))
                {
                    isPathValid = false;
                }

                ProviderInfo provider;
                var resolvedPaths = context.SessionState.Path.GetResolvedProviderPathFromPSPath(psDataFilePath, out provider);

                // ConfigPath should be resolved as FileSystem provider
                if (provider == null || !Microsoft.PowerShell.Commands.FileSystemProvider.ProviderName.Equals(provider.Name, StringComparison.OrdinalIgnoreCase))
                {
                    isPathValid = false;
                }

                // ConfigPath should be resolved to a single path
                if (resolvedPaths.Count != 1)
                {
                    isPathValid = false;
                }

                if (!isPathValid)
                {
                    throw PSTraceSource.NewArgumentException(
                             parameterName,
                             ParserStrings.CannotResolvePowerShellDataFilePath,
                             psDataFilePath);
                }

                resolvedPath = resolvedPaths[0];

                #endregion "ValidatePowerShellDataFilePath"
            }

            #region "LoadAndEvaluatePowerShellDataFile"

            object evaluationResult;
            try
            {
                // Create the scriptInfo for the .psd1 file
                string dataFileName = Path.GetFileName(resolvedPath);
                var dataFileScriptInfo = new ExternalScriptInfo(dataFileName, resolvedPath, context);
                ScriptBlock scriptBlock = dataFileScriptInfo.ScriptBlock;

                // Validate the scriptblock
                scriptBlock.CheckRestrictedLanguage(allowedCommands, allowedVariables, allowEnvironmentVariables);

                // Evaluate the scriptblock
                object oldPsScriptRoot = context.GetVariableValue(SpecialVariables.PSScriptRootVarPath);
                try
                {
                    // Set the $PSScriptRoot before the evaluation
                    context.SetVariable(SpecialVariables.PSScriptRootVarPath, Path.GetDirectoryName(resolvedPath));
                    evaluationResult = PSObject.Base(scriptBlock.InvokeReturnAsIs());
                }
                finally
                {
                    context.SetVariable(SpecialVariables.PSScriptRootVarPath, oldPsScriptRoot);
                }
            }
            catch (RuntimeException ex)
            {
                throw PSTraceSource.NewInvalidOperationException(
                         ex,
                         ParserStrings.CannotLoadPowerShellDataFile,
                         psDataFilePath,
                         ex.Message);
            }

            var retResult = evaluationResult as Hashtable;
            if (retResult == null)
            {
                throw PSTraceSource.NewInvalidOperationException(
                         ParserStrings.InvalidPowerShellDataFile,
                         psDataFilePath);
            }

            #endregion "LoadAndEvaluatePowerShellDataFile"

            return retResult;
        }
开发者ID:40a,项目名称:PowerShell,代码行数:101,代码来源:PsUtils.cs

示例9: SetErrorVariables

 internal static void SetErrorVariables(IScriptExtent extent, RuntimeException rte, ExecutionContext context, Pipe outputPipe)
 {
     string newValue = null;
     Exception innerException = rte;
     int num = 0;
     while ((innerException != null) && (num++ < 10))
     {
         if (!string.IsNullOrEmpty(innerException.StackTrace))
         {
             newValue = innerException.StackTrace;
         }
         innerException = innerException.InnerException;
     }
     context.SetVariable(SpecialVariables.StackTraceVarPath, newValue);
     InterpreterError.UpdateExceptionErrorRecordPosition(rte, extent);
     ErrorRecord record = rte.ErrorRecord.WrapException(rte);
     if (!(rte is PipelineStoppedException))
     {
         if (outputPipe != null)
         {
             outputPipe.AppendVariableList(VariableStreamKind.Error, record);
         }
         context.AppendDollarError(record);
     }
 }
开发者ID:nickchal,项目名称:pash,代码行数:25,代码来源:ExceptionHandlingOps.cs

示例10: SetPreviousFirstLastToken

 internal void SetPreviousFirstLastToken(ExecutionContext context)
 {
     if (this._tokenizer.FirstToken != null)
     {
         context.SetVariable(SpecialVariables.FirstTokenVarPath, this._previousFirstToken);
         if (!Parser.IgnoreTokenWhenUpdatingPreviousFirstLast(this._tokenizer.FirstToken))
         {
             this._previousFirstToken = this._tokenizer.FirstToken.Text;
         }
         context.SetVariable(SpecialVariables.LastTokenVarPath, this._previousLastToken);
         if (!Parser.IgnoreTokenWhenUpdatingPreviousFirstLast(this._tokenizer.LastToken))
         {
             this._previousLastToken = this._tokenizer.LastToken.Text;
         }
     }
 }
开发者ID:nickchal,项目名称:pash,代码行数:16,代码来源:Parser.cs

示例11: Execute

        public override string Execute(ExecutionContext context)
        {
            context.SetVariable(Variable, new ExecutionContext.OsqFunction((token, subContext) => {
                subContext.PushScope();

                try {
                    var parameters = token == null ? new TokenNode[] { } : token.ChildrenTokenNodes;

                    if(parameters.Count == 1 && parameters[0].Token.IsSymbol(",")) {
                        parameters = parameters[0].ChildrenTokenNodes;
                    }

                    var parameterVariables = FunctionParameters ?? new string[] { };

                    using(var paramNameEnumerator = parameterVariables.GetEnumerator()) {
                        foreach(var child in parameters) {
                            if(!paramNameEnumerator.MoveNext()) {
                                break;
                            }

                            object value = child.Evaluate(context);

                            subContext.SetLocalVariable(paramNameEnumerator.Current, value);
                        }
                    }

                    string output = ExecuteChildren(context);

                    return output.TrimEnd(Environment.NewLine.ToCharArray());
                } finally {
                    subContext.PopScope();
                }
            }));

            return "";
        }
开发者ID:strager,项目名称:osq2osb,代码行数:36,代码来源:DefineNode.cs

示例12: SetPreviousFirstLastToken

        internal void SetPreviousFirstLastToken(ExecutionContext context)
        {
            var firstToken = _tokenizer.FirstToken;
            if (firstToken != null)
            {
                context.SetVariable(SpecialVariables.FirstTokenVarPath, _previousFirstTokenText);
                if (!IgnoreTokenWhenUpdatingPreviousFirstLast(firstToken))
                {
                    var stringToken = firstToken as StringToken;
                    _previousFirstTokenText = stringToken != null
                        ? stringToken.Value
                        : firstToken.Text;
                }

                context.SetVariable(SpecialVariables.LastTokenVarPath, _previousLastTokenText);

                var lastToken = _tokenizer.LastToken;
                if (!IgnoreTokenWhenUpdatingPreviousFirstLast(lastToken))
                {
                    var stringToken = lastToken as StringToken;
                    _previousLastTokenText = stringToken != null
                        ? stringToken.Value
                        : lastToken.Text;
                }
            }
        }
开发者ID:dfinke,项目名称:powershell,代码行数:26,代码来源:Parser.cs


注:本文中的ExecutionContext.SetVariable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。