36 lines
1.3 KiB
C#
36 lines
1.3 KiB
C#
using System.IO;
|
|
using Livia.Utility;
|
|
using Livia.Utility.DependencyInjection;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace Livia.Models.Data;
|
|
|
|
public class DataBlock(string sourceDir)
|
|
{
|
|
public string ZipPath { get; private set; } = string.Empty;
|
|
public string ResultPath { get; set; } = string.Empty;
|
|
public string Key { get; set; } = string.Empty;
|
|
public string SourceDir { get; } = sourceDir;
|
|
public Dictionary<string, string>? ArgsDict { get; init; }
|
|
|
|
private readonly ILogger _logger = ServiceProviderFactory.ServiceProvider.GetRequiredService<ILogger>();
|
|
|
|
public async Task Pack(CancellationToken token)
|
|
{
|
|
// in case it is not there
|
|
try
|
|
{
|
|
// ReSharper disable once StringLiteralTypo
|
|
string zipName = DateTime.Now.ToString("yyyyMMddHHmmssffff") + ".zip";
|
|
string zipPath = Path.Combine(ServiceConfigurations.TempFolder, zipName);
|
|
await Task.Run(() => LiviaUtility.CreateFromDirectory(SourceDir, zipPath, token), token).ConfigureAwait(false);
|
|
ZipPath = zipPath;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
_logger.LogError(e, "Error packing {path}", SourceDir);
|
|
throw;
|
|
}
|
|
}
|
|
} |