Beispiel #1
0
        // Check export status and return output once we get 200
        private async Task <IList <Uri> > CheckExportStatus(Uri contentLocation)
        {
            HttpStatusCode      resultCode = HttpStatusCode.Accepted;
            HttpResponseMessage response   = null;

            while (resultCode == HttpStatusCode.Accepted)
            {
                await Task.Delay(5000);

                response = await _testFhirClient.CheckExportAsync(contentLocation);

                resultCode = response.StatusCode;
            }

            if (resultCode != HttpStatusCode.OK)
            {
                throw new Exception($"Export request failed with status code {resultCode}");
            }

            // we have got the result. Deserialize into output response.
            var contentString = await response.Content.ReadAsStringAsync();

            ExportJobResult exportJobResult = JsonConvert.DeserializeObject <ExportJobResult>(contentString);

            return(exportJobResult.Output.Select(x => x.FileUri).ToList());
        }
Beispiel #2
0
        // Check export status and return output once we get 200
        internal static async Task <IList <Uri> > CheckExportStatus(TestFhirClient testFhirClient, Uri contentLocation, int timeToWaitInMinutes = 5)
        {
            HttpStatusCode      resultCode = HttpStatusCode.Accepted;
            HttpResponseMessage response   = null;
            int retryCount = 0;

            // Wait until status change or timeout
            while ((resultCode == HttpStatusCode.Accepted || resultCode == HttpStatusCode.ServiceUnavailable) && retryCount < 60)
            {
                await Task.Delay(timeToWaitInMinutes * 1000);

                response = await testFhirClient.CheckExportAsync(contentLocation);

                resultCode = response.StatusCode;

                retryCount++;
            }

            if (retryCount >= 60)
            {
                throw new Exception($"Export request timed out");
            }

            if (resultCode != HttpStatusCode.OK)
            {
                throw new Exception($"Export request failed with status code {resultCode}");
            }

            // we have got the result. Deserialize into output response.
            var contentString = await response.Content.ReadAsStringAsync();

            ExportJobResult exportJobResult = JsonConvert.DeserializeObject <ExportJobResult>(contentString);

            return(exportJobResult.Output.Select(x => x.FileUri).ToList());
        }
        private async Task <HttpResponseMessage> WaitForCompleteAsync(Uri contentLocation)
        {
            HttpStatusCode      resultCode = HttpStatusCode.Accepted;
            HttpResponseMessage response   = null;

            while (resultCode == HttpStatusCode.Accepted)
            {
                await Task.Delay(5000);

                response = await _testFhirClient.CheckExportAsync(contentLocation);

                resultCode = response.StatusCode;
            }

            return(response);
        }