private async Task <Dictionary <string, string> > dmRunPointRead(string docId, string objectTitle, string containerName, string objectType) { Dictionary <string, string> queryData = new Dictionary <string, string>(); dmCosmosConnection C = new dmCosmosConnection(); C.connectionSetup(); var container = C.database.GetContainer(containerName); // Time the query Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); ItemResponse <dynamic> documentResponse = await container.ReadItemAsync <dynamic>(docId, new PartitionKey(objectTitle)); var result = documentResponse.Resource; stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; //Print results string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10); queryData.Add("exampleResult", documentResponse.Resource.ToString()); queryData.Add("requestCharge", documentResponse.RequestCharge.ToString()); queryData.Add("totalTime", elapsedTime); queryData.Add("recordCount", "1"); if (objectType == "person") { queryData.Add("searchResults", dmActorPointResults(documentResponse.Resource, containerName)); } else { queryData.Add("searchResults", dmMoviePointResults(documentResponse.Resource, containerName)); } return(queryData); }
private async Task <Dictionary <string, string> > dmRunSqlQuery(string sqlQueryText, string containerName, string singleQuerySelected) { Dictionary <string, string> queryData = new Dictionary <string, string>(); dmCosmosConnection C = new dmCosmosConnection(); C.connectionSetup(); double totalRequestCharge = 0; QueryDefinition queryDefinition = new QueryDefinition(sqlQueryText); var container = C.database.GetContainer(containerName); QueryRequestOptions requestOptions; requestOptions = new QueryRequestOptions(); //use all default query options // Time the query Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); FeedIterator <dynamic> queryResultSetIterator = container.GetItemQueryIterator <dynamic>(queryDefinition, requestOptions: requestOptions); List <dynamic> movies = new List <dynamic>(); int itemCount = 0; string exampleResult = "[No Results Found]"; while (queryResultSetIterator.HasMoreResults) { FeedResponse <dynamic> currentResultSet = await queryResultSetIterator.ReadNextAsync(); totalRequestCharge += currentResultSet.RequestCharge; //Console.WriteLine("another page"); foreach (var item in currentResultSet) { movies.Add(item); if (itemCount == 0) { exampleResult = formatJson(item.ToString()); itemCount++; } } } queryData.Add("exampleResult", exampleResult); queryData.Add("requestCharge", totalRequestCharge.ToString()); stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; //Print results string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10); //Total time to execute queryData.Add("totalTime", elapsedTime); //Total Records queryData.Add("recordCount", movies.Count.ToString()); queryData.Add("searchResults", dmMovieSQLResults(movies, containerName, singleQuerySelected)); return(queryData); }