diff --git a/src/Couchbase.Lite.Shared/Manager.cs b/src/Couchbase.Lite.Shared/Manager.cs index b5babceff..c66eb6b9b 100644 --- a/src/Couchbase.Lite.Shared/Manager.cs +++ b/src/Couchbase.Lite.Shared/Manager.cs @@ -852,6 +852,7 @@ internal Replication ReplicationWithProperties(IDictionary prope rep.FilterParams = properties.Get("query_params").AsDictionary(); rep.DocIds = properties.Get("doc_ids").AsList(); rep.Headers = new Dictionary(); + rep.ReplicationOptions = new ReplicationOptions(properties); foreach(var header in results.Get("headers").AsDictionary()) { if(header.Key.ToLowerInvariant() == "cookie") { var cookie = default(Cookie); @@ -987,6 +988,8 @@ private Status ParseReplicationProperties(IDictionary properties } } + + // Can't specify both a filter and doc IDs if (properties.ContainsKey("filter") && properties.ContainsKey("doc_ids")) { return new Status(StatusCode.BadRequest); diff --git a/src/Couchbase.Lite.Shared/Replication/ReplicationOptions.cs b/src/Couchbase.Lite.Shared/Replication/ReplicationOptions.cs index 8d36165a8..56111eb3a 100644 --- a/src/Couchbase.Lite.Shared/Replication/ReplicationOptions.cs +++ b/src/Couchbase.Lite.Shared/Replication/ReplicationOptions.cs @@ -19,6 +19,7 @@ // limitations under the License. // using System; +using System.Collections.Generic; using Couchbase.Lite.Util; namespace Couchbase.Lite @@ -31,6 +32,8 @@ public sealed class ReplicationOptions #region Constants + private const string Tag = nameof(ReplicationOptions); + /// /// The default value for Heartbeat (5 minutes) /// @@ -194,6 +197,35 @@ public ReplicationOptions() ReplicationRetryDelay = DefaultReplicationRetryDelay; } + internal ReplicationOptions(IDictionary dictionary) + : this() + { + long heartbeatMs; + if(dictionary.TryGetValue("heartbeat", out heartbeatMs)) { + Heartbeat = TimeSpan.FromMilliseconds(heartbeatMs); + } + + long requestTimeoutMs; + if(dictionary.TryGetValue("connection_timeout", out requestTimeoutMs)) { + RequestTimeout = TimeSpan.FromMilliseconds(requestTimeoutMs); + } + + long pollIntervalMs; + if(dictionary.TryGetValue("poll", out pollIntervalMs)) { + if(pollIntervalMs >= 30000) { + PollInterval = TimeSpan.FromMilliseconds(pollIntervalMs); + } else { + Log.To.Sync.W(Tag, $"poll interval of {pollIntervalMs} seconds is too short!"); + } + } + + UseWebSocket = dictionary.GetCast("websocket"); + RemoteUUID = dictionary.GetCast("remoteUUID"); + PurgePushed = dictionary.GetCast("purgePushed"); + AllNew = dictionary.GetCast("allNew"); + Reset = dictionary.GetCast("reset"); + } + #endregion #region Overrides