示例#1
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");

            string  body        = req.Query["body"];
            string  callback    = req.Query["callback"];
            string  batchid     = req.Query["batchid"];
            string  requestBody = await new StreamReader(req.Body).ReadToEndAsync();
            dynamic data        = JsonConvert.DeserializeObject(requestBody);

            body     = body ?? data?.body;
            callback = callback ?? data?.callback;
            batchid  = batchid ?? data?.batchid;
            string responseMessage = string.IsNullOrEmpty(body)
                                ? "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response."
                                : $"Hello,  body: {body}. This HTTP triggered function executed successfully.";

            var auditStatusCreaate = new AuditStatus {
                Status = "STARTED", Detail = body, BatchId = batchid
            };

            await PostToStart(auditStatusCreaate, callback);

            // Those code just simulate  the update status of the http put
            Thread.Sleep(5000);
            var auditStatus = new AuditStatus {
                Status = "PROCESSED", Detail = body, BatchId = batchid
            };

            await PutToStart(auditStatus, "http://localhost:7071/api/TrackingUpdate");

            return(new OkObjectResult(responseMessage));
        }
示例#2
0
        public static ActionResult <object> TrackingUpdate(
            [HttpTrigger(AuthorizationLevel.Function, "put", Route = null)] HttpRequest req,
            [CosmosDB("DemoStatus", "AuditStatus", Id = "id", ConnectionStringSetting = "CosmosDBConn", CreateIfNotExists = true, PartitionKey = "/Status")] out dynamic document,
            ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");

            string batchid = req.Query["batchid"];
            string status  = req.Query["status"];
            string detail  = req.Query["detail"];

            string  requestBody = new StreamReader(req.Body).ReadToEnd();
            dynamic data        = JsonConvert.DeserializeObject(requestBody);

            batchid = batchid ?? data?.batchid;
            status  = status ?? data?.status;
            detail  = detail ?? data?.detail;

            document = new AuditStatus {
                id = Guid.NewGuid().ToString(), BatchId = batchid, Status = status, TimeStamp = DateTime.Now, Detail = detail
            };

            string responseMessage = string.IsNullOrEmpty(detail)
                                ? "This HTTP triggered function executed successfully. Pass a body in the query string or in the request body for a personalized response."
                                : $"Hello, {detail}. This HTTP triggered function executed successfully.";

            return(new OkObjectResult(responseMessage));
        }
示例#3
0
        /// <summary>
        /// Creates a Cosmos DB database and a container with the specified partition key.
        /// </summary>
        /// <returns></returns>
        private static async Task <ICosmosDbService> InitializeCosmosClientInstanceAsync()
        {
            Microsoft.Azure.Cosmos.CosmosClient client = new Microsoft.Azure.Cosmos.CosmosClient(account, key);
            CosmosDbService cosmosDbService            = new CosmosDbService(client, databaseName, containerName);

            AuditStatus a = new AuditStatus {
                id = "0C805497-2BA1-4524-9D41-E5D556488F9D", BatchId = "C8F9F1C1-4BD1-447F-9F0E-D8E96DF8A1E7", Status = "start", TimeStamp = DateTime.Now
            };


            Microsoft.Azure.Cosmos.DatabaseResponse database = await client.CreateDatabaseIfNotExistsAsync(databaseName);

            await database.Database.CreateContainerIfNotExistsAsync(containerName, "/id");

            await cosmosDbService.AddAuditStatusAsync(a);

            return(cosmosDbService);
        }