Esempio n. 1
0
        private async Task <List <GenericDocument> > ReadGenericDocuments(int maxCount)
        {
            List <GenericDocument> genericDocs            = new List <GenericDocument>();
            string                 sql                    = $"SELECT c.id, c.pk FROM c offset 0 limit {maxCount}";
            QueryDefinition        queryDefinition        = new QueryDefinition(sql);
            QueryRequestOptions    requestOptions         = new QueryRequestOptions();
            FeedIterator <dynamic> queryResultSetIterator =
                currentContainer.GetItemQueryIterator <dynamic>(
                    queryDefinition, requestOptions: requestOptions);

            while (queryResultSetIterator.HasMoreResults)
            {
                FeedResponse <dynamic> feedResponse =
                    await queryResultSetIterator.ReadNextAsync();

                foreach (var item in feedResponse)
                {
                    // Item is an instance of Newtonsoft.Json.Linq.JObject
                    GenericDocument gd = new GenericDocument();
                    gd.id = (string)item.Property("id");
                    gd.pk = (string)item.Property("pk");
                    genericDocs.Add(gd);
                }
            }
            return(genericDocs);
        }
Esempio n. 2
0
        private static async Task DeleteRoute()
        {
            string dbname = cliArgs[1];
            string cname  = cliArgs[2];
            string route  = cliArgs[3];

            cosmosClient = CosmosClientFactory.RegularClient();
            CosmosQueryUtil util = new CosmosQueryUtil(cosmosClient, config.IsVerbose());
            await util.SetCurrentDatabase(dbname);

            await util.SetCurrentContainer(cname);

            string sql = $"select c.id, c.pk from c where c.route = '{route}'";

            QueryResponse respObj = await util.ExecuteQuery(sql);

            string jstr    = respObj.ToJson();
            string outfile = "out/delete_route.json";
            await File.WriteAllTextAsync(outfile, jstr);

            Console.WriteLine($"file written: {outfile}");

            for (int i = 0; i < respObj.itemCount; i++)
            {
                dynamic         item = respObj.items[i];
                string          id   = item["id"];
                string          pk   = item["pk"];
                GenericDocument gd   = new GenericDocument(id, pk);
                Console.WriteLine($"deleting {gd.ToJson()}");
                ItemResponse <GenericDocument> resp = await util.DeleteGenericDocument(gd);

                Console.WriteLine($"resp, status: {resp.StatusCode} ru: {resp.RequestCharge}");
            }
        }
Esempio n. 3
0
        public async Task <ItemResponse <GenericDocument> > DeleteGenericDocument(GenericDocument doc)
        {
            ItemResponse <GenericDocument> response =
                await this.currentContainer.DeleteItemAsync <GenericDocument>(
                    doc.id, new PartitionKey(doc.pk));

            return(response);
        }