From d421a9fdd0a43cd614803faa435ca263ff7b2aa0 Mon Sep 17 00:00:00 2001 From: Jaben Cargman Date: Fri, 8 Feb 2019 17:45:08 -0500 Subject: [PATCH] GetAllAsync and GetAllAssetsAsync added as helper extensions. --- .../SquidexClientExtensions.cs | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/SquidexClientExtensions.cs diff --git a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/SquidexClientExtensions.cs b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/SquidexClientExtensions.cs new file mode 100644 index 00000000..fc314ce1 --- /dev/null +++ b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/SquidexClientExtensions.cs @@ -0,0 +1,51 @@ +using System.Threading.Tasks; + +namespace Squidex.ClientLibrary +{ + public static class SquidexClientExtensions + { + public static async Task> GetAllAsync( + this SquidexClient client, + int batchSize = 200) + where TEntity : SquidexEntityBase + where TData : class, new() + { + Guard.NotNull(client, nameof(client)); + + int skip = 0; + var entities = new SquidexEntities(); + 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 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; + } + } +} \ No newline at end of file