Skip to content

Commit

Permalink
Release 24.4 (#86)
Browse files Browse the repository at this point in the history
* Add ScanBarcode endpoint

* Version 24.4.0

* Drop outdated 'netcoreapp3.1' support

* Update examples
  • Loading branch information
Denis-Averin committed Apr 29, 2024
1 parent 9aed71f commit f3663e2
Show file tree
Hide file tree
Showing 132 changed files with 429 additions and 2,518 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/dotnet-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ jobs:
# and https://github.com/dotnet/core/blob/main/releases.md
# for versions
include:
- dotnet-version: 3.1.x
framework: netcoreapp3.1
- dotnet-version: 6.0.x
framework: net6.0
- dotnet-version: 7.0.x
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/net-framework.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
run: |
$ErrorActionPreference = "Stop"
VSTest.Console.exe /Framework:".NETFramework,Version=${{ matrix.net-version }}" /ResultsDirectory:Tests\Results /Logger:"trx;LogFileName=test.log" Tests\bin\Release\${{ matrix.framework }}\Aspose.BarCode.Cloud.Sdk.Tests.dll
if( ([xml](Get-Content Tests\Results\test.log)).TestRun.ResultSummary.Counters.total -ne 26 ){ throw "Not all tests were explored or added new tests" }
if( ([xml](Get-Content Tests\Results\test.log)).TestRun.ResultSummary.Counters.total -ne 28 ){ throw "Not all tests were explored or added new tests" }
env:
TEST_CONFIGURATION_JWT_TOKEN: ${{ secrets.TEST_CONFIGURATION_ACCESS_TOKEN }}
54 changes: 24 additions & 30 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: 3.0
- SDK version: 24.3.0
- SDK version: 24.4.0

## Demo applications

Expand Down Expand Up @@ -69,6 +69,7 @@ using Aspose.BarCode.Cloud.Sdk.Interfaces;
using Aspose.BarCode.Cloud.Sdk.Model;
using Aspose.BarCode.Cloud.Sdk.Model.Requests;
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Threading.Tasks;
Expand All @@ -79,7 +80,7 @@ internal static class Program
{
private static Configuration MakeConfiguration()
{
Configuration config = new Configuration();
var config = new Configuration();

string? envToken = Environment.GetEnvironmentVariable("TEST_CONFIGURATION_JWT_TOKEN");
if (string.IsNullOrEmpty(envToken))
Expand All @@ -97,18 +98,15 @@ internal static class Program

private static async Task<string> ReadQR(IBarcodeApi api, string fileName)
{
await using (FileStream imageStream = File.OpenRead(fileName))
{
BarcodeResponseList recognized = await api.PostBarcodeRecognizeFromUrlOrContentAsync(
new PostBarcodeRecognizeFromUrlOrContentRequest(image: imageStream)
{
Type = DecodeBarcodeType.QR.ToString(),
Preset = PresetType.HighPerformance.ToString(),
}
);

return recognized.Barcodes[0].BarcodeValue;
}
await using FileStream imageStream = File.OpenRead(fileName);
BarcodeResponseList recognized = await api.ScanBarcodeAsync(
new ScanBarcodeRequest(imageStream)
{
decodeTypes = new List<DecodeBarcodeType> { DecodeBarcodeType.QR }
}
);

return recognized.Barcodes[0].BarcodeValue;
}

public static async Task Main(string[] args)
Expand All @@ -119,7 +117,7 @@ internal static class Program
"qr.png"
));

BarcodeApi api = new BarcodeApi(MakeConfiguration());
var api = new BarcodeApi(MakeConfiguration());

string result = await ReadQR(api, fileName);
Console.WriteLine($"File '{fileName}' recognized, result: '{result}'");
Expand Down Expand Up @@ -148,7 +146,7 @@ internal static class Program
{
private static Configuration MakeConfiguration()
{
Configuration config = new Configuration();
var config = new Configuration();

string? envToken = Environment.GetEnvironmentVariable("TEST_CONFIGURATION_JWT_TOKEN");
if (string.IsNullOrEmpty(envToken))
Expand All @@ -166,21 +164,16 @@ internal static class Program

private static async Task GenerateQR(IBarcodeApi api, string fileName)
{
await using (Stream generated = await api.GetBarcodeGenerateAsync(
new GetBarcodeGenerateRequest(
EncodeBarcodeType.QR.ToString(),
"QR code text")
{
TextLocation = "None",
format = "png"
})
)
{
await using (FileStream stream = File.Create(fileName))
await using Stream generated = await api.GetBarcodeGenerateAsync(
new GetBarcodeGenerateRequest(
EncodeBarcodeType.QR.ToString(),
"QR code text")
{
await generated.CopyToAsync(stream);
}
}
TextLocation = CodeLocation.None.ToString(),
format = "png"
});
await using FileStream stream = File.Create(fileName);
await generated.CopyToAsync(stream);
}

public static async Task Main(string[] args)
Expand Down Expand Up @@ -230,6 +223,7 @@ Class | Method | HTTP request | Description
*BarcodeApi* | [**PutBarcodeGenerateFile**](docs/BarcodeApi.md#putbarcodegeneratefile) | **PUT** /barcode/{name}/generate | Generate barcode and save on server (from query params or from file with json or xml content)
*BarcodeApi* | [**PutBarcodeRecognizeFromBody**](docs/BarcodeApi.md#putbarcoderecognizefrombody) | **PUT** /barcode/{name}/recognize | Recognition of a barcode from file on server with parameters in body.
*BarcodeApi* | [**PutGenerateMultiple**](docs/BarcodeApi.md#putgeneratemultiple) | **PUT** /barcode/{name}/generateMultiple | Generate image with multiple barcodes and put new file on server
*BarcodeApi* | [**ScanBarcode**](docs/BarcodeApi.md#scanbarcode) | **POST** /barcode/scan | Quickly scan a barcode from an image.
*FileApi* | [**CopyFile**](docs/FileApi.md#copyfile) | **PUT** /barcode/storage/file/copy/{srcPath} | Copy file
*FileApi* | [**DeleteFile**](docs/FileApi.md#deletefile) | **DELETE** /barcode/storage/file/{path} | Delete file
*FileApi* | [**DownloadFile**](docs/FileApi.md#downloadfile) | **GET** /barcode/storage/file/{path} | Download file
Expand Down
2 changes: 0 additions & 2 deletions Tests/ApiExceptionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
using Aspose.BarCode.Cloud.Sdk.Model;
using Aspose.BarCode.Cloud.Sdk.Model.Requests;
using NUnit.Framework;
using System;
using System.Threading.Tasks;

namespace Aspose.BarCode.Cloud.Sdk.Tests
{
Expand Down
42 changes: 21 additions & 21 deletions Tests/Aspose.BarCode.Cloud.Sdk.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netcoreapp3.1;net462;net480;net481;net6.0;net7.0;net8.0</TargetFrameworks>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<IsTestProject>true</IsTestProject>
<LangVersion>8.0</LangVersion>
</PropertyGroup>
<ItemGroup>
<Compile Remove="TestResults\**" />
<EmbeddedResource Remove="TestResults\**" />
<None Remove="TestResults\**" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Moq" Version="4.20.70" />
<PackageReference Include="NUnit" Version="3.14.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\src\Aspose.BarCode.Cloud.Sdk.csproj" />
</ItemGroup>
<PropertyGroup>
<TargetFrameworks>net462;net480;net481;net6.0;net7.0;net8.0</TargetFrameworks>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<IsTestProject>true</IsTestProject>
<LangVersion>8.0</LangVersion>
</PropertyGroup>
<ItemGroup>
<Compile Remove="TestResults\**"/>
<EmbeddedResource Remove="TestResults\**"/>
<None Remove="TestResults\**"/>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Moq" Version="4.20.70"/>
<PackageReference Include="NUnit" Version="3.14.0"/>
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0"/>
<PackageReference Include="System.Net.Http" Version="4.3.4"/>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\src\Aspose.BarCode.Cloud.Sdk.csproj"/>
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion Tests/BarcodeApiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public async Task PostBarcodeRecognizeFromUrlOrContentAsyncTest()
{
ChecksumValidation = ChecksumValidation.Off.ToString(),
Preset = PresetType.HighPerformance.ToString(),
Types = new List<DecodeBarcodeType> { DecodeBarcodeType.Code11 },
Types = new List<DecodeBarcodeType> { DecodeBarcodeType.Code11 }
}
);

Expand Down
8 changes: 4 additions & 4 deletions Tests/Configuration.template.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"ClientId": "Client Id from https://dashboard.aspose.cloud/applications",
"ClientSecret": "Client Secret from https://dashboard.aspose.cloud/applications",
"ApiBaseUrl": "https://api.aspose.cloud",
"TokenUrl":"https://api.aspose.cloud/connect/token"
"ClientId": "Client Id from https://dashboard.aspose.cloud/applications",
"ClientSecret": "Client Secret from https://dashboard.aspose.cloud/applications",
"ApiBaseUrl": "https://api.aspose.cloud",
"TokenUrl": "https://api.aspose.cloud/connect/token"
}
4 changes: 2 additions & 2 deletions Tests/JWTRequestHandlerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ public void TestTokenFetched()

// assert
Assert.Contains("Authorization", request.Headers.Keys);
var auth = request.Headers["Authorization"];
string auth = request.Headers["Authorization"];
Assert.Greater(auth.Length, "Bearer ".Length);
var token = auth.Substring("Bearer ".Length);
string token = auth.Substring("Bearer ".Length);
AssertTokenIsValid(token);
}

Expand Down
4 changes: 2 additions & 2 deletions Tests/JwtAuthTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public async Task CanUseExternalTokenWithAsync()
var api = new BarcodeApi(configWithToken);
using Stream generated = await api.GetBarcodeGenerateAsync(
new GetBarcodeGenerateRequest(
EncodeBarcodeType.QR.ToString(), "Test")
);
EncodeBarcodeType.QR.ToString(), "Test")
);
Assert.Greater(generated.Length, 0);
}
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/RecognizeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public async Task RecognizeQrAsyncTest()
new PostBarcodeRecognizeFromUrlOrContentRequest(image)
{
Preset = PresetType.HighPerformance.ToString(),
Types = new List<DecodeBarcodeType> { DecodeBarcodeType.QR },
Types = new List<DecodeBarcodeType> { DecodeBarcodeType.QR }
}
);

Expand Down
67 changes: 67 additions & 0 deletions Tests/ScanTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using Aspose.BarCode.Cloud.Sdk.Api;
using Aspose.BarCode.Cloud.Sdk.Interfaces;
using Aspose.BarCode.Cloud.Sdk.Model;
using Aspose.BarCode.Cloud.Sdk.Model.Requests;
using NUnit.Framework;

namespace Aspose.BarCode.Cloud.Sdk.Tests
{
[TestFixture]
public class ScanTests : TestsBase
{
private IBarcodeApi _api;

[SetUp]
public void Init()
{
_api = new BarcodeApi(TestConfiguration);
}


[Test]
public async Task ScanBarcodeAsyncTest()
{
// Arrange
using Stream image = GetTestImage("Test_PostGenerateMultiple.png");

// Act
BarcodeResponseList response = await _api.ScanBarcodeAsync(
new ScanBarcodeRequest(image)
{
decodeTypes = new List<DecodeBarcodeType> { DecodeBarcodeType.Code128, DecodeBarcodeType.QR }
}
);

// Assert
Assert.AreEqual(2, response.Barcodes.Count);
Assert.AreEqual(DecodeBarcodeType.QR.ToString(), response.Barcodes[0].Type);
Assert.AreEqual("Hello world!", response.Barcodes[0].BarcodeValue);
}


[Test]
public void ScanBarcodeAsyncTimeoutTest()
{
// Arrange
using Stream image = GetTestImage("Test_PostGenerateMultiple.png");

// Act
var apiException = Assert.ThrowsAsync<ApiException>(async () =>
{
await _api.ScanBarcodeAsync(
new ScanBarcodeRequest(image)
{
timeout = 1
}
);
});

// Assert
Assert.IsNotNull(apiException);
Assert.AreEqual(408, apiException.ErrorCode);
}
}
}
1 change: 0 additions & 1 deletion Tests/TestsBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ private static Configuration LoadTestConfiguration()

private static Configuration LoadFromEnv()
{

string jsonStr = JsonConvert.SerializeObject(new Configuration());
JObject obj = JObject.Parse(jsonStr);
foreach (KeyValuePair<string, JToken> i in obj)
Expand Down
2 changes: 1 addition & 1 deletion docs/AustralianPostParams.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ AustralianPost barcode parameters.

Name | Type | Description | Notes
---- | ---- | ----------- | -----
**EncodingTable** | **CustomerInformationInterpretingType** | Interpreting type for the Customer Information of AustralianPost, default to CustomerInformationInterpretingType.Other\&quot; | [optional]
**EncodingTable** | **CustomerInformationInterpretingType** | Interpreting type for the Customer Information of AustralianPost, default to CustomerInformationInterpretingType.Other | [optional]
**ShortBarHeight** | **double?** | Short bar&#39;s height of AustralianPost barcode. | [optional]
31 changes: 29 additions & 2 deletions docs/BarcodeApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Method | HTTP request | Description
[**PutBarcodeGenerateFile**](BarcodeApi.md#putbarcodegeneratefile) | **PUT** /barcode/{name}/generate | Generate barcode and save on server (from query params or from file with json or xml content)
[**PutBarcodeRecognizeFromBody**](BarcodeApi.md#putbarcoderecognizefrombody) | **PUT** /barcode/{name}/recognize | Recognition of a barcode from file on server with parameters in body.
[**PutGenerateMultiple**](BarcodeApi.md#putgeneratemultiple) | **PUT** /barcode/{name}/generateMultiple | Generate image with multiple barcodes and put new file on server
[**ScanBarcode**](BarcodeApi.md#scanbarcode) | **POST** /barcode/scan | Quickly scan a barcode from an image.


## **GetBarcodeGenerate**
Expand Down Expand Up @@ -116,7 +117,7 @@ Name | Type | Description | Notes
**allowAdditionalRestorations** | **bool?**| Allows engine using additional image restorations to recognize corrupted barcodes. At this time, it is used only in MicroPdf417 barcode type. Default value: False. | [optional]
**regionLikelihoodThresholdPercent** | **double?**| Sets threshold for detected regions that may contain barcodes. Value 0.7 means that bottom 70% of possible regions are filtered out and not processed further. Region likelihood threshold must be between [0.05, 0.9] Use high values for clear images with few barcodes. Use low values for images with many barcodes or for noisy images. Low value may lead to a bigger recognition time. | [optional]
**scanWindowSizes** | [**List&lt;int?&gt;**](int?.md)| Scan window sizes in pixels. Allowed sizes are 10, 15, 20, 25, 30. Scanning with small window size takes more time and provides more accuracy but may fail in detecting very big barcodes. Combining of several window sizes can improve detection quality. | [optional]
**similarity** | **double?**| Similarity coefficient depends on how homogeneous barcodes are. Use high value for for clear barcodes. Use low values to detect barcodes that ara partly damaged or not lighten evenly. Similarity coefficient must be between [0.5, 0.9] | [optional]
**similarity** | **double?**| Similarity coefficient depends on how homogeneous barcodes are. Use high value for clear barcodes. Use low values to detect barcodes that ara partly damaged or not lighten evenly. Similarity coefficient must be between [0.5, 0.9] | [optional]
**skipDiagonalSearch** | **bool?**| Allows detector to skip search for diagonal barcodes. Setting it to false will increase detection time but allow to find diagonal barcodes that can be missed otherwise. Enabling of diagonal search leads to a bigger detection time. | [optional]
**readTinyBarcodes** | **bool?**| Allows engine to recognize tiny barcodes on large images. Ignored if AllowIncorrectBarcodes is set to True. Default value: False. | [optional]
**australianPostEncodingTable** | **string**| Interpreting Type for the Customer Information of AustralianPost BarCode.Default is CustomerInformationInterpretingType.Other. | [optional]
Expand Down Expand Up @@ -177,7 +178,7 @@ Name | Type | Description | Notes
**allowAdditionalRestorations** | **bool?**| Allows engine using additional image restorations to recognize corrupted barcodes. At this time, it is used only in MicroPdf417 barcode type. Default value: False. | [optional]
**regionLikelihoodThresholdPercent** | **double?**| Sets threshold for detected regions that may contain barcodes. Value 0.7 means that bottom 70% of possible regions are filtered out and not processed further. Region likelihood threshold must be between [0.05, 0.9] Use high values for clear images with few barcodes. Use low values for images with many barcodes or for noisy images. Low value may lead to a bigger recognition time. | [optional]
**scanWindowSizes** | [**List&lt;int?&gt;**](int?.md)| Scan window sizes in pixels. Allowed sizes are 10, 15, 20, 25, 30. Scanning with small window size takes more time and provides more accuracy but may fail in detecting very big barcodes. Combining of several window sizes can improve detection quality. | [optional]
**similarity** | **double?**| Similarity coefficient depends on how homogeneous barcodes are. Use high value for for clear barcodes. Use low values to detect barcodes that ara partly damaged or not lighten evenly. Similarity coefficient must be between [0.5, 0.9] | [optional]
**similarity** | **double?**| Similarity coefficient depends on how homogeneous barcodes are. Use high value for clear barcodes. Use low values to detect barcodes that ara partly damaged or not lighten evenly. Similarity coefficient must be between [0.5, 0.9] | [optional]
**skipDiagonalSearch** | **bool?**| Allows detector to skip search for diagonal barcodes. Setting it to false will increase detection time but allow to find diagonal barcodes that can be missed otherwise. Enabling of diagonal search leads to a bigger detection time. | [optional]
**readTinyBarcodes** | **bool?**| Allows engine to recognize tiny barcodes on large images. Ignored if AllowIncorrectBarcodes is set to True. Default value: False. | [optional]
**australianPostEncodingTable** | **string**| Interpreting Type for the Customer Information of AustralianPost BarCode.Default is CustomerInformationInterpretingType.Other. | [optional]
Expand Down Expand Up @@ -337,3 +338,29 @@ Name | Type | Description | Notes
- **Content-Type**: application/json, application/xml
- **Accept**: application/json


## **ScanBarcode**

```csharp
BarcodeResponseList ScanBarcode (System.IO.Stream imageFile, List<DecodeBarcodeType> decodeTypes = null, int? timeout = null)
```

Quickly scan a barcode from an image.

### Parameters

Name | Type | Description | Notes
---- | ---- | ------------ | -----
**imageFile** | **System.IO.Stream**| Image as file |
**decodeTypes** | [**List&lt;DecodeBarcodeType&gt;**](DecodeBarcodeType.md)| Types of barcode to recognize | [optional]
**timeout** | **int?**| Timeout of recognition process in milliseconds. Default value is 15_000 (15 seconds). Maximum value is 30_000 (1/2 minute). In case of a timeout RequestTimeout (408) status will be returned. Try reducing the image size to avoid timeout. | [optional]

### Return type

[**BarcodeResponseList**](BarcodeResponseList.md)

### HTTP request headers

- **Content-Type**: multipart/form-data
- **Accept**: application/json

0 comments on commit f3663e2

Please sign in to comment.