コード例 #1
0
        public static async Task <IActionResult> AdxExportFunctionHttpTriggered(
            [HttpTrigger(AuthorizationLevel.Function, "post")] HttpRequest req,
            ILogger log,
            [DurableClient] IDurableOrchestrationClient starter)
        {
            log.LogInformation("AdxExportFunction processed a request.");

            var requestBody   = await new StreamReader(req.Body).ReadToEndAsync();
            var exportRequest = JsonConvert.DeserializeObject <AdxExportRequest>(requestBody);

            if (exportRequest == null || string.IsNullOrEmpty(exportRequest.AdxQuery) || string.IsNullOrEmpty(exportRequest.UserEmailAddress))
            {
                return(new BadRequestObjectResult("Invalid ADX export request. Check your parameters"));
            }

            using (var client = KustoClientFactory.CreateCslAdminProvider(await GetKustoConnectionStringBuilder()))
            {
                // TODO: Write actual query from user input
                var exportQuery  = CslCommandGenerator.GenerateExportCommand(new[] { storageConnectionString }, "datatable1 | take 100", true, true);
                var resultReader = new ObjectReader <DataExportToBlobCommandResult>(client.ExecuteControlCommand(adxDatabaseName, exportQuery));

                var res = resultReader?.FirstOrDefault();
                var adxExportOperationId = res?.Path;

                if (!string.IsNullOrEmpty(adxExportOperationId))
                {
                    // Start durable orchestrator for the status checking
                    var durableInstanceId = await starter.StartNewAsync(nameof(AdxExportOrchestrator), new Tuple <string, string>(adxExportOperationId, exportRequest.UserEmailAddress));

                    return(new OkObjectResult("Request Accepted. Durable Instance=" + durableInstanceId));
                }
                else
                {
                    log.LogError("Path is empty in result");
                    log.LogError(JsonConvert.SerializeObject(res));
                }
            }
            return(new BadRequestObjectResult("Error on starting ADX export"));
        }