|
|
|
@ -30,20 +30,17 @@ namespace Txgy.FilesWatcher.ViewModels
|
|
|
|
|
{
|
|
|
|
|
internal class MainViewModel : BindableBase
|
|
|
|
|
{
|
|
|
|
|
public MainViewModel(WebsocketClient websocketClient, IEventAggregator ea)
|
|
|
|
|
public MainViewModel(WebsocketClient websocketClient, SystemConfig systemConfig, IEventAggregator ea)
|
|
|
|
|
{
|
|
|
|
|
string filter = "*.index";
|
|
|
|
|
string str = File.ReadAllText("systemconfig.json");
|
|
|
|
|
systemConfig = JsonSerializer.Deserialize<SystemConfig>(str, new JsonSerializerOptions
|
|
|
|
|
{
|
|
|
|
|
ReadCommentHandling = JsonCommentHandling.Skip
|
|
|
|
|
});
|
|
|
|
|
PostPath = systemConfig.realtimepath;
|
|
|
|
|
RealtimePath= systemConfig.postpath;
|
|
|
|
|
_systemConfig = systemConfig;
|
|
|
|
|
PostPath = systemConfig.postpath;
|
|
|
|
|
RealtimePath= systemConfig.realtimepath;
|
|
|
|
|
MseedPath = systemConfig.mseedpath;
|
|
|
|
|
MainPath= systemConfig.mainpath;
|
|
|
|
|
|
|
|
|
|
DataBaseConnect.DataBaseConfig = systemConfig.dBConfig;
|
|
|
|
|
DataBaseConnect.GetInstance.DataBaseConfig = systemConfig.dBConfig;
|
|
|
|
|
|
|
|
|
|
watcherArray[0] = new FileSystemWatcher();
|
|
|
|
|
watcherArray[1] = new FileSystemWatcher();
|
|
|
|
@ -82,6 +79,45 @@ namespace Txgy.FilesWatcher.ViewModels
|
|
|
|
|
get { return mainPath; }
|
|
|
|
|
set { SetProperty(ref mainPath, value); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool isUploadMseedPath;
|
|
|
|
|
public bool IsUploadMseedPath
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
get { return isUploadMseedPath; }
|
|
|
|
|
set { SetProperty(ref isUploadMseedPath, value); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool isUploadRealtimePath;
|
|
|
|
|
public bool IsUploadRealtimePath
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
get { return isUploadRealtimePath; }
|
|
|
|
|
set { SetProperty(ref isUploadRealtimePath, value); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool isUploadPostPath;
|
|
|
|
|
public bool IsUploadPostPath
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
get { return isUploadPostPath; }
|
|
|
|
|
set { SetProperty(ref isUploadPostPath, value); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool isUploadDB = false;
|
|
|
|
|
|
|
|
|
|
public bool IsUploadDB
|
|
|
|
|
{
|
|
|
|
|
get { return isUploadDB; }
|
|
|
|
|
set { SetProperty(ref isUploadDB, value); }
|
|
|
|
|
}
|
|
|
|
|
private bool isUploadMQTT = false;
|
|
|
|
|
|
|
|
|
|
public bool IsUploadMQTT
|
|
|
|
|
{
|
|
|
|
|
get { return isUploadMQTT; }
|
|
|
|
|
set { SetProperty(ref isUploadMQTT, value); }
|
|
|
|
|
}
|
|
|
|
|
private ObservableCollection<WatcherFileModel> dataList = new ObservableCollection<WatcherFileModel>();
|
|
|
|
|
|
|
|
|
|
public ObservableCollection<WatcherFileModel> DataList
|
|
|
|
@ -115,7 +151,7 @@ namespace Txgy.FilesWatcher.ViewModels
|
|
|
|
|
get { return selectedIndex; }
|
|
|
|
|
set { SetProperty(ref selectedIndex, value); }
|
|
|
|
|
}
|
|
|
|
|
private int proMonInterval = 5;
|
|
|
|
|
private int proMonInterval = 30;
|
|
|
|
|
public int ProMonInterval
|
|
|
|
|
{
|
|
|
|
|
get => proMonInterval;
|
|
|
|
@ -143,20 +179,6 @@ namespace Txgy.FilesWatcher.ViewModels
|
|
|
|
|
set { SetProperty(ref workAreaId, value); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool isUploadDB = false;
|
|
|
|
|
|
|
|
|
|
public bool IsUploadDB
|
|
|
|
|
{
|
|
|
|
|
get { return isUploadDB; }
|
|
|
|
|
set { SetProperty(ref isUploadDB, value); }
|
|
|
|
|
}
|
|
|
|
|
private bool isUploadMQTT = false;
|
|
|
|
|
|
|
|
|
|
public bool IsUploadMQTT
|
|
|
|
|
{
|
|
|
|
|
get { return isUploadMQTT; }
|
|
|
|
|
set { SetProperty(ref isUploadMQTT, value); }
|
|
|
|
|
}
|
|
|
|
|
public DelegateCommand StartCommand => new(Start);
|
|
|
|
|
|
|
|
|
|
public DelegateCommand StopCommand => new(Stop);
|
|
|
|
@ -188,27 +210,35 @@ namespace Txgy.FilesWatcher.ViewModels
|
|
|
|
|
fbd.ShowNewFolderButton = true;
|
|
|
|
|
if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
if (fbd.SelectedPath != MainPath)
|
|
|
|
|
{
|
|
|
|
|
MainPath = fbd.SelectedPath;
|
|
|
|
|
systemConfig.mainpath = MainPath;
|
|
|
|
|
UpdateJsonConfig(systemConfig);
|
|
|
|
|
}
|
|
|
|
|
sure(para, fbd.SelectedPath);
|
|
|
|
|
UpdateJsonConfig(_systemConfig);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
public DelegateCommand<object> SureCommand => new((obj) =>
|
|
|
|
|
void sure(string para,string filePath)
|
|
|
|
|
{
|
|
|
|
|
string para = obj.ToString();
|
|
|
|
|
if (para == "MseedPath")
|
|
|
|
|
if (para == "MainPath")
|
|
|
|
|
{
|
|
|
|
|
if (!Directory.Exists(filePath))
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show($"{filePath} 不存在!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
MainPath = filePath;
|
|
|
|
|
_systemConfig.mainpath = filePath;
|
|
|
|
|
}
|
|
|
|
|
else if (para == "MseedPath")
|
|
|
|
|
{
|
|
|
|
|
string path = Path.Combine(MainPath, MseedPath);
|
|
|
|
|
|
|
|
|
|
var name = Path.GetDirectoryName(filePath);
|
|
|
|
|
string path = Path.Combine(MainPath, name);
|
|
|
|
|
if (!Directory.Exists(path))
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show($"{path} 不存在!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
systemConfig.mseedpath = MseedPath;
|
|
|
|
|
_systemConfig.mseedpath = name;
|
|
|
|
|
}
|
|
|
|
|
else if (para == "RealtimePath")
|
|
|
|
|
{
|
|
|
|
@ -219,7 +249,7 @@ namespace Txgy.FilesWatcher.ViewModels
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
watcherArray[0].Path = Path.Combine(MainPath, RealtimePath);
|
|
|
|
|
systemConfig.realtimepath = RealtimePath;
|
|
|
|
|
_systemConfig.realtimepath = RealtimePath;
|
|
|
|
|
}
|
|
|
|
|
else if (para == "PostPath")
|
|
|
|
|
{
|
|
|
|
@ -230,10 +260,10 @@ namespace Txgy.FilesWatcher.ViewModels
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
watcherArray[1].Path = Path.Combine(MainPath, PostPath);
|
|
|
|
|
systemConfig.postpath = PostPath;
|
|
|
|
|
_systemConfig.postpath = PostPath;
|
|
|
|
|
}
|
|
|
|
|
UpdateJsonConfig(_systemConfig);
|
|
|
|
|
}
|
|
|
|
|
UpdateJsonConfig(systemConfig);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
private void InitializeParams(string fileFilter)
|
|
|
|
|
{
|
|
|
|
@ -281,6 +311,7 @@ namespace Txgy.FilesWatcher.ViewModels
|
|
|
|
|
|
|
|
|
|
private void UpdateJsonConfig(SystemConfig systemConfig)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
var options = new JsonSerializerOptions
|
|
|
|
|
{
|
|
|
|
|
// 整齐打印
|
|
|
|
@ -300,8 +331,9 @@ namespace Txgy.FilesWatcher.ViewModels
|
|
|
|
|
DateTime currentT= DateTime.Now;
|
|
|
|
|
RunTime = DateDiff(currentT, StartTime);
|
|
|
|
|
string path = $"{Path.Combine(MainPath, MseedPath)}/{currentT.Month.ToString("D2")}/{currentT.Day.ToString("D2")}/{currentT.Hour.ToString("D2")}/{currentT.AddMinutes(-2).Minute.ToString("D2")}";
|
|
|
|
|
// path = "I:\\DATA/NET2023/06/22/22/56";
|
|
|
|
|
if (Directory.Exists(path) && IsUploadDB)
|
|
|
|
|
// path = "I:\\yuwuN3102mseed\\NET2023\\06\\22\\21\\50";
|
|
|
|
|
Debug.WriteLine($"**********当前时间:{currentT},监控路径:{path}");
|
|
|
|
|
if (Directory.Exists(path) && IsUploadDB&& IsUploadMseedPath)
|
|
|
|
|
{
|
|
|
|
|
UploadMseedFile.UploadMSeedOnce(path, WorkAreaId);
|
|
|
|
|
}
|
|
|
|
@ -362,21 +394,22 @@ namespace Txgy.FilesWatcher.ViewModels
|
|
|
|
|
}
|
|
|
|
|
private void Watcher_Changed(object sender, System.IO.FileSystemEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Thread.Sleep(100);
|
|
|
|
|
// string tmp = dt.Hour.ToString() + "时" + dt.Minute.ToString() + "分" + dt.Second.ToString() + "秒" + dt.Millisecond.ToString() + "毫秒,目录发生变化\r\n";
|
|
|
|
|
DateTime lastWriteTime = File.GetLastWriteTime(e.FullPath);
|
|
|
|
|
DateTime lastWriteTime = DateTime.Now;//File.GetLastWriteTime(e.FullPath);
|
|
|
|
|
var watch= sender as FileSystemWatcher;
|
|
|
|
|
string lastLine = File.ReadAllLines(e.FullPath).Last().Trim();
|
|
|
|
|
string lastLine = File.ReadLines(e.FullPath).Last().Trim();
|
|
|
|
|
Debug.WriteLine($"最后修改时间:{lastWriteTime},文件路径:{watch.Path}");
|
|
|
|
|
if (watch != null && watch.Path == watcherArray[0].Path)
|
|
|
|
|
{
|
|
|
|
|
watcherArray[0].EnableRaisingEvents = false;
|
|
|
|
|
if (IsUploadDB)
|
|
|
|
|
UploadRealtimeFile.UploadRealtimeFileOnce(e.FullPath, lastLine, IsUploadMQTT, WorkAreaId);
|
|
|
|
|
if (IsUploadDB&& isUploadRealtimePath)
|
|
|
|
|
UploadRealtimeFile.UploadRealtimeFileOnce(watcherArray[0].Path, lastLine, IsUploadMQTT, WorkAreaId);
|
|
|
|
|
}
|
|
|
|
|
else if (watch != null && watch.Path == watcherArray[1].Path)
|
|
|
|
|
{
|
|
|
|
|
watcherArray[1].EnableRaisingEvents = false;
|
|
|
|
|
if (IsUploadDB)
|
|
|
|
|
if (IsUploadDB&& IsUploadPostPath)
|
|
|
|
|
UploadPostproFile.UploadPostproFileOnce(watcherArray[1].Path, lastLine, WorkAreaId);
|
|
|
|
|
}
|
|
|
|
|
var str= dataList.Where(f => f.Data == lastLine).FirstOrDefault();
|
|
|
|
@ -460,7 +493,7 @@ namespace Txgy.FilesWatcher.ViewModels
|
|
|
|
|
|
|
|
|
|
private FileSystemWatcher[] watcherArray = new FileSystemWatcher[2];
|
|
|
|
|
private DispatcherTimer timer1 = new DispatcherTimer();
|
|
|
|
|
private SystemConfig systemConfig = new SystemConfig();
|
|
|
|
|
private readonly SystemConfig _systemConfig;
|
|
|
|
|
// private readonly WebsocketClient _websocketClient;
|
|
|
|
|
private readonly IEventAggregator _ea;
|
|
|
|
|
|
|
|
|
|