Skip to content

Commit b9834af

Browse files
authored
Dotnet releases (#78)
* Build examples with new NuGet package * Fix examples code
1 parent 80a485e commit b9834af

10 files changed

Lines changed: 127 additions & 86 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Build examples
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
build-examples:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v3
15+
- name: Setup latest version of dotnet
16+
uses: actions/setup-dotnet@v3
17+
- name: Build nuget with latest version
18+
run: ./scripts/pack-nuget.bash "examples/nuget-packages"
19+
- name: Build examples with new nuget
20+
run: dotnet build --warnaserror "examples/examples.sln"

.github/workflows/dotnet-core.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ jobs:
1313
strategy:
1414
matrix:
1515
# See https://learn.microsoft.com/en-us/lifecycle/products/microsoft-net-and-net-core
16-
# For versions
16+
# and https://github.com/dotnet/core/blob/main/releases.md
17+
# for versions
1718
include:
1819
- dotnet-version: 3.1.x
1920
framework: netcoreapp3.1
@@ -31,9 +32,7 @@ jobs:
3132
- name: Setup latest version of dotnet
3233
uses: actions/setup-dotnet@v3
3334
- name: Build with latest version
34-
run: |
35-
dotnet build --warnaserror Aspose.BarCode.Cloud.Sdk.sln
36-
dotnet build --warnaserror examples/examples.sln
35+
run: dotnet build --warnaserror Aspose.BarCode.Cloud.Sdk.sln
3736

3837
- name: Setup ${{ matrix.dotnet-version }} version of dotnet
3938
uses: actions/setup-dotnet@v3

Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ update:
3535
.PHONY: lint
3636
lint:
3737
dotnet build --warnaserror Aspose.BarCode.Cloud.Sdk.sln
38-
dotnet build --warnaserror examples/examples.sln
3938

4039
.PHONY: clean
4140
clean:

examples/GenerateQR/GenerateQR.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
55
<TargetFramework>net6.0</TargetFramework>
6+
<Nullable>enable</Nullable>
67
</PropertyGroup>
78

89
<ItemGroup>

examples/GenerateQR/Program.cs

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -5,60 +5,60 @@
55
using System;
66
using System.IO;
77
using System.Reflection;
8+
using System.Threading.Tasks;
89

9-
namespace GenerateQR
10+
namespace GenerateQR;
11+
12+
internal static class Program
1013
{
11-
class Program
14+
private static Configuration MakeConfiguration()
1215
{
13-
static Configuration MakeConfiguration()
14-
{
15-
var config = new Configuration();
16+
Configuration config = new Configuration();
1617

17-
var envToken = Environment.GetEnvironmentVariable("TEST_CONFIGURATION_JWT_TOKEN");
18-
if (string.IsNullOrEmpty(envToken))
19-
{
20-
config.ClientId = "Client Id from https://dashboard.aspose.cloud/applications";
21-
config.ClientSecret = "Client Secret from https://dashboard.aspose.cloud/applications";
22-
}
23-
else
24-
{
25-
config.JwtToken = envToken;
26-
}
27-
28-
return config;
18+
string? envToken = Environment.GetEnvironmentVariable("TEST_CONFIGURATION_JWT_TOKEN");
19+
if (string.IsNullOrEmpty(envToken))
20+
{
21+
config.ClientId = "Client Id from https://dashboard.aspose.cloud/applications";
22+
config.ClientSecret = "Client Secret from https://dashboard.aspose.cloud/applications";
2923
}
24+
else
25+
{
26+
config.JwtToken = envToken;
27+
}
28+
29+
return config;
30+
}
3031

31-
private static void GenerateQR(IBarcodeApi api, string fileName)
32+
private static async Task GenerateQR(IBarcodeApi api, string fileName)
33+
{
34+
await using (Stream generated = await api.GetBarcodeGenerateAsync(
35+
new GetBarcodeGenerateRequest(
36+
EncodeBarcodeType.QR.ToString(),
37+
"QR code text")
38+
{
39+
TextLocation = "None",
40+
format = "png"
41+
})
42+
)
3243
{
33-
using (Stream generated = api.GetBarcodeGenerate(
34-
new GetBarcodeGenerateRequest(
35-
EncodeBarcodeType.QR.ToString(),
36-
"QR code text")
37-
{
38-
TextLocation = "None",
39-
format = "png"
40-
})
41-
)
44+
await using (FileStream stream = File.Create(fileName))
4245
{
43-
using (FileStream stream = File.Create(fileName))
44-
{
45-
generated.CopyTo(stream);
46-
}
46+
await generated.CopyToAsync(stream);
4747
}
4848
}
49+
}
4950

50-
static void Main(string[] args)
51-
{
52-
string fileName = Path.GetFullPath(Path.Join(
53-
Path.GetDirectoryName(Assembly.GetEntryAssembly()!.Location),
54-
"..", "..", "..", "..",
55-
"qr.png"
56-
));
51+
public static async Task Main(string[] args)
52+
{
53+
string fileName = Path.GetFullPath(Path.Join(
54+
Path.GetDirectoryName(Assembly.GetEntryAssembly()!.Location),
55+
"..", "..", "..", "..",
56+
"qr.png"
57+
));
5758

58-
var api = new BarcodeApi(MakeConfiguration());
59+
BarcodeApi api = new BarcodeApi(MakeConfiguration());
5960

60-
GenerateQR(api, fileName);
61-
Console.WriteLine($"File '{fileName}' generated.");
62-
}
61+
await GenerateQR(api, fileName);
62+
Console.WriteLine($"File '{fileName}' generated.");
6363
}
6464
}

examples/ReadQR/Program.cs

Lines changed: 41 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5,53 +5,57 @@
55
using System;
66
using System.IO;
77
using System.Reflection;
8+
using System.Threading.Tasks;
89

9-
namespace ReadQR
10+
namespace ReadQR;
11+
12+
internal static class Program
1013
{
11-
internal static class Program
14+
private static Configuration MakeConfiguration()
1215
{
13-
private static Configuration MakeConfiguration()
16+
Configuration config = new Configuration();
17+
18+
string? envToken = Environment.GetEnvironmentVariable("TEST_CONFIGURATION_JWT_TOKEN");
19+
if (string.IsNullOrEmpty(envToken))
1420
{
15-
var config = new Configuration();
16-
17-
string envToken = Environment.GetEnvironmentVariable("TEST_CONFIGURATION_JWT_TOKEN");
18-
if (string.IsNullOrEmpty(envToken))
19-
{
20-
config.ClientId = "Client Id from https://dashboard.aspose.cloud/applications";
21-
config.ClientSecret = "Client Secret from https://dashboard.aspose.cloud/applications";
22-
}
23-
else
24-
{
25-
config.JwtToken = envToken;
26-
}
27-
28-
return config;
21+
config.ClientId = "Client Id from https://dashboard.aspose.cloud/applications";
22+
config.ClientSecret = "Client Secret from https://dashboard.aspose.cloud/applications";
2923
}
30-
31-
private static string ReadQR(IBarcodeApi api, string fileName)
24+
else
3225
{
33-
using (FileStream imageStream = File.OpenRead(fileName))
34-
{
35-
BarcodeResponseList recognized = api.PostBarcodeRecognizeFromUrlOrContent(
36-
new PostBarcodeRecognizeFromUrlOrContentRequest(image: imageStream)
37-
);
38-
39-
return recognized.Barcodes[0].BarcodeValue;
40-
}
26+
config.JwtToken = envToken;
4127
}
4228

43-
static void Main(string[] args)
29+
return config;
30+
}
31+
32+
private static async Task<string> ReadQR(IBarcodeApi api, string fileName)
33+
{
34+
await using (FileStream imageStream = File.OpenRead(fileName))
4435
{
45-
string fileName = Path.GetFullPath(Path.Join(
46-
Path.GetDirectoryName(Assembly.GetEntryAssembly()!.Location),
47-
"..", "..", "..", "..",
48-
"qr.png"
49-
));
36+
BarcodeResponseList recognized = await api.PostBarcodeRecognizeFromUrlOrContentAsync(
37+
new PostBarcodeRecognizeFromUrlOrContentRequest(image: imageStream)
38+
{
39+
Type = DecodeBarcodeType.QR.ToString(),
40+
Preset = PresetType.HighPerformance.ToString(),
41+
}
42+
);
43+
44+
return recognized.Barcodes[0].BarcodeValue;
45+
}
46+
}
5047

51-
var api = new BarcodeApi(MakeConfiguration());
48+
public static async Task Main(string[] args)
49+
{
50+
string fileName = Path.GetFullPath(Path.Join(
51+
Path.GetDirectoryName(Assembly.GetEntryAssembly()!.Location),
52+
"..", "..", "..", "..",
53+
"qr.png"
54+
));
5255

53-
string result = ReadQR(api, fileName);
54-
Console.WriteLine($"File '{fileName}' recognized, result: '{result}'");
55-
}
56+
BarcodeApi api = new BarcodeApi(MakeConfiguration());
57+
58+
string result = await ReadQR(api, fileName);
59+
Console.WriteLine($"File '{fileName}' recognized, result: '{result}'");
5660
}
5761
}

examples/ReadQR/ReadQR.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
55
<TargetFramework>net6.0</TargetFramework>
6+
<Nullable>enable</Nullable>
67
</PropertyGroup>
78

89
<ItemGroup>

examples/nuget-packages/.gitkeep

Whitespace-only changes.

examples/nuget.config

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<configuration>
2+
3+
<packageSources>
4+
<add key="local" value="nuget-packages" />
5+
</packageSources>
6+
7+
<packageSourceMapping>
8+
<packageSource key="local">
9+
<package pattern="Aspose.BarCode-Cloud" />
10+
</packageSource>
11+
<packageSource key="nuget.org">
12+
<package pattern="*" />
13+
</packageSource>
14+
</packageSourceMapping>
15+
16+
</configuration>

scripts/pack-nuget.bash

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
set -euo pipefail
33

44
if [ $# -ge 1 ]; then
5-
output_dir="$1"
5+
output_dir="$(realpath "$1")"
66
else
7-
output_dir=".."
7+
output_dir="$(realpath .)"
88
fi
99

1010
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
@@ -13,5 +13,6 @@ SRC_DIR="$( cd "${SCRIPT_DIR}/../src" &> /dev/null && pwd )"
1313
pushd "${SRC_DIR}"
1414
export RELEASE_BUILD=true
1515
dotnet build --warnaserror --configuration=Release Aspose.BarCode.Cloud.Sdk.csproj
16+
echo "Packing nuget package to \"${output_dir}\" ..."
1617
dotnet pack --configuration=Release Aspose.BarCode.Cloud.Sdk.csproj --output="${output_dir}"
1718
popd

0 commit comments

Comments
 (0)