Beispiel #1
0
        /// <summary>
        /// Call a Convertigo Server backend service and return data as an XML Document.
        /// CallXML will asynchrously call a "requestable" (Sequence, transaction or FullSync database) and return a
        /// C8oPromise object.
        /// </summary>
        /// <param name="requestable">
        /// A "requestable" object of this form :
        /// <list type ="bullet">
        ///     <item>project.sequence to call a Sequence in the convertigo server. If project is not specified explicitly here,
        ///     (.sequence) the default project specified in the enpoint will be used.</item>
        ///     <item>
        ///     project.connector.transaction to call a transaction in the convertigo server. if project is not specified explicitly here,
        ///     (.connector.transaction) the default project specified in the enpoint will be used. If
        ///     connector is not specified (..transaction) the default connector will be used.</item>
        ///     <item>fs://database.fullsync_verb   to call the local NoSQL database for quering, updating and syncing according to the full_sync
        ///     verb used. See FullSync documentation for a list of verbs and parameters.</item>
        /// </list>
        /// </param>
        /// <param name="parameters">
        /// A IDictionary of Key/Value pairs mapped on Sequence/transaction/fullsync variables.
        /// </param>
        /// <returns>
        /// A C8oPromise object on which you can chain other requests to get the data with the Then(), ThenUI() methods or
        /// use the Async() to wait for the server response without blocking the request thread. You can also use the .Fail() and
        /// FailUI() methods to handle errors.
        /// </returns>
        public C8oPromise <XDocument> CallXml(string requestable, IDictionary <string, object> parameters)
        {
            var promise = new C8oPromise <XDocument>(this);

            Call(requestable, parameters, new C8oResponseXmlListener((response, requestParameters) =>
            {
                if (response == null && requestParameters.ContainsKey(ENGINE_PARAMETER_PROGRESS))
                {
                    promise.OnProgress(requestParameters[ENGINE_PARAMETER_PROGRESS] as C8oProgress);
                }
                else
                {
                    promise.OnResponse(response, requestParameters);
                }
            }), new C8oExceptionListener((exception, requestParameters) =>
            {
                promise.OnFailure(exception, requestParameters);
            }));

            return(promise);
        }
Beispiel #2
0
        private void OnResponse()
        {
            try
            {
                if (!c8oResponse.Equals(default(KeyValuePair <C8oOnResponse <T>, bool>)))
                {
                    var promise = new C8oPromise <T> [1];
                    if (c8oResponse.Value)
                    {
                        Exception failure = null;
                        lock (promise)
                        {
                            c8o.RunUI(() =>
                            {
                                lock (promise)
                                {
                                    try
                                    {
                                        promise[0] = c8oResponse.Key.Invoke(lastResponse, lastParameters);
                                    }
                                    catch (Exception e)
                                    {
                                        failure = e;
                                    }
                                    Monitor.Pulse(promise);
                                }
                            });
                            Monitor.Wait(promise);
                            if (failure != null)
                            {
                                throw failure;
                            }
                        }
                    }
                    else
                    {
                        promise[0] = c8oResponse.Key.Invoke(lastResponse, lastParameters);
                    }

                    if (promise[0] != null)
                    {
                        if (nextPromise != null)
                        {
                            var lastPromise = promise[0];
                            while (lastPromise.nextPromise != null)
                            {
                                lastPromise = lastPromise.nextPromise;
                            }
                            lastPromise.nextPromise = nextPromise;
                        }
                        nextPromise = promise[0];
                    }
                    else if (nextPromise != null)
                    {
                        nextPromise.OnResponse(lastResponse, lastParameters);
                    }
                }
                else if (nextPromise != null)
                {
                    nextPromise.OnResponse(lastResponse, lastParameters);
                }
                else
                {
                    // Response received and no handler.
                }
            }
            catch (Exception exception)
            {
                OnFailure(exception, lastParameters);
            }
        }