Пример #1
0
        public EvaluationResult <ProductDocument> CosmosDBSQLDownload(ICosmosDBSQLContext context, string containerName)
        {
            var result = new EvaluationResult <ProductDocument>();

            try
            {
                result.Results = context.GetDocuments(containerName);
                result.Code    = result.Results.Count > 0 ? 0 : 1;
                result.Text    = result.Results.Count > 0 ? "Successfully returned product documents from Cosmos DB" : "Did not return any documents from Cosmos DB";
            }
            catch (Exception ex)
            {
                result.Code = 2;
                result.Text = $"There was an error downloading product documents from Cosmos DB: {ex.Message}";
            }
            return(result);
        }
Пример #2
0
        public EvaluationResult <ProductDocument> CosmosDBSQLUpload(ICosmosDBSQLContext context, string containerName)
        {
            var result = new EvaluationResult <ProductDocument>();
            var data   = sampleData.ProductData();

            try
            {
                Task t = Task.Run(async() =>
                {
                    await context.CreateCollection(containerName);
                    await context.UploadDocuments(data, containerName);
                });
                t.Wait();
            }
            catch (Exception ex)
            {
                result.Code = 2;
                result.Text = $"There was an error uploading product documents to Cosmos DB: {ex.Message}";
            }

            return(result);
        }