예제 #1
0
        private Replication GetReplication(FullSyncReplication fsReplication)
        {
            StopReplication(fsReplication);
            var replication = fsReplication.replication = createReplication(c8o, fsReplication.pull, database, c8oFullSyncDatabaseUrl);

            return(replication);
        }
예제 #2
0
 private void StopReplication(FullSyncReplication fsReplication)
 {
     if (fsReplication.replication != null)
     {
         StopReplication(fsReplication.replication);
         if (fsReplication.changeListener != null)
         {
             fsReplication.replication.Changed -= fsReplication.changeListener;
             fsReplication.changeListener       = null;
         }
         fsReplication.replication = null;
     }
 }
예제 #3
0
        private void StartReplication(FullSyncReplication fullSyncReplication, IDictionary <string, object> parameters, C8oResponseListener c8oResponseListener)
        {
            bool continuous;
            bool cancel = false;

            if (parameters.ContainsKey("live"))
            {
                continuous = parameters["live"].ToString().Equals("true", StringComparison.OrdinalIgnoreCase);
            }
            else if (parameters.ContainsKey("continuous"))
            {
                continuous = parameters["continuous"].ToString().Equals("true", StringComparison.OrdinalIgnoreCase);
            }
            else
            {
                continuous = false;
            }

            if (parameters.ContainsKey("cancel"))
            {
                cancel = parameters["cancel"].ToString().Equals("true", StringComparison.OrdinalIgnoreCase);
            }

            var rep       = GetReplication(fullSyncReplication);
            var _progress = new C8oProgress();

            _progress.Raw  = rep;
            _progress.Pull = rep.IsPull;

            if (cancel)
            {
                StopReplication(fullSyncReplication);
                _progress.Finished = true;

                if (c8oResponseListener != null && c8oResponseListener is C8oResponseProgressListener)
                {
                    (c8oResponseListener as C8oResponseProgressListener).OnProgressResponse(_progress, null);
                }

                return;
            }

            var param = new Dictionary <string, object>(parameters);

            rep.Changed +=
                fullSyncReplication.changeListener =
                    new EventHandler <ReplicationChangeEventArgs>((source, changeEvt) =>
            {
                var progress      = _progress;
                progress.Total    = rep.ChangesCount;
                progress.Current  = rep.CompletedChangesCount;
                progress.TaskInfo = C8oFullSyncTranslator.DictionaryToString(rep.ActiveTaskInfo);
                progress.Status   = "" + rep.Status;
                progress.Finished = rep.Status != ReplicationStatus.Active;

                if (progress.Changed)
                {
                    _progress = new C8oProgress(progress);

                    if (c8oResponseListener != null && c8oResponseListener is C8oResponseProgressListener)
                    {
                        param[C8o.ENGINE_PARAMETER_PROGRESS] = progress;
                        (c8oResponseListener as C8oResponseProgressListener).OnProgressResponse(progress, param);
                    }
                }

                if (progress.Finished)
                {
                    StopReplication(fullSyncReplication);
                    if (continuous)
                    {
                        long lastCurrent = progress.Current;
                        rep                  = GetReplication(fullSyncReplication);
                        _progress.Raw        = rep;
                        _progress.Continuous = true;
                        rep.Continuous       = true;
                        rep.Changed         +=
                            fullSyncReplication.changeListener =
                                new EventHandler <ReplicationChangeEventArgs>((src, chEvt) =>
                        {
                            progress          = _progress;
                            progress.Total    = rep.ChangesCount;
                            progress.Current  = rep.CompletedChangesCount;
                            progress.TaskInfo = C8oFullSyncTranslator.DictionaryToString(rep.ActiveTaskInfo);
                            progress.Status   = "" + rep.Status;

                            //if (progress.Current > lastCurrent && progress.Changed)
                            if (progress.Changed)
                            {
                                _progress = new C8oProgress(progress);

                                if (c8oResponseListener != null && c8oResponseListener is C8oResponseProgressListener)
                                {
                                    param[C8o.ENGINE_PARAMETER_PROGRESS] = progress;
                                    (c8oResponseListener as C8oResponseProgressListener).OnProgressResponse(progress, param);
                                }
                            }
                        });
                        rep.Start();
                    }
                }
            });

            rep.Start();
        }