public void ReplicationChanged(object sender, ReplicationChangeEventArgs args)
        {
            Couchbase.Lite.Util.Log.D(Tag, "Replication Changed: {0}", args);

            var replicator = args.Source;

            var totalCount = replicator.ChangesCount;
            var completedCount = replicator.CompletedChangesCount;

            if (totalCount > 0 && completedCount < totalCount) {
                SetProgressBarIndeterminateVisibility(true);
            } else {
                SetProgressBarIndeterminateVisibility(false);
            }
        }
        public void Changed(object sender, ReplicationChangeEventArgs args)
        {
            if (replicationFinished) {
                return;
            }

            var replicator = args.Source;
            Log.D(Tag, replicator + " changed: " + replicator.CompletedChangesCount + " / " + replicator.ChangesCount);

            if (replicator.CompletedChangesCount < 0) {
                var msg = replicator + ": replicator.CompletedChangesCount < 0";
                Log.E(Tag, msg);
                throw new Exception(msg);
            }

            if (replicator.ChangesCount < 0) {
                var msg = replicator + ": replicator.ChangesCount < 0";
                Log.E(Tag, msg);
                throw new Exception(msg);
            }

            if (replicator.CompletedChangesCount > replicator.ChangesCount) {
                var msgStr = "replicator.CompletedChangesCount : " + replicator.CompletedChangesCount +
                             " > replicator.ChangesCount : " + replicator.ChangesCount;

                Log.E(Tag, msgStr);
                throw new Exception(msgStr);
            }

            if (!replicator.IsRunning ) {
                this.replicationFinished = true;
                string msg = "ReplicationFinishedObserver.changed called, set replicationFinished to true";
                Log.D(Tag, msg);
                if(doneSignal.CurrentCount > 0) {
                    doneSignal.Signal();
                }

                replicator.Changed -= Changed;
            } else {
                string msg = string.Format("ReplicationFinishedObserver.changed called, but replicator still running, so ignore it");
                Log.D(Tag, msg);
            }
        }
Ejemplo n.º 3
0
        private void NotifyChangeListeners(ReplicationStateTransition transition = null)
        {
            Log.V(TAG, "NotifyChangeListeners ({0}/{1}, state={2} (batch={3}, net={4}))",
                CompletedChangesCount, ChangesCount,
                _stateMachine.State, Batcher == null ? 0 : Batcher.Count(), _requests.Count);

            var evt = _changed;
            if (evt == null) {
                return;
            }

            var args = new ReplicationChangeEventArgs(this, transition);

            // Ensure callback runs on captured context, which should be the UI thread.
            var stackTrace = Environment.StackTrace;
            LocalDatabase.Manager.CapturedContext.StartNew(() =>
            {
                evt(this, args);
            });
        }
 public void Changed(object sender, ReplicationChangeEventArgs args) {
     var replicator = args.Source;
     if (replicator.Status == ReplicationStatus.Idle && doneSignal.CurrentCount > 0) {
         doneSignal.Signal();
     }
 }
 public void Changed(object sender, ReplicationChangeEventArgs args) {
     if (args.LastError != null && doneSignal.CurrentCount > 0) {
         doneSignal.Signal();
     }
 }
 public void Changed(object sender, ReplicationChangeEventArgs args) {
     var replicator = args.Source;
     if (replicator.LastError != null && doneSignal.CurrentCount > 0) {
         doneSignal.Signal();
     }
 }
Ejemplo n.º 7
0
 public void Changed(ReplicationChangeEventArgs args)
 {
     var replicator = args.Source;
     if (replicator.LastError != null)
     {
         doneSignal.CountDown();
     }
 }
Ejemplo n.º 8
0
 public void Changed(ReplicationChangeEventArgs args)
 {
     var replicator = args.Source;
     if (replicator.Status == ReplicationStatus.Stopped)
     {
         doneSignal.CountDown();
     }
 }
    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 ();

    }
Ejemplo n.º 10
0
        void NotifyChangeListeners()
        {
            UpdateProgress();

            var evt = Changed;
            if (evt == null) return;

            var args = new ReplicationChangeEventArgs(this);

            // Ensure callback runs on captured context, which should be the UI thread.
            Log.D(Tag, "Firing NotifyChangeListeners event! [{0} -> {1}]", TaskScheduler.Current.GetType().Name, LocalDatabase.Manager.CapturedContext.Scheduler.GetType().Name);
            LocalDatabase.Manager.CapturedContext.StartNew(()=>evt(this, args));
        }
Ejemplo n.º 11
0
 public void Changed(object sender, ReplicationChangeEventArgs args)
 {
     if (args.Status == ReplicationStatus.Stopped && doneSignal.CurrentCount > 0)
     {
         doneSignal.Signal();
     }
 }
Ejemplo n.º 12
0
        void NotifyChangeListeners ()
        {
            var evt = Changed;
            if (evt == null) return;

            var args = new ReplicationChangeEventArgs(this);
            evt(this, args);
        }
Ejemplo n.º 13
0
        private void NotifyChangeListeners(ReplicationStateTransition transition = null)
        {
            Log.V(TAG, "NotifyChangeListeners ({0}/{1}, state={2} (batch={3}, net={4}))",
                CompletedChangesCount, ChangesCount,
                _stateMachine.State, Batcher == null ? 0 : Batcher.Count(), _requests.Count);

            _pendingDocumentIDs = null;
            var evt = _changed;
            if (evt == null) {
                return;
            }

            var args = new ReplicationChangeEventArgs(this, transition);

            // Ensure callback runs on captured context, which should be the UI thread.
            var stackTrace = Environment.StackTrace;

            lock(_eventQueue) {
                _eventQueue.Enqueue(args);
            }

            if (_eventContext != null) {
                _eventContext.StartNew(() =>
                {
                    lock (_eventQueue) { 
                        while (_eventQueue.Count > 0) {
                            evt(this, _eventQueue.Dequeue());
                        }
                    }
                });
            }
        }
Ejemplo n.º 14
0
 private void WaitForStopped (object sender, ReplicationChangeEventArgs e)
 {
     if (e.Status != ReplicationStatus.Stopped) {
         return;
     }
         
     Changed -= WaitForStopped;
     Start();
 }
 private void Push_Changed(object sender, ReplicationChangeEventArgs e)
 {
     Console.WriteLine("Push: " + e.Status + " " + e.ChangesCount);
 }
Ejemplo n.º 16
0
        private void NotifyChangeListeners(ReplicationStateTransition transition = null) 
        {
            Log.To.Sync.I(Tag, "NotifyChangeListeners ({0}/{1}, state={2} (batch={3}, net={4}))",
                CompletedChangesCount, ChangesCount,
                _stateMachine.State, Batcher == null ? 0 : Batcher.Count(), _remoteSession.RequestCount);

            _pendingDocumentIDs = null;
            Username = (Authenticator as IAuthorizer)?.Username;

            var evt = _changed;
            if (evt == null) {
                return;
            }

            var args = new ReplicationChangeEventArgs(this, transition);

            // Ensure callback runs on captured context, which should be the UI thread.
            var stackTrace = Environment.StackTrace;

            lock(_eventQueue) {
                _eventQueue.Enqueue(args);
            }

            Log.To.TaskScheduling.V(Tag, "Scheduling Changed callback...");
            if (_eventContext != null) {
                _eventContext.StartNew(() =>
                {
                    lock (_eventQueue) { 
                        if(_eventQueue.Count > 0) {
                            Log.To.TaskScheduling.V(Tag, "Firing {0} queued callback(s)", _eventQueue.Count);
                        } else {
                            Log.To.TaskScheduling.V(Tag, "No callback scheduled, not firing");
                        }

                        while (_eventQueue.Count > 0) {
                            try {
                                evt (this, _eventQueue.Dequeue ());
                            } catch (Exception e) {
                                Log.To.Sync.E (Tag, "Exception in Changed callback, " +
                                               "this will cause instability unless corrected!", e);
                            }
                        }
                    }
                });
            }
        }