/// <summary> /// Gets a count of all the entities in a collection /// </summary> /// <returns>The async task which returns the count.</returns> /// <param name="ct">[optional] CancellationToken used to cancel the request.</param> public async Task <uint> GetCountAsync(IQueryable <object> query = null, KinveyDelegate <uint> cacheCount = null, CancellationToken ct = default(CancellationToken)) { GetCountRequest <T> getCountRequest = new GetCountRequest <T>(client, collectionName, cache, storeType.ReadPolicy, DeltaSetFetchingEnabled, cacheCount, query); ct.ThrowIfCancellationRequested(); return(await getCountRequest.ExecuteAsync()); }
/// <summary> /// Perfoms a find operation, with an optional query filter. /// </summary> /// <param name="query">[optional] LINQ-style query that can be used to filter the search results</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 <List <T> > FindAsync(IQueryable <object> query = null, KinveyDelegate <List <T> > cacheResults = null, CancellationToken ct = default(CancellationToken)) { FindRequest <T> findByQueryRequest = new FindRequest <T>(client, collectionName, cache, storeType.ReadPolicy, DeltaSetFetchingEnabled, cacheResults, query, null); ct.ThrowIfCancellationRequested(); return(await findByQueryRequest.ExecuteAsync()); }
/// <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()); }
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); }
/// <summary> /// Initializes a new instance of the <see cref="T:KinveyXamarin.FindAggregateRequest`1"/> class. /// </summary> /// <param name="client">Client.</param> /// <param name="collection">Collection.</param> /// <param name="reduceFunction">Reduce function.</param> /// <param name="cache">Cache.</param> /// <param name="policy"> The <see cref="ReadPolicy"/> to be used for this request.</param> /// <param name="deltaSetFetchingEnabled">If set to <c>true</c> delta set fetching enabled.</param> /// <param name="cacheDelegate">Cache delegate.</param> /// <param name="query">[optional] Query used to filter the results that are to be aggregated.</param> /// <param name="groupField">Property name to be used for grouping.</param> /// <param name="aggregateField">Property name to be used for aggregation.</param> public FindAggregateRequest(AbstractClient client, string collection, EnumReduceFunction reduceFunction, ICache <T> cache, ReadPolicy policy, bool deltaSetFetchingEnabled, KinveyDelegate <List <GroupAggregationResults> > cacheDelegate, IQueryable <object> query, string groupField, string aggregateField) : base(client, collection, cache, query, policy, deltaSetFetchingEnabled) { this.cacheDelegate = cacheDelegate; this.reduceFunction = reduceFunction; this.groupField = groupField; this.aggregateField = aggregateField; }
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); }
/// <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); }
/// <summary> /// Initializes a new instance of the <see cref="T:KinveyXamarin.FindRequest`1"/> class. /// </summary> /// <param name="client">Client.</param> /// <param name="collection">Collection.</param> /// <param name="cache">Cache.</param> /// <param name="policy">Policy.</param> /// <param name="deltaSetFetchingEnabled">If set to <c>true</c> delta set fetching enabled.</param> /// <param name="cacheDelegate">Cache delegate.</param> /// <param name="query">Query.</param> /// <param name="listIDs">List identifier.</param> public FindRequest(AbstractClient client, string collection, ICache <T> cache, ReadPolicy policy, bool deltaSetFetchingEnabled, KinveyDelegate <List <T> > cacheDelegate, IQueryable <object> query, List <string> listIDs) : base(client, collection, cache, query, policy, deltaSetFetchingEnabled, listIDs) { this.cacheDelegate = cacheDelegate; }
/// <summary> /// Gets the aggregate value, by grouping, of the values in the given entity field. /// </summary> /// <returns>The sum of the values of the given property name for the entities in the <see cref="DataStore{T}"/>.</returns> /// <param name="groupField">Property name of field to be used in grouping.</param> /// <param name="aggregateField">Property name of field to be used in aggregation. This is not necessary when using the <see cref="KinveyXamarin.EnumReduceFunction.REDUCE_FUNCTION_COUNT"/> method.</param> /// <param name="query">[optional] Query used to filter results prior to aggregation.</param> /// <param name="cacheDelegate">Delegate used to return the sum aggregate value based on what is available in offline cache.</param> /// <param name="ct">[optional] CancellationToken used to cancel the request.</param> public async Task <List <GroupAggregationResults> > GroupAndAggregateAsync(EnumReduceFunction reduceFunction, string groupField = "", string aggregateField = "", IQueryable <object> query = null, KinveyDelegate <List <GroupAggregationResults> > cacheDelegate = null, CancellationToken ct = default(CancellationToken)) { FindAggregateRequest <T> findByAggregateQueryRequest = new FindAggregateRequest <T>(client, collectionName, reduceFunction, cache, storeType.ReadPolicy, DeltaSetFetchingEnabled, cacheDelegate, query, groupField, aggregateField); ct.ThrowIfCancellationRequested(); return(await findByAggregateQueryRequest.ExecuteAsync()); }
/// <summary> /// Initializes a new instance of the <see cref="GetCountRequest{T}"/> class. /// </summary> /// <param name="client">Client that the user is logged in.</param> /// <param name="collection">Collection name.</param> /// <param name="cache">Cache.</param> /// <param name="policy">Read policy.</param> /// <param name="deltaSetFetchingEnabled">If set to <c>true</c> delta set fetching enabled.</param> /// <param name="cacheDelegate">Cache delegate.</param> /// <param name="query">Query.</param> public GetCountRequest(AbstractClient client, string collection, ICache <T> cache, ReadPolicy policy, bool deltaSetFetchingEnabled, KinveyDelegate <uint> cacheDelegate, IQueryable <object> query) : base(client, collection, cache, query, policy, deltaSetFetchingEnabled) { this.cacheDelegate = cacheDelegate; }