예제 #1
0
        /// <summary>
        /// Perfoms a find operation, based on a given Kinvey ID.
        /// </summary>
        /// <param name="entityID">The ID of the entity to be retrieved</param>
        /// <param name="cacheResults">[optional] The intermediate cache results, returned via delegate prior to the
        /// network results being returned.  This is only valid if the <see cref="KinveyXamarin.DataStoreType"/> is
        /// <see cref="KinveyXamarin.DataStoreType.CACHE"/></param>
        /// <param name="ct">[optional] CancellationToken used to cancel the request.</param>
        public async Task <T> FindByIDAsync(string entityID, KinveyDelegate <T> cacheResult = null, CancellationToken ct = default(CancellationToken))
        {
            List <string> listIDs = new List <string>();

            if (entityID != null)
            {
                listIDs.Add(entityID);
            }

            var cacheDelegate = new KinveyDelegate <List <T> >
            {
                onSuccess = (listCacheResults) => {
                    cacheResult?.onSuccess(listCacheResults.FirstOrDefault());
                },
                onError = (error) => {
                    cacheResult?.onError(error);
                }
            };

            FindRequest <T> findByQueryRequest = new FindRequest <T>(client, collectionName, cache, storeType.ReadPolicy, DeltaSetFetchingEnabled, cacheDelegate, null, listIDs);

            ct.ThrowIfCancellationRequested();
            var results = await findByQueryRequest.ExecuteAsync();

            return(results.FirstOrDefault());
        }
예제 #2
0
        private uint PerformLocalCount(KinveyDelegate <uint> localDelegate = null)
        {
            uint localCount = default(uint);

            try
            {
                if (Query != null)
                {
                    var query = Query;
                    localCount = (uint)Cache.CountByQuery(query.Expression);
                }
                else
                {
                    localCount = (uint)Cache.CountAll();
                }

                localDelegate?.onSuccess(localCount);
            }
            catch (Exception e)
            {
                if (localDelegate != null)
                {
                    localDelegate.onError(e);
                }
                else
                {
                    throw;
                }
            }

            return(localCount);
        }
예제 #3
0
        private List <GroupAggregationResults> PerformLocalAggregateFind(KinveyDelegate <List <GroupAggregationResults> > localDelegate = null)
        {
            List <GroupAggregationResults> localResults = new List <GroupAggregationResults>();

            try
            {
                localResults = Cache.GetAggregateResult(reduceFunction, groupField, aggregateField, Query?.Expression);

                localDelegate?.onSuccess(localResults);
            }
            catch (Exception e)
            {
                if (localDelegate != null)
                {
                    localDelegate.onError(e);
                }
                else
                {
                    throw;
                }
            }

            return(localResults);
        }
예제 #4
0
        /// <summary>
        /// Perfoms finding in a local storage.
        /// </summary>
        /// <param name="localDelegate">[optional] Delegate for returning results.</param>
        /// <returns>The list of entities.</returns>
        protected List <T> PerformLocalFind(KinveyDelegate <List <T> > localDelegate = null)
        {
            List <T> cacheHits = default(List <T>);

            try
            {
                if (Query != null)
                {
                    var query = Query;
                    cacheHits = Cache.FindByQuery(query.Expression);
                }
                else if (EntityIDs?.Count > 0)
                {
                    cacheHits = Cache.FindByIDs(EntityIDs);
                }
                else
                {
                    cacheHits = Cache.FindAll();
                }

                localDelegate?.onSuccess(cacheHits);
            }
            catch (Exception e)
            {
                if (localDelegate != null)
                {
                    localDelegate.onError(e);
                }
                else
                {
                    throw;
                }
            }

            return(cacheHits);
        }