| | | 1 | | using Anichron.Core.Data.Repository; |
| | | 2 | | using Anichron.Core.Domain; |
| | | 3 | | |
| | | 4 | | namespace Anichron.Worker.Ingestion.Classification; |
| | | 5 | | |
| | | 6 | | internal static class ProxyFileRows |
| | | 7 | | { |
| | | 8 | | /// <summary> |
| | | 9 | | /// Makes the asset's proxy rows describe <paramref name="replacements"/>, by type: an existing row of a |
| | | 10 | | /// type is updated in place, a missing type is added, and a type not among the replacements is removed. |
| | | 11 | | /// </summary> |
| | | 12 | | /// <param name="repository">Tracks the added and removed rows.</param> |
| | | 13 | | /// <param name="asset">The asset whose proxy rows change.</param> |
| | | 14 | | /// <param name="replacements">The proxies the asset has from now on, owned by the asset.</param> |
| | | 15 | | public static void Replace(IMediaAssetRepository repository, MediaAsset asset, IReadOnlyList<ProxyFile> replacements |
| | 59 | 16 | | { |
| | 59 | 17 | | var stale = asset.ProxyFiles.Where(old => replacements.All(proxy => proxy.ProxyType != old.ProxyType)); |
| | 267 | 18 | | foreach (var proxy in stale.ToList()) |
| | 45 | 19 | | repository.RemoveProxyFile(proxy); |
| | | 20 | | |
| | 59 | 21 | | var added = new List<ProxyFile>(); |
| | 259 | 22 | | foreach (var proxy in replacements) |
| | 41 | 23 | | { |
| | 41 | 24 | | if (asset.ProxyFiles.FirstOrDefault(old => old.ProxyType == proxy.ProxyType) is not { } existing) |
| | 18 | 25 | | { |
| | 18 | 26 | | added.Add(proxy); |
| | 18 | 27 | | continue; |
| | | 28 | | } |
| | | 29 | | |
| | 23 | 30 | | existing.ProxyPath = proxy.ProxyPath; |
| | 23 | 31 | | existing.SizeBytes = proxy.SizeBytes; |
| | 23 | 32 | | existing.CreatedAt = proxy.CreatedAt; |
| | 23 | 33 | | } |
| | | 34 | | |
| | 59 | 35 | | repository.AddProxyFiles(added); |
| | 59 | 36 | | } |
| | | 37 | | } |