Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions .github/workflows/dotnet-core.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: .NET Core Linux
name: .NET Linux

on:
push:
Expand All @@ -16,14 +16,10 @@ jobs:
# and https://github.com/dotnet/core/blob/main/releases.md
# for versions
include:
- dotnet-version: 3.1.x
framework: netcoreapp3.1
- dotnet-version: 5.0.x
framework: net5.0
- dotnet-version: 6.0.x
framework: net6.0
- dotnet-version: 8.0.x
framework: net8.0
- dotnet-version: 9.0.x
framework: net9.0

continue-on-error: true

Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/test-examples-and-snippets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ on:

jobs:
build-examples:
runs-on: ubuntu-22.04
runs-on: ubuntu-latest


steps:
- uses: actions/checkout@v4
Expand Down
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[![Nuget](https://img.shields.io/nuget/v/Aspose.BarCode-Cloud)](https://www.nuget.org/packages/Aspose.BarCode-Cloud/)

- API version: 4.0
- SDK version: 25.3.0
- SDK version: 25.4.0

## SDK and API Version Compatibility:

Expand All @@ -27,9 +27,8 @@ This repository contains Aspose.BarCode Cloud SDK for .NET source code. This SDK

Aspose.BarCode Cloud SDK for .NET provides cross-platform bindings for:

- .NET 5 and higher
- .NET 8 and higher
- .NET Standard 2.0 and higher
- .NET Core 3.1 and higher
- .NET Framework 4.6.2 and higher

To use these SDKs, you will need Client Id and Client Secret which can be looked up at [Aspose Cloud Dashboard](https://dashboard.aspose.cloud/applications) (free registration in Aspose Cloud is required for this).
Expand Down Expand Up @@ -201,7 +200,7 @@ internal static class Program

## Dependencies

- [Json.NET](https://www.nuget.org/packages/Newtonsoft.Json/)
- [System.Text.Json](https://www.nuget.org/packages/System.Text.json)

## Licensing

Expand Down
2 changes: 1 addition & 1 deletion Tests/Aspose.BarCode.Cloud.Sdk.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net462;net480;net481;netcoreapp3.1;net5.0;net6.0;net8.0</TargetFrameworks>
<TargetFrameworks>net462;net480;net481;net8.0;net9.0</TargetFrameworks>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<IsTestProject>true</IsTestProject>
<LangVersion>8.0</LangVersion>
Expand Down
10 changes: 4 additions & 6 deletions Tests/ConfigurationTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Collections.Generic;
using System.IO;
using Aspose.BarCode.Cloud.Sdk.Api;
using Newtonsoft.Json;
using System.Text.Json;
using NUnit.Framework;

namespace Aspose.BarCode.Cloud.Sdk.Tests
Expand Down Expand Up @@ -90,13 +90,11 @@ public void DefaultParamsTest()
[Test]
public void DeserializeTest()
{
using StreamReader file = File.OpenText(Path.Combine(
using FileStream file = File.OpenRead(Path.Combine(
TestContext.CurrentContext.TestDirectory,
"..", "..", "..",
"Configuration.template.json"));
JsonSerializer serializer = new JsonSerializer();
using JsonTextReader reader = new JsonTextReader(file);
Configuration config = serializer.Deserialize<Configuration>(reader);
var config = JsonSerializer.Deserialize<Configuration>(file);

Assert.IsNotNull(config);
Assert.AreEqual("Client Secret from https://dashboard.aspose.cloud/applications", config.ClientSecret);
Expand Down Expand Up @@ -131,7 +129,7 @@ public void SerializationTest()
"ApiVersion\":\"4.0\",\"" +
"DefaultHeaders\":{}" +
"}",
JsonConvert.SerializeObject(config));
JsonSerializer.Serialize(config));
}
}
}
6 changes: 3 additions & 3 deletions Tests/JWTRequestHandlerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
using System.Net;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using Aspose.BarCode.Cloud.Sdk.Api;
using Aspose.BarCode.Cloud.Sdk.Internal;
using Aspose.BarCode.Cloud.Sdk.Internal.RequestHandlers;
using Moq;
using Newtonsoft.Json.Linq;
using NUnit.Framework;

namespace Aspose.BarCode.Cloud.Sdk.Tests
Expand Down Expand Up @@ -169,9 +169,9 @@ private static void AssertTokenIsValid(string token)
{
string firstPartBeforeDot = new string(token.TakeWhile(c => c != '.').ToArray());
byte[] tokenBytes = Convert.FromBase64String(firstPartBeforeDot);
JObject tokenHeader = JObject.Parse(Encoding.UTF8.GetString(tokenBytes));
JsonElement tokenHeader = JsonDocument.Parse(Encoding.UTF8.GetString(tokenBytes)).RootElement;

Assert.AreEqual("JWT", tokenHeader["typ"]?.ToString());
Assert.AreEqual("JWT", tokenHeader.GetProperty("typ").GetString());
}
}
}
7 changes: 3 additions & 4 deletions Tests/JwtAuthTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
using System.Collections.Generic;
using System.IO;
using System.Net.Http;
using System.Text.Json;
using System.Threading.Tasks;
using Aspose.BarCode.Cloud.Sdk.Api;
using Aspose.BarCode.Cloud.Sdk.Model;

using Newtonsoft.Json.Linq;
using NUnit.Framework;

namespace Aspose.BarCode.Cloud.Sdk.Tests
Expand All @@ -27,8 +26,8 @@ private async Task<string> FetchToken()
FormUrlEncodedContent formContent = new FormUrlEncodedContent(formParams);
HttpResponseMessage response = await new HttpClient().PostAsync(TestConfiguration.TokenUrl, formContent);
response.EnsureSuccessStatusCode();
JObject json = JObject.Parse(await response.Content.ReadAsStringAsync());
string accessToken = Convert.ToString(json["access_token"]);
JsonDocument json = JsonDocument.Parse(await response.Content.ReadAsStringAsync());
string accessToken = json.RootElement.GetProperty("access_token").GetString();
return accessToken;
}

Expand Down
2 changes: 1 addition & 1 deletion Tests/RecognizeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public async Task RecognizeBase64AsyncTest()
using Stream image = GetTestImage("Test_PostGenerateMultiple.png");

byte[] buffer = new byte[image.Length];
await image.ReadAsync(buffer, 0, buffer.Length);
_ = await image.ReadAsync(buffer, 0, buffer.Length);

// Act
BarcodeResponseList response = await _api.RecognizeBase64Async(
Expand Down
2 changes: 1 addition & 1 deletion Tests/ScanTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public async Task ScanBase64AsyncTest()

byte[] buffer = new byte[image.Length];

await image.ReadAsync(buffer, 0, buffer.Length);
_ = await image.ReadAsync(buffer, 0, buffer.Length);
// Act
BarcodeResponseList response = await _api.ScanBase64Async(
new ScanBase64Request()
Expand Down
43 changes: 24 additions & 19 deletions Tests/TestsBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
using System.IO;
using System.Text;
using Aspose.BarCode.Cloud.Sdk.Api;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Text.Json;
using NUnit.Framework;

namespace Aspose.BarCode.Cloud.Sdk.Tests
Expand Down Expand Up @@ -36,38 +35,44 @@ private static Configuration LoadTestConfiguration()
"Configuration.json"));
if (File.Exists(configFilename))
{
using StreamReader file = File.OpenText(configFilename);
using JsonTextReader reader = new JsonTextReader(file);
JsonSerializer serializer = new JsonSerializer();
return serializer.Deserialize<Configuration>(reader);
using FileStream file = File.OpenRead(configFilename);
return JsonSerializer.Deserialize<Configuration>(file)
?? throw new Exception("Configuration file is empty or invalid");
}

Configuration config = LoadFromEnv();

return config;
}

private static Configuration LoadFromEnv()
{
string jsonStr = JsonConvert.SerializeObject(new Configuration());
JObject obj = JObject.Parse(jsonStr);
foreach (KeyValuePair<string, JToken> i in obj)
// Serialize default config to JSON then to a dictionary
string jsonStr = JsonSerializer.Serialize(new Configuration());
var dict = JsonSerializer.Deserialize<Dictionary<string, object>>(jsonStr);

if (dict == null)
throw new Exception("Default configuration invalid");

foreach (var key in new List<string>(dict.Keys))
{
if (!(i.Value.Type == JTokenType.String || i.Value.Type == JTokenType.Null))
{
var value = dict[key];

// Accept strings and nulls (JSON null becomes null here)
if (value != null && !(value is string))
continue;
}

string name = i.Key;
string envName = $"{ENV_NAME_PREFIX}{CamelCaseToUpper(name)}";
string envName = $"{ENV_NAME_PREFIX}{CamelCaseToUpper(key)}";
string envValue = Environment.GetEnvironmentVariable(envName);
if (!string.IsNullOrEmpty(envValue))
{
obj[name] = envValue;
dict[key] = envValue;
}
}

return JsonConvert.DeserializeObject<Configuration>(obj.ToString());
// Serialize back and then deserialize to Configuration
string updatedJson = JsonSerializer.Serialize(dict);
var config = JsonSerializer.Deserialize<Configuration>(updatedJson);
if (config == null)
throw new Exception("Failed to create Configuration from environment variables");
return config;
}

private static string CamelCaseToUpper(string name)
Expand Down
4 changes: 2 additions & 2 deletions examples/GenerateQR/GenerateQR.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Aspose.BarCode-Cloud" Version="25.3.0" />
<PackageReference Include="Aspose.BarCode-Cloud" Version="25.4.0" />
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions examples/ReadQR/ReadQR.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Aspose.BarCode-Cloud" Version="25.3.0" />
<PackageReference Include="Aspose.BarCode-Cloud" Version="25.4.0" />
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions snippets/Snippets.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Aspose.BarCode-Cloud" Version="25.3.0" />
<PackageReference Include="Aspose.BarCode-Cloud" Version="25.4.0" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion snippets/dependency.xml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<PackageReference Include="Aspose.BarCode-Cloud" Version="25.3.0" />
<PackageReference Include="Aspose.BarCode-Cloud" Version="25.4.0" />
5 changes: 2 additions & 3 deletions src/Api/Configuration.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System.Text.Json.Serialization;

namespace Aspose.BarCode.Cloud.Sdk.Api
{
Expand Down Expand Up @@ -71,7 +70,7 @@ public string JwtToken
/// <summary>
/// Authentication type.
/// </summary>
[JsonConverter(typeof(StringEnumConverter))]
[JsonConverter(typeof(JsonStringEnumConverter))]
public AuthType AuthType { get; private set; }

/// <summary>
Expand Down
8 changes: 4 additions & 4 deletions src/Aspose.BarCode.Cloud.Sdk.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ Aspose.Barcode for Cloud allows you to control all aspects of the image and barc
<PackageId>Aspose.BarCode-Cloud</PackageId>
<Product>Aspose.BarCode Cloud SDK for .NET</Product>
<PackageIcon>PackageIcon.png</PackageIcon>
<Version>25.3.0</Version>
<Version>25.4.0</Version>
<Authors>Aspose</Authors>
<AssemblyVersion>25.3.0.0</AssemblyVersion>
<AssemblyVersion>25.4.0.0</AssemblyVersion>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageReleaseNotes>https://github.com/aspose-barcode-cloud/aspose-barcode-cloud-dotnet/releases/tag/v25.3.0</PackageReleaseNotes>
<PackageReleaseNotes>https://github.com/aspose-barcode-cloud/aspose-barcode-cloud-dotnet/releases/tag/v25.4.0</PackageReleaseNotes>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
Expand All @@ -48,7 +48,7 @@ Aspose.Barcode for Cloud allows you to control all aspects of the image and barc

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="System.Text.Json" Version="9.0.4" />
</ItemGroup>

<ItemGroup>
Expand Down
9 changes: 5 additions & 4 deletions src/Internal/RequestHandlers/JWTRequestHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
using System.Threading.Tasks;
using Aspose.BarCode.Cloud.Sdk.Api;
using Aspose.BarCode.Cloud.Sdk.Interfaces;
using Newtonsoft.Json;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Aspose.BarCode.Cloud.Sdk.Internal.RequestHandlers
{
Expand Down Expand Up @@ -198,13 +199,13 @@ public async Task ProcessResponseAsync(HttpResponseMessage response)

private class GetAccessTokenResult
{
[JsonProperty(PropertyName = "access_token")]
[JsonPropertyName("access_token")]
public string AccessToken { get; set; }

[JsonProperty(PropertyName = "expires_in")]
[JsonPropertyName("expires_in")]
public long ExpiresIn { get; set; }

[JsonProperty(PropertyName = "token_type")]
[JsonPropertyName("token_type")]
public string TokenType { get; set; }
}
}
Expand Down
Loading