修改测试问题

master
mzhifa 10 months ago
parent 7b51a075dd
commit 35119b232c

@ -1,6 +1,8 @@
using Prism.Ioc;
using Prism.Regions;
using System.Text.Json;
using System.Windows;
using Txgy.FilesWatcher.model;
using Txgy.FilesWatcher.Views;
namespace Txgy.FilesWatcher
@ -19,7 +21,14 @@ namespace Txgy.FilesWatcher
{
containerRegistry.RegisterSingleton<WebsocketClient>();
containerRegistry.RegisterSingleton<SystemConfig>(a=>
{
string str = System.IO.File.ReadAllText("systemconfig.json");
return JsonSerializer.Deserialize<SystemConfig>(str, new JsonSerializerOptions
{
ReadCommentHandling = JsonCommentHandling.Skip
});
});
var iregion= Container.Resolve<IRegionManager>();
iregion.RegisterViewWithRegion("MainContentRegion", typeof(MainView));

@ -8,6 +8,7 @@
<ItemGroup>
<PackageReference Include="Dapper" Version="2.1.21" />
<PackageReference Include="HandyControl" Version="3.4.0" />
<PackageReference Include="MQTTnet.Extensions.ManagedClient" Version="3.0.5" />
<PackageReference Include="MySql.Data" Version="8.2.0" />
<PackageReference Include="Prism.DryIoc" Version="8.1.97" />
<PackageReference Include="WebSocket4Net" Version="0.15.2" />

@ -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;

@ -59,34 +59,34 @@
<Run Text="运行时间:"/>
<Run Text="{Binding RunTime, StringFormat=yyyy-MM-dd HH:mm:ss}"/>
</TextBlock>
<CheckBox Grid.Row="4" Grid.Column="0" Content="上传数据库" IsChecked="{Binding IsUploadDB}" IsEnabled="{Binding ElementName=btnStart,Path=IsChecked}" Style="{StaticResource ToggleButtonSwitchBaseStyle}" Width="120"/>
<CheckBox Grid.Row="4" Grid.Column="1" Content="MQ转发数据" IsChecked="{Binding IsUploadMQTT}" IsEnabled="{Binding ElementName=btnStart,Path=IsChecked}" Style="{StaticResource ToggleButtonSwitchBaseStyle}" Width="120"/>
<Grid Grid.Row="5" Grid.ColumnSpan="2" IsEnabled="{Binding ElementName=btnStop,Path=IsChecked}">
<CheckBox Grid.Row="4" Grid.Column="0" Content="上传数据库" IsChecked="{Binding IsUploadDB}" Style="{StaticResource ToggleButtonSwitchBaseStyle}" Width="120"/>
<CheckBox Grid.Row="4" Grid.Column="1" Content="MQ转发数据" IsChecked="{Binding IsUploadMQTT}" Style="{StaticResource ToggleButtonSwitchBaseStyle}" Width="120"/>
<Grid Grid.Row="5" Grid.ColumnSpan="2">
<Grid.RowDefinitions>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
</Grid.RowDefinitions>
<DockPanel Grid.Row="0">
<DockPanel Grid.Row="0" IsEnabled="{Binding ElementName=btnStop,Path=IsChecked}">
<Label Content="主目录" BorderBrush="Transparent" Grid.Row="0" Grid.Column="0" VerticalAlignment="Center" Width="110" HorizontalContentAlignment="Right"/>
<Button Content="..." Command="{Binding FilePathSaveCommand}" CommandParameter="MainPath" DockPanel.Dock="Right" HorizontalAlignment="Right"/>
<TextBox Text="{Binding MainPath}" IsReadOnly="True" DockPanel.Dock="Right" FontSize="10"/>
</DockPanel>
<DockPanel Grid.Row="1">
<CheckBox Content="原始数据 " IsChecked="{Binding IsUploadMseedPath}" Grid.Row="0" Grid.Column="0" VerticalAlignment="Center" Style="{StaticResource ToggleButtonSwitchBaseStyle}" Width="110"/>
<Button Content="OK" Command="{Binding SureCommand}" CommandParameter="MseedPath" DockPanel.Dock="Right" HorizontalAlignment="Right" />
<TextBox Text="{Binding MseedPath}" DockPanel.Dock="Right" FontSize="10" />
<Button Content="..." Command="{Binding FilePathSaveCommand}" IsEnabled="{Binding ElementName=btnStop,Path=IsChecked}" CommandParameter="MseedPath" DockPanel.Dock="Right" HorizontalAlignment="Right" />
<TextBox Text="{Binding MseedPath}" IsReadOnly="True" DockPanel.Dock="Right" FontSize="10" />
</DockPanel>
<DockPanel Grid.Row="2">
<CheckBox Content="实时结果 " IsChecked="{Binding IsUploadRealtimePath}" Grid.Row="2" Grid.Column="0" Style="{StaticResource ToggleButtonSwitchBaseStyle}" Width="110"/>
<Button Content="OK" Command="{Binding SureCommand}" CommandParameter="RealtimePath" DockPanel.Dock="Right" HorizontalAlignment="Right" />
<TextBox Text="{Binding RealtimePath}" DockPanel.Dock="Right" FontSize="10"/>
<Button Content="..." Command="{Binding FilePathSaveCommand}" IsEnabled="{Binding ElementName=btnStop,Path=IsChecked}" CommandParameter="RealtimePath" DockPanel.Dock="Right" HorizontalAlignment="Right" />
<TextBox Text="{Binding RealtimePath}" IsReadOnly="True" DockPanel.Dock="Right" FontSize="10"/>
</DockPanel>
<DockPanel Grid.Row="3">
<CheckBox Content="后处理结果" IsChecked="{Binding IsUploadPostPath}" Grid.Row="4" Grid.Column="0" Style="{StaticResource ToggleButtonSwitchBaseStyle}" Width="110"/>
<Button Content="OK" Command="{Binding SureCommand}" CommandParameter="PostPath" DockPanel.Dock="Right" HorizontalAlignment="Right" />
<TextBox Text="{Binding PostPath}" DockPanel.Dock="Right" FontSize="10" />
<Button Content="..." Command="{Binding FilePathSaveCommand}" IsEnabled="{Binding ElementName=btnStop,Path=IsChecked}" CommandParameter="PostPath" DockPanel.Dock="Right" HorizontalAlignment="Right" />
<TextBox Text="{Binding PostPath}" IsReadOnly="True" DockPanel.Dock="Right" FontSize="10" />
</DockPanel>
</Grid>
<!--<DockPanel Grid.Row="4" Grid.ColumnSpan="2" >

@ -10,21 +10,32 @@ namespace Txgy.FilesWatcher.model
{
public class DataBaseConnect
{
private static readonly string _connStr;
static DataBaseConnect()
private string _connStr;
DataBaseConnect()
{
_connStr = $"Server={DataBaseConfig.serverIP};Port={DataBaseConfig.port};Database={DataBaseConfig.database};Uid={DataBaseConfig.userName};Pwd={DataBaseConfig.password};charset='utf8'";
// _connStr = $"Server=bj-cdb-q64mbxr6.sql.tencentcdb.com;Port=60027;Database=yuwu2021;Uid=yuwudba;Pwd=Yw123456;charset='utf8'";
}
public static MySqlConnection OpenConnection()
public DBConfig DataBaseConfig { get; set; }
private static DataBaseConnect getInstance;
public static DataBaseConnect GetInstance
{
get
{
if (getInstance == null)
{
getInstance= new DataBaseConnect();
}
return getInstance;
}
}
public MySqlConnection OpenConnection()
{
_connStr = $"Server={DataBaseConfig.serverIP};Port={DataBaseConfig.port};Database={DataBaseConfig.database};Uid={DataBaseConfig.userName};Pwd={DataBaseConfig.password};charset='utf8'";
MySqlConnection connection = new MySqlConnection(_connStr);
connection.Open();
return connection;
}
public static DBConfig DataBaseConfig { get; set; }
/////////////////////////////////
//createtables 配置
//起始台站号

@ -35,7 +35,7 @@ namespace Txgy.FilesWatcher.model
string sqlNumber = $"SELECT COUNT(*) FROM {uploadedtbname} WHERE filename = '{file}'";
//检查文件是否已经上传
using (var conn = DataBaseConnect.OpenConnection())
using (var conn = DataBaseConnect.GetInstance.OpenConnection())
{
MySqlCommand cmd = new MySqlCommand(sqlNumber, conn);
var a = conn.QueryFirst<int>(sqlNumber);
@ -46,7 +46,9 @@ namespace Txgy.FilesWatcher.model
BinaryReader mbr = new BinaryReader(fs);
Byte[] mseedDatas = mbr.ReadBytes((int)fs.Length);
fs.Close();
string WaveTime = tbname.Substring(3);
string WaveTime = Path.GetFileNameWithoutExtension(file).Substring(7); //tbname.Substring(3);
WaveTime = WaveTime.Insert(4, "-").Insert(7, "-").Insert(10, "T").Insert(13, ":").Insert(16, ":00");
sqlNumber = $"INSERT INTO {tbname} (WaveTime, WorkAreaID, WaveData) VALUES('{WaveTime}', '{workAreaId}', @mseedD)";
var res = conn.Execute(sqlNumber, new { mseedD=mseedDatas});

@ -29,7 +29,7 @@ namespace Txgy.FilesWatcher.model
string uploadedtbname = "uploadedpostpro";
string sqlNumber = $"SELECT COUNT(*) FROM {uploadedtbname} WHERE filename = '{file}'";
//检查文件是否已经上传
using (var conn = DataBaseConnect.OpenConnection())
using (var conn = DataBaseConnect.GetInstance.OpenConnection())
{
MySqlCommand cmd = new MySqlCommand(sqlNumber, conn);
var a = conn.QueryFirst<int>(sqlNumber);

@ -36,7 +36,7 @@ namespace Txgy.FilesWatcher.model
string uploadedtbname = "uploadedrealtime";
string sqlNumber = $"SELECT COUNT(*) FROM {uploadedtbname} WHERE filename = '{file}'";
//检查文件是否已经上传
using (var conn = DataBaseConnect.OpenConnection())
using (var conn = DataBaseConnect.GetInstance.OpenConnection())
{
MySqlCommand cmd = new MySqlCommand(sqlNumber, conn);
var a = conn.QueryFirst<int>(sqlNumber);

Loading…
Cancel
Save