Ejemplo n.º 1
0
        /// <summary>
        /// Executes the request asynchronously.
        /// </summary>
        /// <returns> The async task with the request result.</returns>
        public override async Task <PushDataStoreResponse <T> > ExecuteAsync()
        {
            var response = new PushDataStoreResponse <T>();

            if (HelperMethods.IsLessThan(Client.ApiVersion, 5))
            {
                response = await PushSingleActionsAsync().ConfigureAwait(false);
            }
            else
            {
                var pushMultiPostActionsResponse = await PushMultiPostActionsAsync().ConfigureAwait(false);

                response.SetResponse(pushMultiPostActionsResponse);

                var pushSinglePutActionsResponse = await PushSingleActionsAsync("PUT").ConfigureAwait(false);

                response.SetResponse(pushSinglePutActionsResponse);

                var pushSingleDeleteActionsResponse = await PushSingleActionsAsync("DELETE").ConfigureAwait(false);

                response.SetResponse(pushSingleDeleteActionsResponse);
            }

            return(response);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Saves specified entities to a Kinvey collection.
        /// </summary>
        /// <returns>An async task with the <see cref="Kinvey.KinveyMultiInsertResponse{T}"/> result.</returns>
        /// <param name="entities">Entities to save.</param>
        /// <param name="ct">[optional] CancellationToken used to cancel a request.</param>
        public async Task <KinveyMultiInsertResponse <T> > SaveAsync(IList <T> entities, CancellationToken ct = default(CancellationToken))
        {
            if (HelperMethods.IsLessThan(KinveyClient.ApiVersion, 5))
            {
                throw new KinveyException(EnumErrorCategory.ERROR_GENERAL, EnumErrorCode.ERROR_DATASTORE_NOT_COMPATIBLE_KINVEY_API_VERSION, string.Empty);
            }

            if (entities == null || entities.Count == 0)
            {
                throw new KinveyException(EnumErrorCategory.ERROR_GENERAL, EnumErrorCode.ERROR_DATASTORE_EMPTY_ARRAY_OF_ENTITIES, string.Empty);
            }

            var request = new MultiInsertRequest <T>(entities, this.client, this.CollectionName, this.cache, this.syncQueue, this.storeType.WritePolicy);

            ct.ThrowIfCancellationRequested();
            return(await request.ExecuteAsync());
        }