This repository was archived by the owner on Jul 28, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFileTransformFunction.cs
More file actions
50 lines (41 loc) · 1.86 KB
/
FileTransformFunction.cs
File metadata and controls
50 lines (41 loc) · 1.86 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using Microsoft.Azure.Functions.Worker;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using ServiceLayer.Mesh.Data;
using ServiceLayer.Mesh.Messaging;
using ServiceLayer.Mesh.Models;
using ServiceLayer.Mesh.Storage;
namespace ServiceLayer.Mesh.Functions;
public class FileTransformFunction(
ILogger<FileTransformFunction> logger,
ServiceLayerDbContext serviceLayerDbContext,
IMeshFilesBlobStore meshFileBlobStore)
{
[Function("FileTransformFunction")]
public async Task Run([QueueTrigger("%FileTransformQueueName%")] FileTransformQueueMessage message)
{
await using var transaction = await serviceLayerDbContext.Database.BeginTransactionAsync();
var file = await serviceLayerDbContext.MeshFiles.FirstOrDefaultAsync(f => f.FileId == message.FileId);
if (file == null)
{
logger.LogWarning("File with id: {fileId} not found in MeshFiles table.", message.FileId);
return;
}
if (file.Status != MeshFileStatus.Extracted)
{
logger.LogWarning("File with id: {fileId} found in MeshFiles table but is not suitable for transformation. Status: {status}", message.FileId, file.Status);
return;
}
await UpdateFileStatusForTransformation(file);
await transaction.CommitAsync();
var fileContent = await meshFileBlobStore.DownloadAsync(file);
// TODO - take dependency on IEnumerable<IFileTransformer>.
// After initial common checks against database, find the appropriate implementation of IFileTransformer to handle the functionality that differs between file type.
}
private async Task UpdateFileStatusForTransformation(MeshFile file)
{
file.Status = MeshFileStatus.Transforming;
file.LastUpdatedUtc = DateTime.UtcNow;
await serviceLayerDbContext.SaveChangesAsync();
}
}