using HslCommunication;
|
using HslCommunication.Core;
|
using Microsoft.AspNetCore.Http;
|
using Microsoft.VisualBasic.FileIO;
|
using Newtonsoft.Json;
|
using Quartz;
|
using SixLabors.ImageSharp.PixelFormats;
|
using System;
|
using System.Collections.Generic;
|
using System.ComponentModel;
|
using System.Linq;
|
using System.Reflection;
|
using System.Reflection.Metadata.Ecma335;
|
using System.Text;
|
using System.Threading.Tasks;
|
using WIDESEA_Common.Log;
|
using WIDESEAWCS_Communicator;
|
using WIDESEAWCS_Core.Helper;
|
using WIDESEAWCS_QuartzJob;
|
using WIDESEAWCS_QuartzJob.DeviceBase;
|
using WIDESEAWCS_QuartzJob.StackerCrane.Enum;
|
|
namespace WIDESEAWCS_Tasks
|
{
|
[DisallowConcurrentExecution]
|
public class LogJob : IJob
|
{
|
public Task Execute(IJobExecutionContext context)
|
{
|
try
|
{
|
|
Task.Run(() =>
|
{
|
try
|
{
|
while (true)
|
{
|
WriteLog.GetLog("LogJob").Write($"日志记录:{DateTime.Now}", "LogJob");
|
Run(10);
|
Run2(10);
|
Thread.Sleep(1000 * 10);
|
}
|
}
|
catch { }
|
});
|
|
}
|
catch (Exception ex)
|
{
|
Console.Out.WriteLine(nameof(LogJob) + ":" + ex.Message);
|
}
|
|
return Task.CompletedTask;
|
}
|
private static void Run(int saveDays)
|
{
|
var logPath = System.Environment.CurrentDirectory + "/log";
|
if (Directory.Exists(logPath))
|
{
|
var nowTime = DateTime.Now;
|
var dayDir = Directory.GetDirectories(logPath, "20*", System.IO.SearchOption.AllDirectories);
|
|
foreach (var dirpath in dayDir)
|
{
|
//文件夹名
|
var dirName = Path.GetFileName(dirpath).Replace("_", "-");
|
|
DateTime targetDate = DateTime.ParseExact(dirName, "yyyyMMdd", null);
|
if ((nowTime - targetDate).TotalDays >= saveDays)
|
{
|
|
//删除文件和文件夹
|
try
|
{
|
var flies = Directory.GetFiles(dirpath);
|
|
foreach (var item in flies)
|
{
|
File.Delete(item);
|
}
|
Directory.Delete(dirpath);
|
}
|
catch { }
|
}
|
}
|
}
|
}
|
|
private static void Run2(int saveDays)
|
{
|
var logPath = System.Environment.CurrentDirectory + "/txt";
|
if (Directory.Exists(logPath))
|
{
|
var nowTime = DateTime.Now;
|
var dayDir = Directory.GetDirectories(logPath, "20*", System.IO.SearchOption.AllDirectories);
|
|
foreach (var dirpath in dayDir)
|
{
|
//文件夹名
|
var dirName = Path.GetFileName(dirpath).Replace("_", "-");
|
|
DateTime targetDate = DateTime.ParseExact(dirName, "yyyyMMdd", null);
|
if ((nowTime - targetDate).TotalDays >= saveDays)
|
{
|
|
//删除文件和文件夹
|
try
|
{
|
var flies = Directory.GetFiles(dirpath);
|
|
foreach (var item in flies)
|
{
|
File.Delete(item);
|
}
|
Directory.Delete(dirpath);
|
}
|
catch { }
|
}
|
}
|
}
|
}
|
}
|
|
|
}
|