本文整理汇总了C#中Couchbase.Lite.Replication类的典型用法代码示例。如果您正苦于以下问题:C# Replication类的具体用法?C# Replication怎么用?C# Replication使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Replication类属于Couchbase.Lite命名空间,在下文中一共展示了Replication类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Start
private IEnumerator Start () {
Debug.LogFormat ("Data path = {0}", Application.persistentDataPath);
#if UNITY_EDITOR_WIN
Log.SetLogger(new UnityLogger());
#endif
_db = Manager.SharedInstance.GetDatabase ("spaceshooter");
_pull = _db.CreatePullReplication (GameController.SYNC_URL);
_pull.Continuous = true;
_pull.Start ();
while (_pull != null && _pull.Status == ReplicationStatus.Active) {
yield return new WaitForSeconds(0.5f);
}
var doc = _db.GetExistingDocument ("player_data");
if (doc != null) {
//We have a record! Get the ship data, if possible.
string assetName = String.Empty;
if(doc.UserProperties.ContainsKey("ship_data")) {
assetName = doc.UserProperties ["ship_data"] as String;
}
StartCoroutine(LoadAsset (assetName));
} else {
//Create a new record
doc = _db.GetDocument("player_data");
doc.PutProperties(new Dictionary<string, object> { { "ship_data", String.Empty } });
}
doc.Change += DocumentChanged;
_push = _db.CreatePushReplication (new Uri ("http://127.0.0.1:4984/spaceshooter"));
_push.Start();
}
示例2: TestIssue490
public void TestIssue490()
{
var sg = new CouchDB("http", GetReplicationServer());
using (var remoteDb = sg.CreateDatabase("issue490")) {
var push = database.CreatePushReplication(remoteDb.RemoteUri);
CreateFilteredDocuments(database, 30);
CreateNonFilteredDocuments (database, 10);
RunReplication(push);
Assert.IsTrue(push.ChangesCount==40);
Assert.IsTrue(push.CompletedChangesCount==40);
Assert.IsNull(push.LastError);
Assert.AreEqual(40, database.DocumentCount);
for (int i = 0; i <= 5; i++) {
pull = database.CreatePullReplication(remoteDb.RemoteUri);
pull.Continuous = true;
pull.Start ();
Task.Delay (1000).Wait();
CallToView ();
Task.Delay (2000).Wait();
RecreateDatabase ();
}
}
}
示例3: UpdateReplications
private void UpdateReplications(string syncURL)
{
if (_puller != null)
{
_puller.Stop();
}
if(_pusher != null)
{
_pusher.Stop();
}
if (String.IsNullOrEmpty(syncURL))
{
return;
}
var uri = new Uri(syncURL);
_puller = _db.CreatePullReplication(uri);
_puller.Continuous = true;
_puller.Start();
_pusher = _db.CreatePushReplication(uri);
_pusher.Continuous = true;
_pusher.Start();
}
示例4: StartReplications
public void StartReplications()
{
var push = database.CreatePushReplication(config.Gateway.Uri);
var pull = database.CreatePullReplication(config.Gateway.Uri);
var auth = AuthenticatorFactory.CreateBasicAuthenticator(config.User.Name, config.User.Password);
push.Authenticator = auth;
pull.Authenticator = auth;
push.Headers = config.CustomHeaders;
pull.Headers = config.CustomHeaders;
push.Continuous = true;
pull.Continuous = true;
push.Changed += (sender, e) =>
{
// Will be called when the push replication status changes
};
pull.Changed += (sender, e) =>
{
// Will be called when the pull replication status changes
};
//push.Start();
pull.Start();
this.push = push;
this.pull = pull;
}
示例5: StartSyncGateway
public void StartSyncGateway(string url = "")
{
pull = _database.CreatePullReplication(CreateSyncUri());
push = _database.CreatePushReplication(CreateSyncUri());
var authenticator = AuthenticatorFactory.CreateBasicAuthenticator("david", "12345");
pull.Authenticator = authenticator;
push.Authenticator = authenticator;
pull.Continuous = true;
push.Continuous = true;
pull.Changed += Pull_Changed;
push.Changed += Push_Changed;
pull.Start();
push.Start();
}
示例6: ReplicationWatcherThread
private static CountdownEvent ReplicationWatcherThread(Replication replication)
{
var started = replication.IsRunning;
var doneSignal = new CountdownEvent(1);
Task.Factory.StartNew(()=>
{
var done = false;
while (!done)
{
if (replication.IsRunning)
{
started = true;
}
var statusIsDone = (
replication.Status == ReplicationStatus.Stopped
|| replication.Status == ReplicationStatus.Idle
);
if (started && statusIsDone)
{
done = true;
}
try
{
System.Threading.Thread.Sleep(1000);
}
catch (Exception e)
{
Runtime.PrintStackTrace(e);
}
}
doneSignal.Signal();
});
return doneSignal;
}
示例7: StartSync
public void StartSync(string syncUrl)
{
Uri uri;
try {
uri = new Uri(syncUrl);
} catch(UriFormatException) {
Log.E("TaskManager", "Invalid URL {0}", syncUrl);
return;
}
if(_pull == null) {
_pull = _db.CreatePullReplication(uri);
_pull.Continuous = true;
_pull.Start();
}
if(_push == null) {
_push = _db.CreatePushReplication(uri);
_push.Continuous = true;
_push.Start();
}
}
示例8: Close
internal Boolean Close()
{
if (!_isOpen)
{
return false;
}
if (_views != null)
{
foreach (View view in _views.Values)
{
view.DatabaseClosing();
}
}
_views = null;
if (ActiveReplicators != null)
{
//
var activeReplicators = new Replication[ActiveReplicators.Count];
ActiveReplicators.CopyTo(activeReplicators, 0);
foreach (Replication replicator in activeReplicators)
{
replicator.DatabaseClosing();
}
ActiveReplicators = null;
}
if (StorageEngine != null && StorageEngine.IsOpen)
{
StorageEngine.Close();
}
_isOpen = false;
_transactionLevel = 0;
return true;
}
示例9: AddActiveReplication
internal void AddActiveReplication(Replication replication)
{
ActiveReplicators.Add(replication);
replication.Changed += (sender, e) =>
{
if (e.Source != null && !e.Source.IsRunning && ActiveReplicators != null)
{
ActiveReplicators.Remove(e.Source);
}
};
}
示例10: AddReplication
internal void AddReplication(Replication replication)
{
lock (_allReplicatorsLocker) { AllReplicators.Add(replication); }
}
示例11: PutReplicationOffline
private void PutReplicationOffline(Replication replication)
{
var doneEvent = new ManualResetEvent(false);
replication.Changed += (object sender, ReplicationChangeEventArgs e) =>
{
if (e.Source.Status == ReplicationStatus.Offline) {
doneEvent.Set();
}
};
replication.GoOffline();
var success = doneEvent.WaitOne(TimeSpan.FromSeconds(30));
Assert.IsTrue(success);
}
示例12: ReplicationWatcherThread
private static CountdownEvent ReplicationWatcherThread(Replication replication, ReplicationObserver observer)
{
var started = replication.IsRunning;
var doneSignal = new CountdownEvent(1);
Task.Factory.StartNew(()=>
{
var done = observer.IsReplicationFinished(); //Prevent race condition where the replicator stops before this portion is reached
while (!done)
{
if (replication.IsRunning)
{
started = true;
}
var statusIsDone = (
replication.Status == ReplicationStatus.Stopped
|| replication.Status == ReplicationStatus.Idle
);
if (started && statusIsDone)
{
break;
}
try
{
Thread.Sleep(1000);
}
catch (Exception e)
{
Runtime.PrintStackTrace(e);
}
}
doneSignal.Signal();
});
return doneSignal;
}
示例13: ForgetSync
void ForgetSync ()
{
var nctr = NSNotificationCenter.DefaultCenter;
if (pull != null) {
pull.Changed -= ReplicationProgress;
pull.Stop();
pull = null;
}
if (push != null) {
push.Changed -= ReplicationProgress;
push.Stop();
push = null;
}
}
开发者ID:transformersprimeabcxyz,项目名称:_TO-DO-couchbase-lite-net-couchbase,代码行数:16,代码来源:RootViewController.cs
示例14: ReplicationProgress
void ReplicationProgress (object replication, ReplicationChangeEventArgs args)
{
var active = args.Source;
Debug.WriteLine (String.Format ("Push: {0}, Pull: {1}", push.Status, pull.Status));
int lastTotal = 0;
if (_leader == null) {
if (active.IsPull && (pull.Status == ReplicationStatus.Active && push.Status != ReplicationStatus.Active)) {
_leader = pull;
} else if (!active.IsPull && (push.Status == ReplicationStatus.Active && pull.Status != ReplicationStatus.Active)) {
_leader = push;
} else {
_leader = null;
}
}
if (active == pull) {
lastTotal = _lastPullCompleted;
} else {
lastTotal = _lastPushCompleted;
}
Debug.WriteLine (String.Format ("Sync: {2} Progress: {0}/{1};", active.CompletedChangesCount - lastTotal, active.ChangesCount - lastTotal, active == push ? "Push" : "Pull"));
var progress = (float)(active.CompletedChangesCount - lastTotal) / (float)(Math.Max (active.ChangesCount - lastTotal, 1));
if (AppDelegate.CurrentSystemVersion < AppDelegate.iOS7) {
ShowSyncStatusLegacy ();
} else {
ShowSyncStatus ();
}
Debug.WriteLine (String.Format ("({0:F})", progress));
if (active == pull) {
if (AppDelegate.CurrentSystemVersion >= AppDelegate.iOS7) Progress.TintColor = UIColor.White;
} else {
if (AppDelegate.CurrentSystemVersion >= AppDelegate.iOS7) Progress.TintColor = UIColor.LightGray;
}
Progress.Hidden = false;
if (progress < Progress.Progress)
Progress.SetProgress (progress, false);
else
Progress.SetProgress (progress, false);
if (!(pull.Status != ReplicationStatus.Active && push.Status != ReplicationStatus.Active))
if (progress < 1f)
return;
if (active == null)
return;
var initiatorName = active.IsPull ? "Pull" : "Push";
_lastPushCompleted = push.ChangesCount;
_lastPullCompleted = pull.ChangesCount;
if (Progress == null)
return;
Progress.Hidden = false;
Progress.SetProgress (1f, false);
var t = new System.Timers.Timer (300);
t.Elapsed += (sender, e) => {
InvokeOnMainThread (() => {
t.Dispose ();
Progress.Hidden = true;
Progress.SetProgress (0f, false);
Debug.WriteLine (String.Format ("{0} Sync Session Finished.", initiatorName));
ShowSyncButton ();
});
};
t.Start ();
}
开发者ID:transformersprimeabcxyz,项目名称:_TO-DO-couchbase-lite-net-couchbase,代码行数:75,代码来源:RootViewController.cs
示例15: UpdateSyncUrl
void UpdateSyncUrl ()
{
if (Database == null)
return;
Uri newRemoteUrl = null;
var syncPoint = NSUserDefaults.StandardUserDefaults.StringForKey (ConfigViewController.SyncUrlKey);
if (!String.IsNullOrWhiteSpace (syncPoint))
newRemoteUrl = new Uri (syncPoint);
else
return;
ForgetSync ();
pull = Database.CreatePullReplication (newRemoteUrl);
push = Database.CreatePushReplication (newRemoteUrl);
pull.Continuous = push.Continuous = true;
pull.Changed += ReplicationProgress;
push.Changed += ReplicationProgress;
pull.Start();
push.Start();
}
开发者ID:transformersprimeabcxyz,项目名称:_TO-DO-couchbase-lite-net-couchbase,代码行数:21,代码来源:RootViewController.cs