- Programmiersprache von VSC zu C# geändert - Framework von .NET Framework zu .NET geändert
73 lines
1.5 KiB
C#
73 lines
1.5 KiB
C#
using System.IO;
|
|
using DigitalData.Modules.Base;
|
|
using DigitalData.Modules.Logging;
|
|
|
|
namespace EnvelopeGenerator.ServiceHost.Jobs;
|
|
|
|
public class TempFiles : BaseClass
|
|
{
|
|
public string TempPath { get; }
|
|
|
|
public TempFiles(LogConfig logConfig) : base(logConfig)
|
|
{
|
|
var tempDirectoryPath = Path.GetTempPath();
|
|
TempPath = Path.Combine(tempDirectoryPath, "EnvelopeGenerator");
|
|
}
|
|
|
|
public bool Create()
|
|
{
|
|
try
|
|
{
|
|
if (!Directory.Exists(TempPath))
|
|
{
|
|
Directory.CreateDirectory(TempPath);
|
|
}
|
|
else
|
|
{
|
|
CleanUpFiles();
|
|
}
|
|
|
|
return true;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Logger.Error(ex);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
private bool CleanUpFiles()
|
|
{
|
|
try
|
|
{
|
|
foreach (var fileItem in Directory.GetFiles(TempPath))
|
|
{
|
|
Logger.Debug("Deleting tempPath-file: {0} ...", fileItem);
|
|
File.Delete(fileItem);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Logger.Error(ex);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public bool CleanUp()
|
|
{
|
|
try
|
|
{
|
|
Logger.Debug("Deleting tempPath-Data: {0} ...", TempPath);
|
|
Directory.Delete(TempPath, true);
|
|
return true;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Logger.Error(ex);
|
|
return false;
|
|
}
|
|
}
|
|
}
|