예제 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="KinveyQueryable{T}"/> class.
        /// </summary>
        /// <param name="queryProvider">My query provider.</param>
        /// <param name="myClass">My class.</param>
        public KinveyQueryable(KinveyQueryProvider queryProvider, Type myClass)
            : base(queryProvider)
        {
            var kExecutor = queryProvider.Executor as KinveyQueryExecutor <T>;

            if (kExecutor != null)
            {
                writer              = new StringQueryBuilder();
                kExecutor.writer    = writer;
                kExecutor.queryable = this;
            }
        }
예제 #2
0
        /// <summary>
        /// Removes data from local storage. This does not affect the backend.
        /// </summary>
        /// <returns>Details of the clear operation, including the number of entities that were cleared.</returns>
        /// <param name="query">Optional Query parameter.</param>
        public KinveyDeleteResponse ClearCache(IQueryable <T> query = null)
        {
            if (this.storeType == DataStoreType.NETWORK)
            {
                throw new KinveyException(EnumErrorCategory.ERROR_DATASTORE_NETWORK, EnumErrorCode.ERROR_DATASTORE_INVALID_CLEAR_CACHE_OPERATION, "");
            }

            var ret = cache.Clear(query?.Expression);

            if (ret?.IDs != null)
            {
                var pendings = ret.IDs.Select(entityId => syncQueue.GetByID(entityId));
                syncQueue.Remove(pendings);
            }
            else
            {
                syncQueue.RemoveAll();
            }

            // Remove any associated entry from the QueryCache (for delta set sync)
            string mongoQuery = null;

            if (query != null)
            {
                StringQueryBuilder queryBuilder = new StringQueryBuilder();

                KinveyQueryVisitor visitor = new KinveyQueryVisitor(queryBuilder, typeof(T), VisitorClause.Order | VisitorClause.SkipTake | VisitorClause.Where | VisitorClause.Select);
                var queryModel             = (query.Provider as KinveyQueryProvider)?.qm;

                queryBuilder.Write("{");
                queryModel?.Accept(visitor);
                queryBuilder.Write("}");

                mongoQuery = queryBuilder.BuildQueryString();
            }

            var qci = client.CacheManager.GetQueryCacheItem(CollectionName, mongoQuery, null);

            if (qci != null)
            {
                client.CacheManager.DeleteQueryCacheItem(qci);
            }

            return(ret);
        }
예제 #3
0
        /// <summary>
        /// Builds the mongo-style query string to be run against the backend.
        /// </summary>
        /// <param name="query">LINQ-style query that can be used to filter delete results.</param>
        /// <param name="visitorClause">Enum to filter LINQ clauses which should be used in a query for network request.</param>
        /// <returns>The mongo-style query string.</returns>
        private static string GetQuery <T>(IQueryable <object> query, VisitorClause visitorClause)
        {
            if (query != null)
            {
                StringQueryBuilder queryBuilder = new StringQueryBuilder();

                KinveyQueryVisitor visitor    = new KinveyQueryVisitor(queryBuilder, typeof(T), visitorClause);
                QueryModel         queryModel = (query.Provider as KinveyQueryProvider)?.qm;

                queryBuilder.Write("{");
                queryModel?.Accept(visitor);
                queryBuilder.Write("}");

                string mongoQuery = queryBuilder.BuildQueryString();
                return(mongoQuery);
            }

            return(default(string));
        }