Skip to content

Commit dba06ea

Browse files
authored
Release 22.1.1 (#36)
* Examples added * Fix ApiInvoker code
1 parent 8b4de8a commit dba06ea

File tree

137 files changed

+1604
-2360
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

137 files changed

+1604
-2360
lines changed

.github/workflows/check-urls.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ on:
1111
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
1212
jobs:
1313
# This workflow contains a single job called "build"
14-
build:
14+
check-urls:
1515
# The type of runner that the job will run on
1616
runs-on: ubuntu-latest
1717

.github/workflows/net-framework.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ jobs:
2323
run: msbuild -restore -p:Configuration=Release
2424

2525
- name: Test with VSTest
26-
run: VSTest.Console.exe Tests\bin\Release\net461\Aspose.BarCode.Cloud.Sdk.Tests.dll
26+
run: VSTest.Console.exe /Framework:".NETFramework,Version=v4.6.1" Tests\bin\Release\net461\Aspose.BarCode.Cloud.Sdk.Tests.dll
2727
env:
2828
TEST_CONFIGURATION_JWT_TOKEN: ${{ secrets.TEST_CONFIGURATION_ACCESS_TOKEN }}

Makefile

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ all: test
33

44
.PHONY: format
55
format:
6-
dotnet format ./Aspose.BarCode.Cloud.Sdk.sln
6+
find . -iname "*.cs" -exec sed -i -e 's_[[:space:]]*$$__' {} \;
7+
~/.dotnet/tools/dotnet-format ./Aspose.BarCode.Cloud.Sdk.sln
8+
9+
.PHONY: format-doc
10+
format-doc:
11+
find . -iname "*.md" -exec sed -i -e 's_[[:space:]]*$$__' {} \;
712

813
.PHONY: test
914
test:
@@ -12,3 +17,10 @@ test:
1217
.PHONY: update
1318
update:
1419
echo "Not implemented"
20+
21+
.PHONY: insert-examples
22+
insert-examples:
23+
./scripts/insert-examples.bash
24+
25+
.PHONY: after-gen
26+
after-gen: insert-examples format format-doc

README.md

Lines changed: 134 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,19 @@
1313

1414
## Demo applications
1515

16-
[Generate Barcode](https://products.aspose.app/barcode/generate) | [Recognize Barcode](https://products.aspose.app/barcode/recognize) | [Embed Barcode](https://products.aspose.app/barcode/embed)
17-
:---: | :---: | :---:
18-
[![Generate](https://products.aspose.app/barcode/generate/img/aspose_generate-app-48.png)](https://products.aspose.app/barcode/generate) | [![Recognize](https://products.aspose.app/barcode/recognize/img/aspose_recognize-app-48.png)](https://products.aspose.app/barcode/recognize) | [![Embed](https://products.aspose.app/barcode/embed/img/aspose_embed-app-48.png)](https://products.aspose.app/barcode/embed)
16+
[Scan QR](https://products.aspose.app/barcode/scanqr) | [Generate Barcode](https://products.aspose.app/barcode/generate) | [Recognize Barcode](https://products.aspose.app/barcode/recognize) | [Embed Barcode](https://products.aspose.app/barcode/embed)
17+
:---: | :---: | :---: | :---:
18+
[![ScanQR](https://products.aspose.app/barcode/scanqr/img/aspose_scanqr-app-48.png)](https://products.aspose.app/barcode/scanqr) | [![Generate](https://products.aspose.app/barcode/generate/img/aspose_generate-app-48.png)](https://products.aspose.app/barcode/generate) | [![Recognize](https://products.aspose.app/barcode/recognize/img/aspose_recognize-app-48.png)](https://products.aspose.app/barcode/recognize) | [![Embed](https://products.aspose.app/barcode/embed/img/aspose_embed-app-48.png)](https://products.aspose.app/barcode/embed)
1919

2020
[Aspose.BarCode for Cloud](https://products.aspose.cloud/barcode/) is a REST API for Linear, 2D and postal barcode generation and recognition in the cloud. API recognizes and generates barcode images in a variety of formats. Barcode REST API allows to specify barcode image attributes like image width, height, border style and output image format in order to customize the generation process. Developers can also specify the barcode type and text attributes such as text location and font styles in order to suit the application requirements.
2121

22-
This repository contains Aspose.BarCode Cloud SDK for .NET source code. This SDK allows you to work with Aspose.BarCode for Cloud REST APIs in your .NET Core or .NET Standard applications quickly and easily.
22+
This repository contains Aspose.BarCode Cloud SDK for .NET source code. This SDK allows you to work with Aspose.BarCode for Cloud REST APIs in your .NET Core or .NET Framework applications quickly and easily.
2323

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

26-
- .NET Standard 2.0
27-
- .NET Framework 2.0 and higher
26+
- .NET Standard 2.0 and higher
27+
- .NET Core 2.1 and higher
28+
- .NET Framework 4.6.1 and higher
2829

2930
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).
3031

@@ -58,27 +59,142 @@ From within Visual Studio:
5859
4. Click on the *Browse* tab and search for "Aspose.BarCode-Cloud".
5960
5. Click on the Aspose.BarCode-Cloud package, select the appropriate version in the right-tab and click *Install*.
6061

61-
## Sample usage
62+
## Recognize QR code
6263

63-
The examples below show how you can generate Code128 barcode and save it into local file using Aspose.BarCode-Cloud library:
64+
The examples below show how you can recognize QR code from image:
6465

6566
```csharp
66-
const string clientId = "Client Id from https://dashboard.aspose.cloud/applications";
67-
const string clientSecret = "Client Secret from https://dashboard.aspose.cloud/applications";
67+
using Aspose.BarCode.Cloud.Sdk.Api;
68+
using Aspose.BarCode.Cloud.Sdk.Interfaces;
69+
using Aspose.BarCode.Cloud.Sdk.Model;
70+
using Aspose.BarCode.Cloud.Sdk.Model.Requests;
71+
using System;
72+
using System.IO;
73+
using System.Reflection;
74+
75+
namespace ReadQR
76+
{
77+
class Program
78+
{
79+
static Configuration MakeConfiguration()
80+
{
81+
var config = new Configuration();
82+
83+
var envToken = Environment.GetEnvironmentVariable("TEST_CONFIGURATION_JWT_TOKEN");
84+
if (string.IsNullOrEmpty(envToken))
85+
{
86+
config.ClientId = "Client Id from https://dashboard.aspose.cloud/applications";
87+
config.ClientSecret = "Client Secret from https://dashboard.aspose.cloud/applications";
88+
}
89+
else
90+
{
91+
config.JwtToken = envToken;
92+
}
93+
94+
return config;
95+
}
96+
97+
static string ReadQR(IBarcodeApi api, string fileName)
98+
{
99+
using (FileStream imageStream = File.OpenRead(fileName))
100+
{
101+
BarcodeResponseList recognized = api.PostBarcodeRecognizeFromUrlOrContent(
102+
new PostBarcodeRecognizeFromUrlOrContentRequest(image: imageStream)
103+
);
104+
105+
return recognized.Barcodes[0].BarcodeValue;
106+
}
107+
}
108+
109+
static void Main(string[] args)
110+
{
111+
string fileName = Path.GetFullPath(Path.Join(
112+
Path.GetDirectoryName(Assembly.GetEntryAssembly().Location),
113+
"..", "..", "..", "..",
114+
"qr.png"
115+
));
116+
117+
var api = new BarcodeApi(MakeConfiguration());
118+
119+
string result = ReadQR(api, fileName);
120+
Console.WriteLine($"File '{fileName}' recognized, result: '{result}'");
121+
}
122+
}
123+
}
68124

69-
var api = new BarcodeApi(clientSecret, clientId);
125+
```
126+
127+
## Generate QR code
128+
129+
The examples below show how you can generate QR code and save it into local file using Aspose.BarCode-Cloud library:
130+
131+
```csharp
132+
using Aspose.BarCode.Cloud.Sdk.Api;
133+
using Aspose.BarCode.Cloud.Sdk.Interfaces;
134+
using Aspose.BarCode.Cloud.Sdk.Model;
135+
using Aspose.BarCode.Cloud.Sdk.Model.Requests;
136+
using System;
137+
using System.IO;
138+
using System.Reflection;
139+
140+
namespace GenerateQR
141+
{
142+
class Program
143+
{
144+
static Configuration MakeConfiguration()
145+
{
146+
var config = new Configuration();
147+
148+
var envToken = Environment.GetEnvironmentVariable("TEST_CONFIGURATION_JWT_TOKEN");
149+
if (string.IsNullOrEmpty(envToken))
150+
{
151+
config.ClientId = "Client Id from https://dashboard.aspose.cloud/applications";
152+
config.ClientSecret = "Client Secret from https://dashboard.aspose.cloud/applications";
153+
}
154+
else
155+
{
156+
config.JwtToken = envToken;
157+
}
158+
159+
return config;
160+
}
161+
162+
static void GenerateQR(IBarcodeApi api, string fileName)
163+
{
164+
using (Stream generated = api.GetBarcodeGenerate(
165+
new GetBarcodeGenerateRequest(
166+
EncodeBarcodeType.QR.ToString(),
167+
"QR code text",
168+
textLocation: "None", format: "png"))
169+
)
170+
{
171+
using (FileStream stream = File.Create(fileName))
172+
{
173+
generated.CopyTo(stream);
174+
}
175+
}
176+
}
177+
178+
static void Main(string[] args)
179+
{
180+
string fileName = Path.GetFullPath(Path.Join(
181+
Path.GetDirectoryName(Assembly.GetEntryAssembly().Location),
182+
"..", "..", "..", "..",
183+
"qr.png"
184+
));
185+
186+
var api = new BarcodeApi(MakeConfiguration());
187+
188+
GenerateQR(api, fileName);
189+
Console.WriteLine($"File '{fileName}' generated.");
190+
}
191+
}
192+
}
70193

71-
using Stream response = api.GetBarcodeGenerate(
72-
new GetBarcodeGenerateRequest(
73-
EncodeBarcodeType.Code128.ToString(), "Sample text", format: "png")
74-
);
75-
using FileStream stream = File.Create("out.png");
76-
response.CopyTo(stream);
77194
```
78195

79196
## Dependencies
80197

81-
- .NET Framework 2.0 or later, .NET Standard 2.0
82198
- [Json.NET](https://www.nuget.org/packages/Newtonsoft.Json/)
83199

84200
## Licensing

Tests/BarcodeApiTests.cs

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ public void GetBarcodeGenerateTest()
8484
public void GetBarcodeRecognizeTest()
8585
{
8686
// Arrange
87-
var barcodesToRecognize = new List<GeneratorParams>
87+
const string fileName = "Test_PostGenerateMultiple.png";
88+
89+
var expectedBarcodes = new List<GeneratorParams>
8890
{
8991
new GeneratorParams
9092
{
@@ -98,22 +100,22 @@ public void GetBarcodeRecognizeTest()
98100
}
99101
};
100102

101-
const string fileName = "Test_PostGenerateMultiple.png";
102103
string folder = PutTestFile(fileName);
103-
var request = new GetBarcodeRecognizeRequest(
104-
fileName,
105-
folder: folder,
106-
preset: PresetType.HighPerformance.ToString()
107-
);
108104

109105
// Act
110-
BarcodeResponseList response = _api.GetBarcodeRecognize(request);
106+
BarcodeResponseList response = _api.GetBarcodeRecognize(
107+
new GetBarcodeRecognizeRequest(
108+
fileName,
109+
folder: folder,
110+
preset: PresetType.HighPerformance.ToString()
111+
)
112+
);
111113

112114
// Assert
113-
Assert.AreEqual(barcodesToRecognize.Count, response.Barcodes.Count);
115+
Assert.AreEqual(expectedBarcodes.Count, response.Barcodes.Count);
114116

115117
foreach ((GeneratorParams generated, BarcodeResponse recognized) in
116-
barcodesToRecognize.Zip(response.Barcodes,
118+
expectedBarcodes.Zip(response.Barcodes,
117119
(generated, recognized) => (generated, recognized)))
118120
{
119121
Assert.AreEqual(generated.TypeOfBarcode.ToString(), recognized.Type);
@@ -139,18 +141,16 @@ public void InstanceTest()
139141
public void PostBarcodeRecognizeFromUrlOrContentTest()
140142
{
141143
// Arrange
142-
BarcodeResponseList response;
143-
using (Stream image = GetTestImage("1.png"))
144-
{
145-
var request = new PostBarcodeRecognizeFromUrlOrContentRequest(
144+
using Stream image = GetTestImage("1.png");
145+
146+
// Act
147+
BarcodeResponseList response = _api.PostBarcodeRecognizeFromUrlOrContent(
148+
new PostBarcodeRecognizeFromUrlOrContentRequest(
146149
image: image,
147150
checksumValidation: ChecksumValidation.Off.ToString(),
148151
preset: PresetType.HighPerformance.ToString()
149-
);
150-
151-
// Act
152-
response = _api.PostBarcodeRecognizeFromUrlOrContent(request);
153-
}
152+
)
153+
);
154154

155155
// Assert
156156
Assert.AreEqual(1, response.Barcodes.Count);
@@ -187,8 +187,8 @@ public void PostGenerateMultipleTest()
187187

188188
// Act
189189
using Stream response = _api.PostGenerateMultiple(request);
190-
// Assert
191190

191+
// Assert
192192
Assert.IsTrue(response.Length > 0);
193193
using FileStream savedFileStream = File.Create(TestFilePath("Test_PostGenerateMultiple.png"));
194194
response.CopyTo(savedFileStream);
@@ -204,8 +204,8 @@ public void PutBarcodeGenerateFileTest()
204204
// Arrange
205205
var request = new PutBarcodeGenerateFileRequest(
206206
"Test_PutBarcodeGenerateFile.png",
207-
EncodeBarcodeType.Code128.ToString(),
208-
"Hello!",
207+
type: EncodeBarcodeType.Code128.ToString(),
208+
text: "Hello!",
209209
folder: TempFolderPath
210210
);
211211

@@ -238,17 +238,17 @@ public void PutBarcodeRecognizeFromBodyTest()
238238
const string fileName = "Test_GetBarcodeGenerate.png";
239239
string folder = PutTestFile(fileName);
240240

241-
var request = new PutBarcodeRecognizeFromBodyRequest(
242-
fileName,
243-
new ReaderParams
244-
{
245-
Preset = PresetType.HighPerformance
246-
},
247-
folder: folder
248-
);
249-
250241
// Act
251-
BarcodeResponseList response = _api.PutBarcodeRecognizeFromBody(request);
242+
BarcodeResponseList response = _api.PutBarcodeRecognizeFromBody(
243+
new PutBarcodeRecognizeFromBodyRequest(
244+
fileName,
245+
readerParams: new ReaderParams
246+
{
247+
Preset = PresetType.HighPerformance
248+
},
249+
folder: folder
250+
)
251+
);
252252

253253
// Assert
254254
Assert.AreEqual(barcodesToRecognize.Count, response.Barcodes.Count);

Tests/GenerateAndThenRecognize.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.IO;
22
using System.Linq;
33
using Aspose.BarCode.Cloud.Sdk.Api;
4+
using Aspose.BarCode.Cloud.Sdk.Interfaces;
45
using Aspose.BarCode.Cloud.Sdk.Model;
56
using Aspose.BarCode.Cloud.Sdk.Model.Requests;
67
using NUnit.Framework;
@@ -16,7 +17,7 @@ public void Init()
1617
_api = new BarcodeApi(TestConfiguration);
1718
}
1819

19-
private BarcodeApi _api;
20+
private IBarcodeApi _api;
2021

2122
[Test]
2223
public void GenerateAndThenRecognizeTest()
@@ -32,6 +33,14 @@ public void GenerateAndThenRecognizeTest()
3233
Assert.AreEqual(1, recognized.Barcodes.Count);
3334
Assert.AreEqual(DecodeBarcodeType.QR.ToString(), recognized.Barcodes.First().Type);
3435
Assert.AreEqual("Test", recognized.Barcodes.First().BarcodeValue);
36+
Assert.AreEqual(
37+
"{\"barcodes\":[{" +
38+
"\"barcodeValue\":\"Test\"," +
39+
"\"type\":\"QR\"," +
40+
"\"region\":[{\"x\":7,\"y\":7},{\"x\":49,\"y\":7},{\"x\":49,\"y\":49},{\"x\":7,\"y\":49}]," +
41+
"\"checksum\":null}]}",
42+
recognized.ToString()
43+
);
3544
}
3645
}
3746
}

0 commit comments

Comments
 (0)