Beispiel #1
0
        public static Task UpsertDesignDocumentAsync(this IViewIndexManager viewManager, DesignDocument designDocument, DesignDocumentNamespace @namespace, Action <UpsertDesignDocumentOptions> configureOptions)
        {
            var options = new UpsertDesignDocumentOptions();

            configureOptions(options);

            return(viewManager.UpsertDesignDocumentAsync(designDocument, @namespace, options));
        }
        public async Task UpsertDesignDocumentAsync(DesignDocument designDocument, DesignDocumentNamespace @namespace, UpsertDesignDocumentOptions options)
        {
            var json = JsonConvert.SerializeObject(designDocument);
            var uri  = GetUri(designDocument.Name, @namespace);

            Logger.LogInformation($"Attempting to upsert design document {_bucketName}/{designDocument.Name} - {uri}");
            Logger.LogDebug(json);

            try
            {
                var content = new StringContent(json, Encoding.UTF8, MediaType.Json);
                var result  = await _client.PutAsync(uri, content, options.CancellationToken).ConfigureAwait(false);

                result.EnsureSuccessStatusCode();
            }
            catch (Exception exception)
            {
                Logger.LogError(exception, $"Failed to upsert design document {_bucketName}/{designDocument.Name} - {uri} - {json}");
                throw;
            }
        }