Skip to content

Commit 5b46c6d

Browse files
committed
feat: Update version to 2.25.0 and add VersionUtility for dynamic SDK version retrieval
1 parent a3b1968 commit 5b46c6d

5 files changed

Lines changed: 173 additions & 41 deletions

File tree

.talismanrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ fileignoreconfig:
33
ignore_detectors:
44
- filecontent
55
- filename: Contentstack.Core/Internals/HttpRequestHandler.cs
6-
checksum: 94288e483056f41ff3a4c2ab652c3ce9ecb53dc0b9d4029456b34baed4f34891
6+
checksum: 62053e1b8772f44db054efc504d5d57f28fb7962c81021325854d478f570de09
77
- filename: Contentstack.Core/Models/Entry.cs
88
checksum: 78a09b03b9fd6aefd0251353b2d8c70962bdfced16a6e1e28d10dc9af43da244
99
- filename: Contentstack.Core/ContentstackClient.cs

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
### Version: 2.25.0
2+
#### Date: Jan-07-2025
3+
4+
##### Feat:
5+
- AssetLibrary
6+
- Added new `Where` method for simple key-value pair queries
7+
- Enhanced `Query` method to support multiple calls with intelligent merging
8+
- Improved query handling with better null safety and error handling
9+
110
### Version: 2.24.0
211
#### Date: Sep-29-2025
312

Contentstack.Core/Internals/HttpRequestHandler.cs

Lines changed: 68 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -12,43 +12,56 @@ namespace Contentstack.Core.Internals
1212
{
1313
internal class HttpRequestHandler
1414
{
15-
ContentstackClient client
16-
{
17-
get; set;
18-
}
15+
ContentstackClient client { get; set; }
16+
1917
internal HttpRequestHandler(ContentstackClient contentstackClient)
2018
{
2119
client = contentstackClient;
2220
}
23-
public async Task<string> ProcessRequest(string Url, Dictionary<string, object> Headers, Dictionary<string, object> BodyJson, string FileName = null, string Branch = null, bool isLivePreview = false, int timeout = 30000, WebProxy proxy = null)
24-
{
2521

26-
String queryParam = String.Join("&", BodyJson.Select(kvp => {
27-
var value = "";
28-
if (kvp.Value is string[])
22+
public async Task<string> ProcessRequest(
23+
string Url,
24+
Dictionary<string, object> Headers,
25+
Dictionary<string, object> BodyJson,
26+
string FileName = null,
27+
string Branch = null,
28+
bool isLivePreview = false,
29+
int timeout = 30000,
30+
WebProxy proxy = null
31+
)
32+
{
33+
String queryParam = String.Join(
34+
"&",
35+
BodyJson.Select(kvp =>
2936
{
30-
string[] vals = (string[])kvp.Value;
31-
value = String.Join("&", vals.Select(item =>
37+
var value = "";
38+
if (kvp.Value is string[])
3239
{
33-
return String.Format("{0}={1}", kvp.Key, item);
34-
}));
35-
return value;
36-
}
37-
else if (kvp.Value is Dictionary<string, object>)
38-
value = JsonConvert.SerializeObject(kvp.Value);
39-
else
40-
return String.Format("{0}={1}", kvp.Key, kvp.Value);
41-
42-
return String.Format("{0}={1}", kvp.Key, value);
40+
string[] vals = (string[])kvp.Value;
41+
value = String.Join(
42+
"&",
43+
vals.Select(item =>
44+
{
45+
return String.Format("{0}={1}", kvp.Key, item);
46+
})
47+
);
48+
return value;
49+
}
50+
else if (kvp.Value is Dictionary<string, object>)
51+
value = JsonConvert.SerializeObject(kvp.Value);
52+
else
53+
return String.Format("{0}={1}", kvp.Key, kvp.Value);
4354

44-
}));
55+
return String.Format("{0}={1}", kvp.Key, value);
56+
})
57+
);
4558

46-
var uri = new Uri(Url+"?"+queryParam);
59+
var uri = new Uri(Url + "?" + queryParam);
4760

4861
var request = (HttpWebRequest)WebRequest.Create(uri);
4962
request.Method = "GET";
5063
request.ContentType = "application/json";
51-
request.Headers["x-user-agent"]="contentstack-delivery-dotnet/2.24.0";
64+
request.Headers["x-user-agent"] = VersionUtility.GetSdkVersion();
5265
request.Timeout = timeout;
5366

5467
if (proxy != null)
@@ -60,52 +73,68 @@ public async Task<string> ProcessRequest(string Url, Dictionary<string, object>
6073
{
6174
request.Headers["branch"] = Branch;
6275
}
63-
if (Headers != default(IDictionary<string, string>)) {
64-
foreach (var header in Headers) {
65-
try {
76+
if (Headers != default(IDictionary<string, string>))
77+
{
78+
foreach (var header in Headers)
79+
{
80+
try
81+
{
6682
request.Headers[header.Key] = header.Value.ToString();
67-
} catch {
68-
6983
}
84+
catch { }
7085
}
7186
}
7287

7388
foreach (var plugin in client.Plugins)
7489
{
7590
request = await plugin.OnRequest(client, request);
76-
};
91+
}
92+
;
7793

7894
var serializedresult = JsonConvert.SerializeObject(BodyJson);
7995
byte[] requestBody = Encoding.UTF8.GetBytes(serializedresult);
8096
StreamReader reader = null;
8197
HttpWebResponse response = null;
8298

83-
try {
99+
try
100+
{
84101
response = (HttpWebResponse)await request.GetResponseAsync();
85-
if (response != null) {
102+
if (response != null)
103+
{
86104
reader = new StreamReader(response.GetResponseStream());
87105

88106
string responseString = await reader.ReadToEndAsync();
89107
foreach (var plugin in client.Plugins)
90108
{
91-
responseString = await plugin.OnResponse(client, request, response, responseString);
109+
responseString = await plugin.OnResponse(
110+
client,
111+
request,
112+
response,
113+
responseString
114+
);
92115
}
93116
return responseString;
94-
} else {
117+
}
118+
else
119+
{
95120
return null;
96121
}
97-
} catch (Exception we) {
122+
}
123+
catch (Exception we)
124+
{
98125
throw we;
99-
} finally {
100-
if (reader != null) {
126+
}
127+
finally
128+
{
129+
if (reader != null)
130+
{
101131
reader.Dispose();
102132
}
103133
if (response != null)
104134
{
105-
response.Dispose();
135+
response.Dispose();
106136
}
107137
}
108-
109138
}
110139

111140
//internal void updateLivePreviewContent(JObject response)
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
using System;
2+
using System.Reflection;
3+
4+
namespace Contentstack.Core.Internals
5+
{
6+
/// <summary>
7+
/// Utility class for handling SDK version information and user-agent string generation.
8+
/// </summary>
9+
internal static class VersionUtility
10+
{
11+
/// <summary>
12+
/// Gets the SDK version dynamically from the assembly.
13+
/// </summary>
14+
/// <returns>The SDK version string in format: contentstack-delivery-dotnet/Major.Minor.Patch</returns>
15+
public static string GetSdkVersion()
16+
{
17+
try
18+
{
19+
var assembly = Assembly.GetExecutingAssembly();
20+
var version = assembly.GetName().Version;
21+
22+
// Check if version is valid (not 0.0.0.0 which is default for unversioned assemblies)
23+
if (version != null && (version.Major > 0 || version.Minor > 0 || version.Build > 0))
24+
{
25+
return $"contentstack-delivery-dotnet/{version.Major}.{version.Minor}.{version.Build}";
26+
}
27+
28+
// Try to get version from assembly file version as fallback
29+
var fileVersion = assembly.GetCustomAttribute<AssemblyFileVersionAttribute>()?.Version;
30+
if (!string.IsNullOrEmpty(fileVersion))
31+
{
32+
// Parse file version and extract only Major.Minor.Build (first 3 parts)
33+
var versionParts = fileVersion.Split('.');
34+
if (versionParts.Length >= 3)
35+
{
36+
return $"contentstack-delivery-dotnet/{versionParts[0]}.{versionParts[1]}.{versionParts[2]}";
37+
}
38+
return $"contentstack-delivery-dotnet/{fileVersion}";
39+
}
40+
41+
// Try to get version from assembly informational version
42+
var infoVersion = assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion;
43+
if (!string.IsNullOrEmpty(infoVersion))
44+
{
45+
// Extract semantic version (Major.Minor.Patch) from informational version
46+
// Handle formats like "2.25.0", "2.25.0-beta.1", "2.25.0+abc123"
47+
var semanticVersion = ExtractSemanticVersion(infoVersion);
48+
if (!string.IsNullOrEmpty(semanticVersion))
49+
{
50+
return $"contentstack-delivery-dotnet/{semanticVersion}";
51+
}
52+
return $"contentstack-delivery-dotnet/{infoVersion}";
53+
}
54+
}
55+
catch
56+
{
57+
// Ignore exceptions and continue to fallback
58+
}
59+
60+
// Final fallback - use a generic identifier that doesn't imply a specific version
61+
return "contentstack-delivery-dotnet/dev";
62+
}
63+
64+
/// <summary>
65+
/// Extracts semantic version (Major.Minor.Patch) from informational version string.
66+
/// </summary>
67+
/// <param name="informationalVersion">The informational version string.</param>
68+
/// <returns>Semantic version in Major.Minor.Patch format.</returns>
69+
private static string ExtractSemanticVersion(string informationalVersion)
70+
{
71+
try
72+
{
73+
// Remove build metadata (everything after +)
74+
var versionWithoutMetadata = informationalVersion.Split('+')[0];
75+
76+
// Split by dots to get version parts
77+
var parts = versionWithoutMetadata.Split('.');
78+
79+
// Ensure we have at least 3 parts (Major.Minor.Patch)
80+
if (parts.Length >= 3)
81+
{
82+
// Take only the first 3 parts (Major.Minor.Patch)
83+
return $"{parts[0]}.{parts[1]}.{parts[2]}";
84+
}
85+
86+
return null;
87+
}
88+
catch
89+
{
90+
return null;
91+
}
92+
}
93+
}
94+
}

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<Project>
22
<PropertyGroup>
3-
<Version>2.24.0</Version>
3+
<Version>2.25.0</Version>
44
</PropertyGroup>
55
</Project>

0 commit comments

Comments
 (0)