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


C# CommandLine.GetWantsHelp方法代码示例

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


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

示例1: Execute

        /// <summary>
        /// The execute.
        /// </summary>
        /// <exception cref="UnauthorizedAccessException">
        /// </exception>
        /// <exception cref="InvalidOperationException">
        /// </exception>
        public void Execute()
        {
            ShowHeader();

            string[] args = Environment.GetCommandLineArgs().Skip(1).ToArray();
            if (!args.Any())
            {
                ShowHelp();
                return;
            }

            var commandLine = new CommandLine(args);
            if (commandLine.GetWantsHelp())
            {
                ShowHelp();
                return;
            }

            // todo: add support for job monitoring

            // Check config file
            ApplicationSettings settings = LoadSettings();

            // Connect to server
            IUpdateServer server = Server.Connect(settings.Server);

            // Check user has admin access
            UpdateServerUserRole role = server.GetCurrentUserRole();
            if (role != UpdateServerUserRole.Administrator)
            {
                throw new UnauthorizedAccessException("You don't have administrator access on the WSUS server.");
            }

            // Get the default rule
            bool isTest = commandLine.GetIsTest();
            RunSetCollection runSets = settings.RunSets;

            switch (commandLine.GetUseRunSet())
            {
                case TriState.Yes:
                    if (runSets == null || runSets.Count == 0)
                    {
                        throw new InvalidOperationException(
                            "/runset specified on the command line.  But there are no runsets defined in the config file.");
                    }

                    // we have run sets
                    // this means our approval logic is more complex
                    DoRunSets(server, runSets, commandLine, isTest);

                    break;

                case TriState.No:
                    DoNoRunSets(settings, server, isTest);

                    break;

                default:
                    if (runSets != null && runSets.Count > 0)
                    {
                        throw new InvalidOperationException(
                            "RunSets exist in the application config. /norunset or /runset must be specified on the command line.");
                    }

                    break;
            }
        }
开发者ID:dpvreony,项目名称:wsussmartapprove,代码行数:74,代码来源:Job.cs


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