From 175e114a9dfe7e79bda71bec1df8bb190469534e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=BD=87=E9=98=B3?= Date: Mon, 27 May 2024 14:51:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=87=8C=E6=99=A82=E7=82=B9?= =?UTF-8?q?=E6=B8=85=E7=90=86=E6=9C=AC=E5=9C=B0=E7=BC=93=E5=AD=98=E6=96=87?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CPF_Cef/Common/Utils.cs | 19 +++++++++++++++++++ CPF_Cef/FrmMain.cs | 39 +++++++++++++++++++++++++++++++++++++++ CPF_Cef/MainModel.cs | 1 + 3 files changed, 59 insertions(+) diff --git a/CPF_Cef/Common/Utils.cs b/CPF_Cef/Common/Utils.cs index 94d1574..38845b7 100644 --- a/CPF_Cef/Common/Utils.cs +++ b/CPF_Cef/Common/Utils.cs @@ -34,5 +34,24 @@ namespace AksWebBrowser.Common fileStream.Close(); } } + + //删除目录下文件 + public static void DeleteAllFiles(string folderPath) + { + // 确保文件夹路径是完整的,并且文件夹存在 + if (!Directory.Exists(folderPath)) + { + Log.Error("未找到删除临时目录"); + } + + // 获取文件夹内所有文件,包括子文件夹内的文件 + string[] files = Directory.GetFiles(folderPath, "*.*", SearchOption.AllDirectories); + + // 删除所有文件 + foreach (string file in files) + { + File.Delete(file); + } + } } } diff --git a/CPF_Cef/FrmMain.cs b/CPF_Cef/FrmMain.cs index f498beb..aa17a05 100644 --- a/CPF_Cef/FrmMain.cs +++ b/CPF_Cef/FrmMain.cs @@ -14,6 +14,7 @@ using AKSWebBrowser.Commen; using System.Collections.Generic; using System.Reflection.Metadata; using AksWebBrowser.Common; +using System.Threading; namespace AKS.EnterpriseLibrary.WebBrowser { @@ -102,6 +103,44 @@ namespace AKS.EnterpriseLibrary.WebBrowser } //获取授权 GetSQObject(); + Task.Run(() => { Time(); }); + } + + //凌晨2点执行,清理当天缓存文件 + public void Time() + { + try + { + // 获取当前时间 + DateTime now = DateTime.Now; + // 计算明天凌晨的时间// 假设凌晨2点执行 + DateTime tomorrowMorning = new DateTime(now.Year, now.Month, now.Day) + TimeSpan.FromDays(1) + TimeSpan.FromHours(2); + // 计算时间差(明天凌晨时间减去现在时间) + TimeSpan timeToGo = tomorrowMorning - now; + // 设置定时器 + Timer timer = new Timer(ExecuteTask, null, timeToGo, Timeout.InfiniteTimeSpan); + } + catch (Exception ex) + { + Log.Error("定时任务开启异常: " + ex.Message); + } + } + + // 要执行的任务 + private static void ExecuteTask(object state) + { + try + { + Log.Info("定时任务执行时间: " + DateTime.Now); + string file = System.IO.Directory.GetCurrentDirectory(); + file = file + @"/aks/wwwroot"; + // 这里添加你的任务代码 + Utils.DeleteAllFiles(file); + } + catch (Exception ex) + { + Log.Error("定时任务执行异常: " + ex.Message); + } } public void Writelog(string str, string dirName = @"logs") diff --git a/CPF_Cef/MainModel.cs b/CPF_Cef/MainModel.cs index 6a569a1..b725e6c 100644 --- a/CPF_Cef/MainModel.cs +++ b/CPF_Cef/MainModel.cs @@ -38,6 +38,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser public static Process recordingProcess; public static Process Typrocess; private string srpath = string.Empty; + /// /// 读取身份证卡号(已国产化) ///