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


C# PSCmdlet.WriteDebug方法代码示例

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


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

示例1: CreateOrderMatrix

 internal static List<OrderByPropertyEntry> CreateOrderMatrix(PSCmdlet cmdlet, List<PSObject> inputObjects, List<MshParameter> mshParameterList)
 {
     List<OrderByPropertyEntry> list = new List<OrderByPropertyEntry>();
     foreach (PSObject obj2 in inputObjects)
     {
         if ((obj2 != null) && (obj2 != AutomationNull.Value))
         {
             List<ErrorRecord> errors = new List<ErrorRecord>();
             List<string> propertyNotFoundMsgs = new List<string>();
             OrderByPropertyEntry item = OrderByPropertyEntryEvaluationHelper.ProcessObject(obj2, mshParameterList, errors, propertyNotFoundMsgs);
             foreach (ErrorRecord record in errors)
             {
                 cmdlet.WriteError(record);
             }
             foreach (string str in propertyNotFoundMsgs)
             {
                 cmdlet.WriteDebug(str);
             }
             list.Add(item);
         }
     }
     return list;
 }
开发者ID:nickchal,项目名称:pash,代码行数:23,代码来源:OrderByProperty.cs

示例2: CheckRuleExtension

        public Dictionary<string, List<string>> CheckRuleExtension(string[] path, PSCmdlet cmdlet)
        {
            Dictionary<string, List<string>> results = new Dictionary<string, List<string>>();

            List<string> invalidPaths = new List<string>();
            List<string> validDllPaths = new List<string>();
            List<string> validModPaths = new List<string>();

            // Gets valid module names
            foreach (string childPath in path)
            {
                try
                {
                    cmdlet.WriteVerbose(string.Format(CultureInfo.CurrentCulture, Strings.CheckModuleName, childPath));

                    string resolvedPath = string.Empty;

                    // Users may provide a valid module path or name,
                    // We have to identify the childPath is really a directory or just a module name.
                    // You can also consider following two commands.
                    //   Get-ScriptAnalyzerRule -RuleExtension "ContosoAnalyzerRules"
                    //   Get-ScriptAnalyzerRule -RuleExtension "%USERPROFILE%\WindowsPowerShell\Modules\ContosoAnalyzerRules"
                    if (Path.GetDirectoryName(childPath) == string.Empty)
                    {
                        resolvedPath = childPath;
                    }
                    else
                    {
                        resolvedPath = cmdlet.SessionState.Path
                            .GetResolvedPSPathFromPSPath(childPath).First().ToString();
                    }

                    using (System.Management.Automation.PowerShell posh =
                           System.Management.Automation.PowerShell.Create())
                    {
                        string script = string.Format(CultureInfo.CurrentCulture, "Get-Module -Name '{0}' -ListAvailable", resolvedPath);
                        PSModuleInfo moduleInfo = posh.AddScript(script).Invoke<PSModuleInfo>().First();

                        // Adds original path, otherwise path.Except<string>(validModPaths) will fail.
                        // It's possible that user can provide something like this:
                        // "..\..\..\ScriptAnalyzer.UnitTest\modules\CommunityAnalyzerRules\CommunityAnalyzerRules.psd1"
                        if (moduleInfo.ExportedFunctions.Count > 0) validModPaths.Add(childPath);
                    }
                }
                catch
                {
                    // User may provide an invalid module name, like c:\temp.
                    // It's a invalid name for a Windows PowerShell module,
                    // But we need test it further since we allow user to provide a folder to extend rules.
                    // You can also consider following two commands.
                    //   Get-ScriptAnalyzerRule -RuleExtension "ContosoAnalyzerRules", "C:\Temp\ExtendScriptAnalyzerRules.dll"
                    //   Get-ScriptAnalyzerRule -RuleExtension "ContosoAnalyzerRules", "C:\Temp\"
                    continue;
                }
            }

            // Gets valid dll paths
            foreach (string childPath in path.Except<string>(validModPaths))
            {
                try
                {
                    string resolvedPath = cmdlet.SessionState.Path
                        .GetResolvedPSPathFromPSPath(childPath).First().ToString();

                    cmdlet.WriteDebug(string.Format(CultureInfo.CurrentCulture, Strings.CheckAssemblyFile, resolvedPath));

                    if (String.Equals(Path.GetExtension(resolvedPath),".dll", StringComparison.OrdinalIgnoreCase))
                    {
                        if (!File.Exists(resolvedPath))
                        {
                            invalidPaths.Add(resolvedPath);
                            continue;
                        }
                    }
                    else
                    {
                        if (!Directory.Exists(resolvedPath))
                        {
                            invalidPaths.Add(resolvedPath);
                            continue;
                        }
                    }

                    validDllPaths.Add(resolvedPath);
                }
                catch
                {
                    invalidPaths.Add(childPath);
                }
            }

            // Resloves relative paths.
            try
            {
                for (int i = 0; i < validModPaths.Count; i++)
                {
                    validModPaths[i] = cmdlet.SessionState.Path
                        .GetResolvedPSPathFromPSPath(validModPaths[i]).First().ToString();
                }
                for (int i = 0; i < validDllPaths.Count; i++)
//.........这里部分代码省略.........
开发者ID:splatteredbits,项目名称:PSScriptAnalyzer,代码行数:101,代码来源:ScriptAnalyzer.cs


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