Ejemplo n.º 1
0
        /// <summary>
        /// Reads data from local store by executing the query.
        /// </summary>
        /// <param name="query">The query to execute on local store.</param>
        /// <returns>A task that will return with results when the query finishes.</returns>
        public override Task <JToken> ReadAsync(MobileServiceTableQueryDescription query)
        {
            if (query == null)
            {
                throw new ArgumentNullException(nameof(query));
            }

            EnsureInitialized();

            var    formatter = new SqlQueryFormatter(query);
            string sql       = formatter.FormatSelect();

            return(_operationSemaphore.WaitAsync()
                   .ContinueWith(t =>
            {
                try
                {
                    IList <JObject> rows = ExecuteQueryInternal(query.TableName, sql, formatter.Parameters);
                    JToken result = new JArray(rows.ToArray());

                    if (query.IncludeTotalCount)
                    {
                        sql = formatter.FormatSelectCount();
                        IList <JObject> countRows = null;

                        countRows = ExecuteQueryInternal(query.TableName, sql, formatter.Parameters);

                        long count = countRows[0].Value <long>("count");
                        result = new JObject()
                        {
                            { "results", result },
                            { "count", count }
                        };
                    }

                    return result;
                }
                finally
                {
                    _operationSemaphore.Release();
                }
            }));
        }
        /// <summary>
        /// Reads data from local store by executing the query.
        /// </summary>
        /// <param name="query">The query to execute on local store.</param>
        /// <returns>A task that will return with results when the query finishes.</returns>
        public override Task<JToken> ReadAsync(MobileServiceTableQueryDescription query)
        {
            if (query == null)
            {
                throw new ArgumentNullException("query");
            }

            this.EnsureInitialized();

            var formatter = new SqlQueryFormatter(query);
            string sql = formatter.FormatSelect();

            return this.operationSemaphore.WaitAsync()
                .ContinueWith(t =>
                {
                    try
                    {
                        IList<JObject> rows = this.ExecuteQuery(query.TableName, sql, formatter.Parameters);
                        JToken result = new JArray(rows.ToArray());

                        if (query.IncludeTotalCount)
                        {
                            sql = formatter.FormatSelectCount();
                            IList<JObject> countRows = null;

                            countRows = this.ExecuteQuery(query.TableName, sql, formatter.Parameters);


                            long count = countRows[0].Value<long>("count");
                            result = new JObject() 
                            { 
                                { "results", result }, 
                                { "count", count } 
                            };
                        }

                        return result;
                    }
                    finally
                    {
                        this.operationSemaphore.Release();
                    }
                });
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Reads data from local store by executing the query.
        /// </summary>
        /// <param name="query">The query to execute on local store.</param>
        /// <returns>A task that will return with results when the query finishes.</returns>
        public override Task<JToken> ReadAsync(MobileServiceTableQueryDescription query)
        {
            if (query == null)
            {
                throw new ArgumentNullException("query");
            }

            this.EnsureInitialized();

            var formatter = new SqlQueryFormatter(query);
            string sql = formatter.FormatSelect();

            IList<JObject> rows = this.ExecuteQuery(query.TableName, sql, formatter.Parameters);
            JToken result = new JArray(rows.ToArray());

            if (query.IncludeTotalCount)
            {
                sql = formatter.FormatSelectCount();
                IList<JObject> countRows = this.ExecuteQuery(query.TableName, sql, formatter.Parameters);
                long count = countRows[0].Value<long>("count");
                result = new JObject() 
                { 
                    { "results", result },
                    { "count", count}
                };
            }

            return Task.FromResult(result);
        }