예제 #1
0
        public Task<Stream> DownloadSignatureRequestDocuments(HSDownloadSignatureRequestData request)
        {
            string getUrl = Config.GetSignatureRequestFilesUri + "/" + request.SignatureRequestId;
            if (!string.IsNullOrEmpty(request.FileType))
                getUrl = getUrl + "?file_type=" + request.FileType;

            return _httpClient.GetAsync(getUrl, HttpCompletionOption.ResponseHeadersRead).ContinueWith(t =>
            {
                HttpResponseMessage response = t.Result;

                // No documents found from the input request data
                if (response.Content.Headers.ContentDisposition == null)
                    return null;

                return response.Content.ReadAsStreamAsync().Result;
            });
        }
예제 #2
0
        public Task<string> DownloadSignatureRequestDocuments(HSDownloadSignatureRequestData request, string outputDir)
        {
            if (FileStorage == null)
                throw new IOException("Undefined FileStore");

            string getUrl = Config.GetSignatureRequestFilesUri + "/" + request.SignatureRequestId;

            if (!string.IsNullOrEmpty(request.FileType))
                getUrl = getUrl + "?file_type=" + request.FileType;

            return _httpClient.GetAsync(getUrl, HttpCompletionOption.ResponseHeadersRead).ContinueWith(t =>
            {
                HttpResponseMessage response = t.Result;
                ContentDispositionHeaderValue contentDisposition = response.Content.Headers.ContentDisposition;

                // Not found
                if (contentDisposition == null)
                    return null;

                var filename = contentDisposition.FileName.Trim('"');

                var download = response.Content.ReadAsStreamAsync()
                    .ContinueWith(a => FileStorage.SaveFileAsync(a.Result, outputDir, filename));
                download.Wait();

                return filename;
            });
        }