Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Squidex/squidex-samples
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianStehle committed Feb 15, 2019
2 parents 2d849bc + d5c5c0d commit 5332602
Showing 1 changed file with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System.Threading.Tasks;

namespace Squidex.ClientLibrary
{
public static class SquidexClientExtensions
{
public static async Task<SquidexEntities<TEntity, TData>> GetAllAsync<TEntity, TData>(
this SquidexClient<TEntity, TData> client,
int batchSize = 200)
where TEntity : SquidexEntityBase<TData>
where TData : class, new()
{
Guard.NotNull(client, nameof(client));

int skip = 0;
var entities = new SquidexEntities<TEntity, TData>();
do
{
var getResult = await client.GetAsync(skip: skip, top: batchSize);

entities.Total = getResult.Total;
entities.Items.AddRange(getResult.Items);

skip += entities.Items.Count;
}
while (skip < entities.Total);

return entities;
}

public static async Task<AssetEntities> GetAllAssetsAsync(this SquidexAssetClient assetClient, int batchSize = 200)
{
Guard.NotNull(assetClient, nameof(assetClient));

int skip = 0;
var entities = new AssetEntities();
do
{
var getResult = await assetClient.GetAssetsAsync(skip: skip, top: batchSize);

entities.Total = getResult.Total;
entities.Items.AddRange(getResult.Items);

skip += entities.Items.Count;
}
while (skip < entities.Total);

return entities;
}
}
}

0 comments on commit 5332602

Please sign in to comment.