Пример #1
0
 private static Command CollectCommand() =>
 new Command(
     "collect",
     "Monitor counters in a .NET application and export the result into a file",
     new Option[] { ProcessIdOption(), RefreshIntervalOption(), ExportFormatOption(), ExportFileNameOption() },
     argument: CounterList(),
     handler: HandlerDescriptor.FromDelegate((ExportDelegate) new CounterMonitor().Collect).GetCommandHandler());
Пример #2
0
 private static Command MonitorCommand() =>
 new Command(
     name: "monitor",
     description: "Start monitoring a .NET application")
 {
     // Handler
     HandlerDescriptor.FromDelegate((MonitorDelegate) new CounterMonitor().Monitor).GetCommandHandler(),
     // Arguments and Options
     CounterList(), CounterOption(), ProcessIdOption(), RefreshIntervalOption(), NameOption(), DiagnosticPortOption(),
 };
Пример #3
0
 private static Command CollectCommand() =>
 new Command(
     name: "collect",
     description: "Monitor counters in a .NET application and export the result into a file")
 {
     // Handler
     HandlerDescriptor.FromDelegate((CollectDelegate) new CounterMonitor().Collect).GetCommandHandler(),
     // Arguments and Options
     CounterList(), CounterOption(), ProcessIdOption(), RefreshIntervalOption(), ExportFormatOption(), ExportFileNameOption(), NameOption(), DiagnosticPortOption()
 };
Пример #4
0
 public static Command CollectCommand() =>
 new Command(
     name: "collect",
     description: "Collects a diagnostic trace from a currently running process")
 {
     // Handler
     HandlerDescriptor.FromDelegate((CollectDelegate)Collect).GetCommandHandler(),
     // Options
     ProcessIdOption(), OutputPathOption(), VerboseOption(), TimeoutOption(), NameOption()
 };
 public static Command ReportCommand() =>
 new Command(
     name: "report",
     description: "Generate report into stdout from a previously generated gcdump or from a running process.")
 {
     // Handler
     HandlerDescriptor.FromDelegate((ReportDelegate)Report).GetCommandHandler(),
     // Options
     FileNameArgument(), ProcessIdOption(), ReportTypeOption()
 };
Пример #6
0
 public static Command CollectCommand() =>
 new Command(
     name: "collect",
     description: "Collects a diagnostic trace from a currently running process",
     symbols: new Option[] {
     ProcessIdOption(),
     OutputPathOption(),
     VerboseOption(),
     TimeoutOption()
 },
     handler: HandlerDescriptor.FromDelegate((CollectDelegate)Collect).GetCommandHandler());
 public static Command ReportCommand() =>
 new Command(
     name: "report",
     description: "reports the managed stacks from a running .NET process")
 {
     // Handler
     HandlerDescriptor.FromDelegate((ReportDelegate)Report).GetCommandHandler(),
     // Options
     ProcessIdOption(),
     NameOption(),
     DurationOption()
 };
Пример #8
0
 private static Command IpcClientTcpServerRouterCommand() =>
 new Command(
     name: "client-server",
     description:    "Start a .NET application Diagnostics Server routing local IPC server <--> remote TCP client. " +
     "Router is configured using an IPC client (connecting diagnostic tool IPC server) " +
     "and a TCP/IP server (accepting runtime TCP client).")
 {
     // Handler
     HandlerDescriptor.FromDelegate((DiagnosticsServerIpcClientTcpServerRouterDelegate) new DiagnosticsServerRouterCommands().RunIpcClientTcpServerRouter).GetCommandHandler(),
     // Options
     IpcClientAddressOption(), TcpServerAddressOption(), RuntimeTimeoutOption(), VerboseOption(), ForwardPortOption()
 };
Пример #9
0
 private static Command IpcServerTcpClientRouterCommand() =>
 new Command(
     name: "server-client",
     description: "Start a .NET application Diagnostics Server routing local IPC client <--> remote TCP server. " +
     "Router is configured using an IPC server (connecting to by diagnostic tools) " +
     "and a TCP/IP client (connecting runtime TCP server).")
 {
     // Handler
     HandlerDescriptor.FromDelegate((DiagnosticsServerIpcServerTcpClientRouterDelegate) new DiagnosticsServerRouterCommands().RunIpcServerTcpClientRouter).GetCommandHandler(),
     // Options
     IpcServerAddressOption(), TcpClientAddressOption(), RuntimeTimeoutOption(), VerboseOption()
 };
Пример #10
0
 public static Command CollectCommand() =>
 new Command(
     name: "collect",
     description: "Collects a diagnostic trace from a currently running process",
     symbols: new Option[] {
     CommonOptions.ProcessIdOption(),
     CircularBufferOption(),
     OutputPathOption(),
     ProvidersOption(),
     ProfileOption(),
     CommonOptions.FormatOption(),
 },
     handler: HandlerDescriptor.FromDelegate((CollectDelegate)Collect).GetCommandHandler());
Пример #11
0
 public static ICommandHandler Create <
     T1,
     T2,
     T3,
     T4,
     T5,
     T6,
     T7,
     T8,
     T9,
     T10,
     T11,
     T12,
     T13
     >(Action <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13> action) =>
 HandlerDescriptor.FromDelegate(action).GetCommandHandler();
Пример #12
0
 public static ICommandHandler Create <
     T1,
     T2,
     T3,
     T4,
     T5,
     T6,
     T7,
     T8,
     T9,
     T10,
     T11,
     T12,
     T13,
     T14
     >(Func <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, Task <int> > action) =>
 HandlerDescriptor.FromDelegate(action).GetCommandHandler();
Пример #13
0
 public static Command CollectCommand() =>
 new Command(
     name: "collect",
     description: "Collects a diagnostic trace from a currently running process")
 {
     // Handler
     HandlerDescriptor.FromDelegate((CollectDelegate)Collect).GetCommandHandler(),
     // Options
     CommonOptions.ProcessIdOption(),
     CircularBufferOption(),
     OutputPathOption(),
     ProvidersOption(),
     ProfileOption(),
     CommonOptions.FormatOption(),
     DurationOption(),
     CLREventsOption(),
     CLREventLevelOption()
 };
Пример #14
0
 public static Command ReportCommand() =>
 new Command(
     name: "report",
     description: "Generates a report into stdout from a previously generated trace.")
 {
     //Handler
     HandlerDescriptor.FromDelegate((ReportDelegate)Report).GetCommandHandler(),
     //Options
     FileNameArgument(),
     new Command(
         name: "topN",
         description: "Finds the top N methods that have been on the callstack the longest.")
     {
         //Handler
         HandlerDescriptor.FromDelegate((TopNReportDelegate)TopNReport).GetCommandHandler(),
         TopNOption(),
         InclusiveOption(),
         VerboseOption(),
     }
 };
 public static Command CollectCommand() =>
 new Command(
     name: "collect",
     description: "Collects a diagnostic trace from a currently running process or launch a child process and trace it. Append -- to the collect command to instruct the tool to run a command and trace it immediately. When tracing a child process, the exit code of dotnet-trace shall be that of the traced process unless the trace process encounters an error.")
 {
     // Handler
     HandlerDescriptor.FromDelegate((CollectDelegate)Collect).GetCommandHandler(),
     // Options
     CommonOptions.ProcessIdOption(),
     CircularBufferOption(),
     OutputPathOption(),
     ProvidersOption(),
     ProfileOption(),
     CommonOptions.FormatOption(),
     DurationOption(),
     CLREventsOption(),
     CLREventLevelOption(),
     CommonOptions.NameOption(),
     DiagnosticPortOption(),
     ShowChildIOOption()
 };
 public static ICommandHandler Create <T1, T2, T3, T4>(
     Func <T1, T2, T3, T4, int> action) =>
 HandlerDescriptor.FromDelegate(action).GetCommandHandler();
 public static ICommandHandler Create(Func <int> action) =>
 HandlerDescriptor.FromDelegate(action).GetCommandHandler();
 public static ICommandHandler Create <T1, T2, T3, T4, T5, T6>(
     Action <T1, T2, T3, T4, T5, T6> action) =>
 HandlerDescriptor.FromDelegate(action).GetCommandHandler();
 public static ICommandHandler Create <T1, T2, T3, T4, T5, T6, T7, T8>(
     Func <T1, T2, T3, T4, T5, T6, T7, T8, Task> action) =>
 HandlerDescriptor.FromDelegate(action).GetCommandHandler();
 public static ICommandHandler Create <T>(
     Action <T> action) =>
 HandlerDescriptor.FromDelegate(action).GetCommandHandler();
 public static ICommandHandler Create(Delegate @delegate) =>
 HandlerDescriptor.FromDelegate(@delegate).GetCommandHandler();
Пример #22
0
        static async Task Main(string[] args)
        {
            TransformationLogging.LoggerFactory = LoggerFactory.Create(builder => {
                builder.AddFilter("Microsoft", LogLevel.Warning)
                .AddFilter("System", LogLevel.Warning)
                .AddFilter("Microsoft.Health.Fhir.Transformation", LogLevel.Information)
                .AddConsole();
            });
            System.Net.ServicePointManager.DefaultConnectionLimit = 10 * 1024;

            ILogger logger = TransformationLogging.CreateLogger <Program>();

            var rootCommand = new RootCommand();

            var generateSchemaCommand = new Command("generate-schema")
            {
                new Option <string>("--clientId"),
                new Option <string>("--tenantId"),
                new Option <string>("--adlsAccount"),
                new Option <string>("--cdmFileSystem"),
                new Option <string>("--configurationContainer", getDefaultValue: () => "config"),
                new Option <string>("--clientSecret"),
                new Option <int>("--maxDepth", getDefaultValue: () => 3)
            };

            generateSchemaCommand.Handler = CommandHandler.Create <string, string, string, string, string, string, int>(
                async(clientId, tenantId, adlsAccount, cdmFileSystem, configurationContainer, clientSecret, maxDepth) =>
            {
                logger.LogInformation("Start to generate CDM schema.");
                ClientSecretCredential credential = GetClientSecretCredential(tenantId, clientId, clientSecret);

                StorageDefinitionLoader configLoader = new StorageDefinitionLoader(GetStorageServiceEndpoint(adlsAccount), configurationContainer, credential, maxDepth);
                TabularMappingDefinition[] mappings  = configLoader.Load();

                AdlsCsvSink sink = new AdlsCsvSink(adlsAccount, cdmFileSystem, credential);
                await sink.InitAsync();
                await sink.CreateFileSystemClientIfNotExistAsync();

                CdmCorpusDefinition defination        = InitAdlscdmCorpusDefinition(adlsAccount, "/" + cdmFileSystem, tenantId, clientId, clientSecret);
                CdmSchemaGenerator cdmSchemaGenerator = new CdmSchemaGenerator(defination);
                List <string> entities = await cdmSchemaGenerator.InitializeCdmFolderAsync(mappings, "adls");

                WriteActivityOutputs(entities);

                logger.LogInformation("Generate CDM schema completed.");
            });
            rootCommand.AddCommand(generateSchemaCommand);

            var transformDataCommand = new Command("transform-data")
            {
                new Option <string>("--clientId"),
                new Option <string>("--tenantId"),
                new Option <string>("--adlsAccount"),
                new Option <string>("--cdmFileSystem"),
                new Option <string>("--inputBlobUri"),
                new Option <string>("--configurationContainer"),
                new Option <string>("--clientSecret"),
                new Option <string>("--operationId"),
                new Option <string>("--maxDepth"),
            };

            Func <string, string, string, string, string, string, string, string, int, Task> transformDataAction =
                async(clientId, tenantId, adlsAccount, cdmFileSystem, inputBlobUri, configurationContainer, operationId, clientSecret, maxDepth) =>
            {
                logger.LogInformation("Start to transform data.");
                ClientSecretCredential credential = GetClientSecretCredential(tenantId, clientId, clientSecret);

                StorageDefinitionLoader    configLoader = new StorageDefinitionLoader(GetStorageServiceEndpoint(adlsAccount), configurationContainer, credential, maxDepth);
                TabularMappingDefinition[] mappings     = configLoader.Load();

                Uri     inputUri = new Uri(inputBlobUri);
                ISource source   = new StorageBlobNdjsonSource(inputUri, credential)
                {
                    ConcurrentCount = Environment.ProcessorCount * 2
                };

                string      fileName = Path.GetFileNameWithoutExtension(inputUri.AbsolutePath);
                AdlsCsvSink sink     = new AdlsCsvSink(adlsAccount, cdmFileSystem, credential)
                {
                    CsvFilePath = (string tableName) =>
                    {
                        return($"data/Local{tableName}/partition-data-{tableName}-{fileName}-{operationId}.csv");
                    },
                    ConcurrentCount = Environment.ProcessorCount * 2
                };

                TransformationExecutor executor = new TransformationExecutor(source,
                                                                             sink,
                                                                             mappings,
                                                                             new BasicFhirElementTabularTransformer());
                executor.ConcurrentCount = Environment.ProcessorCount * 2;
                IProgress <(int, int)> progressHandler = new Progress <(int, int)>(progress =>
                {
                    if (progress.Item1 % 100 == 0 || progress.Item2 % 100 == 0)
                    {
                        logger.LogInformation($"({progress.Item1} loaded, {progress.Item2} transformed) to CDM folder. {DateTime.UtcNow.ToLongTimeString()}");
                    }
                });

                await executor.ExecuteAsync(progressHandler);

                logger.LogInformation("Transform data complete.");
            };

            transformDataCommand.Handler = HandlerDescriptor.FromDelegate(transformDataAction).GetCommandHandler();
            rootCommand.AddCommand(transformDataCommand);

            await rootCommand.InvokeAsync(args);
        }
Пример #23
0
        static Bootstrap()
        {
            var userNameArgument = new Argument <string> {
                Name = "username", Description = "Geek username."
            };
            var passwordArgument = new Argument <string> {
                Name = "password", Description = "Geek password."
            };

            var passwordOption = new Option <string>(new[] { "--password", "-p" }, "Geek password. Defaults to last specified.");

            var dateOption       = new Option <DateTime>(new[] { "--date", "-d" }, () => DateTime.Now.Date, "Date of play. Defaults to current date.").WithFormat("yyyy-MM-dd");
            var locationOption   = new Option <string>(new[] { "--location", "-l" }, "Location of play. Defaults to unspecified.");
            var quantityOption   = new Option <int>(new[] { "--quantity", "-q" }, () => 1, "Quantity of play. Defaults to 1.");
            var gameIdOption     = new Option <int?>(new[] { "--game-id", "-g" }, "Game id of play. Defaults to unspecified.");
            var gameNameOption   = new Option <string>(new[] { "--game-name" }, "Game name of play. Defaults to unspecified.");
            var lengthOption     = new Option <int>(new[] { "--length" }, "Length of play (minutes). Defaults to 0.");
            var incompleteOption = new Option <bool>(new[] { "--incomplete" }, "Incomplete play. Defaults to false.");
            var noWinStatsOption = new Option <bool>(new[] { "--no-win-stats" }, "No win stats for play. Defaults to false.");
            var commentsOption   = new Option <string>(new[] { "--comments" }, "Comments for play. Defaults to unspecified.");

            var allOption  = new Option <bool>(new[] { "--all", "-a" }, "Analyze all override. Defaults to false.");
            var yearOption = new Option <int?>(new[] { "--year", "-y" }, () => DateTime.Now.Year, "Year to analyze. Defaults to current year.");

            var loginUserCommand = new Command("login", "Login user.")
            {
                userNameArgument, passwordArgument
            };

            loginUserCommand.Handler = CommandHandler.Create <string, string>(LoginUserAsync);
            var logPlayCommand = new Command("play", "Log user play.")
            {
                userNameArgument, passwordOption, dateOption, locationOption, quantityOption, gameIdOption, gameNameOption, lengthOption, incompleteOption, noWinStatsOption, commentsOption
            };

            logPlayCommand.AddValidator(symbol => !(symbol.Children.Contains("game-id") ^ symbol.Children.Contains("game-name")) ? "Play must specify one of game id or game name" : null);
            logPlayCommand.Handler = HandlerDescriptor.FromDelegate(new Func <string, string, DateTime, string, int, int?, string, int, bool, bool, string, Task>(LogUserPlayAsync)).GetCommandHandler();
            var getUserPlaysCommand = new Command("plays", "Get user plays.")
            {
                userNameArgument, allOption, yearOption
            };

            getUserPlaysCommand.Handler = CommandHandler.Create <string, bool, int?>(GetUserPlaysAsync);
            var getUserStatsCommand = new Command("stats", "Get user stats.")
            {
                userNameArgument, allOption, yearOption
            };

            getUserStatsCommand.Handler = CommandHandler.Create <string, bool, int?>(GetUserStatsAsync);

            Parser = new CommandLineBuilder(new RootCommand("A command line tool for interacting with the BoardGameGeek API"))
                     .AddCommand(loginUserCommand)
                     .AddCommand(new Command("log", "Log commands.")
            {
                logPlayCommand
            })
                     .AddCommand(new Command("get", "Get commands.")
            {
                getUserPlaysCommand, getUserStatsCommand
            })
                     .UseDefaults()
                     .Build();
        }
Пример #24
0
        public RootCommand GetRootCommand()
        {
            var outputOption = new Option("--output", "The output directory path for the generated code files.")
            {
                Argument = new Argument <string>(() => "./output")
            };

            outputOption.AddAlias("-o");

            var languageOption = new Option("--language", "The target language for the generated code files.")
            {
                Argument = new Argument <GenerationLanguage?>(() => GenerationLanguage.CSharp)
            };

            languageOption.AddAlias("-l");
            AddEnumValidator <GenerationLanguage>(languageOption.Argument, "language");
            var classOption = new Option("--class-name", "The class name to use for the core client class.")
            {
                Argument = new Argument <string>(() => "ApiClient")
            };

            classOption.AddAlias("-c");
            AddStringRegexValidator(classOption.Argument, @"^[a-zA-Z_][\w_-]+", "class name");

            var namespaceOption = new Option("--namespace-name", "The namespace to use for the core client class specified with the --class-name option.")
            {
                Argument = new Argument <string>(() => "ApiClient")
            };

            namespaceOption.AddAlias("-n");
            AddStringRegexValidator(namespaceOption.Argument, @"^[\w][\w\._-]+", "namespace name");

            var logLevelOption = new Option("--loglevel", "The log level to use when logging messages to the main output.")
            {
                Argument = new Argument <LogLevel>(() => LogLevel.Warning)
            };

            logLevelOption.AddAlias("--ll");
            AddEnumValidator <LogLevel>(logLevelOption.Argument, "log level");
            var descriptionOption = new Option("--openapi", "The path to the OpenAPI description file used to generate the code files.")
            {
                Argument = new Argument <string>(() => "openapi.yml")
            };

            descriptionOption.AddAlias("-d");

            var backingStoreOption = new Option("--backing-store", "The fully qualified name for the backing store class to use.")
            {
                Argument = new Argument <string>()
            };

            backingStoreOption.AddAlias("-b");

            var serializerOption = new Option <List <String> >("--serializer", "The fully qualified class names for serializers.")
            {
                Argument = new Argument <List <string> >(() => new List <string> {
                    "Microsoft.Kiota.Serialization.Json.JsonSerializationWriterFactory"
                })
            };

            serializerOption.AddAlias("-s");

            var deserializerOption = new Option <List <String> >("--deserializer", "The fully qualified class names for deserializers.")
            {
                Argument = new Argument <List <string> >(() => new List <string> {
                    "Microsoft.Kiota.Serialization.Json.JsonParseNodeFactory"
                })
            };

            deserializerOption.AddAlias("--ds");

            var command = new RootCommand {
                outputOption,
                languageOption,
                descriptionOption,
                backingStoreOption,
                classOption,
                logLevelOption,
                namespaceOption,
                serializerOption,
                deserializerOption,
            };

            command.Handler = HandlerDescriptor.FromDelegate(new HandleCommandCallDel(HandleCommandCall)).GetCommandHandler();
            return(command);
        }
Пример #25
0
 public static Command ProcessStatusCommand(string description) =>
 new Command(name: "ps", description)
 {
     HandlerDescriptor.FromDelegate((ProcessStatusDelegate)ProcessStatus).GetCommandHandler()
 };