示例#1
0
 /// <inheritdoc/>
 public void Dispose()
 {
     if (_listener != null)
     {
         _listener.Dispose();
         _listener = null;
     }
 }
 protected override void Dispose(bool disposing)
 {
     base.Dispose(disposing);
     if (disposing && _azureEventSourceListener != null)
     {
         _azureEventSourceListener.Dispose();
         _azureEventSourceListener = null;
     }
 }
        private static CommandLineBuilder GetCommandLine()
        {
            RootCommand root = new RootCommand("parent")
            {
                Description = $"Microsoft IoT Models Repository CommandLine v{Outputs.CommandLineVersion}"
            };

            root.Name = Outputs.RootCommandName;
            root.Add(BuildExportCommand());
            root.Add(BuildValidateCommand());
            root.Add(BuildImportModelCommand());
            root.Add(BuildRepoIndexCommand());
            root.Add(BuildRepoExpandCommand());

            root.AddGlobalOption(CommonOptions.Debug);
            root.AddGlobalOption(CommonOptions.Silent);

            CommandLineBuilder builder = new CommandLineBuilder(root);

            builder.UseMiddleware(async(context, next) =>
            {
                AzureEventSourceListener listener = null;
                try
                {
                    if (context.ParseResult.Tokens.Any(x => x.Type == TokenType.Option && x.Value == "--debug"))
                    {
                        Outputs.WriteHeader();
                        listener = AzureEventSourceListener.CreateConsoleLogger(EventLevel.Verbose);
                        Outputs.WriteDebug(context.ParseResult.ToString());
                    }

                    if (context.ParseResult.Tokens.Any(x => x.Type == TokenType.Option && x.Value == "--silent"))
                    {
                        System.Console.SetOut(TextWriter.Null);
                    }

                    await next(context);
                }
                finally
                {
                    if (listener != null)
                    {
                        listener.Dispose();
                    }
                }
            });

            return(builder);
        }
 public void Dispose() => _logger.Dispose();
 /// <summary>
 /// Cleans up the <see cref="AzureEventSourceListener"/> instance.
 /// </summary>
 public void Dispose() => _eventSourceListener.Dispose();