コード例 #1
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            Container container = InitializeClientAndGetContainer(req);

            //PARAMETERS
            string QUERY = req.Query["query"];

            //If post get the query from the body
            if (req.Method == "POST")
            {
                QUERY = await new StreamReader(req.Body).ReadToEndAsync();
            }

            log.LogInformation("QUERY:" + QUERY);

            QueryDefinition        query     = new QueryDefinition(QUERY);
            FeedIterator <dynamic> resultSet = container.GetItemQueryIterator <dynamic>(
                query,
                requestOptions: new QueryRequestOptions()
            {
                MaxItemCount = -1
            });

            List <dynamic> L = new List <dynamic>();
            double         t = 0;

            while (resultSet.HasMoreResults)
            {
                FeedResponse <dynamic> response = await resultSet.ReadNextAsync();

                t += response.RequestCharge;
                L  = L.Concat(response).ToList();
            }

            QResult R = new QResult()
            {
                RU = t, NR = L.Count, LB = JsonConvert.SerializeObject(L).Length, Data = L
            };

            return((ActionResult) new OkObjectResult(R));
        }
コード例 #2
0
        public static async Task <IActionResult> Upsert(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            Container container = InitializeClientAndGetContainer(req);

            //PARAMETERS
            string  partitionKeyValue = req.Query["partitionKeyValue"];
            string  requestBody       = await new StreamReader(req.Body).ReadToEndAsync();
            dynamic inputDoc          = JsonConvert.DeserializeObject(requestBody);

            PartitionKey           PK       = new PartitionKey(partitionKeyValue);
            ItemResponse <dynamic> response = await container.UpsertItemAsync <dynamic>(inputDoc, PK);

            QResult R = new QResult()
            {
                RU = response.RequestCharge, NR = 1, LB = 0, Data = response.StatusCode
            };

            return((ActionResult) new OkObjectResult(R));
        }
コード例 #3
0
        public static async Task <IActionResult> Delete(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            Container container = InitializeClientAndGetContainer(req);

            //PARAMETERS
            string partitionKeyValue = req.Query["partitionKeyValue"];
            string id = req.Query["id"];

            if (id != null)
            {
                log.LogInformation("DELETING " + id);
                ItemResponse <dynamic> response = await container.DeleteItemAsync <dynamic>(id, new PartitionKey(partitionKeyValue));

                QResult R = new QResult()
                {
                    RU = response.RequestCharge, NR = 1, LB = 0, Data = response.StatusCode
                };
                return((ActionResult) new OkObjectResult(R));
            }
            return((ActionResult) new OkObjectResult(false));
        }