diff --git a/CHANGELOG.md b/CHANGELOG.md index 6988b61..537409e 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,13 @@ +### Version: 2.1.1 +#### Date: Sept-03-2019 + +##### New Features: +- Config + - added property attribute 'region' +- Query + - added method 'ReferenceIn' + - added method 'ReferenceNotIn' + ### Version: 2.1.0 #### Date: Jul-29-2019 @@ -7,7 +17,7 @@ - Entry - added method 'includeReferenceContentTypeUid' -### Version: 2.0 +### Version: #### Date: Jun-28-2019 ##### New Features: diff --git a/Contentstack.AspNetCore/Contentstack.AspNetCore.csproj b/Contentstack.AspNetCore/Contentstack.AspNetCore.csproj index c70adc4..45bdc6e 100644 --- a/Contentstack.AspNetCore/Contentstack.AspNetCore.csproj +++ b/Contentstack.AspNetCore/Contentstack.AspNetCore.csproj @@ -6,13 +6,13 @@ contentstack.aspnetcore Contentstack Contentstack - 2.1.0 1.0.0 Main release Copyright (c) 2012-2019 Contentstack (http://app.contentstack.com). All Rights Reserved https://github.com/contentstack/contentstack-dotnet v1.0.0 + 2.0 @@ -23,7 +23,7 @@ - + diff --git a/Contentstack.Core.Tests/AssetTest.cs b/Contentstack.Core.Tests/AssetTest.cs index cbe88fe..addfa84 100644 --- a/Contentstack.Core.Tests/AssetTest.cs +++ b/Contentstack.Core.Tests/AssetTest.cs @@ -12,12 +12,14 @@ namespace Contentstack.Core.Tests { public class AssetTest { + string uid = "blt14d101ddeddaeefb"; + //string uid = "blt649cfadb08b577db"; ContentstackClient client = StackConfig.GetStack(); [Fact] public async Task FetchAssetByUid() { - Asset asset = client.Asset("blt649cfadb08b577db"); + Asset asset = client.Asset(uid); await asset.Fetch().ContinueWith((t) => { Asset result = t.Result; @@ -56,7 +58,7 @@ public async Task FetchAssetsOrderByAscending() { if (dateTime != null) { - if (dateTime.CompareTo(asset.GetCreateAt()) != -1) + if (dateTime.CompareTo(asset.GetCreateAt()) != -1 && dateTime.CompareTo(asset.GetCreateAt()) != 0) { Assert.False(true); } diff --git a/Contentstack.Core.Tests/EntryTest.cs b/Contentstack.Core.Tests/EntryTest.cs index 9abf61e..4d271b4 100644 --- a/Contentstack.Core.Tests/EntryTest.cs +++ b/Contentstack.Core.Tests/EntryTest.cs @@ -13,11 +13,18 @@ public class EntryTest { ContentstackClient client = StackConfig.GetStack(); - + ////PROD STAG + //String source = "source"; + //String singelEntryFetchUID = "blt1f94e478501bba46"; + //string htmlSource = "blt2f0dd6a81f7f40e7"; + //String referenceFieldUID = "reference"; + //EU String source = "source"; - String singelEntryFetchUID = "blt1f94e478501bba46"; + String singelEntryFetchUID = "bltf4268538a14fc5e1"; + string htmlSource = "blt7c4197d43c1156ba"; String referenceFieldUID = "reference"; + [Fact] public async Task FetchByUid() { ContentType contenttype = client.ContentType(source); @@ -209,7 +216,7 @@ public async Task GetTags() public async Task GetHTMLText() { ContentType contenttype = client.ContentType(source); - Entry sourceEntry = contenttype.Entry("blt2f0dd6a81f7f40e7"); + Entry sourceEntry = contenttype.Entry(htmlSource); var result = await sourceEntry.Fetch(); diff --git a/Contentstack.Core.Tests/Models/SourceModel.cs b/Contentstack.Core.Tests/Models/SourceModel.cs index f02b396..6e3ea63 100644 --- a/Contentstack.Core.Tests/Models/SourceModel.cs +++ b/Contentstack.Core.Tests/Models/SourceModel.cs @@ -17,8 +17,10 @@ public class SourceModel public Boolean Boolean; public string Date; public Asset file; - public List Reference; - public List Other_reference; + //public List Reference; + //public List Other_reference; + public List> Reference; + public List> Other_reference; public Dictionary Group; public List> Modular_blocks; public object[] Tags; diff --git a/Contentstack.Core.Tests/Models/SourceModelIncludeRef.cs b/Contentstack.Core.Tests/Models/SourceModelIncludeRef.cs index fec6c13..4f6d577 100644 --- a/Contentstack.Core.Tests/Models/SourceModelIncludeRef.cs +++ b/Contentstack.Core.Tests/Models/SourceModelIncludeRef.cs @@ -15,7 +15,8 @@ public class SourceModelIncludeRef public Boolean Boolean; public string Date; public List Reference; - public List Other_reference; + //public List Other_reference; + public List> Other_reference; public Dictionary Group; public List> Modular_blocks; diff --git a/Contentstack.Core.Tests/QueryTest.cs b/Contentstack.Core.Tests/QueryTest.cs index 0269add..a9fa018 100644 --- a/Contentstack.Core.Tests/QueryTest.cs +++ b/Contentstack.Core.Tests/QueryTest.cs @@ -325,7 +325,6 @@ public async Task And() } } - // //Not working [Fact] public async Task Or() @@ -1316,7 +1315,71 @@ public async Task WhereTags() } } + [Fact] + public async Task ReferenceIn() + { + ContentType contentTypeObj = client.ContentType(source); + Query query = contentTypeObj.Query(); + query.IncludeReference("reference"); + Query referencequery = contentTypeObj.Query(); + referencequery.Where("title", "ref-1 test3"); + + query.ReferenceIn("reference", referencequery); + + var result = await query.Find(); + if (result == null && result.Items.Count() == 0) + { + Assert.False(true, "Query.Exec is not match with expected result."); + } + else + { + bool IsTrue = false; + foreach (var data in result.Items) + { + foreach (var entry in data.Reference) + { + IsTrue = (entry.Title == "ref-1 test3"); + if (!IsTrue) + break; + } + + } + Assert.True(IsTrue); + } + } + [Fact] + public async Task ReferenceNotIn() + { + ContentType contentTypeObj = client.ContentType(source); + Query query = contentTypeObj.Query(); + query.IncludeReference("reference"); + Query referencequery = contentTypeObj.Query(); + referencequery.Where("title", "ref-1 test3"); + + query.ReferenceNotIn("reference", referencequery); + + var result = await query.Find(); + if (result == null && result.Items.Count() == 0) + { + Assert.False(true, "Query.Exec is not match with expected result."); + } + else + { + bool IsTrue = false; + foreach (var data in result.Items) + { + foreach (var entry in data.Reference) + { + IsTrue = (entry.Title != "ref-1 test3"); + if (!IsTrue) + break; + } + + } + Assert.True(IsTrue); + } + } } } diff --git a/Contentstack.Core.Tests/StackConfig.cs b/Contentstack.Core.Tests/StackConfig.cs index 05d7b20..3ff46a6 100644 --- a/Contentstack.Core.Tests/StackConfig.cs +++ b/Contentstack.Core.Tests/StackConfig.cs @@ -61,7 +61,7 @@ public static ContentstackClient GetStack() ApiKey = apiKey, AccessToken = accessToken, Environment = environment, - Host = host + Host = host, }; ContentstackClient contentstackClient = new ContentstackClient(new OptionsWrapper(contentstackOptions)); diff --git a/Contentstack.Core.Tests/SyncStackTest.cs b/Contentstack.Core.Tests/SyncStackTest.cs index bff44ed..f85c5dc 100644 --- a/Contentstack.Core.Tests/SyncStackTest.cs +++ b/Contentstack.Core.Tests/SyncStackTest.cs @@ -11,14 +11,19 @@ public class SyncStackTest { ContentstackClient client = StackConfig.GetSyncStack(); + + //EU + //String PaginationToken = "***REMOVED***"; + //String SyncToken = "***REMOVED***"; + //STAG - String PaginationToken = "***REMOVED***"; - String SyncToken = "***REMOVED***"; + //String PaginationToken = "***REMOVED***"; + //String SyncToken = "***REMOVED***"; // //PROD - // String PaginationToken = "***REMOVED***"; - // String SyncToken = "***REMOVED***"; + String PaginationToken = "***REMOVED***"; + String SyncToken = "***REMOVED***"; [Fact] public async Task SyncInit() { diff --git a/Contentstack.Core/Configuration/Config.cs b/Contentstack.Core/Configuration/Config.cs index 7426831..823c8bc 100644 --- a/Contentstack.Core/Configuration/Config.cs +++ b/Contentstack.Core/Configuration/Config.cs @@ -3,7 +3,8 @@ using System.Linq; using System.Text; using System.Threading.Tasks; - +using Contentstack.Core.Internals; + namespace Contentstack.Core.Configuration { internal class Config @@ -12,7 +13,6 @@ internal class Config private string _Protocol; private string _Host; private string _Port; - private string _BaseURL; private string _Version; private string _Environment; #endregion @@ -35,10 +35,12 @@ public string Protocol { } public string Host { - get { return this._Host ?? "cdn.contentstack.io"; } + get { return _Host ?? HostURL; } set { this._Host = value; } } + public ContentstackRegion Region { get; set; } = ContentstackRegion.US; + public string Version { get { return this._Version ?? "v3"; } @@ -55,18 +57,35 @@ public string BaseUrl { get { - string port = (this.Port == "80") ? string.Empty : ":" + this.Port; - this._BaseURL = string.Format("{0}://{1}{2}/{3}", - this.Protocol.Trim('/').Trim('\\'), - this.Host.Trim('/').Trim('\\'), port.Trim('/').Trim('\\'), this.Version.Trim('/').Trim('\\')); - return this._BaseURL; - } - set - { - this._BaseURL = value; + string BaseURL = string.Format("{0}://{1}{2}/{3}", + this.Protocol.Trim('/').Trim('\\'), + regionCode(), + this.Host.Trim('/').Trim('\\'), + this.Version.Trim('/').Trim('\\')); + return BaseURL; } + } + + #endregion + + #region Internal + + internal string regionCode() + { + if (Region == ContentstackRegion.US) return ""; + ContentstackRegionCode[] regionCodes = Enum.GetValues(typeof(ContentstackRegionCode)).Cast().ToArray(); + return string.Format("{0}-", regionCodes[(int)Region].ToString()); } + internal string HostURL + { + get + { + if (Region == ContentstackRegion.EU) + return "cdn.contentstack.com"; + return "cdn.contentstack.io"; + } + } #endregion } } diff --git a/Contentstack.Core/Configuration/ContentstackOptions.cs b/Contentstack.Core/Configuration/ContentstackOptions.cs index c95fc57..9437280 100644 --- a/Contentstack.Core/Configuration/ContentstackOptions.cs +++ b/Contentstack.Core/Configuration/ContentstackOptions.cs @@ -1,4 +1,9 @@ -using System; +using System; +using System.ComponentModel; +using System.Globalization; +using System.Linq; +using Contentstack.Core.Internals; + namespace Contentstack.Core.Configuration { /// @@ -26,9 +31,47 @@ public class ContentstackOptions /// public string Host { get; set; } + /// + /// The Region used to set region for the ContentStack API. + /// + [TypeConverter(typeof(ContentstackRegionConverter))] + public ContentstackRegion Region { get; set; } = ContentstackRegion.US; + /// /// The Version number for the ContentStack API. /// public string Version { get; set; } } + + internal class ContentstackRegionConverter : TypeConverter + { + public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) + { + string stringValue; + object result; + + result = null; + stringValue = value as string; + + if (!string.IsNullOrEmpty(stringValue)) + { + int nonDigitIndex; + + nonDigitIndex = stringValue.IndexOf(stringValue.FirstOrDefault(char.IsLetter)); + + if (nonDigitIndex > 0) + { + result = (ContentstackRegion)Enum.Parse(typeof(ContentstackRegion), stringValue.Substring(nonDigitIndex), true); + } + } + + return result ?? base.ConvertFrom(context, culture, value); + } + } } + diff --git a/Contentstack.Core/Contentstack.Core.csproj b/Contentstack.Core/Contentstack.Core.csproj index 79237b8..71a1b89 100644 --- a/Contentstack.Core/Contentstack.Core.csproj +++ b/Contentstack.Core/Contentstack.Core.csproj @@ -5,16 +5,16 @@ contentstack.csharp Contentstack .NET SDK for the Contentstack Content Delivery API. - 2.0 + 2.1.1 Contentstack Query Find method, Entry Fetch method returns ContentstackCollection of Model. - 2.1.0 Copyright © 2012-2019 Contentstack. All Rights Reserved true - v2.1.0 + v2.1.1 https://github.com/contentstack/contentstack-dotnet https://github.com/contentstack/contentstack-dotnet/blob/master/LICENSE + 2.0 diff --git a/Contentstack.Core/ContentstackClient.cs b/Contentstack.Core/ContentstackClient.cs index f20546b..fad8ff3 100644 --- a/Contentstack.Core/ContentstackClient.cs +++ b/Contentstack.Core/ContentstackClient.cs @@ -88,6 +88,7 @@ public ContentstackClient(IOptions options) { cnfig.Version = _options.Version; } + cnfig.Region = _options.Region; this.SetConfig(cnfig); this.SerializerSettings.DateParseHandling = DateParseHandling.None; @@ -120,13 +121,14 @@ public ContentstackClient(ContentstackOptions options) : /// ContentType contentType = stack.ContentType("contentType_name"); /// /// - public ContentstackClient(string apiKey, string accessToken, string environment, string host = null, string version = null) : + public ContentstackClient(string apiKey, string accessToken, string environment, string host = null, ContentstackRegion region = ContentstackRegion.US, string version = null) : this(new OptionsWrapper(new ContentstackOptions() { ApiKey = apiKey, AccessToken = accessToken, Environment = environment, Host = host, + Region = region, Version = version } )) diff --git a/Contentstack.Core/Internals/ContentstackRegion.cs b/Contentstack.Core/Internals/ContentstackRegion.cs new file mode 100644 index 0000000..28b4edd --- /dev/null +++ b/Contentstack.Core/Internals/ContentstackRegion.cs @@ -0,0 +1,26 @@ +using System; +namespace Contentstack.Core.Internals +{ + /// + /// Contentstack region. + /// + public enum ContentstackRegion + { + /// + /// To specify US region. + /// + US, + /// + /// To specify EU region. + /// + EU + } + + + internal enum ContentstackRegionCode + { + us, + + eu + } +} diff --git a/Contentstack.Core/Internals/StackConstants.cs b/Contentstack.Core/Internals/StackConstants.cs index 3718ac9..35bc051 100644 --- a/Contentstack.Core/Internals/StackConstants.cs +++ b/Contentstack.Core/Internals/StackConstants.cs @@ -12,6 +12,8 @@ internal class StackConstants public const string NotEqualTo = "$ne"; public const string ContainedIn = "$in"; public const string NotContainedIn = "$nin"; + public const string InQuery = "$in_query"; + public const string NotInQuery = "$nin_query"; public const string Exists = "$exists"; public const string Ascending = "\"asc\":\""; public const string Descending = "\"desc\":\""; diff --git a/Contentstack.Core/Models/Query.cs b/Contentstack.Core/Models/Query.cs index fdbc47f..707233e 100644 --- a/Contentstack.Core/Models/Query.cs +++ b/Contentstack.Core/Models/Query.cs @@ -300,6 +300,52 @@ public Query Where(String key, Object value) return this; } + public Query ReferenceIn(String key, Query query) + { + try + { + if (key != null && query != null) + { + Dictionary queryDictionary = new Dictionary(); + queryDictionary.Add(StackConstants.InQuery, query.QueryValueJson); + QueryValueJson.Add(key, queryDictionary); + } + else + { + throw new Exception(StackConstants.ErrorMessage_QueryFilterException, null); + } + } + catch (Exception e) + { + throw new Exception(StackConstants.ErrorMessage_QueryFilterException, e); + } + + return this; + } + + public Query ReferenceNotIn(String key, Query query) + { + try + { + if (key != null && query != null) + { + Dictionary queryDictionary = new Dictionary(); + queryDictionary.Add(StackConstants.NotInQuery, query.QueryValueJson); + QueryValueJson.Add(key, queryDictionary); + } + else + { + throw new Exception(StackConstants.ErrorMessage_QueryFilterException, null); + } + } + catch (Exception e) + { + throw new Exception(StackConstants.ErrorMessage_QueryFilterException, e); + } + + return this; + } + /// /// Add a custom query against specified key. ///