You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
using log4net;
|
|
|
|
|
using Quartz;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Configuration;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Web;
|
|
|
|
|
|
|
|
|
|
namespace MailSend.Common
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 清理临时文件
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class ClearTempJob : IJob
|
|
|
|
|
{
|
|
|
|
|
private ILog logger = LogManager.GetLogger("ClearTempJob");
|
|
|
|
|
|
|
|
|
|
Task IJob.Execute(IJobExecutionContext context)
|
|
|
|
|
{
|
|
|
|
|
return Task.Run(() =>
|
|
|
|
|
{
|
|
|
|
|
var tmpDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Temp");
|
|
|
|
|
var clearCount = 0;
|
|
|
|
|
if (Directory.Exists(tmpDir))
|
|
|
|
|
{
|
|
|
|
|
var files = Directory.GetFiles(tmpDir);
|
|
|
|
|
foreach (string file in files)
|
|
|
|
|
{
|
|
|
|
|
var fi = new FileInfo(file);
|
|
|
|
|
if (fi.LastAccessTime < DateTime.Now.AddDays(-1))
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
File.Delete(file);
|
|
|
|
|
clearCount++;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
logger.Error(ex.Message);
|
|
|
|
|
logger.Error(ex.StackTrace);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (clearCount > 0)
|
|
|
|
|
{
|
|
|
|
|
logger.Debug($"成功清理临时文件{clearCount}个");
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|