static async Task Main(string[] args)
        {
            Console.WriteLine("Tradecloud download document example.");

            using (HttpClient httpClient = new HttpClient())
            {
                if (useToken)
                {
                    var authenticationClient = new Authentication(httpClient, authenticationUrl);
                    var(accessToken, refreshToken) = await authenticationClient.Login(username, password);

                    httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", accessToken);
                }
                else
                {
                    var base64EncodedUsernamePassword = Convert.ToBase64String(Encoding.ASCII.GetBytes(username + ":" + password));
                    httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", base64EncodedUsernamePassword);
                }

                var objectStorage = new ObjectStorage(httpClient, objectStorageDocumentUrl);
                var meta          = await objectStorage.GetDocumentMetadata(objectId);
                await DownloadDocumentRequest();

                async Task DownloadDocumentRequest()
                {
                    using (HttpClient httpS3Client = new HttpClient())
                    {
                        Console.WriteLine("DownloadDocument ... please wait");

                        var    start     = DateTime.Now;
                        var    watch     = System.Diagnostics.Stopwatch.StartNew();
                        byte[] fileBytes = await httpS3Client.GetByteArrayAsync(meta.downloadUrl);

                        watch.Stop();

                        File.WriteAllBytes(meta.filename, fileBytes);

                        Console.WriteLine("DownloadDocument start=" + start + " elapsed=" + watch.ElapsedMilliseconds + "ms");
                    }
                }
            }
        }
예제 #2
0
        static async Task Main(string[] args)
        {
            Console.WriteLine("Tradecloud get document metadata example.");

            HttpClient httpClient = new HttpClient();

            if (useToken)
            {
                var authenticationClient = new Authentication(httpClient, authenticationUrl);
                var(accessToken, refreshToken) = await authenticationClient.Login(username, password);

                httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", accessToken);
            }
            else
            {
                var base64EncodedUsernamePassword = Convert.ToBase64String(Encoding.ASCII.GetBytes(username + ":" + password));
                httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", base64EncodedUsernamePassword);
            }

            var objectStorage = new ObjectStorage(httpClient, objectStorageDocumentUrl);
            var meta          = await objectStorage.GetDocumentMetadata(objectId);
        }