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


C# ExecutionContext.GetVariableValue方法代码示例

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


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

示例1: 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

示例2: GetPSLogUserData

 private static string GetPSLogUserData(ExecutionContext context)
 {
     if (context == null)
     {
         return string.Empty;
     }
     object variableValue = context.GetVariableValue(SpecialVariables.PSLogUserDataPath);
     if (variableValue == null)
     {
         return string.Empty;
     }
     return variableValue.ToString();
 }
开发者ID:nickchal,项目名称:pash,代码行数:13,代码来源:PSEtwLogProvider.cs

示例3: GetCommandDiscoveryPreference

 internal static PSModuleAutoLoadingPreference GetCommandDiscoveryPreference(ExecutionContext context, VariablePath variablePath, string environmentVariable)
 {
     if (context == null)
     {
         throw PSTraceSource.NewArgumentNullException("context");
     }
     object variableValue = context.GetVariableValue(variablePath);
     if (variableValue != null)
     {
         return LanguagePrimitives.ConvertTo<PSModuleAutoLoadingPreference>(variableValue);
     }
     string str = Environment.GetEnvironmentVariable(environmentVariable);
     if (!string.IsNullOrEmpty(str))
     {
         return LanguagePrimitives.ConvertTo<PSModuleAutoLoadingPreference>(str);
     }
     return PSModuleAutoLoadingPreference.All;
 }
开发者ID:nickchal,项目名称:pash,代码行数:18,代码来源:CommandDiscovery.cs

示例4: EvaluatePowerShellDataFile

        /// <summary>
        /// Get a Hashtable object out of a PowerShell data file (.psd1)
        /// </summary>
        /// <param name="parameterName">
        /// Name of the parameter that takes the specified .psd1 file as a value
        /// </param>
        /// <param name="psDataFilePath">
        /// Path to the powershell data file
        /// </param>
        /// <param name="context">
        /// ExecutionContext to use
        /// </param>
        /// <param name="allowedCommands">
        /// Set of command names that are allowed to use in the .psd1 file
        /// </param>
        /// <param name="allowedVariables">
        /// Set of variable names that are allowed to use in the .psd1 file
        /// </param>
        /// <param name="allowEnvironmentVariables">
        /// If true, allow to use environment variables in the .psd1 file
        /// </param>
        /// <param name="skipPathValidation">
        /// If true, caller guarantees the path is valid
        /// </param>
        /// <returns></returns>
        internal static Hashtable EvaluatePowerShellDataFile(
                                     string parameterName,
                                     string psDataFilePath,
                                     ExecutionContext context,
                                     IEnumerable<string> allowedCommands,
                                     IEnumerable<string> allowedVariables,
                                     bool allowEnvironmentVariables,
                                     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);
//.........这里部分代码省略.........
开发者ID:40a,项目名称:PowerShell,代码行数:101,代码来源:PsUtils.cs


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