The TempFiles class, including its TempPath property, constructor,
and methods (Create, CleanUpFiles, CleanUp), is now marked with
the [Obsolete("Use memory cache instead of temp files.")] attribute.
This deprecates the use of temp files in favor of a memory cache
approach for future development.
85 lines
1.9 KiB
C#
85 lines
1.9 KiB
C#
using EnvelopeGenerator.ServiceHost.Extensions;
|
|
|
|
namespace EnvelopeGenerator.ServiceHost.Jobs;
|
|
|
|
[Obsolete("Use memory cache instead of temp files.")]
|
|
public class TempFiles
|
|
{
|
|
|
|
[Obsolete("Use memory cache instead of temp files.")]
|
|
public string TempPath { get; }
|
|
|
|
private readonly ILogger<TempFiles> _logger;
|
|
|
|
|
|
[Obsolete("Use memory cache instead of temp files.")]
|
|
public TempFiles(ILogger<TempFiles> logger)
|
|
{
|
|
_logger = logger;
|
|
var tempDirectoryPath = Path.GetTempPath();
|
|
TempPath = Path.Combine(tempDirectoryPath, "EnvelopeGenerator");
|
|
}
|
|
|
|
|
|
[Obsolete("Use memory cache instead of temp files.")]
|
|
public bool Create()
|
|
{
|
|
try
|
|
{
|
|
if (!Directory.Exists(TempPath))
|
|
{
|
|
Directory.CreateDirectory(TempPath);
|
|
}
|
|
else
|
|
{
|
|
CleanUpFiles();
|
|
}
|
|
|
|
return true;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
[Obsolete("Use memory cache instead of temp files.")]
|
|
private bool CleanUpFiles()
|
|
{
|
|
try
|
|
{
|
|
foreach (var fileItem in Directory.GetFiles(TempPath))
|
|
{
|
|
_logger.LogDebug("Deleting tempPath-file: {fileItem} ...", fileItem);
|
|
File.Delete(fileItem);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
[Obsolete("Use memory cache instead of temp files.")]
|
|
public bool CleanUp()
|
|
{
|
|
try
|
|
{
|
|
_logger.LogDebug("Deleting tempPath-Data: {TempPath} ...", TempPath);
|
|
Directory.Delete(TempPath, true);
|
|
return true;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex);
|
|
return false;
|
|
}
|
|
}
|
|
}
|