public async Task CreateAsync(DesignDocument designDocument, CreateViewIndexOptions options) { var json = JsonConvert.SerializeObject(designDocument); var uri = GetUri(designDocument.Name, options.IsProduction); Logger.LogInformation($"Attempting to create design document {_bucketName}/{designDocument.Name} - {uri}"); Logger.LogDebug(json); try { try { // Check design document doesn't already exist - will throw if not await GetAsync(designDocument.Name, new GetViewIndexOptions { IsProduction = options.IsProduction }).ConfigureAwait(false); throw new DesignDocumentAlreadyExistsException(_bucketName, designDocument.Name); } catch (DesignDocumentNotFoundException) { // we expect this exception } 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 create design document {_bucketName}/{designDocument.Name} - {uri} - {json}"); throw; } }
public static Task CreateAsync(this IViewManager viewManager, DesignDocument designDocument, Action <CreateViewIndexOptions> configureOptions) { var options = new CreateViewIndexOptions(); configureOptions(options); return(viewManager.CreateAsync(designDocument, options)); }