Skip to content

Commit 7ca3557

Browse files
authored
Merge pull request #15 from contentstack/bug/livepreview
Live preview Query update issue resolved
2 parents fcd340d + 062c066 commit 7ca3557

9 files changed

Lines changed: 123 additions & 42 deletions

File tree

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
### Version: 2.8.0
2+
#### Date: Jan-11-2021
3+
4+
##### Bug fix:
5+
- Live preview Query issue
6+
##### New Feature:
7+
- Entry
8+
- IncludeOnlyReference function added
9+
- IncludeExceptReference function added
10+
- Query
11+
- IncludeOnlyReference function added
12+
- IncludeExceptReference function added
13+
114
### Version: 2.7.0
215
#### Date: Oct-14-2021
316

Contentstack.AspNetCore/Contentstack.AspNetCore.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<Copyright>Copyright (c) 2012-2020 Contentstack (http://app.contentstack.com). All Rights Reserved</Copyright>
1212
<PackageProjectUrl>https://github.com/contentstack/contentstack-dotnet</PackageProjectUrl>
1313
<PackageTags>v2.7.0</PackageTags>
14-
<ReleaseVersion>2.7.0</ReleaseVersion>
14+
<ReleaseVersion>2.8.0</ReleaseVersion>
1515
<Configurations>Release;Debug</Configurations>
1616
</PropertyGroup>
1717

Contentstack.Core.Tests/Contentstack.Core.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<TargetFramework>netcoreapp2.1</TargetFramework>
55

66
<IsPackable>false</IsPackable>
7-
<ReleaseVersion>2.7.0</ReleaseVersion>
7+
<ReleaseVersion>2.8.0</ReleaseVersion>
88
</PropertyGroup>
99

1010
<ItemGroup>

Contentstack.Core/Contentstack.Core.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
<PackageId>contentstack.csharp</PackageId>
66
<Authors>Contentstack</Authors>
77
<Description>.NET SDK for the Contentstack Content Delivery API.</Description>
8-
<PackageVersion>2.7.0</PackageVersion>
8+
<PackageVersion>2.8.0</PackageVersion>
99
<Owners>Contentstack</Owners>
1010
<PackageReleaseNotes>Live preview feature support added</PackageReleaseNotes>
11-
<Copyright>Copyright © 2012-2021 Contentstack. All Rights Reserved</Copyright>
11+
<Copyright>Copyright © 2012-2022 Contentstack. All Rights Reserved</Copyright>
1212
<PackOnBuild>true</PackOnBuild>
13-
<PackageTags>v2.7.0</PackageTags>
13+
<PackageTags>v2.8.0</PackageTags>
1414
<PackageProjectUrl>https://github.com/contentstack/contentstack-dotnet</PackageProjectUrl>
1515
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
16-
<ReleaseVersion>2.7.0</ReleaseVersion>
16+
<ReleaseVersion>2.8.0</ReleaseVersion>
1717
</PropertyGroup>
1818

1919
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">

Contentstack.Core/ContentstackClient.cs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -477,14 +477,18 @@ public void SetHeader(string key, string value)
477477
/// </example>
478478
public void LivePreviewQuery(Dictionary<string, string> query)
479479
{
480-
string contentTypeUID = null;
481-
query.TryGetValue("content_type_uid", out contentTypeUID);
482-
this.LivePreviewConfig.ContentTypeUID = contentTypeUID;
483-
484-
string hash = null;
485-
query.TryGetValue("live_preview", out hash);
486-
this.LivePreviewConfig.LivePreview = hash;
487-
480+
if (query.Keys.Contains("content_type_uid"))
481+
{
482+
string contentTypeUID = null;
483+
query.TryGetValue("content_type_uid", out contentTypeUID);
484+
this.LivePreviewConfig.ContentTypeUID = contentTypeUID;
485+
}
486+
if (query.Keys.Contains("live_preview"))
487+
{
488+
string hash = null;
489+
query.TryGetValue("live_preview", out hash);
490+
this.LivePreviewConfig.LivePreview = hash;
491+
}
488492
}
489493

490494
/// <summary>

Contentstack.Core/LICENSE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2012-2021 Contentstack (http://app.contentstack.com). All Rights Reserved
3+
Copyright (c) 2012-2022 Contentstack (http://app.contentstack.com). All Rights Reserved
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

Contentstack.Core/Models/Entry.cs

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -983,20 +983,18 @@ public Entry IncludeReference(String[] referenceFields)
983983
/// </example>
984984
public Entry IncludeOnlyReference(string[] keys, string referenceKey)
985985
{
986-
List<string> objectUidForOnly = new List<string>();
987-
Dictionary<string, object> onlyValueJson = new Dictionary<string, object>();
988986
if (keys != null && keys.Length > 0)
989987
{
990-
991-
int count = keys.Length;
992-
for (int i = 0; i < count; i++)
993-
{
994-
objectUidForOnly.Add(keys[i]);
988+
var referenceKeys = new string[] { referenceKey };
989+
if (UrlQueries.ContainsKey("include[]") == false)
990+
{
991+
UrlQueries.Add("", referenceKeys);
992+
993+
}
994+
if (UrlQueries.ContainsKey($"only[{referenceKey}][]") == false)
995+
{
996+
UrlQueries.Add($"only[{referenceKey}][]", keys);
995997
}
996-
onlyValueJson.Add(referenceKey, objectUidForOnly);
997-
UrlQueries.Add("include", new object[] { referenceKey });
998-
UrlQueries.Add("only", onlyValueJson);
999-
1000998
}
1001999

10021000
return this;
@@ -1184,22 +1182,20 @@ public Entry IncludeOwner()
11841182
/// </example>
11851183
public Entry IncludeExceptReference(string[] keys, string referenceKey)
11861184
{
1187-
List<string> objectUidForOnly = new List<string>();
1188-
Dictionary<string, object> onlyValueJson = new Dictionary<string, object>();
1185+
11891186
if (keys != null && keys.Length > 0)
11901187
{
1191-
1192-
int count = keys.Length;
1193-
for (int i = 0; i < count; i++)
1194-
{
1195-
objectUidForOnly.Add(keys[i]);
1188+
var referenceKeys = new string[] { referenceKey };
1189+
if (UrlQueries.ContainsKey("include[]") == false)
1190+
{
1191+
UrlQueries.Add("include[]", referenceKeys);
1192+
1193+
}
1194+
if (UrlQueries.ContainsKey($"except[{ referenceKey}][]") == false)
1195+
{
1196+
UrlQueries.Add($"except[{referenceKey}][]", keys);
11961197
}
1197-
onlyValueJson.Add(referenceKey, objectUidForOnly);
1198-
UrlQueries.Add("include", new object[] { referenceKey });
1199-
UrlQueries.Add("except", onlyValueJson);
1200-
12011198
}
1202-
12031199
return this;
12041200
}
12051201

@@ -1294,7 +1290,7 @@ public async Task<T> Fetch<T>()
12941290
}
12951291

12961292
HttpRequestHandler RequestHandler = new HttpRequestHandler();
1297-
var outputResult = await RequestHandler.ProcessRequest(_Url, headers, mainJson, Branch: this.ContentTypeInstance.StackInstance.Config.Branch, config: this.ContentTypeInstance.StackInstance.LivePreviewConfig);
1293+
var outputResult = await RequestHandler.ProcessRequest(_Url, headerAll, mainJson, Branch: this.ContentTypeInstance.StackInstance.Config.Branch, config: this.ContentTypeInstance.StackInstance.LivePreviewConfig);
12981294
JObject obj = JObject.Parse(ContentstackConvert.ToString(outputResult, "{}"));
12991295
var serializedObject = obj.SelectToken("$.entry").ToObject<T>(this.ContentTypeInstance.StackInstance.Serializer);
13001296
if (serializedObject.GetType() == typeof(Entry))

Contentstack.Core/Models/Query.cs

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,9 +1212,43 @@ public Query Only(String[] fieldUid)
12121212
Console.WriteLine("IOException source: {0}", e.Source);
12131213
}
12141214

1215+
return this;
1216+
}
1217+
1218+
/// <summary>
1219+
/// Specifies an array of only keys that would be included in the response.
1220+
/// </summary>
1221+
/// <param name="keys">Array of the only reference keys to be included in response.</param>
1222+
/// <param name="referenceKey">Key who has reference to some other class object.</param>
1223+
/// <returns>Current instance of Entry, this will be useful for a chaining calls.</returns>
1224+
/// <example>
1225+
/// <code>
1226+
/// ContentstackClient stack = new ContentstackClinet(&quot;api_key&quot;, &quot;delivery_token&quot;, &quot;environment&quot;);
1227+
/// Query csQuery = stack.ContentType(&quot;contentType_id&quot;).Query();
1228+
///
1229+
/// csQuery.IncludeOnlyReference(new String[]{&quot;name&quot;, &quot;description&quot;}, &quot;referenceUid&quot;);
1230+
/// csQuery.Find&lt;Product&gt;().ContinueWith((queryResult) =&gt; {
1231+
/// //Your callback code.
1232+
/// });
1233+
/// </code>
1234+
/// </example>
1235+
public Query IncludeOnlyReference(string[] keys, string referenceKey)
1236+
{
1237+
if (keys != null && keys.Length > 0)
1238+
{
1239+
var referenceKeys = new string[] { referenceKey };
1240+
if (UrlQueries.ContainsKey("include[]") == false)
1241+
{
1242+
UrlQueries.Add("include[]", referenceKeys);
1243+
1244+
}
1245+
if (UrlQueries.ContainsKey($"only[{ referenceKey}][]") == false)
1246+
{
1247+
UrlQueries.Add($"only[{referenceKey}][]", keys);
1248+
}
1249+
}
12151250
return this;
12161251
}
1217-
12181252
/// <summary>
12191253
/// Specifies list of field uids that would be excluded from the response.
12201254
/// </summary>
@@ -1249,6 +1283,40 @@ public Query Except(String[] fieldUids)
12491283
return this;
12501284
}
12511285

1286+
/// <summary>
1287+
/// Specifies an array of except keys that would be excluded in the response.
1288+
/// </summary>
1289+
/// <param name="keys">Array of the except reference keys to be excluded in response.</param>
1290+
/// <param name="referenceKey">Key who has reference to some other class object.</param>
1291+
/// <returns>Current instance of Entry, this will be useful for a chaining calls.</returns>
1292+
/// <example>
1293+
/// <code>
1294+
/// ContentstackClient stack = new ContentstackClinet(&quot;api_key&quot;, &quot;delivery_token&quot;, &quot;environment&quot;);
1295+
/// Query csQuery = stack.ContentType(&quot;contentType_id&quot;).Query();
1296+
/// csQuery.IncludeExceptReference(new String[]{&quot;name&quot;, &quot;description&quot;},&quot;referenceUid&quot;);
1297+
/// csQuery.Find&lt;Product&gt;().ContinueWith((queryResult) =&gt; {
1298+
/// //Your callback code.
1299+
/// });
1300+
/// </code>
1301+
/// </example>
1302+
public Query IncludeExceptReference(string[] keys, string referenceKey)
1303+
{
1304+
if (keys != null && keys.Length > 0)
1305+
{
1306+
var referenceKeys = new string[] { referenceKey };
1307+
if (UrlQueries.ContainsKey("include[]") == false)
1308+
{
1309+
UrlQueries.Add("include[]", referenceKeys);
1310+
1311+
}
1312+
if (UrlQueries.ContainsKey($"except[{ referenceKey}][]") == false)
1313+
{
1314+
UrlQueries.Add($"except[{referenceKey}][]", keys);
1315+
}
1316+
}
1317+
return this;
1318+
}
1319+
12521320
/// <summary>
12531321
/// Include fallback locale publish content, if specified locale content is not publish.
12541322
/// </summary>
@@ -1693,7 +1761,7 @@ private async Task<JObject> Exec()
16931761
try
16941762
{
16951763
HttpRequestHandler requestHandler = new HttpRequestHandler();
1696-
var outputResult = await requestHandler.ProcessRequest(_Url, headers, mainJson, Branch: this.ContentTypeInstance.StackInstance.Config.Branch, config: this.ContentTypeInstance.StackInstance.LivePreviewConfig);
1764+
var outputResult = await requestHandler.ProcessRequest(_Url, headerAll, mainJson, Branch: this.ContentTypeInstance.StackInstance.Config.Branch, config: this.ContentTypeInstance.StackInstance.LivePreviewConfig);
16971765
return JObject.Parse(ContentstackConvert.ToString(outputResult, "{}"));
16981766
}
16991767
catch (Exception ex)

Contentstack.Net.sln

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,6 @@ Global
132132
$0.XmlFormattingPolicy = $9
133133
$9.scope = application/xml
134134
$0.StandardHeader = $10
135-
version = 2.7.0
135+
version = 2.8.0
136136
EndGlobalSection
137137
EndGlobal

0 commit comments

Comments
 (0)