Example #1
0
        internal static XDocument FullSyncDefaultResponseToXml(FullSyncDefaultResponse fullSyncDefaultResponse)
        {
            var       json = FullSyncDefaultResponseToJson(fullSyncDefaultResponse);
            XDocument xml  = C8oFullSyncTranslator.FullSyncJsonToXml(json);

            return(xml);
        }
Example #2
0
        internal static XDocument QueryEnumeratorToXml(QueryEnumerator queryEnumerator)
        {
            var       json = QueryEnumeratorToJson(queryEnumerator);
            XDocument xml  = C8oFullSyncTranslator.FullSyncJsonToXml(json);

            return(xml);
        }
Example #3
0
        internal static XDocument FullSyncDocumentOperationResponseToXml(FullSyncDocumentOperationResponse fullSyncDocumentOperationResponse)
        {
            var json = FullSyncDocumentOperationResponseToJSON(fullSyncDocumentOperationResponse);
            var xml  = C8oFullSyncTranslator.FullSyncJsonToXml(json);

            return(xml);
        }
Example #4
0
        internal static XDocument DocumentToXml(Document document)
        {
            var json = DocumentToJson(document);
            var xml  = C8oFullSyncTranslator.FullSyncJsonToXml(json);

            return(xml);
        }
Example #5
0
        internal static XDocument ReplicationChangeEventArgsToXml(ReplicationChangeEventArgs changeEvent)
        {
            var    json = ReplicationChangeEventArgsToJson(changeEvent);
            string toto = json.ToString();
            var    xml  = C8oFullSyncTranslator.FullSyncJsonToXml(json);

            return(xml);
        }
Example #6
0
        /// <summary>
        /// Handles the fullSync response depending to the C8oResponseListener.
        /// </summary>
        /// <param name="response"></param>
        /// <param name="parameters"></param>
        /// <param name="c8oResponseListener"></param>
        public virtual object HandleFullSyncResponse(object response, C8oResponseListener listener)
        {
            if (response is JObject)
            {
                if (listener is C8oResponseXmlListener)
                {
                    response = C8oFullSyncTranslator.FullSyncJsonToXml(response as JObject);
                }
            }

            return(response);
        }
Example #7
0
        //*** QueryEnumerator ***//
        //*** GetAllDocuments ***//

        internal static JObject QueryEnumeratorToJson(QueryEnumerator queryEnumerator)
        {
            var json      = new JObject();
            var rowsArray = new JArray();

            var queryRows = queryEnumerator.GetEnumerator();

            while (queryRows.MoveNext())
            {
                var queryRow     = queryRows.Current;
                var queryRowJson = C8oFullSyncTranslator.DictionaryToJson(queryRow.AsJSONDictionary());
                rowsArray.Add(queryRowJson);
            }

            json[C8oFullSyncTranslator.FULL_SYNC_RESPONSE_KEY_COUNT] = queryEnumerator.Count;
            json[C8oFullSyncTranslator.FULL_SYNC_RESPONSE_KEY_ROWS]  = rowsArray;

            return(json);
        }
Example #8
0
        //*** 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);
        }
Example #9
0
        //*** DefaultResponse ***//
        //*** Sync, ReplicatePull, ReplicatePush, Reset ***//

        internal static JObject FullSyncDefaultResponseToJson(FullSyncDefaultResponse fullSyncDefaultResponse)
        {
            var json = C8oFullSyncTranslator.DictionaryToJson(fullSyncDefaultResponse.GetProperties());

            return(json);
        }
Example #10
0
        //*** Document ***//

        internal static JObject DocumentToJson(Document document)
        {
            var json = C8oFullSyncTranslator.DictionaryToJson(document.Properties);

            return(json);
        }
Example #11
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();
        }