diff --git a/Txgy.FilesWatcher/ViewModels/MainViewModel.cs b/Txgy.FilesWatcher/ViewModels/MainViewModel.cs
index 6034fdf..bf1f979 100644
--- a/Txgy.FilesWatcher/ViewModels/MainViewModel.cs
+++ b/Txgy.FilesWatcher/ViewModels/MainViewModel.cs
@@ -48,6 +48,8 @@ namespace Txgy.FilesWatcher.ViewModels
MseedPath = systemConfig.mseedpath;
MainPath= systemConfig.mainpath;
ToolPath = systemConfig.toolpath;
+ WorkAreaId = systemConfig.workAreaId;
+ CycleTime = systemConfig.cycleTime;
DataBaseConnect.GetInstance.DataBaseConfig = systemConfig.dBConfig;
@@ -124,7 +126,7 @@ namespace Txgy.FilesWatcher.ViewModels
set { SetProperty(ref isUploadPostPath, value); }
}
- private bool isUploadDB = false;
+ private bool isUploadDB = true;
public bool IsUploadDB
{
@@ -294,6 +296,9 @@ namespace Txgy.FilesWatcher.ViewModels
timerTool.Start();
StartConnectMQ();
mseedFileTime = DateTime.Now;
+ _systemConfig.cycleTime = CycleTime;
+ _systemConfig.workAreaId = WorkAreaId;
+ UpdateJsonConfig(_systemConfig);
}
}
@@ -504,7 +509,7 @@ namespace Txgy.FilesWatcher.ViewModels
DateTime currentT= DateTime.Now;
RunTime = DateDiff(currentT, StartTime);
// path = "I:\\yuwuN3102mseed\\NET2023\\06\\22\\21\\51";
- if ((currentT - mseedFileTime).TotalSeconds >= 15)
+ if ((currentT - mseedFileTime).TotalSeconds >= CycleTime)
{
mseedFileTime = DateTime.Now;
//DateTime end= DateTime.Now.AddDays(-3);
@@ -519,8 +524,6 @@ namespace Txgy.FilesWatcher.ViewModels
private void MseedFileChanged(DateTime currentT)
{
- _log.Log.Debug("MainViewModel.MseedFileChanged() > enter....");
- _log.Log.DebugFormat("MainViewModel.MseedFileChanged() currentT:{0}", currentT);
string path = $"{Path.Combine(MainPath, MseedPath)}/{currentT.Month.ToString("D2")}/{currentT.Day.ToString("D2")}/{currentT.Hour.ToString("D2")}/{currentT.AddMinutes(-2).Minute.ToString("D2")}";
Debug.WriteLine($"**********当前时间:{currentT},监控路径:{path}");
if (Directory.Exists(path) && IsUploadDB && IsUploadMseedPath)
@@ -538,8 +541,6 @@ namespace Txgy.FilesWatcher.ViewModels
});
}), path, WorkAreaId);
}
- _log.Log.Debug("MainViewModel.MseedFileChanged() < exit....");
-
}
@@ -567,8 +568,8 @@ namespace Txgy.FilesWatcher.ViewModels
}
}
}
- watcherArray[0].EnableRaisingEvents =IsUploadRealtimePath;
- watcherArray[1].EnableRaisingEvents = IsUploadPostPath;
+ watcherArray[0].EnableRaisingEvents = IsUploadRealtimePath && IsEnableRaising;
+ watcherArray[1].EnableRaisingEvents = IsUploadPostPath && IsEnableRaising;
IsIndeterminate = IsEnableRaising;
}
catch (Exception ex)
diff --git a/Txgy.FilesWatcher/ViewModels/ManualModeDialogViewModel.cs b/Txgy.FilesWatcher/ViewModels/ManualModeDialogViewModel.cs
index bace928..809c87e 100644
--- a/Txgy.FilesWatcher/ViewModels/ManualModeDialogViewModel.cs
+++ b/Txgy.FilesWatcher/ViewModels/ManualModeDialogViewModel.cs
@@ -105,7 +105,6 @@ namespace Txgy.FilesWatcher.ViewModels
CancellationTokenSource cts = new CancellationTokenSource();
public async Task StartHandle(DateTime start, DateTime end)
{
- _log.Log.Debug("ManualModeDialogViewModel.StartHandle() > enter...");
_log.Log.DebugFormat("ManualModeDialogViewModel.StartHandle() start:{0},end:{1}",start, end);
CancellationToken cancellationToken = cts.Token;
string realtimePath = Path.Combine(mainModel.MainPath, mainModel.RealtimePath);
@@ -158,7 +157,6 @@ namespace Txgy.FilesWatcher.ViewModels
}
}, cancellationToken);
await Task.WhenAll(task1, task2, task3);
- _log.Log.Debug("ManualModeDialogViewModel.StartHandle() < exit...");
}
@@ -169,7 +167,6 @@ namespace Txgy.FilesWatcher.ViewModels
private void MseedUpload(DateTime currentT)
{
- _log.Log.Debug("ManualModeDialogViewModel.MseedUpload() > enter...");
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}");
@@ -189,13 +186,10 @@ namespace Txgy.FilesWatcher.ViewModels
});
}), path, mainModel.WorkAreaId);
}
- _log.Log.Debug("ManualModeDialogViewModel.MseedUpload() < exit...");
-
}
private void RealtimeChanged(string filePath, string lastLine)
{
- _log.Log.Debug("ManualModeDialogViewModel.RealtimeChanged() > enter...");
// 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}");
@@ -224,13 +218,11 @@ namespace Txgy.FilesWatcher.ViewModels
}, filePath, lastLine);
}
- _log.Log.Debug("ManualModeDialogViewModel.RealtimeChanged() < exit...");
}
private void PostChanged(string filePath, string lastLine)
{
- _log.Log.Debug("ManualModeDialogViewModel.PostChanged() > enter...");
// 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}");
@@ -264,7 +256,6 @@ namespace Txgy.FilesWatcher.ViewModels
});
}, filePath, lastLine);
}
- _log.Log.Debug("ManualModeDialogViewModel.PostChanged() < exit...");
}
private DispatcherTimer timer1 = new DispatcherTimer();
diff --git a/Txgy.FilesWatcher/Views/MainView.xaml b/Txgy.FilesWatcher/Views/MainView.xaml
index 55a2e10..700cac7 100644
--- a/Txgy.FilesWatcher/Views/MainView.xaml
+++ b/Txgy.FilesWatcher/Views/MainView.xaml
@@ -128,7 +128,7 @@
-
+
diff --git a/Txgy.FilesWatcher/log4net.config b/Txgy.FilesWatcher/log4net.config
index b6fc137..8b02f99 100644
--- a/Txgy.FilesWatcher/log4net.config
+++ b/Txgy.FilesWatcher/log4net.config
@@ -26,7 +26,7 @@
-
+
diff --git a/Txgy.FilesWatcher/model/SystemConfig.cs b/Txgy.FilesWatcher/model/SystemConfig.cs
index b46af9a..af61df0 100644
--- a/Txgy.FilesWatcher/model/SystemConfig.cs
+++ b/Txgy.FilesWatcher/model/SystemConfig.cs
@@ -16,6 +16,8 @@ namespace Txgy.FilesWatcher.model
public string toolpath { get; set; }
public int cycleTime { get; set; }
+
+ public int workAreaId { get; set; }
public MQTTConfig mQTTConfig { get; set; }
public DBConfig dBConfig { get; set; }
diff --git a/Txgy.FilesWatcher/model/UploadMseedFile.cs b/Txgy.FilesWatcher/model/UploadMseedFile.cs
index ecb0fd3..96a2a2e 100644
--- a/Txgy.FilesWatcher/model/UploadMseedFile.cs
+++ b/Txgy.FilesWatcher/model/UploadMseedFile.cs
@@ -23,7 +23,6 @@ namespace Txgy.FilesWatcher.model
public static void UploadMSeedOnce(Action mseedAction, string path, int workAreaId)
{
GetLogger _log = new GetLogger("UploadMseedFile");
- _log.Log.Debug("UploadMseedFile.UploadMSeedOnce() > enter....");
_log.Log.DebugFormat("UploadMseedFile.UploadMSeedOnce() path:{0},workAreaId:{1}", path, workAreaId);
try
{
@@ -75,8 +74,6 @@ namespace Txgy.FilesWatcher.model
{
_log.Log.ErrorFormat("UploadMseedFile.UploadMSeedOnce()() error:{0}", ex);
}
- _log.Log.Debug("UploadMseedFile.UploadMSeedOnce()() < exit....");
-
}
}
diff --git a/Txgy.FilesWatcher/model/UploadPostproFile.cs b/Txgy.FilesWatcher/model/UploadPostproFile.cs
index c267826..91a281f 100644
--- a/Txgy.FilesWatcher/model/UploadPostproFile.cs
+++ b/Txgy.FilesWatcher/model/UploadPostproFile.cs
@@ -20,7 +20,6 @@ namespace Txgy.FilesWatcher.model
public static void UploadPostproFileOnce(string path, string eventMessage, int workAreaId , out bool isUpload)
{
GetLogger _log = new GetLogger("UploadPostproFile");
- _log.Log.Debug("UploadPostproFile.UploadPostproFileOnce() > enter....");
_log.Log.DebugFormat("UploadPostproFile.UploadPostproFileOnce() path:{0},eventMessage:{1},workAreaId:{2}", path, eventMessage, workAreaId);
isUpload = false;
try
@@ -50,12 +49,28 @@ namespace Txgy.FilesWatcher.model
}
string EventTime = index_file_line[0].Substring(0, 23);
string OriginTime = EventTime;
-
- //WorkAreaId = 1,更新realtimeeventresult
- sqlNumber = $"INSERT INTO {tbrealtimeresult}(WorkAreaId, EventTime, OriginTime, X, Y, Z, ML, LocSta, MLSta, RMS) VALUES('{workAreaId}', '{EventTime}', '{OriginTime}', '{index_file_line[1]}', '{index_file_line[2]}', '{index_file_line[3]}', '{index_file_line[5]}', '{index_file_line[7]}', '{index_file_line[8]}', '{index_file_line[6]}')";
- var res = conn.Execute(sqlNumber);
+ //.json文件
+ string JPath = dFile.FullName.Replace(".mseed", "A.json");
+ if (File.Exists(JPath))
+ {
+ string mes = File.ReadAllText(JPath);
+ if (!mes.Contains(EventTime))
+ {
+ //和json文件的otime 时间需要一致
+ continue;
+ }
+ }
+ // 上传前,检查workAreaId和eventTime
+ sqlNumber = $"SELECT COUNT(*) FROM {tbrealtimeresult} WHERE WorkAreaId = '{workAreaId}' && EventTime='{EventTime}'";
+ cmd = new MySqlCommand(sqlNumber, conn);
+ int b = conn.QueryFirst(sqlNumber);
+ if (b == 0)
+ {
+ sqlNumber = $"INSERT INTO {tbrealtimeresult}(WorkAreaId, EventTime, OriginTime, X, Y, Z, ML, LocSta, MLSta, RMS) VALUES('{workAreaId}', '{EventTime}', '{OriginTime}', '{index_file_line[1]}', '{index_file_line[2]}', '{index_file_line[3]}', '{index_file_line[5]}', '{index_file_line[7]}', '{index_file_line[8]}', '{index_file_line[6]}')";
+ var res = conn.Execute(sqlNumber);
+ _log.Log.DebugFormat("UploadPostproFileOnce() 上传数据表:{0},eventMessage:{1}", tbrealtimeresult, eventMessage);
+ }
isUpload = true;
- _log.Log.DebugFormat("UploadPostproFileOnce() 上传数据表:{0},eventMessage:{1}", tbrealtimeresult, eventMessage);
// .mseed文件
FileStream fs = new FileStream(dFile.FullName, FileMode.Open, FileAccess.Read);
BinaryReader mbr = new BinaryReader(fs);
@@ -83,12 +98,12 @@ namespace Txgy.FilesWatcher.model
{
sqlNumber = $"INSERT INTO {tbname} (EventTime, WorkAreaID, WaveData, JsonFile) VALUES('{EventTime}', '{workAreaId}', @mDatas, @jDatas);";
MySqlCommand mycomm = new MySqlCommand(sqlNumber, conn);
- res = conn.Execute(sqlNumber, new { mDatas = mseedDatas, jDatas = jsonDatas });
+ conn.Execute(sqlNumber, new { mDatas = mseedDatas, jDatas = jsonDatas });
_log.Log.DebugFormat("UploadPostproFileOnce() 上传数据表:{0}", tbname);
}
sqlNumber = $"INSERT INTO {uploadedtbname}(filename, uploadtime) VALUES('{file}', '{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}')";
- res = conn.Execute(sqlNumber);
+ conn.Execute(sqlNumber);
_log.Log.DebugFormat("UploadPostproFileOnce() 上传数据表:{0},文件:{1}", uploadedtbname, file);
}
}
@@ -97,14 +112,11 @@ namespace Txgy.FilesWatcher.model
catch (Exception ex)
{
_log.Log.ErrorFormat("UploadPostproFile.UploadPostproFileOnce() error:{0}", ex);
- System.Windows.MessageBox.Show(ex.ToString());
}
- _log.Log.Debug("UploadPostproFile.UploadPostproFileOnce() < exit....");
}
public static void UploadPostproFileMQ(Action mqAction, string path, string eventMessage)
{
GetLogger _log = new GetLogger("UploadPostproFile");
- _log.Log.Debug("UploadPostproFile.UploadPostproFileMQ() > enter....");
_log.Log.DebugFormat("UploadPostproFile.UploadPostproFileMQ() path:{0},eventMessage:{1}", path, eventMessage);
try
{
@@ -141,7 +153,6 @@ namespace Txgy.FilesWatcher.model
{
_log.Log.ErrorFormat("UploadPostproFile.UploadPostproFileMQ() error:{0}", ex);
}
- _log.Log.Debug("UploadPostproFile.UploadPostproFileMQ() < exit....");
}
}
diff --git a/Txgy.FilesWatcher/model/UploadRealtimeFile.cs b/Txgy.FilesWatcher/model/UploadRealtimeFile.cs
index a64c4c3..fb760ce 100644
--- a/Txgy.FilesWatcher/model/UploadRealtimeFile.cs
+++ b/Txgy.FilesWatcher/model/UploadRealtimeFile.cs
@@ -26,7 +26,6 @@ namespace Txgy.FilesWatcher.model
public static void UploadRealtimeFileOnce(string path, string eventMessage, int workAreaId, out bool isUpload)
{
GetLogger _log = new GetLogger("UploadRealtimeFile");
- _log.Log.Debug("UploadRealtimeFile.UploadRealtimeFileOnce() > enter....");
_log.Log.DebugFormat("UploadRealtimeFile.UploadRealtimeFileOnce() path:{0},eventMessage:{1},workAreaId:{2}", path, eventMessage, workAreaId);
isUpload = false;
try
@@ -57,20 +56,29 @@ namespace Txgy.FilesWatcher.model
string EventTime = index_file_line[0].Substring(0, 23);
string OriginTime = EventTime;
-
- //上传前,检查workAreaId和eventTime
+ //.json文件
+ string JPath = dFile.FullName.Replace(".mseed", "A.json");
+ if(File.Exists(JPath))
{
- //int workAreaId = 10;
- //string eventTime = "0";
- //if (workAreaId == 0 && eventTime == "0")
- //{ }
+ string mes= File.ReadAllText(JPath);
+ if (!mes.Contains(EventTime))
+ {
+ //和json文件的otime 时间需要一致
+ continue;
+ }
}
- //WorkAreaId = 1,更新realtimeeventresult
- sqlNumber = $"INSERT INTO {tbrealtimeresult}(WorkAreaId, EventTime, OriginTime, X, Y, Z, ML, LocSta, MLSta, RMS) VALUES('{workAreaId}', '{EventTime}', '{OriginTime}', '{index_file_line[1]}', '{index_file_line[2]}', '{index_file_line[3]}', '{index_file_line[5]}', '{index_file_line[7]}', '{index_file_line[8]}', '{index_file_line[6]}')";
- var res = conn.Execute(sqlNumber);
+ // 上传前,检查workAreaId和eventTime
+ sqlNumber = $"SELECT COUNT(*) FROM {tbrealtimeresult} WHERE WorkAreaId = '{workAreaId}' && EventTime='{EventTime}'";
+ cmd = new MySqlCommand(sqlNumber, conn);
+ int b = conn.QueryFirst(sqlNumber);
+ if (b == 0)
+ {
+ sqlNumber = $"INSERT INTO {tbrealtimeresult}(WorkAreaId, EventTime, OriginTime, X, Y, Z, ML, LocSta, MLSta, RMS) VALUES('{workAreaId}', '{EventTime}', '{OriginTime}', '{index_file_line[1]}', '{index_file_line[2]}', '{index_file_line[3]}', '{index_file_line[5]}', '{index_file_line[7]}', '{index_file_line[8]}', '{index_file_line[6]}')";
+ conn.Execute(sqlNumber);
+ _log.Log.DebugFormat("UploadRealtimeFileOnce() 上传数据表:{0},eventMessage:{1}", tbrealtimeresult, eventMessage);
+ }
isUpload = true;
- _log.Log.DebugFormat("UploadRealtimeFileOnce() 上传数据表:{0},eventMessage:{1}", tbrealtimeresult, eventMessage);
// .mseed文件
FileStream fs = new FileStream(dFile.FullName, FileMode.Open, FileAccess.Read);
BinaryReader mbr = new BinaryReader(fs);
@@ -97,12 +105,11 @@ namespace Txgy.FilesWatcher.model
{
sqlNumber = $"INSERT INTO {tbname} (EventTime, WorkAreaID, WaveData, JsonFile) VALUES('{EventTime}', '{workAreaId}', @mDatas, @jDatas);";
MySqlCommand mycomm = new MySqlCommand(sqlNumber, conn);
- res = conn.Execute(sqlNumber, new { mDatas = mseedDatas, jDatas = jsonDatas });
+ conn.Execute(sqlNumber, new { mDatas = mseedDatas, jDatas = jsonDatas });
_log.Log.DebugFormat("UploadRealtimeFileOnce() 上传数据表:{0}", tbname);
-
}
sqlNumber = $"INSERT INTO {uploadedtbname}(filename, uploadtime) VALUES('{file}', '{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}')";
- res = conn.Execute(sqlNumber);
+ int res = conn.Execute(sqlNumber);
_log.Log.DebugFormat("UploadRealtimeFileOnce() 上传数据表:{0},文传:{1}", uploadedtbname, file);
}
@@ -112,15 +119,12 @@ namespace Txgy.FilesWatcher.model
catch (Exception ex)
{
_log.Log.ErrorFormat("UploadRealtimeFile.UploadRealtimeFileOnce() error:{0}", ex);
- MessageBox.Show(ex.ToString());
}
- _log.Log.Debug("UploadRealtimeFile.UploadRealtimeFileOnce() < exit....");
}
public static void UploadRealtimeFileMQ(Action mqAction, string path, string eventMessage)
{
GetLogger _log = new GetLogger("UploadRealtimeFile");
- _log.Log.Debug("UploadRealtimeFile.UploadRealtimeFileMQ() > enter....");
_log.Log.DebugFormat("UploadRealtimeFile.UploadRealtimeFileMQ() path:{0},eventMessage:{1}", path, eventMessage);
try
{
@@ -151,10 +155,8 @@ namespace Txgy.FilesWatcher.model
}
catch (Exception ex)
{
- //MessageBox.Show(ex.ToString());
_log.Log.ErrorFormat("UploadRealtimeFile.UploadRealtimeFileMQ() error:{0}", ex);
}
- _log.Log.Debug("UploadRealtimeFile.UploadRealtimeFileMQ() < exit....");
}
}
diff --git a/Txgy.FilesWatcher/systemconfig.json b/Txgy.FilesWatcher/systemconfig.json
index fdc97e3..dcae212 100644
--- a/Txgy.FilesWatcher/systemconfig.json
+++ b/Txgy.FilesWatcher/systemconfig.json
@@ -9,6 +9,9 @@
"toolpath": "post20231119",
//原始波形目录
"mseedpath": "NET2023",
+ //工区号
+ "workAreaId": 8,
+ "cycleTime": 3600,
"mQTTConfig": {
"serverIP": "49.232.209.49",
"port": 1883,