@@ -314,6 +314,112 @@ public async Task<IEnumerable<CouchActiveTask>> GetActiveTasksAsync(Cancellation
314
314
315
315
#endregion
316
316
317
+ #region Replication
318
+ public async Task < bool > ReplicateAsync ( string source , string target , CouchReplication ? replication = null , bool persistent = true , CancellationToken cancellationToken = default )
319
+ {
320
+ var request = NewRequest ( ) ;
321
+
322
+ if ( replication == null )
323
+ {
324
+ replication = new CouchReplication ( ) ;
325
+ }
326
+
327
+ if ( replication . SourceCredentials == null )
328
+ {
329
+ replication . Source = source ;
330
+ }
331
+ else
332
+ {
333
+ replication . Source = new CouchReplicationHost ( )
334
+ {
335
+ Url = source ,
336
+ Auth = new CouchReplicationAuth ( )
337
+ {
338
+ BasicCredentials = replication . SourceCredentials ,
339
+ }
340
+ } ;
341
+ }
342
+
343
+ if ( replication . TargetCredentials == null )
344
+ {
345
+ replication . Target = target ;
346
+ }
347
+ else
348
+ {
349
+ replication . Target = new CouchReplicationHost ( )
350
+ {
351
+ Url = target ,
352
+ Auth = new CouchReplicationAuth ( )
353
+ {
354
+ BasicCredentials = replication . TargetCredentials ,
355
+ }
356
+ } ;
357
+ }
358
+
359
+ OperationResult result = await request
360
+ . AppendPathSegments ( persistent ? "_replicator" : "_replicate" )
361
+ . PostJsonAsync ( replication , cancellationToken )
362
+ . SendRequestAsync ( )
363
+ . ReceiveJson < OperationResult > ( )
364
+ . ConfigureAwait ( false ) ;
365
+
366
+ return result . Ok ;
367
+ }
368
+
369
+ public async Task < bool > RemoveReplicationAsync ( string source , string target , CouchReplication ? replication = null , bool persistent = true , CancellationToken cancellationToken = default )
370
+ {
371
+ var request = NewRequest ( ) ;
372
+
373
+ if ( replication == null )
374
+ {
375
+ replication = new CouchReplication ( ) ;
376
+ }
377
+
378
+ if ( replication . SourceCredentials == null )
379
+ {
380
+ replication . Source = source ;
381
+ }
382
+ else
383
+ {
384
+ replication . Source = new CouchReplicationHost ( )
385
+ {
386
+ Url = source ,
387
+ Auth = new CouchReplicationAuth ( )
388
+ {
389
+ BasicCredentials = replication . SourceCredentials ,
390
+ }
391
+ } ;
392
+ }
393
+
394
+ if ( replication . TargetCredentials == null )
395
+ {
396
+ replication . Target = target ;
397
+ }
398
+ else
399
+ {
400
+ replication . Target = new CouchReplicationHost ( )
401
+ {
402
+ Url = target ,
403
+ Auth = new CouchReplicationAuth ( )
404
+ {
405
+ BasicCredentials = replication . TargetCredentials ,
406
+ }
407
+ } ;
408
+ }
409
+
410
+ replication . Cancel = true ;
411
+
412
+ OperationResult result = await request
413
+ . AppendPathSegments ( persistent ? "_replicator" : "_replicate" )
414
+ . PostJsonAsync ( replication , cancellationToken )
415
+ . SendRequestAsync ( )
416
+ . ReceiveJson < OperationResult > ( )
417
+ . ConfigureAwait ( false ) ;
418
+
419
+ return result . Ok ;
420
+ }
421
+ #endregion
422
+
317
423
#endregion
318
424
319
425
#region Implementations
0 commit comments