Skip to content

Commit

Permalink
Make sure that all of the cross platform REST API replication options…
Browse files Browse the repository at this point in the history
… are available
  • Loading branch information
borrrden committed Sep 27, 2016
1 parent ba886b8 commit 5cfe25b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Couchbase.Lite.Shared/Manager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,7 @@ internal Replication ReplicationWithProperties(IDictionary<string, object> prope
rep.FilterParams = properties.Get("query_params").AsDictionary<string, object>();
rep.DocIds = properties.Get("doc_ids").AsList<string>();
rep.Headers = new Dictionary<string, string>();
rep.ReplicationOptions = new ReplicationOptions(properties);
foreach(var header in results.Get("headers").AsDictionary<string, string>()) {
if(header.Key.ToLowerInvariant() == "cookie") {
var cookie = default(Cookie);
Expand Down Expand Up @@ -987,6 +988,8 @@ private Status ParseReplicationProperties(IDictionary<string, object> properties
}
}



// Can't specify both a filter and doc IDs
if (properties.ContainsKey("filter") && properties.ContainsKey("doc_ids")) {
return new Status(StatusCode.BadRequest);
Expand Down
32 changes: 32 additions & 0 deletions src/Couchbase.Lite.Shared/Replication/ReplicationOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
// limitations under the License.
//
using System;
using System.Collections.Generic;
using Couchbase.Lite.Util;

namespace Couchbase.Lite
Expand All @@ -31,6 +32,8 @@ public sealed class ReplicationOptions

#region Constants

private const string Tag = nameof(ReplicationOptions);

/// <summary>
/// The default value for Heartbeat (5 minutes)
/// </summary>
Expand Down Expand Up @@ -194,6 +197,35 @@ public ReplicationOptions()
ReplicationRetryDelay = DefaultReplicationRetryDelay;
}

internal ReplicationOptions(IDictionary<string, object> dictionary)
: this()
{
long heartbeatMs;
if(dictionary.TryGetValue<long>("heartbeat", out heartbeatMs)) {
Heartbeat = TimeSpan.FromMilliseconds(heartbeatMs);
}

long requestTimeoutMs;
if(dictionary.TryGetValue<long>("connection_timeout", out requestTimeoutMs)) {
RequestTimeout = TimeSpan.FromMilliseconds(requestTimeoutMs);
}

long pollIntervalMs;
if(dictionary.TryGetValue<long>("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<bool>("websocket");
RemoteUUID = dictionary.GetCast<string>("remoteUUID");
PurgePushed = dictionary.GetCast<bool>("purgePushed");
AllNew = dictionary.GetCast<bool>("allNew");
Reset = dictionary.GetCast<bool>("reset");
}

#endregion

#region Overrides
Expand Down

0 comments on commit 5cfe25b

Please sign in to comment.