diff --git a/Txgy.FilesWatcher/ViewModels/MainViewModel.cs b/Txgy.FilesWatcher/ViewModels/MainViewModel.cs index bf1f979..302d55d 100644 --- a/Txgy.FilesWatcher/ViewModels/MainViewModel.cs +++ b/Txgy.FilesWatcher/ViewModels/MainViewModel.cs @@ -30,6 +30,7 @@ using System.Xml.Linq; using Prism.Services.Dialogs; using Microsoft.VisualBasic.Logging; using log4net; +using System.Windows.Documents; namespace Txgy.FilesWatcher.ViewModels { @@ -156,6 +157,15 @@ namespace Txgy.FilesWatcher.ViewModels get { return dataList; } set { SetProperty(ref dataList, value); } } + private ObservableCollection autoDataList = new ObservableCollection(); + + public ObservableCollection AutoDataList + + { + get { return autoDataList; } + set { SetProperty(ref autoDataList, value); } + } + private ObservableCollection realTimeDataList = new ObservableCollection(); public ObservableCollection RealTimeDataList @@ -205,7 +215,7 @@ namespace Txgy.FilesWatcher.ViewModels get { return selectedIndex; } set { SetProperty(ref selectedIndex, value); } } - private int proMonInterval = 5; + private int proMonInterval = 10; public int ProMonInterval { get => proMonInterval; @@ -283,6 +293,10 @@ namespace Txgy.FilesWatcher.ViewModels })); }); + public DelegateCommand ClearLogCommand => new DelegateCommand(() => + { + if (AutoDataList.Count > 0) { AutoDataList.Clear(); } + }); private void Start() { int res = WatchStartOrSopt(true); @@ -504,7 +518,7 @@ namespace Txgy.FilesWatcher.ViewModels } private string settingDataPath = "systemconfig.json"; - private void timer1_Tick(object? sender, EventArgs e) + private async void timer1_Tick(object? sender, EventArgs e) { DateTime currentT= DateTime.Now; RunTime = DateDiff(currentT, StartTime); @@ -512,11 +526,20 @@ namespace Txgy.FilesWatcher.ViewModels if ((currentT - mseedFileTime).TotalSeconds >= CycleTime) { mseedFileTime = DateTime.Now; - //DateTime end= DateTime.Now.AddDays(-3); - _manualModeDialog.StartHandle(mseedFileTime.AddDays(-4), mseedFileTime); + if (AutoDataList.Count >= 100) { AutoDataList.Remove(AutoDataList.Last()); } + var list = await _manualModeDialog.StartHandle(mseedFileTime.AddDays(-4), mseedFileTime); + foreach (var item in list) + { + AutoDataList.Insert(0, new FileModel + { + CreateTime = DateTime.Now.ToString("yyyy-MM-dd T HH:mm:ss"), + Data = $"{item}" + }); + } } else { + Thread.Sleep(20000); MseedFileChanged(currentT); } } diff --git a/Txgy.FilesWatcher/ViewModels/ManualModeDialogViewModel.cs b/Txgy.FilesWatcher/ViewModels/ManualModeDialogViewModel.cs index 809c87e..ea2080f 100644 --- a/Txgy.FilesWatcher/ViewModels/ManualModeDialogViewModel.cs +++ b/Txgy.FilesWatcher/ViewModels/ManualModeDialogViewModel.cs @@ -97,25 +97,36 @@ namespace Txgy.FilesWatcher.ViewModels //} StateMes = "执行中"; StartEnable = false; - await StartHandle(StartTime,EndTime); - StateMes = "未开始"; + var list= await StartHandle(StartTime,EndTime); + foreach (var item in list) + { + DataList.Insert(0, new FileModel + { + CreateTime = DateTime.Now.ToString("yyyy-MM-dd T HH:mm:ss"), + Data = $"{item}" + }); + } + + StateMes = "已完成"; StartEnable = true; }).ObservesCanExecute(()=>StartEnable); CancellationTokenSource cts = new CancellationTokenSource(); - public async Task StartHandle(DateTime start, DateTime end) + public async Task> StartHandle(DateTime start, DateTime end) { _log.Log.DebugFormat("ManualModeDialogViewModel.StartHandle() start:{0},end:{1}",start, end); + cts = new CancellationTokenSource(); CancellationToken cancellationToken = cts.Token; string realtimePath = Path.Combine(mainModel.MainPath, mainModel.RealtimePath); string postPath = Path.Combine(mainModel.MainPath, mainModel.PostPath); + List logList=new List(); Task task1 = Task.Run(() => { DateTime time = start.AddMinutes(1); while (!cancellationToken.IsCancellationRequested) { time = time.AddMinutes(1); - MseedUpload(time); + logList.AddRange(MseedUpload(time)); if (time >= end) { break; @@ -135,7 +146,7 @@ namespace Txgy.FilesWatcher.ViewModels Console.WriteLine("Cancellation"); break; } - RealtimeChanged(file.FullName, line); + logList.AddRange(RealtimeChanged(file.FullName, line)); } } }, cancellationToken); @@ -152,11 +163,12 @@ namespace Txgy.FilesWatcher.ViewModels Console.WriteLine("Cancellation"); break; } - PostChanged(file.FullName, line); + logList.AddRange(PostChanged(file.FullName, line)); } } }, cancellationToken); await Task.WhenAll(task1, task2, task3); + return logList; } @@ -165,39 +177,47 @@ namespace Txgy.FilesWatcher.ViewModels cts.Cancel(); }); - private void MseedUpload(DateTime currentT) + public DelegateCommand ClearLogCommand => new DelegateCommand(() => + { + if (DataList.Count > 0) { DataList.Clear(); } + }); + + private List MseedUpload(DateTime currentT) { string path = $"{Path.Combine(mainModel.MainPath, mainModel.MseedPath)}/{currentT.Month.ToString("D2")}/{currentT.Day.ToString("D2")}/{currentT.Hour.ToString("D2")}/{currentT.Minute.ToString("D2")}"; // path = "I:\\yuwuN3102mseed\\NET2023\\06\\22\\21\\51"; Debug.WriteLine($"**********当前时间:{currentT},监控路径:{path}"); + List logList = new List(); if (Directory.Exists(path) && mainModel.IsUploadDB && mainModel.IsUploadMseedPath) { _log.Log.DebugFormat("ManualModeDialogViewModel.MseedUpload() currentT:{0},path:{1}", currentT, path); - UploadMseedFile.UploadMSeedOnce((a => + logList= UploadMseedFile.UploadMSeedOnce((a => { - timer1.Dispatcher.Invoke(() => - { - // if (DataList.Count >= 20) { DataList.Remove(dataList.Last()); } - DataList.Insert(0, new FileModel - { - CreateTime = DateTime.Now.ToString("yyyy-MM-dd T HH:mm:ss"), - Data = $"{currentT.AddMinutes(-2).ToString("yyyy-MM-dd T HH:mm:ss")}{a}" - }); - }); + //timer1.Dispatcher.Invoke(() => + //{ + // // if (DataList.Count >= 20) { DataList.Remove(dataList.Last()); } + // DataList.Insert(0, new FileModel + // { + // CreateTime = DateTime.Now.ToString("yyyy-MM-dd T HH:mm:ss"), + // Data = $"{currentT.AddMinutes(-2).ToString("yyyy-MM-dd T HH:mm:ss")}{a}" + // }); + //}); }), path, mainModel.WorkAreaId); } + return logList; } - private void RealtimeChanged(string filePath, string lastLine) + private List RealtimeChanged(string filePath, string lastLine) { // string tmp = dt.Hour.ToString() + "时" + dt.Minute.ToString() + "分" + dt.Second.ToString() + "秒" + dt.Millisecond.ToString() + "毫秒,目录发生变化\r\n"; DateTime lastWriteTime = DateTime.Now; //File.GetLastWriteTime(e.FullPath); Debug.WriteLine($"最后修改时间:{lastWriteTime},文件路径:{filePath}"); filePath = Path.GetDirectoryName(filePath); _log.Log.DebugFormat("ManualModeDialogViewModel.RealtimeChanged() filePath:{0},path:{1}", filePath, lastLine); + List logList = new List(); if (mainModel.IsUploadDB && mainModel.IsUploadRealtimePath) { - UploadRealtimeFile.UploadRealtimeFileOnce(filePath, lastLine, mainModel.WorkAreaId, out bool isUpload); + logList= UploadRealtimeFile.UploadRealtimeFileOnce(filePath, lastLine, mainModel.WorkAreaId, out bool isUpload); timer1.Dispatcher.Invoke(() => { // if (RealTimeDataList.Count >= 20) { RealTimeDataList.Remove(RealTimeDataList.Last()); } @@ -218,19 +238,21 @@ namespace Txgy.FilesWatcher.ViewModels }, filePath, lastLine); } + return logList; } - private void PostChanged(string filePath, string lastLine) + private List PostChanged(string filePath, string lastLine) { // string tmp = dt.Hour.ToString() + "时" + dt.Minute.ToString() + "分" + dt.Second.ToString() + "秒" + dt.Millisecond.ToString() + "毫秒,目录发生变化\r\n"; DateTime lastWriteTime = DateTime.Now; //File.GetLastWriteTime(e.FullPath); Debug.WriteLine($"最后修改时间:{lastWriteTime},文件路径:{filePath}"); filePath = Path.GetDirectoryName(filePath); _log.Log.DebugFormat("ManualModeDialogViewModel.RealtimeChanged() filePath:{0},path:{1}", filePath, lastLine); + List logList = new List(); if (mainModel.IsUploadDB && mainModel.IsUploadPostPath) { - UploadPostproFile.UploadPostproFileOnce(filePath, lastLine, mainModel.WorkAreaId, out bool isUpload); + logList= UploadPostproFile.UploadPostproFileOnce(filePath, lastLine, mainModel.WorkAreaId, out bool isUpload); { timer1.Dispatcher.Invoke(() => { @@ -256,6 +278,7 @@ namespace Txgy.FilesWatcher.ViewModels }); }, filePath, lastLine); } + return logList; } private DispatcherTimer timer1 = new DispatcherTimer(); diff --git a/Txgy.FilesWatcher/Views/MainView.xaml b/Txgy.FilesWatcher/Views/MainView.xaml index 700cac7..904f15e 100644 --- a/Txgy.FilesWatcher/Views/MainView.xaml +++ b/Txgy.FilesWatcher/Views/MainView.xaml @@ -141,92 +141,123 @@ Value="0" /> - - - - - - - - - - - - - - - - + + + + + + + - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +