本文整理汇总了C#中Couchbase.Lite.Replication类的典型用法代码示例。如果您正苦于以下问题:C# Replication类的具体用法?C# Replication怎么用?C# Replication使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Replication类属于Couchbase.Lite命名空间,在下文中一共展示了Replication类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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();
}
开发者ID:serjee,项目名称:space-shooter,代码行数:32,代码来源:AssetChangeListener.cs
示例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 ();
}
}
}
开发者ID:JiboStore,项目名称:couchbase-lite-net,代码行数:27,代码来源:ViewsTest.cs
示例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();
}
开发者ID:jonfunkhouser,项目名称:couchbase-lite-net,代码行数:27,代码来源:MainPage.xaml.cs
示例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;
}
开发者ID:AnthonyWard,项目名称:couchbase-lite-net-samples,代码行数:31,代码来源:SyncManager.cs
示例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();
}
开发者ID:Branor,项目名称:CouchbaseLite-Delphi-ComInterop,代码行数:18,代码来源:CouchbaseLiteFacade.cs
示例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;
}
开发者ID:FireflyLogic,项目名称:couchbase-lite-net,代码行数:39,代码来源:ReplicationTest.cs
示例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();
}
}
开发者ID:richardkeller411,项目名称:dev-days-labs,代码行数:22,代码来源:TaskManager.cs
示例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;
}
开发者ID:FireflyLogic,项目名称:couchbase-lite-net,代码行数:33,代码来源:Database.cs
示例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);
}
};
}
开发者ID:DotNetEra,项目名称:couchbase-lite-net,代码行数:11,代码来源:Database.cs
示例10: AddReplication
internal void AddReplication(Replication replication)
{
lock (_allReplicatorsLocker) { AllReplicators.Add(replication); }
}
开发者ID:DotNetEra,项目名称:couchbase-lite-net,代码行数:4,代码来源:Database.cs
示例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);
}
开发者ID:jonfunkhouser,项目名称:couchbase-lite-net,代码行数:15,代码来源:ReplicationTest.cs
示例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;
}
开发者ID:ertrupti9,项目名称:couchbase-lite-net,代码行数:39,代码来源:ReplicationTest.cs
示例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
示例16: AddActiveReplication
internal void AddActiveReplication(Replication replication)
{
if (ActiveReplicators == null) {
Log.W(TAG, "ActiveReplicators is null, so replication will not be added");
return;
}
ActiveReplicators.Add(replication);
replication.Changed += (sender, e) =>
{
if (e.Source != null && !e.Source.IsRunning && ActiveReplicators != null)
{
ActiveReplicators.Remove(e.Source);
}
};
}
开发者ID:howbazaar,项目名称:couchbase-lite-net,代码行数:16,代码来源:Database.cs
示例17: RunReplication
protected virtual void RunReplication(Replication replication)
{
var replicationDoneSignal = new CountdownEvent(1);
var observer = new ReplicationObserver(replicationDoneSignal);
replication.Changed += observer.Changed;
replication.Start();
var success = replicationDoneSignal.Wait(TimeSpan.FromSeconds(60));
Assert.IsTrue(success);
replication.Changed -= observer.Changed;
}
开发者ID:wilsondy,项目名称:couchbase-lite-net,代码行数:11,代码来源:LiteTestCase.cs
示例18: DoReplication
IEnumerator DoReplication(Replication replication)
{
replication.Start ();
while (replication != null && replication.Status == ReplicationStatus.Active) {
yield return new WaitForSeconds(0.5f);
}
}
开发者ID:lesterlecong,项目名称:UpVenture,代码行数:8,代码来源:CouchbaseDatabase.cs
示例19: TestGetReplicator
public void TestGetReplicator()
{
if (!Boolean.Parse((string)Runtime.Properties["replicationTestsEnabled"]))
{
Assert.Inconclusive("Replication tests disabled.");
return;
}
var replicationUrl = GetReplicationURL();
var replicator = database.CreatePullReplication(replicationUrl);
Assert.IsNotNull(replicator);
Assert.IsTrue(replicator.IsPull);
Assert.IsFalse(replicator.Continuous);
Assert.IsFalse(replicator.IsRunning);
replicator.Start();
Assert.IsTrue(replicator.IsRunning);
var activeReplicators = new Replication[database.ActiveReplicators.Count];
database.ActiveReplicators.CopyTo(activeReplicators, 0);
Assert.AreEqual(1, activeReplicators.Length);
Assert.AreEqual(replicator, activeReplicators [0]);
replicator.Stop();
// Wait for a second to ensure that the replicator finishes
// updating all status (esp Database.ActiveReplicator that will
// be updated when receiving a Replication.Changed event which
// is distached asynchronously when running tests.
System.Threading.Thread.Sleep(1000);
Assert.IsFalse(replicator.IsRunning);
activeReplicators = new Replication[database.ActiveReplicators.Count];
database.ActiveReplicators.CopyTo(activeReplicators, 0);
Assert.AreEqual(0, activeReplicators.Length);
}
开发者ID:ertrupti9,项目名称:couchbase-lite-net,代码行数:35,代码来源:ReplicationTest.cs
示例20: RunReplication
private void RunReplication(Replication replication)
{
var replicationDoneSignal = new CountdownEvent(1);
var observer = new ReplicationObserver(replicationDoneSignal);
replication.Changed += observer.Changed;
replication.Start();
var replicationDoneSignalPolling = ReplicationWatcherThread(replication, observer);
Log.D(Tag, "Waiting for replicator to finish.");
var success = WaitHandle.WaitAll(new[] { replicationDoneSignal.WaitHandle, replicationDoneSignalPolling.WaitHandle }, 60*1000);
Assert.IsTrue(success);
Log.D(Tag, "replicator finished");
replication.Changed -= observer.Changed;
}
开发者ID:ertrupti9,项目名称:couchbase-lite-net,代码行数:18,代码来源:ReplicationTest.cs
注:本文中的Couchbase.Lite.Replication类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论