Exemplo n.º 1
0
        public async Task<Stream> DownloadAsync(Link link, CancellationToken cancellationToken = default(CancellationToken))
        {
            var url = new Uri(link.Href);

            var method = new HttpMethod(link.Method);

            var requestMessage = new HttpRequestMessage(method, url);

            HttpResponseMessage responseMessage = await SendAsync(requestMessage, cancellationToken).ConfigureAwait(false);

            return await responseMessage.Content.ReadAsStreamAsync().ConfigureAwait(false);
        }
Exemplo n.º 2
0
        public Task UploadAsync(Link link, Stream file, CancellationToken cancellationToken = default(CancellationToken))
        {
            var url = new Uri(link.Href);

            var method = new HttpMethod(link.Method);

            var content = new StreamContent(file);

            var requestMessage = new HttpRequestMessage(method, url) { Content = content };

            return SendAsync(requestMessage, cancellationToken);
        }
        public async Task<Operation> GetOperationStatus(Link link, CancellationToken cancellationToken)
        {
            var url = new Uri(link.Href);

            var method = new HttpMethod(link.Method);

            var requestMessage = new HttpRequestMessage(method, url);

            HttpResponseMessage responseMessage = await SendAsync(requestMessage, cancellationToken);

            return await responseMessage.Content.ReadAsAsync<Operation>(cancellationToken);
        }
Exemplo n.º 4
0
        public async Task<Operation> GetOperationStatus(Link link, CancellationToken cancellationToken = default(CancellationToken))
        {
            var url = new Uri(link.Href);

            var method = new HttpMethod(link.Method);

            var requestMessage = new HttpRequestMessage(method, url);

            HttpResponseMessage responseMessage = await SendAsync(requestMessage, cancellationToken).ConfigureAwait(false);

            Operation operation = await ReadResponse<Operation>(responseMessage, cancellationToken).ConfigureAwait(false);

            if (operation == null)
            {
                throw new Exception("Unexpected empty result.");
            }

            return operation;
        }
        public async Task UploadTest()
        {
            var link = new Link
            {
                Href = "https://uploader1d.dst.yandex.net/upload-target/",
                Method = "PUT",
                Templated = false
            };

            var httpClientTest = new TestHttpClient(
                methodName: link.Method, 
                url: link.Href, 
                httpStatusCode: HttpStatusCode.Created, 
                result: @"");

            var diskClient = new DiskHttpApi(TestHttpClient.BaseUrl,
                                             TestHttpClient.ApiKey,
                                             logSaver: null,
                                             httpClient: httpClientTest);

            await diskClient.Files.UploadAsync(link, new MemoryStream(), CancellationToken.None).ConfigureAwait(false);
        }
Exemplo n.º 6
-1
        public async Task DownloadTest()
        {
            var link = new Link
            {
                Href = "https://downloader.dst.yandex.ru/disk/",
                Method = "GET",
                Templated = false
            };

            var httpClientTest = new TestHttpClient(
                methodName: link.Method, 
                url: link.Href, 
                httpStatusCode: HttpStatusCode.Created, 
                result: @"Test file content");

            var diskClient = new DiskHttpApi(TestHttpClient.BaseUrl,
                                             TestHttpClient.ApiKey,
                                             logSaver: null,
                                             httpClient: httpClientTest);

            Stream stream = await diskClient.Files.DownloadAsync(link, CancellationToken.None).ConfigureAwait(false);

            var content = new StreamReader(stream).ReadToEnd();

            Assert.AreEqual(@"Test file content", content);
        }