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.
54 lines
1.5 KiB
C#
54 lines
1.5 KiB
C#
using DSWeb.Common.DB;
|
|
using log4net;
|
|
using MailKit.Net.Smtp;
|
|
using MimeKit;
|
|
using Quartz;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Configuration;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Web;
|
|
|
|
namespace DSWeb.Job.Common
|
|
{
|
|
/// <summary>
|
|
/// 清理临时文件
|
|
/// </summary>
|
|
public class ClearTempJob : IJob
|
|
{
|
|
private ILog logger = LogManager.GetLogger("ClearTempJob");
|
|
|
|
public void Execute(IJobExecutionContext context)
|
|
{
|
|
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}个");
|
|
}
|
|
}
|
|
}
|
|
} |