diff --git a/.gitignore b/.gitignore index 4d22f55..fe75f65 100644 --- a/.gitignore +++ b/.gitignore @@ -19,4 +19,5 @@ packages/ *.nupkg *.nuspec *.trx -*/TestResults/ \ No newline at end of file +*/TestResults/ +*/app.config \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index d36eabf..43dad59 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,18 @@ +### Version: 2.5.0 +#### Date: Dec-05-2020 + +##### Update API: + - AssetLibrary + - IncludeFallback function added + - SetLocale function added +- Asset + - IncludeFallback function added + - SetLocale function added +- Entry + - IncludeFallback function added +- Query + - IncludeFallback function added + ### Version: 2.4.0 #### Date: Aug-12-2020 diff --git a/Contentstack.AspNetCore/Contentstack.AspNetCore.csproj b/Contentstack.AspNetCore/Contentstack.AspNetCore.csproj index 9a0680c..523d2ae 100644 --- a/Contentstack.AspNetCore/Contentstack.AspNetCore.csproj +++ b/Contentstack.AspNetCore/Contentstack.AspNetCore.csproj @@ -7,14 +7,17 @@ Contentstack Contentstack 2.1.1 - 1.0.0 + 2.5.0 Main release Copyright (c) 2012-2020 Contentstack (http://app.contentstack.com). All Rights Reserved https://github.com/contentstack/contentstack-dotnet - v1.0.0 - 2.4.0 + v2.5.0 + 2.5.0 + + + ..\Contentstack.Core\bin\Debug\Contentstack.Core.dll diff --git a/Contentstack.Core.Tests/AssetTest.cs b/Contentstack.Core.Tests/AssetTest.cs index f8b877c..b903419 100644 --- a/Contentstack.Core.Tests/AssetTest.cs +++ b/Contentstack.Core.Tests/AssetTest.cs @@ -43,6 +43,40 @@ await asset.Fetch().ContinueWith((t) => }); } + [Fact] + public async Task FetchAssetsPublishFallback() + { + List list = new List(); + list.Add("en-us"); + list.Add("ja-jp"); + ContentstackCollection assets = await client.AssetLibrary() + .SetLocale("ja-jp") + .IncludeFallback() + .FetchAll(); + ; + Assert.True(assets.Items.Count() > 0); + foreach (Asset asset in assets) + { + Assert.Contains((string)(asset.Get("publish_details") as JObject).GetValue("locale"), list); + } + } + + [Fact] + public async Task FetchAssetsPublishWithoutFallback() + { + List list = new List(); + list.Add("ja-jp"); + ContentstackCollection 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); + } + } + [Fact] public async Task FetchAssets() { @@ -94,7 +128,7 @@ public async Task FetchAssetsIncludeRelativeURL() [Fact] public async Task FetchAssetCountAsync() { - AssetLibrary assetLibrary = client.AssetLibrary(); + AssetLibrary assetLibrary = client.AssetLibrary().SetLocale("en-us"); JObject jObject = await assetLibrary.Count(); if (jObject == null) { @@ -114,7 +148,7 @@ public async Task FetchAssetCountAsync() [Fact] public async Task FetchAssetSkipLimit() { - AssetLibrary assetLibrary = client.AssetLibrary().Skip(2).Limit(5); + AssetLibrary assetLibrary = client.AssetLibrary().SetLocale("en-us").Skip(2).Limit(5); ContentstackCollection assets = await assetLibrary.FetchAll(); if (assets == null) { diff --git a/Contentstack.Core.Tests/Contentstack.Core.Tests.csproj b/Contentstack.Core.Tests/Contentstack.Core.Tests.csproj index 1e2d6a2..8b3619a 100644 --- a/Contentstack.Core.Tests/Contentstack.Core.Tests.csproj +++ b/Contentstack.Core.Tests/Contentstack.Core.Tests.csproj @@ -4,7 +4,7 @@ netcoreapp2.1 false - 2.4.0 + 2.5.0 diff --git a/Contentstack.Core.Tests/EntryTest.cs b/Contentstack.Core.Tests/EntryTest.cs index 975055e..819d3d6 100644 --- a/Contentstack.Core.Tests/EntryTest.cs +++ b/Contentstack.Core.Tests/EntryTest.cs @@ -6,6 +6,8 @@ using System.Linq; using System.Text.RegularExpressions; using Contentstack.Core.Tests.Models; +using Newtonsoft.Json.Linq; + namespace Contentstack.Core.Tests { @@ -61,6 +63,36 @@ await sourceEntry.Fetch().ContinueWith((t) => }); } + [Fact] + public async Task FetchEntryByUIDPublishFallback() + { + List list = new List(); + list.Add("en-us"); + list.Add("ja-jp"); + ContentType contenttype = client.ContentType(source); + string uid = await GetUID("source1"); + Entry sourceEntry = await contenttype.Entry(uid) + .SetLocale("ja-jp") + .IncludeFallback() + .Fetch(); + + Assert.Contains((string)(sourceEntry.Get("publish_details") as JObject).GetValue("locale"), list); + } + + [Fact] + public async Task FetchEntryByUIDPublishWithoutFallback() + { + List list = new List(); + list.Add("ja-jp"); + ContentType contenttype = client.ContentType(source); + string uid = await GetUID("source1"); + Entry sourceEntry = await contenttype.Entry(uid) + .SetLocale("ja-jp") + .Fetch(); + + Assert.Contains((string)(sourceEntry.Get("publish_details") as JObject).GetValue("locale"), list); + } + [Fact] public async Task IncludeReference() { ContentType contenttype = client.ContentType(source); diff --git a/Contentstack.Core.Tests/QueryTest.cs b/Contentstack.Core.Tests/QueryTest.cs index c2475f7..f22c87f 100644 --- a/Contentstack.Core.Tests/QueryTest.cs +++ b/Contentstack.Core.Tests/QueryTest.cs @@ -52,6 +52,40 @@ public async Task FetchAllGetContentType() } } + [Fact] + public async Task FetchEntriesPublishFallback() + { + List list = new List(); + list.Add("en-us"); + list.Add("ja-jp"); + ContentstackCollection entries = await client.ContentType(source).Query() + .SetLocale("ja-jp") + .IncludeFallback() + .Find(); + ; + Assert.True(entries.Items.Count() > 0); + foreach (Entry entry in entries) + { + Assert.Contains((string)(entry.Get("publish_details") as JObject).GetValue("locale"), list); + } + } + + [Fact] + public async Task FetchEntriesPublishWithoutFallback() + { + List list = new List(); + list.Add("ja-jp"); + ContentstackCollection entries = await client.ContentType(source).Query() + .SetLocale("ja-jp") + .Find(); + ; + Assert.True(entries.Items.Count() > 0); + foreach (Entry entry in entries) + { + Assert.Contains((string)(entry.Get("publish_details") as JObject).GetValue("locale"), list); + } + } + [Fact] public async Task FetchAllCount() { diff --git a/Contentstack.Core/Contentstack.Core.csproj b/Contentstack.Core/Contentstack.Core.csproj index b31f051..880caf5 100644 --- a/Contentstack.Core/Contentstack.Core.csproj +++ b/Contentstack.Core/Contentstack.Core.csproj @@ -1,20 +1,19 @@  - netstandard2.0 + netstandard2.0;net47;net472; contentstack.csharp Contentstack .NET SDK for the Contentstack Content Delivery API. - 2.4.0 + 2.5.0 Contentstack - Entry model, JsonConverter added -Bug fixes Environment, Entry content types resolved + Publish content fallback Copyright © 2012-2020 Contentstack. All Rights Reserved true - v2.4.0 + v2.5.0 https://github.com/contentstack/contentstack-dotnet https://github.com/contentstack/contentstack-dotnet/blob/master/LICENSE - 2.4.0 + 2.5.0 @@ -28,29 +27,14 @@ Bug fixes Environment, Entry content types resolved - - - all -runtime; build; native; contentfiles; analyzers; buildtransitive - + - - - - - - - - - - - diff --git a/Contentstack.Core/ContentstackClient.cs b/Contentstack.Core/ContentstackClient.cs index cffda00..4ddf1d6 100644 --- a/Contentstack.Core/ContentstackClient.cs +++ b/Contentstack.Core/ContentstackClient.cs @@ -11,7 +11,6 @@ using System.Net; using System.IO; using System.Collections; -using System.Reflection; namespace Contentstack.Core { diff --git a/Contentstack.Core/Models/Asset.cs b/Contentstack.Core/Models/Asset.cs index b5c2872..ef00864 100644 --- a/Contentstack.Core/Models/Asset.cs +++ b/Contentstack.Core/Models/Asset.cs @@ -147,6 +147,28 @@ public void SetHeader(string key, string value) } } + + /// + /// Include fallback locale publish content, if specified locale content is not publish. + /// + /// Current instance of Entry, this will be useful for a chaining calls. + /// + /// + /// //"blt5d4sample2633b" is a dummy Stack API key + /// //"blt6d0240b5sample254090d" is dummy access token. + /// ContentstackClient stack = new ContentstackClinet("blt5d4sample2633b", "blt6d0240b5sample254090d", "stag"); + /// Asset asset = stack.Asset("asset_uid"); + /// asset.IncludeFallback(); + /// asset.Fetch<Product>().ContinueWith((assetResult) => { + /// //Your callback code. + /// }); + /// + /// + public Asset includeFallback() + { + this.UrlQueries.Add("include_fallback", true); + return this; + } public void RemoveHeader(string key) { @@ -176,6 +198,25 @@ public DateTime GetCreateAt() return DateTime.MinValue; } + public Object Get(String key) + { + try + { + if (_ObjectAttributes.ContainsKey(key)) + { + var value = _ObjectAttributes[key]; + return value; + } + else + return null; + } + catch + { + //CSAppUtils.showLog(TAG, "-----------------getUpdateAtDate|" + e); + } + return null; + } + public String GetCreatedBy() { diff --git a/Contentstack.Core/Models/AssetLibrary.cs b/Contentstack.Core/Models/AssetLibrary.cs index 5af7a41..a490e81 100644 --- a/Contentstack.Core/Models/AssetLibrary.cs +++ b/Contentstack.Core/Models/AssetLibrary.cs @@ -94,6 +94,62 @@ public async Task Count() return await Exec(); } + /// + /// Include fallback locale publish content, if specified locale content is not publish. + /// + /// Current instance of AssetLibrary, this will be useful for a chaining calls. + /// + /// + /// //"blt5d4sample2633b" is a dummy Stack API key + /// //"blt6d0240b5sample254090d" is dummy access token. + /// ContentstackClient stack = new ContentstackClinet("blt5d4sample2633b", "blt6d0240b5sample254090d", "stag"); + /// AssetLibrary assetLibrary = stack.AssetLibrary(); + /// assetLibrary.IncludeFallback(); + /// ContentstackCollection contentstackCollection = await assetLibrary.FetchAll(); + /// + /// + public AssetLibrary IncludeFallback() + { + try + { + UrlQueries.Add("include_fallback", "true"); + } + catch (Exception e) + { + throw new Exception(StackConstants.ErrorMessage_QueryFilterException, e); + } + return this; + } + + /// + /// Sets the locale. + /// + /// The locale. + /// Locale. + /// + /// + /// //"blt5d4sample2633b" is a dummy Stack API key + /// //"blt6d0240b5sample254090d" is dummy access token. + /// ContentstackClient stack = new ContentstackClinet("blt5d4sample2633b", "blt6d0240b5sample254090d", "stag"); + /// AssetLibrary assetLibrary = stack.AssetLibrary(); + /// assetLibrary.SetLocale("en-us"); + /// ContentstackCollection contentstackCollection = await assetLibrary.FetchAll(); + /// + /// + public AssetLibrary SetLocale(String Locale) + { + if (UrlQueries != null && !UrlQueries.ContainsKey("locale")) + { + UrlQueries.Remove("locale"); + UrlQueries.Add("locale", Locale); + } + else + { + UrlQueries["locale"] = Locale; + } + return this; + } + /// /// This method also includes the total number of assets returned in the response. /// @@ -134,7 +190,7 @@ public void IncludeRelativeUrls() /// The number of objects to skip before returning any. /// /// No of objects to skip from returned objects. - /// Current instance of Query, this will be useful for a chaining calls. + /// Current instance of AssetLibrary, this will be useful for a chaining calls. /// /// /// //"blt5d4sample2633b" is a dummy Stack API key @@ -162,7 +218,7 @@ public AssetLibrary Skip(int number) /// A limit on the number of objects to return. /// /// No of objects to limit. - /// Current instance of Query, this will be useful for a chaining calls. + /// Current instance of AssetLibrary, this will be useful for a chaining calls. /// /// /// //"blt5d4sample2633b" is a dummy Stack API key @@ -190,7 +246,7 @@ public AssetLibrary Limit(int number) /// Specifies an array of 'only' keys in BASE object that would be 'included' in the response. /// /// Array of the 'only' keys to be included in response. - /// Current instance of Query, this will be useful for a chaining calls. + /// Current instance of AssetLibrary, this will be useful for a chaining calls. /// /// /// //"blt5d4sample2633b" is a dummy Stack API key @@ -222,7 +278,7 @@ public AssetLibrary Only(String[] fieldUid) /// Specifies list of field uids that would be excluded from the response. /// /// field uid which get excluded from the response. - /// Current instance of Query, this will be useful for a chaining calls. + /// Current instance of AssetLibrary, this will be useful for a chaining calls. /// /// /// //"blt5d4sample2633b" is a dummy Stack API key diff --git a/Contentstack.Core/Models/Entry.cs b/Contentstack.Core/Models/Entry.cs index 9ce687e..4bc4c57 100644 --- a/Contentstack.Core/Models/Entry.cs +++ b/Contentstack.Core/Models/Entry.cs @@ -1098,6 +1098,35 @@ public Entry IncludeReferenceContentTypeUID() return this; } + /// + /// Include fallback locale publish content, if specified locale content is not publish. + /// + /// Current instance of Entry, this will be useful for a chaining calls. + /// + /// + /// //"blt5d4sample2633b" is a dummy Stack API key + /// //"blt6d0240b5sample254090d" is dummy access token. + /// ContentstackClient stack = new ContentstackClinet("blt5d4sample2633b", "blt6d0240b5sample254090d", "stag"); + /// Entry entry = stack.ContentType("contentType_id").Entry("entry_uid"); + /// entry.IncludeFallback(); + /// entry.Fetch<Product>().ContinueWith((entryResult) => { + /// //Your callback code. + /// }); + /// + /// + public Entry IncludeFallback() + { + try + { + UrlQueries.Add("include_fallback", true); + } + catch (Exception e) + { + throw new Exception(StackConstants.ErrorMessage_QueryFilterException, e); + } + return this; + } + /// /// Include schemas of all returned objects along with objects themselves. /// diff --git a/Contentstack.Core/Models/Query.cs b/Contentstack.Core/Models/Query.cs index fa86e23..26248f3 100644 --- a/Contentstack.Core/Models/Query.cs +++ b/Contentstack.Core/Models/Query.cs @@ -1317,6 +1317,36 @@ public Query Except(String[] fieldUids) return this; } + /// + /// Include fallback locale publish content, if specified locale content is not publish. + /// + /// Current instance of Query, this will be useful for a chaining calls. + /// + /// + /// //"blt5d4sample2633b" is a dummy Stack API key + /// //"blt6d0240b5sample254090d" is dummy access token. + /// ContentstackClient stack = new ContentstackClinet("blt5d4sample2633b", "blt6d0240b5sample254090d", "stag"); + /// Query csQuery = stack.ContentType("contentType_id").Query(); + /// + /// csQuery.IncludeFallback(); + /// csQuery.Find<Product>().ContinueWith((queryResult) => { + /// //Your callback code. + /// }); + /// + /// + public Query IncludeFallback() + { + try + { + UrlQueries.Add("include_fallback", true); + } + catch (Exception e) + { + throw new Exception(StackConstants.ErrorMessage_QueryFilterException, e); + } + return this; + } + /// /// Include schemas of all returned objects along with objects themselves. /// diff --git a/Contentstack.Net.sln b/Contentstack.Net.sln index bd45f8c..f1499b4 100644 --- a/Contentstack.Net.sln +++ b/Contentstack.Net.sln @@ -132,6 +132,6 @@ Global $0.XmlFormattingPolicy = $9 $9.scope = application/xml $0.StandardHeader = $10 - version = 2.4.0 + version = 2.5.0 EndGlobalSection EndGlobal