public async Task <FileInfo> Query(Guid containerId, Guid modelSetId, int version, string selectQuery) { var query = new IndexQuery { Statement = selectQuery }; var filename = query.GetThumbprint() + ".txt.gz"; var resultFile = _fileManager.NewPath(filename); if (!resultFile.Exists) { _stopwatch.Reset(); _stopwatch.Start(); var status = await _indexClient.QueryModelSetVersionIndexAsync( containerId, modelSetId, (int)version, query, CancellationToken.None).CompleteJob( job => _indexClient.GetModelSetJobAsync(containerId, modelSetId, job.JobId), job => job.Status == IndexJobStatus.Running); _stopwatch.Stop(); Debug.WriteLine($"Server-side query execution time (ms) : {_stopwatch.ElapsedMilliseconds}"); if (status.Status != IndexJobStatus.Succeeded) { throw new InvalidOperationException(JsonConvert.SerializeObject(status)); } var resource = new Uri(status.Resources.Results.Url); using (var httpStream = await resource.OpenHttpStream(status.Resources.Results.Headers)) using (var fout = resultFile.Open(FileMode.Create)) { _stopwatch.Reset(); _stopwatch.Start(); await httpStream.CopyToAsync(fout); _stopwatch.Stop(); Debug.WriteLine($"Index query result download processing time (ms) : {_stopwatch.ElapsedMilliseconds}"); } } resultFile.Refresh(); Debug.WriteLine($"Index query result size (bytes) : {resultFile.Length}"); return(resultFile); }