|
|
|
@ -22,7 +22,9 @@ using System.Text.Unicode;
|
|
|
|
|
using System.Net.Sockets;
|
|
|
|
|
using System.Security.Policy;
|
|
|
|
|
using Prism.Events;
|
|
|
|
|
using System.Windows.Shapes;
|
|
|
|
|
using ImTools;
|
|
|
|
|
using static System.Windows.Forms.Design.AxImporter;
|
|
|
|
|
using HandyControl.Controls;
|
|
|
|
|
|
|
|
|
|
namespace Txgy.FilesWatcher.ViewModels
|
|
|
|
|
{
|
|
|
|
@ -32,41 +34,53 @@ namespace Txgy.FilesWatcher.ViewModels
|
|
|
|
|
{
|
|
|
|
|
string filter = "*.index";
|
|
|
|
|
string str = File.ReadAllText("systemconfig.json");
|
|
|
|
|
systemConfig = JsonSerializer.Deserialize<SystemConfig>(str);
|
|
|
|
|
WatcherPath = systemConfig.FilePath;
|
|
|
|
|
WatcherMseedPath= systemConfig.WatcherMseedPath;
|
|
|
|
|
MseedFilePath = systemConfig.MseedFilePath;
|
|
|
|
|
systemConfig = JsonSerializer.Deserialize<SystemConfig>(str, new JsonSerializerOptions
|
|
|
|
|
{
|
|
|
|
|
ReadCommentHandling = JsonCommentHandling.Skip
|
|
|
|
|
});
|
|
|
|
|
PostPath = systemConfig.realtimepath;
|
|
|
|
|
RealtimePath= systemConfig.postpath;
|
|
|
|
|
MseedPath = systemConfig.mseedpath;
|
|
|
|
|
MainPath= systemConfig.mainpath;
|
|
|
|
|
|
|
|
|
|
DataBaseConnect.DataBaseConfig = systemConfig.dBConfig;
|
|
|
|
|
|
|
|
|
|
watcherArray[0] = new FileSystemWatcher();
|
|
|
|
|
watcherArray[1] = new FileSystemWatcher();
|
|
|
|
|
InitializeParams(filter);
|
|
|
|
|
StartTime = DateTime.Now;
|
|
|
|
|
this._ea = ea;
|
|
|
|
|
// this._websocketClient = websocketClient;
|
|
|
|
|
// _websocketClient.WebsocketError = WebSocket_Error;
|
|
|
|
|
// _websocketClient.WebSocketMessageReceived = WebSocket4Net_MessageReceived;
|
|
|
|
|
// _websocketClient.WebSocketInit(systemConfig.Url);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
private string watcherPath;
|
|
|
|
|
|
|
|
|
|
public string WatcherPath
|
|
|
|
|
public string PostPath
|
|
|
|
|
{
|
|
|
|
|
get { return watcherPath; }
|
|
|
|
|
set { SetProperty(ref watcherPath, value); }
|
|
|
|
|
}
|
|
|
|
|
private string watcherMseedPath;
|
|
|
|
|
private string realtimePath;
|
|
|
|
|
|
|
|
|
|
public string RealtimePath
|
|
|
|
|
{
|
|
|
|
|
get { return realtimePath; }
|
|
|
|
|
set { SetProperty(ref realtimePath, value); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string mseedPath;
|
|
|
|
|
public string MseedPath
|
|
|
|
|
|
|
|
|
|
public string WatcherMseedPath
|
|
|
|
|
{
|
|
|
|
|
get { return watcherMseedPath; }
|
|
|
|
|
set { SetProperty(ref watcherMseedPath, value); }
|
|
|
|
|
get { return mseedPath; }
|
|
|
|
|
set { SetProperty(ref mseedPath, value); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string mseedFilePath;
|
|
|
|
|
public string MseedFilePath
|
|
|
|
|
private string mainPath;
|
|
|
|
|
public string MainPath
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
get { return mseedFilePath; }
|
|
|
|
|
set { SetProperty(ref mseedFilePath, value); }
|
|
|
|
|
get { return mainPath; }
|
|
|
|
|
set { SetProperty(ref mainPath, value); }
|
|
|
|
|
}
|
|
|
|
|
private ObservableCollection<WatcherFileModel> dataList = new ObservableCollection<WatcherFileModel>();
|
|
|
|
|
|
|
|
|
@ -128,84 +142,98 @@ namespace Txgy.FilesWatcher.ViewModels
|
|
|
|
|
get { return workAreaId; }
|
|
|
|
|
set { SetProperty(ref workAreaId, value); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool isUploadDB = false;
|
|
|
|
|
|
|
|
|
|
bool isLogin = false;
|
|
|
|
|
public DelegateCommand SureCommand => new(() => {
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
private void Start()
|
|
|
|
|
{
|
|
|
|
|
WatchStartOrSopt(true);
|
|
|
|
|
StartTime=DateTime.Now;
|
|
|
|
|
timer1.Interval = TimeSpan.FromSeconds(ProMonInterval);
|
|
|
|
|
timer1.Start();
|
|
|
|
|
timer1.Tick += timer1_Tick;
|
|
|
|
|
IsIndeterminate = true;
|
|
|
|
|
int res= WatchStartOrSopt(true);
|
|
|
|
|
if (res == 0)
|
|
|
|
|
{
|
|
|
|
|
StartTime = DateTime.Now;
|
|
|
|
|
timer1.Interval = TimeSpan.FromSeconds(ProMonInterval);
|
|
|
|
|
timer1.Start();
|
|
|
|
|
timer1.Tick += timer1_Tick;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Stop()
|
|
|
|
|
{
|
|
|
|
|
WatchStartOrSopt(false);
|
|
|
|
|
timer1.Stop();
|
|
|
|
|
IsIndeterminate = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DelegateCommand<object> FilePathSaveCommand => new((obj) =>
|
|
|
|
|
{
|
|
|
|
|
System.Windows.Forms.FolderBrowserDialog fbd = new System.Windows.Forms.FolderBrowserDialog();
|
|
|
|
|
string para = obj.ToString();
|
|
|
|
|
fbd.SelectedPath = (para == "WatcherPath") ? WatcherPath : watcherMseedPath;
|
|
|
|
|
fbd.SelectedPath = MainPath;// (para == "PostPath") ? PostPath : RealtimePath;
|
|
|
|
|
fbd.Description = "请选择文件路径";
|
|
|
|
|
fbd.ShowNewFolderButton = true;
|
|
|
|
|
if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
if (fbd.SelectedPath != WatcherPath)
|
|
|
|
|
if (fbd.SelectedPath != MainPath)
|
|
|
|
|
{
|
|
|
|
|
if (para == "WatcherPath")
|
|
|
|
|
{
|
|
|
|
|
WatcherPath = fbd.SelectedPath;
|
|
|
|
|
watcherArray[0].Path = watcherPath;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
watcherMseedPath = fbd.SelectedPath;
|
|
|
|
|
watcherArray[1].Path = watcherMseedPath;
|
|
|
|
|
}
|
|
|
|
|
systemConfig.FilePath = WatcherPath;
|
|
|
|
|
systemConfig.WatcherMseedPath = watcherMseedPath;
|
|
|
|
|
var options = new JsonSerializerOptions
|
|
|
|
|
{
|
|
|
|
|
// 整齐打印
|
|
|
|
|
WriteIndented = true,
|
|
|
|
|
//重新编码,解决中文乱码问题
|
|
|
|
|
Encoder = JavaScriptEncoder.Create(UnicodeRanges.All)
|
|
|
|
|
};
|
|
|
|
|
string message = JsonSerializer.Serialize(systemConfig, options);
|
|
|
|
|
if (File.Exists(settingDataPath))
|
|
|
|
|
{
|
|
|
|
|
File.WriteAllText(settingDataPath, message);
|
|
|
|
|
}
|
|
|
|
|
MainPath = fbd.SelectedPath;
|
|
|
|
|
systemConfig.mainpath = MainPath;
|
|
|
|
|
UpdateJsonConfig(systemConfig);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
private string settingDataPath = "systemconfig.json";
|
|
|
|
|
private void timer1_Tick(object? sender, EventArgs e)
|
|
|
|
|
public DelegateCommand<object> SureCommand => new((obj) =>
|
|
|
|
|
{
|
|
|
|
|
DateTime currentT= DateTime.Now;
|
|
|
|
|
RunTime = DateDiff(currentT, StartTime);
|
|
|
|
|
string path = $"{MseedFilePath}/NET{currentT.Year.ToString("D4")}/{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))
|
|
|
|
|
string para = obj.ToString();
|
|
|
|
|
if (para == "MseedPath")
|
|
|
|
|
{
|
|
|
|
|
UploadMseedFile.UploadMSeedOnce(path, WorkAreaId);
|
|
|
|
|
string path = Path.Combine(MainPath, MseedPath);
|
|
|
|
|
if (!Directory.Exists(path))
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show($"{path} 不存在!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
systemConfig.mseedpath = MseedPath;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (para == "RealtimePath")
|
|
|
|
|
{
|
|
|
|
|
string path = Path.Combine(MainPath, RealtimePath);
|
|
|
|
|
if (!Directory.Exists(path))
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show($"{path} 不存在!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
watcherArray[0].Path = Path.Combine(MainPath, RealtimePath);
|
|
|
|
|
systemConfig.realtimepath = RealtimePath;
|
|
|
|
|
}
|
|
|
|
|
else if (para == "PostPath")
|
|
|
|
|
{
|
|
|
|
|
string path = Path.Combine(MainPath, PostPath);
|
|
|
|
|
if (!Directory.Exists(path))
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show($"{path} 不存在!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
watcherArray[1].Path = Path.Combine(MainPath, PostPath);
|
|
|
|
|
systemConfig.postpath = PostPath;
|
|
|
|
|
}
|
|
|
|
|
UpdateJsonConfig(systemConfig);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
private void InitializeParams(string fileFilter)
|
|
|
|
|
{
|
|
|
|
@ -217,18 +245,7 @@ namespace Txgy.FilesWatcher.ViewModels
|
|
|
|
|
IntervalTimesSource.Add(30);
|
|
|
|
|
IntervalTimesSource.Add(60);
|
|
|
|
|
SelectedIndex = 1;
|
|
|
|
|
//如果设置的目录不存在设置到根目录
|
|
|
|
|
if (!Directory.Exists(WatcherPath))
|
|
|
|
|
{
|
|
|
|
|
WatcherPath = AppDomain.CurrentDomain.BaseDirectory;
|
|
|
|
|
}
|
|
|
|
|
if (!Directory.Exists(watcherMseedPath))
|
|
|
|
|
{
|
|
|
|
|
watcherMseedPath = AppDomain.CurrentDomain.BaseDirectory;
|
|
|
|
|
}
|
|
|
|
|
watcherArray[0].Path = watcherPath;
|
|
|
|
|
watcherArray[1].Path = watcherMseedPath;
|
|
|
|
|
//watcherArray = new FileSystemWatcher();
|
|
|
|
|
|
|
|
|
|
foreach (var watcher in watcherArray)
|
|
|
|
|
{
|
|
|
|
|
//初始化监听
|
|
|
|
@ -244,7 +261,7 @@ namespace Txgy.FilesWatcher.ViewModels
|
|
|
|
|
| NotifyFilters.Security
|
|
|
|
|
| NotifyFilters.Size;
|
|
|
|
|
//设置监听的路径
|
|
|
|
|
// watcher.Path = WatcherPath;
|
|
|
|
|
// watcher.Path = PostPath;
|
|
|
|
|
watcher.Changed += new FileSystemEventHandler(Watcher_Changed);
|
|
|
|
|
// watcherArray.Created += Watcher_Created;
|
|
|
|
|
watcher.Deleted += new FileSystemEventHandler(Watcher_Deleted);
|
|
|
|
@ -259,8 +276,62 @@ namespace Txgy.FilesWatcher.ViewModels
|
|
|
|
|
watcher.EnableRaisingEvents = false;
|
|
|
|
|
watcher.EndInit();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void UpdateJsonConfig(SystemConfig systemConfig)
|
|
|
|
|
{
|
|
|
|
|
var options = new JsonSerializerOptions
|
|
|
|
|
{
|
|
|
|
|
// 整齐打印
|
|
|
|
|
WriteIndented = true,
|
|
|
|
|
//重新编码,解决中文乱码问题
|
|
|
|
|
Encoder = JavaScriptEncoder.Create(UnicodeRanges.All)
|
|
|
|
|
};
|
|
|
|
|
string message = JsonSerializer.Serialize(systemConfig, options);
|
|
|
|
|
if (File.Exists(settingDataPath))
|
|
|
|
|
{
|
|
|
|
|
File.WriteAllText(settingDataPath, message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private string settingDataPath = "systemconfig.json";
|
|
|
|
|
private void timer1_Tick(object? sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
UploadMseedFile.UploadMSeedOnce(path, WorkAreaId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 启动或者停止监听
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="IsEnableRaising">True:启用监听,False:关闭监听</param>
|
|
|
|
|
private int WatchStartOrSopt(bool IsEnableRaising)
|
|
|
|
|
{
|
|
|
|
|
int result = 0;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (IsEnableRaising)
|
|
|
|
|
{
|
|
|
|
|
watcherArray[0].Path = Path.Combine(MainPath, RealtimePath);
|
|
|
|
|
watcherArray[1].Path = Path.Combine(MainPath, PostPath);
|
|
|
|
|
}
|
|
|
|
|
watcherArray[0].EnableRaisingEvents = IsEnableRaising;
|
|
|
|
|
watcherArray[1].EnableRaisingEvents = IsEnableRaising;
|
|
|
|
|
IsIndeterminate = IsEnableRaising;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
result = 1;
|
|
|
|
|
MessageBox.Show(ex.ToString());
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private string DateDiff(DateTime DateTime1, DateTime DateTime2)
|
|
|
|
|
{
|
|
|
|
@ -299,12 +370,14 @@ namespace Txgy.FilesWatcher.ViewModels
|
|
|
|
|
if (watch != null && watch.Path == watcherArray[0].Path)
|
|
|
|
|
{
|
|
|
|
|
watcherArray[0].EnableRaisingEvents = false;
|
|
|
|
|
UploadRealtimeFile.UploadRealtimeFileOnce(e.FullPath, lastLine, WorkAreaId);
|
|
|
|
|
if (IsUploadDB)
|
|
|
|
|
UploadRealtimeFile.UploadRealtimeFileOnce(e.FullPath, lastLine, IsUploadMQTT, WorkAreaId);
|
|
|
|
|
}
|
|
|
|
|
else if (watch != null && watch.Path == watcherArray[1].Path)
|
|
|
|
|
{
|
|
|
|
|
watcherArray[1].EnableRaisingEvents = false;
|
|
|
|
|
UploadPostproFile.UploadPostproFileOnce(watcherArray[1].Path, lastLine, WorkAreaId);
|
|
|
|
|
if (IsUploadDB)
|
|
|
|
|
UploadPostproFile.UploadPostproFileOnce(watcherArray[1].Path, lastLine, WorkAreaId);
|
|
|
|
|
}
|
|
|
|
|
var str= dataList.Where(f => f.Data == lastLine).FirstOrDefault();
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(lastLine)
|
|
|
|
@ -384,16 +457,6 @@ namespace Txgy.FilesWatcher.ViewModels
|
|
|
|
|
// Data=tmp
|
|
|
|
|
//});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 启动或者停止监听
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="IsEnableRaising">True:启用监听,False:关闭监听</param>
|
|
|
|
|
private void WatchStartOrSopt(bool IsEnableRaising)
|
|
|
|
|
{
|
|
|
|
|
watcherArray[0].EnableRaisingEvents = IsEnableRaising;
|
|
|
|
|
watcherArray[1].EnableRaisingEvents = IsEnableRaising;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private FileSystemWatcher[] watcherArray = new FileSystemWatcher[2];
|
|
|
|
|
private DispatcherTimer timer1 = new DispatcherTimer();
|
|
|
|
|