private void ProcessBatch(int batchNumber, ContentstackCollection <FieldSubsetEntry> entries, string contentTypeUid, OutputWriter writer)
 {
     foreach (FieldSubsetEntry entry in entries.Items)
     {
         writer.Message(this, $"batch {batchNumber} [{contentTypeUid}] : {entry.Title}");
     }
 }
Пример #2
0
        public async Task FetchAssetOnly()
        {
            AssetLibrary assetLibrary             = client.AssetLibrary().Only(new string[] { "url" });
            ContentstackCollection <Asset> assets = await assetLibrary.FetchAll();

            if (assets == null)
            {
                Assert.False(true, "Query.Exec is not match with expected result.");
            }
            else if (assets != null)
            {
                foreach (Asset asset in assets)
                {
                    Assert.DoesNotContain(asset.Url, "http");
                    Assert.Null(asset.Description);
                    Assert.Null(asset.FileSize);
                    Assert.Null(asset.Tags);
                    Assert.Null(asset.Description);
                }
            }
            else
            {
                Assert.False(true, "Result doesn't mathced the count.");
            }
        }
        private void ProcessContentType(ContentType contentType, OutputWriter writer)
        {
            // https://www.contentstack.com/docs/platforms/dot-net/api-reference/api/Contentstack.Core.Models.Query.html
            Query query = contentType.Query().Only(new[] { "title", "url" }).Limit(ContentstackQueryResultLimit);

            query.IncludeCount();

            // https://www.contentstack.com/docs/developers/apis/content-delivery-api/#queries
            // https://www.contentstack.com/docs/platforms/dot-net/api-reference/api/Contentstack.Core.Models.ContentstackCollection-1.html
            ContentstackCollection <FieldSubsetEntry> firstBatch = query.Find <FieldSubsetEntry>().GetAwaiter().GetResult();

            if (firstBatch.Count < 1)
            {
                return;
            }

            new Thread(() => { ProcessBatch(1, firstBatch, contentType.ContentTypeId, writer); }).Start();

            // https://www.contentstack.com/docs/developers/apis/content-delivery-api/#pagination
            for (int skip = ContentstackQueryResultLimit; skip < firstBatch.Count; skip += ContentstackQueryResultLimit)
            {
                //WARN: https://stackoverflow.com/questions/271440/captured-variable-in-a-loop-in-c-sharp
                int mySkip = skip;
                new Thread(() => { QueryBatch((skip - ContentstackQueryResultLimit) / ContentstackQueryResultLimit, contentType, mySkip, writer); }).Start();
            }
        }
Пример #4
0
        public async Task <string> FetchAssetUID()
        {
            AssetLibrary assetLibrary             = client.AssetLibrary();
            ContentstackCollection <Asset> assets = await assetLibrary.FetchAll();

            Assert.True(assets.Count() > 0);
            return(assets.First <Asset>().Uid);
        }
Пример #5
0
        public async Task FetchAssets()
        {
            AssetLibrary assetLibrary             = client.AssetLibrary();
            ContentstackCollection <Asset> assets = await assetLibrary.FetchAll();

            Assert.True(assets.Count() > 0);
            foreach (Asset asset in assets)
            {
                Assert.True(asset.FileName.Length > 0);
            }
        }
Пример #6
0
        public async Task FetchAssetsIncludeRelativeURL()
        {
            AssetLibrary assetLibrary = client.AssetLibrary();

            assetLibrary.IncludeRelativeUrls();
            ContentstackCollection <Asset> assets = await assetLibrary.FetchAll();

            Assert.True(assets.Count() > 0);
            foreach (Asset asset in assets)
            {
                Assert.DoesNotContain(asset.Url, "http");
                Assert.True(asset.FileName.Length > 0);
            }
        }
Пример #7
0
        private void ProcessBatch(int batchNumber, ContentstackCollection <Entry> entries, string contentTypeUid, OutputWriter writer)
        {
            foreach (Entry entry in entries.Items)
            {
                string message = $"batch {batchNumber} [{contentTypeUid}] : {entry.Uid} : {entry.Title}";

                if (entry.Object.ContainsKey("url"))
                {
                    message += " (" + entry.Object["url"] + ")";
                }

                writer.Message(this, message);
            }
        }
Пример #8
0
        public async Task FetchAssetsPublishWithoutFallback()
        {
            List <string> list = new List <string>();

            list.Add("ja-jp");
            ContentstackCollection <Asset> assets = await client.AssetLibrary()
                                                    .SetLocale("ja-jp")
                                                    .FetchAll();

            ;
            Assert.True(assets.Items.Count() > 0);
            foreach (Asset asset in assets)
            {
                Assert.Contains((string)(asset.Get("publish_details") as JObject).GetValue("locale"), list);
            }
        }
Пример #9
0
        public async Task FetchAssetSkipLimit()
        {
            AssetLibrary assetLibrary             = client.AssetLibrary().SetLocale("en-us").Skip(2).Limit(5);
            ContentstackCollection <Asset> assets = await assetLibrary.FetchAll();

            if (assets == null)
            {
                Assert.False(true, "Query.Exec is not match with expected result.");
            }
            else if (assets != null)
            {
                Assert.Equal(3, assets.Items.Count());
            }
            else
            {
                Assert.False(true, "Result doesn't mathced the count.");
            }
        }
Пример #10
0
        public async Task FetchAssetsOrderByAscending()
        {
            AssetLibrary assetLibrary = client.AssetLibrary();

            assetLibrary.SortWithKeyAndOrderBy("created_at", Internals.OrderBy.OrderByAscending);
            ContentstackCollection <Asset> assets = await assetLibrary.FetchAll();

            Assert.True(assets.Count() > 0);
            DateTime dateTime = new DateTime();

            foreach (Asset asset in assets)
            {
                if (dateTime != null)
                {
                    if (dateTime.CompareTo(asset.GetCreateAt()) != -1 && dateTime.CompareTo(asset.GetCreateAt()) != 0)
                    {
                        Assert.False(true);
                    }
                }
                dateTime = asset.GetCreateAt();
                Assert.True(asset.FileName.Length > 0);
            }
        }