//*** ChangeEvent ***// //*** Sync, ReplicatePull, ReplicatePush ***// internal static JObject ReplicationChangeEventArgsToJson(ReplicationChangeEventArgs changeEvent) { var json = new JObject(); // Change count (total) json[C8oFullSyncTranslator.FULL_SYNC_RESPONSE_KEY_TOTAL] = changeEvent.Source.ChangesCount; // Completed change count (current) json[C8oFullSyncTranslator.FULL_SYNC_RESPONSE_KEY_CURRENT] = changeEvent.Source.CompletedChangesCount; // Progress // ??? // Direction if (changeEvent.Source.IsPull) { json[C8oFullSyncTranslator.FULL_SYNC_RESPONSE_KEY_DIRECTION] = C8oFullSyncTranslator.FULL_SYNC_RESPONSE_VALUE_DIRECTION_PULL; } else { json[C8oFullSyncTranslator.FULL_SYNC_RESPONSE_KEY_DIRECTION] = C8oFullSyncTranslator.FULL_SYNC_RESPONSE_VALUE_DIRECTION_PUSH; } // Status (ok) if (changeEvent.Source.LastError == null) { json[C8oFullSyncTranslator.FULL_SYNC_RESPONSE_KEY_OK] = true; } else { json[C8oFullSyncTranslator.FULL_SYNC_RESPONSE_KEY_OK] = false; } if (changeEvent.Source.DocIds != null) { json["docids"] = changeEvent.Source.DocIds.ToString(); } json["taskInfo"] = C8oFullSyncTranslator.DictionaryToString(changeEvent.Source.ActiveTaskInfo); json["status"] = "" + changeEvent.Source.Status; return(json); }
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(); }