using Furion.JsonSerialization;
|
using Newtonsoft.Json;
|
using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
|
using Quartz;
|
using System;
|
using System.Collections.Generic;
|
using System.IO;
|
using System.Runtime.Serialization.Json;
|
using System.Security.Policy;
|
using System.Text;
|
using System.Threading.Tasks;
|
using WIDESEA_Entity.DomainModels.Equipment;
|
using WIDESEA_Services.Services;
|
using WIDESEA_WCS.Jobs;
|
using WIDESEA_WCS.JobsPart.AGV;
|
using WIDESEA_WCS.SchedulerExecute.AGV;
|
using WIDESEA_WCS.WCSClient;
|
|
namespace WIDESEA_WCS
|
{
|
/// <summary>
|
/// AGV调度
|
/// </summary>
|
[DisallowConcurrentExecution]
|
public class AGVJob : JobBase, IJob
|
{
|
public Task Execute(IJobExecutionContext context)
|
{
|
try
|
{
|
ExecuteJob(context, DoAction);
|
}
|
catch { }
|
return Task.FromResult(string.Empty);
|
}
|
|
|
private void DoAction(IJobExecutionContext context)
|
{
|
try
|
{
|
PLCClient client = context.JobDetail.JobDataMap.Get("JobParams") as PLCClient;
|
AGVSchedulerExecute.SendAGVTask1(client);
|
// 清除7日以上的Logs日志记录
|
string date = DateTime.Now.ToString("yyyy-MM-dd");
|
string json = File.ReadAllText(AppContext.BaseDirectory + "modified_data.json", Encoding.UTF8);
|
var logstime = JsonConvert.DeserializeObject<timelist>(json);
|
if (date != logstime.logtime)
|
{
|
logstime.logtime = date;
|
string modifiedJson = JsonConvert.SerializeObject(logstime);
|
File.WriteAllText("modified_data.json", modifiedJson);
|
string folderPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "logs");
|
DateTime tenDaysAgo = DateTime.Now.AddDays(-7); // 获取当前时间的七天之前的日期
|
DeleteFilesAndFolders(folderPath, tenDaysAgo);
|
}
|
}
|
catch (Exception ex)
|
{
|
|
throw new Exception(ex.Message);
|
}
|
|
// 清楚7日以上的Logs日志记录
|
//try
|
//{
|
// string date = DateTime.Now.ToString("yyyy-MM-dd");
|
// string json = File.ReadAllText(AppContext.BaseDirectory + "modified_data.json", Encoding.UTF8);
|
// var logstime = JsonConvert.DeserializeObject<timelist>(json);
|
// if (date != logstime.logtime)
|
// {
|
// logstime.logtime = date;
|
// string modifiedJson = JsonConvert.SerializeObject(logstime);
|
// File.WriteAllText("modified_data.json", modifiedJson);
|
// string folderPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "logs");
|
// DateTime tenDaysAgo = DateTime.Now.AddDays(-7); // 获取当前时间的七天之前的日期
|
// DeleteFilesAndFolders(folderPath, tenDaysAgo);
|
// }
|
//}
|
//catch (Exception)
|
//{
|
|
//}
|
#region
|
//PLCClient client = context.JobDetail.JobDataMap.Get("JobParams") as PLCClient;
|
|
//AGVServer agvServer = new AGVServer();
|
//if (client != null)
|
//{
|
// try
|
// {
|
// AGVSchedulerExecute.SendAGVTask1(client);
|
// }
|
// catch (Exception) { }
|
// try
|
// {
|
// agvServer.UpdateAgvTask(client);
|
// }
|
// catch (Exception) { }
|
|
// // 清楚7日以上的Logs日志记录
|
// try
|
// {
|
// string date = DateTime.Now.ToString("yyyy-MM-dd");
|
// string json = File.ReadAllText(AppContext.BaseDirectory + "modified_data.json", Encoding.UTF8);
|
// var logstime = JsonConvert.DeserializeObject<timelist>(json);
|
// if (date != logstime.logtime)
|
// {
|
// logstime.logtime = date;
|
// string modifiedJson = JsonConvert.SerializeObject(logstime);
|
// File.WriteAllText("modified_data.json", modifiedJson);
|
// string folderPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "logs");
|
// DateTime tenDaysAgo = DateTime.Now.AddDays(-7); // 获取当前时间的七天之前的日期
|
|
// DeleteFilesAndFolders(folderPath, tenDaysAgo);
|
// }
|
// }
|
// catch (Exception)
|
// {
|
// throw;
|
// }
|
//}
|
#endregion
|
}
|
|
static void DeleteFilesAndFolders(string path, DateTime dateTime)
|
{
|
DirectoryInfo directory = new DirectoryInfo(path);
|
|
foreach (FileSystemInfo fileOrFolder in directory.GetFileSystemInfos())
|
{
|
if ((fileOrFolder is FileInfo && ((DateTime)((FileInfo)fileOrFolder).LastWriteTime < dateTime)) ||
|
(fileOrFolder is DirectoryInfo && ((DirectoryInfo)fileOrFolder).CreationTime < dateTime))
|
{
|
try
|
{
|
if (fileOrFolder is FileInfo)
|
{
|
((FileInfo)fileOrFolder).Delete();
|
}
|
else if (fileOrFolder is DirectoryInfo)
|
{
|
DeleteFilesAndFolders(fileOrFolder.FullName, dateTime);
|
((DirectoryInfo)fileOrFolder).Delete();
|
}
|
}
|
catch (Exception ex)
|
{
|
Console.WriteLine("无法删除文件或文件夹: " + fileOrFolder.FullName + "\n错误信息: " + ex.Message);
|
}
|
}
|
}
|
}
|
}
|
|
public class timelist {
|
public string MM { get; set; }
|
//日志删除过滤时间
|
public string logtime { get; set; }
|
|
}
|
}
|