Beispiel #1
0
        private async Task <BlittableJsonReaderArray> GetRavenFsHeadersArray(string lastEtag, TransactionOperationContext context)
        {
            var response = await RunWithAuthRetry(async() =>
            {
                var url             = $"{Options.ServerUrl}/fs/{Options.DatabaseName}/streams/files?pageSize={RavenFsHeadersPageSize}&etag={lastEtag}";
                var request         = new HttpRequestMessage(HttpMethod.Get, url);
                var responseMessage = await Parameters.HttpClient.SendAsync(request, Parameters.CancelToken.Token);
                return(responseMessage);
            });

            if (response.IsSuccessStatusCode == false)
            {
                var responseString = await response.Content.ReadAsStringAsync();

                throw new InvalidOperationException($"Failed to get RavenFS headers list from server: {Options.ServerUrl}, " +
                                                    $"status code: {response.StatusCode}, " +
                                                    $"error: {responseString}");
            }

            await using (var responseStream = await response.Content.ReadAsStreamAsync())
            {
                var headersList = await context.ReadForMemoryAsync(responseStream, "ravenfs-headers-list");

                if (headersList.TryGet("Results", out BlittableJsonReaderArray headers) == false)
                {
                    throw new InvalidDataException("Response is invalid");
                }

                return(headers);
            }
        }
Beispiel #2
0
        private async Task <BlittableJsonReaderObject> GetOperationStatus(
            string databaseName, long operationId, TransactionOperationContext context)
        {
            var response = await RunWithAuthRetry(async() =>
            {
                var url             = $"{Options.ServerUrl}/databases/{databaseName}/operation/status?id={operationId}";
                var request         = new HttpRequestMessage(HttpMethod.Get, url);
                var responseMessage = await Parameters.HttpClient.SendAsync(request, Parameters.CancelToken.Token);
                return(responseMessage);
            });

            if (response.StatusCode == HttpStatusCode.NotFound)
            {
                // the operation status was deleted before we could get it
                return(null);
            }

            if (response.IsSuccessStatusCode == false)
            {
                var responseString = await response.Content.ReadAsStringAsync();

                throw new InvalidOperationException($"Failed to get operation status from server: {Options.ServerUrl}, " +
                                                    $"status code: {response.StatusCode}, " +
                                                    $"error: {responseString}");
            }

            var responseStream = await response.Content.ReadAsStreamAsync();

            return(await context.ReadForMemoryAsync(responseStream, "migration-operation-state"));
        }
Beispiel #3
0
        private async Task <BlittableJsonReaderArray> GetAttachmentsList(string lastEtag, TransactionOperationContext context)
        {
            var response = await RunWithAuthRetry(async() =>
            {
                var url             = $"{Options.ServerUrl}/databases/{Options.DatabaseName}/static?pageSize={AttachmentsPageSize}&etag={lastEtag}";
                var request         = new HttpRequestMessage(HttpMethod.Get, url);
                var responseMessage = await Parameters.HttpClient.SendAsync(request, Parameters.CancelToken.Token);
                return(responseMessage);
            });

            if (response.IsSuccessStatusCode == false)
            {
                var responseString = await response.Content.ReadAsStringAsync();

                throw new InvalidOperationException($"Failed to get attachments list from server: {Options.ServerUrl}, " +
                                                    $"status code: {response.StatusCode}, " +
                                                    $"error: {responseString}");
            }

            const string propertyName = "Attachments";

            await using (var responseStream = await response.Content.ReadAsStreamAsync())
                await using (var attachmentsListStream = new ArrayStream(responseStream, propertyName))
                {
                    var attachmentsList = await context.ReadForMemoryAsync(attachmentsListStream, "attachments-list");

                    if (attachmentsList.TryGet(propertyName, out BlittableJsonReaderArray attachments) == false)
                    {
                        throw new InvalidDataException("Response is invalid");
                    }

                    return(attachments);
                }
        }