Creato metodo per la rimozione delle ispezioni più vecchie di 60 giorni
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System.IO.Compression;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SteUp.Data.LocalDb;
|
||||
using SteUp.Shared.Core.Dto;
|
||||
using SteUp.Shared.Core.Entities;
|
||||
@@ -7,7 +8,9 @@ using SteUp.Shared.Core.Interface.System;
|
||||
|
||||
namespace SteUp.Maui.Core.Services;
|
||||
|
||||
public class FileManager(IDbPathProvider dbPathProvider) : IFileManager
|
||||
public class FileManager(
|
||||
IDbPathProvider dbPathProvider,
|
||||
ILogger<FileManager> logger) : IFileManager
|
||||
{
|
||||
private static string AttachedRoot =>
|
||||
Path.Combine(FileSystem.CacheDirectory, "attached");
|
||||
@@ -212,6 +215,49 @@ public class FileManager(IDbPathProvider dbPathProvider) : IFileManager
|
||||
|
||||
return removed;
|
||||
}
|
||||
|
||||
public bool RemoveInspection(Ispezione ispezione, bool removeAlsoFromFinal, bool removeAlsoFromToUpload)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(ispezione);
|
||||
|
||||
var removedAnything = false;
|
||||
|
||||
if (removeAlsoFromToUpload)
|
||||
TryDeleteDirectory(GetInspectionToUploadDir(ispezione));
|
||||
|
||||
if (removeAlsoFromFinal)
|
||||
TryDeleteDirectory(GetInspectionFinalDir(ispezione));
|
||||
|
||||
try
|
||||
{
|
||||
CleanupDirectoriesIfEmpty(ispezione);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
logger.LogError(e, e.Message);
|
||||
SentrySdk.CaptureException(e);
|
||||
}
|
||||
|
||||
return removedAnything;
|
||||
|
||||
void TryDeleteDirectory(string? dir)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(dir)) return;
|
||||
|
||||
try
|
||||
{
|
||||
if (!Directory.Exists(dir)) return;
|
||||
|
||||
Directory.Delete(dir, recursive: true);
|
||||
removedAnything = true;
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
logger.LogError(e, e.Message);
|
||||
SentrySdk.CaptureException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void CleanupDirectoriesIfEmpty(Ispezione ispezione)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user