Пример #1
0
        private async Task MigrateIndexes()
        {
            var response = await RunWithAuthRetry(async() =>
            {
                var url             = $"{Options.ServerUrl}/databases/{Options.DatabaseName}/indexes";
                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 export indexes from server: {Options.ServerUrl}, " +
                                                    $"status code: {response.StatusCode}, " +
                                                    $"error: {responseString}");
            }

            using (var responseStream = await response.Content.ReadAsStreamAsync())
                using (var indexesStream = new ArrayStream(responseStream, "Indexes")) // indexes endpoint returns an array
                    using (Parameters.Database.DocumentsStorage.ContextPool.AllocateOperationContext(out DocumentsOperationContext context))
                        using (var source = new StreamSource(indexesStream, context, Parameters.Database))
                        {
                            var destination = new DatabaseDestination(Parameters.Database);
                            var options     = new DatabaseSmugglerOptionsServerSide
                            {
                                RemoveAnalyzers = Options.RemoveAnalyzers,
                            };
                            var smuggler = new DatabaseSmuggler(Parameters.Database, source, destination, Parameters.Database.Time, options, Parameters.Result, Parameters.OnProgress, Parameters.CancelToken.Token);

                            smuggler.Execute();
                        }
        }
Пример #2
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}");
            }

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

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

                    return(attachments);
                }
        }