Esempio n. 1
0
        private void ExecCount(KiiQuery query, KiiHttpClientFactory factory, CountCallback callback)
        {
            Utils.CheckInitialize(false);
            if (query == null)
            {
                query = new KiiQuery(null);
            }

            KiiHttpClient client = factory.Create(QueryUrl, Kii.AppId, Kii.AppKey, KiiHttpMethod.POST);

            KiiCloudEngine.SetAuthBearer(client);
            client.ContentType = "application/vnd.kii.QueryRequest+json";

            // send request
            string queryString = CountAggregationQuery(query);
            int    count       = 0;

            client.SendRequest(queryString, (ApiResponse response, Exception e) =>
            {
                if (e != null)
                {
                    callback(this, query, count, e);
                    return;
                }
                // parse response
                try {
                    JsonObject responseJson = new JsonObject(response.Body);
                    JsonObject aggregations = responseJson.GetJsonObject("aggregations");
                    count = aggregations.GetInt("count_field");
                    callback(this, query, count, null);
                } catch (JsonException jse) {
                    callback(this, query, count, new IllegalKiiBaseObjectFormatException(jse.Message));
                }
            });
        }
Esempio n. 2
0
 /// <summary>
 /// Asynchronous version of <see cref = 'Count(KiiQuery)'/>.
 /// </summary>
 /// <remarks>
 /// This API sends a request to KiiCloud.
 /// </remarks>
 /// <param name = 'callback'>
 /// Executes when count execution completed.
 /// </param>
 /// <param name = 'query'>
 /// query to be executed. If null, the operation will be same as <see cref = 'Count(CountCallback)'/>.
 /// </param>
 /// <exception cref='ArgumentException'>
 /// Is thrown when callback is null.
 /// </exception>
 public void Count(KiiQuery query, CountCallback callback)
 {
     if (callback == null)
     {
         throw new ArgumentException("Specified callback is null");
     }
     ExecCount(query, Kii.AsyncHttpClientFactory, callback);
 }
        public void Test_1_3_CountAllAsyncWithNullCallback()
        {
            string        bucketName = "TestBucket";
            KiiBucket     bucket     = Kii.Bucket(bucketName);
            CountCallback callback   = null;

            bucket.Count(callback);
        }
        public void Test_2_3_CountAllAsyncWithNullCallback()
        {
            string        bucketName = "TestBucket";
            KiiBucket     bucket     = Kii.Bucket(bucketName);
            KiiQuery      query      = new KiiQuery(null);
            CountCallback callback   = null;

            bucket.Count(query, callback);
        }
Esempio n. 5
0
        private void Execute(int sequence, CountCallback callback)
        {
            fThread.Post(new HouseDelegate(() =>
            {
                if (fCancel == false)
                {
                    LongOper();
                }

                // Three alternate ways to call
                fUI.Post(callback, sequence);

                fUI.Post(new HouseDelegate(() =>
                {
                    callback(sequence);
                }));

                fUI.Post(() =>
                {
                    callback(sequence);
                });
            }));
        }
Esempio n. 6
0
 /// <summary>
 /// Asynchronous version of <see cref='Count'/>.
 /// </summary>
 /// <remarks>
 /// This API sends a request to KiiCloud.
 /// </remarks>
 /// <param name = 'callback'>
 /// Executes when count execution completed.
 /// </param>
 /// <exception cref='ArgumentException'>
 /// Is thrown when callback is null.
 /// </exception>
 public void Count(CountCallback callback)
 {
     Count(null, callback);
 }
Esempio n. 7
0
 private void Execute(int sequence, CountCallback callback)
 {
     fAsync.Await(LongOper);
     fDebug.WriteLn("Executed " + sequence);
     callback(sequence);
 }