-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
28 lines (23 loc) · 1 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
using Azure;
using Azure.AI.FormRecognizer.DocumentAnalysis;
using Azure.Storage.Blobs;
using OcrProject;
using static OcrProject.DataConverter;
// Initialize clients
var credential = new AzureKeyCredential(Settings.Key);
var client = new DocumentAnalysisClient(new Uri(Settings.Endpoint), credential);
var blobContainerClient = new BlobContainerClient(Settings.BlobConnectionString, Settings.ContainerName);
await foreach (var blobItem in blobContainerClient.GetBlobsAsync())
{
var blobClient = blobContainerClient.GetBlobClient(blobItem.Name);
using var stream = new MemoryStream();
await blobClient.DownloadToAsync(stream);
stream.Position = 0;
await WriteJsonFile(blobItem.Name, await Scanner(stream,"prebuilt-invoice"));
}
async Task<IReadOnlyList<InvoiceFields>> Scanner(Stream stream, string modelId)
{
var operation = await client.AnalyzeDocumentAsync(WaitUntil.Completed, modelId, stream);
var result = operation.Value;
return result.Documents.Select(Convert).ToList();
}