-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:Squidex/squidex-samples
- Loading branch information
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/SquidexClientExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |