Exemple #1
0
        public async Task <ExportJobStatusContract> PollExportStatus(string jobId, long timeoutMilliSecond)
        {
            ExportJobStatusContract jobStatus = null;
            Stopwatch sw = new Stopwatch();

            while (jobStatus == null || string.Equals(jobStatus.Status, "Queued") || string.Equals(jobStatus.Status, "Running"))
            {
                await Task.Delay(1000);

                jobStatus = await ExecuteNewRequest <ExportJobStatusContract>(string.Format(GetUrl, jobId), Method.Get);

                if (sw.ElapsedMilliseconds > timeoutMilliSecond)
                {
                    throw new Exception("Timeout period exceeded but export Job is still running.");
                }
            }

            if (string.Equals(jobStatus.Status, "Success"))
            {
                return(jobStatus);
            }
            else
            {
                throw new Exception($"Export Job [{jobId}] status: {jobStatus.Status}");
            }
        }
Exemple #2
0
        public async Task DownloadExportedFile(ExportJobStatusContract jobStatus, string filePath)
        {
            var dirPath = Path.GetDirectoryName(filePath);

            if (!Directory.Exists(dirPath))
            {
                Directory.CreateDirectory(dirPath);
            }

            using (var request = NewRequest(jobStatus.File.EntityUri, Method.Get))
            {
                request.AddAuthorizationHeader(jobStatus.File.AuthorizationHeader);

                using (var response = await Send(request))
                    using (var fs = new FileStream(filePath, FileMode.Create))
                    {
                        var responseStream = await response.ReadContentAsStreamAsync();

                        await responseStream.CopyToAsync(fs);
                    }
            }
        }