|
5 | 5 | using System; |
6 | 6 | using System.IO; |
7 | 7 | using System.Reflection; |
| 8 | +using System.Threading.Tasks; |
8 | 9 |
|
9 | | -namespace ReadQR |
| 10 | +namespace ReadQR; |
| 11 | + |
| 12 | +internal static class Program |
10 | 13 | { |
11 | | - internal static class Program |
| 14 | + private static Configuration MakeConfiguration() |
12 | 15 | { |
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)) |
14 | 20 | { |
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"; |
29 | 23 | } |
30 | | - |
31 | | - private static string ReadQR(IBarcodeApi api, string fileName) |
| 24 | + else |
32 | 25 | { |
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; |
41 | 27 | } |
42 | 28 |
|
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)) |
44 | 35 | { |
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 | + } |
50 | 47 |
|
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 | + )); |
52 | 55 |
|
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}'"); |
56 | 60 | } |
57 | 61 | } |
0 commit comments