1 修改post 拼接问题;

2 上传数据库和MQ分开处理;
3 增加tool软件定时调用(60s);
master
mzhifa 10 months ago
parent 60dda83726
commit 6fcb6df58d

@ -13,22 +13,20 @@ using System.Text.Json.Serialization;
using System.Text.Json; using System.Text.Json;
using System.Net.NetworkInformation; using System.Net.NetworkInformation;
using System.Threading; using System.Threading;
using System.Net.WebSockets;
using System.Diagnostics; using System.Diagnostics;
using WebSocket4Net;
using System.IO; using System.IO;
using System.Text.Encodings.Web; using System.Text.Encodings.Web;
using System.Text.Unicode; using System.Text.Unicode;
using System.Net.Sockets;
using System.Security.Policy; using System.Security.Policy;
using Prism.Events; using Prism.Events;
using ImTools; using ImTools;
using static System.Windows.Forms.Design.AxImporter;
using HandyControl.Controls; using HandyControl.Controls;
using MQTTnet.Extensions.ManagedClient; using MQTTnet.Extensions.ManagedClient;
using MQTTnet; using MQTTnet;
using MQTTnet.Client.Options; using MQTTnet.Client.Options;
using System.Windows.Markup; using System.Windows.Markup;
using System.Windows.Forms.VisualStyles;
using System.Xml.Linq;
namespace Txgy.FilesWatcher.ViewModels namespace Txgy.FilesWatcher.ViewModels
{ {
@ -36,6 +34,8 @@ namespace Txgy.FilesWatcher.ViewModels
{ {
public MainViewModel(WebsocketClient websocketClient, SystemConfig systemConfig, IEventAggregator ea) public MainViewModel(WebsocketClient websocketClient, SystemConfig systemConfig, IEventAggregator ea)
{ {
StartCommand = new DelegateCommand(Start, StartCanExecute).ObservesProperty(() => StartEnable);
StopCommand= new DelegateCommand(Stop, StopCanExecute).ObservesProperty(() => StopEnable);
string filter = "*.index"; string filter = "*.index";
string str = File.ReadAllText("systemconfig.json"); string str = File.ReadAllText("systemconfig.json");
_systemConfig = systemConfig; _systemConfig = systemConfig;
@ -43,6 +43,7 @@ namespace Txgy.FilesWatcher.ViewModels
RealtimePath= systemConfig.realtimepath; RealtimePath= systemConfig.realtimepath;
MseedPath = systemConfig.mseedpath; MseedPath = systemConfig.mseedpath;
MainPath= systemConfig.mainpath; MainPath= systemConfig.mainpath;
ToolPath = systemConfig.toolpath;
DataBaseConnect.GetInstance.DataBaseConfig = systemConfig.dBConfig; DataBaseConnect.GetInstance.DataBaseConfig = systemConfig.dBConfig;
@ -84,6 +85,14 @@ namespace Txgy.FilesWatcher.ViewModels
set { SetProperty(ref mainPath, value); } set { SetProperty(ref mainPath, value); }
} }
private string toolPath;
public string ToolPath
{
get { return toolPath; }
set { SetProperty(ref toolPath, value); }
}
private bool isUploadMseedPath; private bool isUploadMseedPath;
public bool IsUploadMseedPath public bool IsUploadMseedPath
@ -122,6 +131,14 @@ namespace Txgy.FilesWatcher.ViewModels
get { return isUploadMQTT; } get { return isUploadMQTT; }
set { SetProperty(ref isUploadMQTT, value); } set { SetProperty(ref isUploadMQTT, value); }
} }
private bool isEnableToolPath = false;
public bool IsEnableToolPath
{
get { return isEnableToolPath; }
set { SetProperty(ref isEnableToolPath, value); }
}
private ObservableCollection<FileModel> dataList = new ObservableCollection<FileModel>(); private ObservableCollection<FileModel> dataList = new ObservableCollection<FileModel>();
public ObservableCollection<FileModel> DataList public ObservableCollection<FileModel> DataList
@ -206,29 +223,70 @@ namespace Txgy.FilesWatcher.ViewModels
get { return workAreaId; } get { return workAreaId; }
set { SetProperty(ref workAreaId, value); } set { SetProperty(ref workAreaId, value); }
} }
private bool startEnable=true;
public bool StartEnable
{
get { return startEnable; }
set {
SetProperty(ref startEnable, value);
StartCommand.RaiseCanExecuteChanged();
}
}
private bool stopEnable = false;
public bool StopEnable
{
get { return stopEnable; }
set
{
SetProperty(ref stopEnable, value);
StopCommand.RaiseCanExecuteChanged();
}
}
public DelegateCommand StartCommand => new(Start); //public DelegateCommand StartCommand => new(Start, StartCanExecute);
public DelegateCommand StartCommand { get; private set; }
public DelegateCommand StopCommand => new(Stop); public DelegateCommand StopCommand { get; private set; }
private void Start() private void Start()
{ {
int res= WatchStartOrSopt(true); int res= WatchStartOrSopt(true);
if (res == 0) if (res == 0)
{ {
StartEnable = false;
StopEnable = true;
StartTime = DateTime.Now; StartTime = DateTime.Now;
timer1.Interval = TimeSpan.FromSeconds(ProMonInterval); timer1.Interval = TimeSpan.FromSeconds(ProMonInterval);
timer1.Start(); timer1.Start();
timer1.Tick += timer1_Tick; timerTool.Start();
StartConnectMQ(); StartConnectMQ();
} }
} }
private bool StartCanExecute()
{
//能否执行的逻辑
return StartEnable;
}
private bool StopCanExecute()
{
//能否执行的逻辑
return StopEnable;
}
private void Stop() private void Stop()
{ {
WatchStartOrSopt(false); WatchStartOrSopt(false);
timer1.Stop(); timer1.Stop();
timerTool.Stop();
StopMQ(); StopMQ();
StartEnable = true;
StopEnable=false;
} }
public DelegateCommand<object> FilePathSaveCommand => new((obj) => public DelegateCommand<object> FilePathSaveCommand => new((obj) =>
@ -240,9 +298,14 @@ namespace Txgy.FilesWatcher.ViewModels
fbd.ShowNewFolderButton = true; fbd.ShowNewFolderButton = true;
if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK) if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{ {
if (para == "ToolPath")
{
ToolPath = fbd.SelectedPath;
_systemConfig.toolpath = ToolPath;
}
sure(para, fbd.SelectedPath); sure(para, fbd.SelectedPath);
UpdateJsonConfig(_systemConfig); UpdateJsonConfig(_systemConfig);
} }
}); });
@ -297,12 +360,14 @@ namespace Txgy.FilesWatcher.ViewModels
_systemConfig.postpath = PostPath; _systemConfig.postpath = PostPath;
watcherArray[1].Path = path; watcherArray[1].Path = path;
} }
UpdateJsonConfig(_systemConfig);
} }
private void InitializeParams(string fileFilter) private void InitializeParams(string fileFilter)
{ {
timer1.Tick += timer1_Tick;
timerTool.Elapsed += TimerTool_Elapsed;
timer1.Interval = TimeSpan.FromSeconds(ProMonInterval); timer1.Interval = TimeSpan.FromSeconds(ProMonInterval);
timerTool.Interval = 1000 * 60; //1分钟
IntervalTimesSource.Add(5); IntervalTimesSource.Add(5);
IntervalTimesSource.Add(10); IntervalTimesSource.Add(10);
IntervalTimesSource.Add(15); IntervalTimesSource.Add(15);
@ -336,7 +401,7 @@ namespace Txgy.FilesWatcher.ViewModels
//设置监听文件类型 //设置监听文件类型
watcher.Filter = fileFilter; watcher.Filter = fileFilter;
//设置是否监听子目录 //设置是否监听子目录
watcher.IncludeSubdirectories = false; watcher.IncludeSubdirectories = true;
//设置是否启用监听 //设置是否启用监听
watcher.EnableRaisingEvents = false; watcher.EnableRaisingEvents = false;
watcher.EndInit(); watcher.EndInit();
@ -374,7 +439,6 @@ namespace Txgy.FilesWatcher.ViewModels
private void UpdateJsonConfig(SystemConfig systemConfig) private void UpdateJsonConfig(SystemConfig systemConfig)
{ {
var options = new JsonSerializerOptions var options = new JsonSerializerOptions
{ {
// 整齐打印 // 整齐打印
@ -388,6 +452,24 @@ namespace Txgy.FilesWatcher.ViewModels
File.WriteAllText(settingDataPath, message); File.WriteAllText(settingDataPath, message);
} }
} }
public static void UpdateApmsJson(string apmsJsonPath, string savePath)
{
StreamReader reader = new StreamReader(apmsJsonPath, Encoding.UTF8);
string saveStr = reader.ReadToEnd();
reader.Close();
int strInd = saveStr.IndexOf("Main.savepath") - 1;
string str1 = saveStr.Substring(strInd);
strInd = str1.IndexOf(",");
string str2 = str1.Substring(0, strInd);
strInd = str2.IndexOf(":");
string strs1 = str2.Substring(0, strInd);
string strs2 = str2.Substring(strInd + 1);
savePath = savePath.Replace("\\", "\\\\");
saveStr = saveStr.Replace(strs2, $"\"{savePath}\"");
File.WriteAllText(apmsJsonPath, saveStr);
}
private string settingDataPath = "systemconfig.json"; private string settingDataPath = "systemconfig.json";
private void timer1_Tick(object? sender, EventArgs e) private void timer1_Tick(object? sender, EventArgs e)
{ {
@ -422,11 +504,21 @@ namespace Txgy.FilesWatcher.ViewModels
{ {
if (IsEnableRaising) if (IsEnableRaising)
{ {
if (IsUploadRealtimePath)
watcherArray[0].Path = Path.Combine(MainPath, RealtimePath); watcherArray[0].Path = Path.Combine(MainPath, RealtimePath);
if (IsUploadPostPath)
watcherArray[1].Path = Path.Combine(MainPath, PostPath); watcherArray[1].Path = Path.Combine(MainPath, PostPath);
if (IsEnableToolPath)
{
if (!Directory.Exists(ToolPath))
{
MessageBox.Show($"{ToolPath} 不存在!");
return 1;
}
}
} }
watcherArray[0].EnableRaisingEvents = IsEnableRaising; watcherArray[0].EnableRaisingEvents =IsUploadRealtimePath;
watcherArray[1].EnableRaisingEvents = IsEnableRaising; watcherArray[1].EnableRaisingEvents = IsUploadPostPath;
IsIndeterminate = IsEnableRaising; IsIndeterminate = IsEnableRaising;
} }
catch (Exception ex) catch (Exception ex)
@ -472,13 +564,13 @@ namespace Txgy.FilesWatcher.ViewModels
var watch= sender as FileSystemWatcher; var watch= sender as FileSystemWatcher;
string lastLine = File.ReadLines(e.FullPath).Last().Trim(); string lastLine = File.ReadLines(e.FullPath).Last().Trim();
Debug.WriteLine($"最后修改时间:{lastWriteTime},文件路径:{watch.Path}"); Debug.WriteLine($"最后修改时间:{lastWriteTime},文件路径:{watch.Path}");
var filePath= Path.GetDirectoryName(e.FullPath);
if (watch != null && watch.Path == watcherArray[0].Path) if (watch != null && watch.Path == watcherArray[0].Path)
{ {
watcherArray[0].EnableRaisingEvents = false; watcherArray[0].EnableRaisingEvents = false;
if (IsUploadDB && isUploadRealtimePath) if (IsUploadDB && isUploadRealtimePath)
{ {
UploadRealtimeFile.UploadRealtimeFileOnce((a, b) => UploadRealtimeFile.UploadRealtimeFileOnce(filePath, lastLine, WorkAreaId);
{
timer1.Dispatcher.Invoke(() => timer1.Dispatcher.Invoke(() =>
{ {
RealTimeDataList.Add(new FileModel RealTimeDataList.Add(new FileModel
@ -487,7 +579,10 @@ namespace Txgy.FilesWatcher.ViewModels
Data = $"{DateTime.Now.ToString("yyyy-MM-dd T HH:mm:ss")}事件上传成功。" Data = $"{DateTime.Now.ToString("yyyy-MM-dd T HH:mm:ss")}事件上传成功。"
}); });
}); });
if (IsUploadMQTT) }
if (IsUploadMQTT && isUploadRealtimePath)
{
UploadRealtimeFile.UploadRealtimeFileMQ((a, b) =>
{ {
MQPublish(a, b); MQPublish(a, b);
timer1.Dispatcher.Invoke(() => timer1.Dispatcher.Invoke(() =>
@ -498,16 +593,16 @@ namespace Txgy.FilesWatcher.ViewModels
Data = $"{DateTime.Now.ToString("yyyy-MM-dd T HH:mm:ss")}事件上传成功。" Data = $"{DateTime.Now.ToString("yyyy-MM-dd T HH:mm:ss")}事件上传成功。"
}); });
}); });
}, filePath, lastLine);
} }
}, watcherArray[0].Path, lastLine, WorkAreaId);
}
} }
else if (watch != null && watch.Path == watcherArray[1].Path) else if (watch != null && watch.Path == watcherArray[1].Path)
{ {
watcherArray[1].EnableRaisingEvents = false; watcherArray[1].EnableRaisingEvents = false;
if (IsUploadDB && IsUploadPostPath) if (IsUploadDB && IsUploadPostPath)
{ {
UploadPostproFile.UploadPostproFileOnce((a, b) => UploadPostproFile.UploadPostproFileOnce(filePath, lastLine, WorkAreaId);
{ {
timer1.Dispatcher.Invoke(() => timer1.Dispatcher.Invoke(() =>
{ {
@ -517,7 +612,11 @@ namespace Txgy.FilesWatcher.ViewModels
Data = $"{DateTime.Now.ToString("yyyy-MM-dd T HH:mm:ss")}事件上传成功。" Data = $"{DateTime.Now.ToString("yyyy-MM-dd T HH:mm:ss")}事件上传成功。"
}); });
}); });
if (IsUploadMQTT) }
}
if (IsUploadMQTT && IsUploadPostPath)
{
UploadPostproFile.UploadPostproFileMQ((a, b) =>
{ {
MQPublish(a, b); MQPublish(a, b);
timer1.Dispatcher.Invoke(() => timer1.Dispatcher.Invoke(() =>
@ -528,8 +627,7 @@ namespace Txgy.FilesWatcher.ViewModels
Data = $"{DateTime.Now.ToString("yyyy-MM-dd T HH:mm:ss")}事件上传成功。" Data = $"{DateTime.Now.ToString("yyyy-MM-dd T HH:mm:ss")}事件上传成功。"
}); });
}); });
} }, filePath, lastLine);
}, watcherArray[1].Path, lastLine, WorkAreaId);
} }
} }
if (watch != null && watch.Path == watcherArray[0].Path) if (watch != null && watch.Path == watcherArray[0].Path)
@ -637,6 +735,7 @@ namespace Txgy.FilesWatcher.ViewModels
private FileSystemWatcher[] watcherArray = new FileSystemWatcher[2]; private FileSystemWatcher[] watcherArray = new FileSystemWatcher[2];
private DispatcherTimer timer1 = new DispatcherTimer(); private DispatcherTimer timer1 = new DispatcherTimer();
private System.Timers.Timer timerTool=new System.Timers.Timer();
private readonly SystemConfig _systemConfig; private readonly SystemConfig _systemConfig;
private IManagedMqttClient mqttClient; private IManagedMqttClient mqttClient;
// private readonly WebsocketClient _websocketClient; // private readonly WebsocketClient _websocketClient;
@ -650,5 +749,55 @@ namespace Txgy.FilesWatcher.ViewModels
{ {
_ea?.GetEvent<LoadingEvent>().Publish(new LoadingPayload { IsShow = false }); _ea?.GetEvent<LoadingEvent>().Publish(new LoadingPayload { IsShow = false });
} }
#region
private void TimerTool_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
DateTime currentT = DateTime.Now;
string path = $"{ToolPath}/{currentT.Month.ToString("D2")}/{currentT.Day.ToString("D2")}/{currentT.Hour.ToString("D2")}/{currentT.AddMinutes(-2).Minute.ToString("D2")}";
// path = "H:/mzhifa/txgy/FileWatchProject/NET2023/11/29/00/06";
Debug.WriteLine($"**********apmTools{currentT},结果路径:{path}");
if (Directory.Exists(path) &&IsEnableToolPath)
{
CMDStartProcess(_systemConfig.proTools,path);
}
}
private bool CMDStartProcess(ProcessInfo proInfo, string path)
{
Process process = new Process();
process.Exited += Process_Exited;
process.EnableRaisingEvents = true;
process.StartInfo.FileName = Path.GetFullPath(proInfo.ProPath + proInfo.ProName + ".exe");
process.StartInfo.UseShellExecute = false;
process.StartInfo.WorkingDirectory = Path.GetFullPath(proInfo.ProPath);
process.StartInfo.Arguments = proInfo.ProParams +path;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.CreateNoWindow = true;
//* Set your output and error (asynchronous) handlers
process.OutputDataReceived += new DataReceivedEventHandler(OutputHandler);
process.ErrorDataReceived += new DataReceivedEventHandler(OutputHandler);
bool res = process.Start();
return res;
}
private void Process_Exited(object? sender, EventArgs e)
{
}
void OutputHandler(object sendingProcess, DataReceivedEventArgs outLine)
{
Debug.WriteLine("output*************:{0},{1}", sendingProcess.ToString(), outLine.Data);
if (string.IsNullOrEmpty(outLine.Data)) return;
}
#endregion
} }
} }

@ -33,21 +33,37 @@
<RowDefinition Height="30*"/> <RowDefinition Height="30*"/>
<RowDefinition Height="30"/> <RowDefinition Height="30"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<RadioButton GroupName="start" x:Name="btnStart" Content="开始监控" Grid.Row="0" Grid.Column="0" VerticalAlignment="Center" Style="{StaticResource ToggleButtonDefault}"> <Button Grid.Row="0" x:Name="btnStart"
Grid.Column="0"
Width="60"
Height="34"
VerticalAlignment="Center"
Style="{StaticResource ButtonPrimary}"
Content="开始"
Command="{Binding StartCommand}" />
<!--<RadioButton GroupName="start" x:Name="btnStart" Content="开始监控" Grid.Row="0" Grid.Column="0" VerticalAlignment="Center" Style="{StaticResource ToggleButtonDefault}">
<i:Interaction.Triggers> <i:Interaction.Triggers>
<i:EventTrigger EventName="Checked"> <i:EventTrigger EventName="Checked">
<i:InvokeCommandAction Command="{Binding StartCommand}"/> <i:InvokeCommandAction Command="{Binding StartCommand}"/>
</i:EventTrigger> </i:EventTrigger>
</i:Interaction.Triggers> </i:Interaction.Triggers>
</RadioButton> </RadioButton>-->
<RadioButton GroupName="start" x:Name="btnStop" Content="停止监控" IsChecked="True" Grid.Row="0" Grid.Column="1" VerticalAlignment="Center" Style="{StaticResource ToggleButtonDefault}"> <Button Grid.Row="0"
Grid.Column="1"
Width="60"
Height="34"
VerticalAlignment="Center"
Style="{StaticResource ButtonPrimary}"
Content="停止"
Command="{Binding StopCommand}" />
<!--<RadioButton GroupName="start" x:Name="btnStop" Content="停止监控" IsChecked="True" Grid.Row="0" Grid.Column="1" VerticalAlignment="Center" Style="{StaticResource ToggleButtonDefault}">
<i:Interaction.Triggers> <i:Interaction.Triggers>
<i:EventTrigger EventName="Checked"> <i:EventTrigger EventName="Checked">
<i:InvokeCommandAction Command="{Binding StopCommand}"/> <i:InvokeCommandAction Command="{Binding StopCommand}"/>
</i:EventTrigger> </i:EventTrigger>
</i:Interaction.Triggers> </i:Interaction.Triggers>
</RadioButton> </RadioButton>-->
<DockPanel Grid.Row="1" IsEnabled="{Binding ElementName=btnStop,Path=IsChecked}"> <DockPanel Grid.Row="1" IsEnabled="{Binding StartEnable}">
<TextBlock Text="工区编号:" VerticalAlignment="Center"/> <TextBlock Text="工区编号:" VerticalAlignment="Center"/>
<hc:NumericUpDown Value="{Binding WorkAreaId}"/> <hc:NumericUpDown Value="{Binding WorkAreaId}"/>
</DockPanel> </DockPanel>
@ -61,31 +77,31 @@
</TextBlock> </TextBlock>
<CheckBox Grid.Row="4" Grid.Column="0" Content="上传数据库" IsChecked="{Binding IsUploadDB}" Style="{StaticResource ToggleButtonSwitchBaseStyle}" Width="120"/> <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"/> <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 Grid.Row="5" Grid.ColumnSpan="2" IsEnabled="{Binding StartEnable}">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="1*"/> <RowDefinition Height="1*"/>
<RowDefinition Height="1*"/> <RowDefinition Height="1*"/>
<RowDefinition Height="1*"/> <RowDefinition Height="1*"/>
<RowDefinition Height="1*"/> <RowDefinition Height="1*"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<DockPanel Grid.Row="0" IsEnabled="{Binding ElementName=btnStop,Path=IsChecked}"> <DockPanel Grid.Row="0" >
<Label Content="主目录" BorderBrush="Transparent" Grid.Row="0" Grid.Column="0" VerticalAlignment="Center" Width="110" HorizontalContentAlignment="Right"/> <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"/> <Button Content="..." Command="{Binding FilePathSaveCommand}" CommandParameter="MainPath" DockPanel.Dock="Right" HorizontalAlignment="Right"/>
<TextBox Text="{Binding MainPath}" IsReadOnly="True" DockPanel.Dock="Right" FontSize="10"/> <TextBox Text="{Binding MainPath}" IsReadOnly="True" DockPanel.Dock="Right" FontSize="10"/>
</DockPanel> </DockPanel>
<DockPanel Grid.Row="1"> <DockPanel Grid.Row="1">
<CheckBox Content="原始数据 " IsChecked="{Binding IsUploadMseedPath}" Grid.Row="0" Grid.Column="0" VerticalAlignment="Center" Style="{StaticResource ToggleButtonSwitchBaseStyle}" Width="110"/> <CheckBox Content="原始数据 " IsChecked="{Binding IsUploadMseedPath}" Grid.Row="0" Grid.Column="0" VerticalAlignment="Center" Style="{StaticResource ToggleButtonSwitchBaseStyle}" Width="110"/>
<Button Content="..." Command="{Binding FilePathSaveCommand}" IsEnabled="{Binding ElementName=btnStop,Path=IsChecked}" CommandParameter="MseedPath" DockPanel.Dock="Right" HorizontalAlignment="Right" /> <Button Content="..." Command="{Binding FilePathSaveCommand}" CommandParameter="MseedPath" DockPanel.Dock="Right" HorizontalAlignment="Right" />
<TextBox Text="{Binding MseedPath}" IsReadOnly="True" DockPanel.Dock="Right" FontSize="10" /> <TextBox Text="{Binding MseedPath}" IsReadOnly="True" DockPanel.Dock="Right" FontSize="10" />
</DockPanel> </DockPanel>
<DockPanel Grid.Row="2"> <DockPanel Grid.Row="2">
<CheckBox Content="实时结果 " IsChecked="{Binding IsUploadRealtimePath}" Grid.Row="2" Grid.Column="0" Style="{StaticResource ToggleButtonSwitchBaseStyle}" Width="110"/> <CheckBox Content="实时结果 " IsChecked="{Binding IsUploadRealtimePath}" Grid.Row="2" Grid.Column="0" Style="{StaticResource ToggleButtonSwitchBaseStyle}" Width="110"/>
<Button Content="..." Command="{Binding FilePathSaveCommand}" IsEnabled="{Binding ElementName=btnStop,Path=IsChecked}" CommandParameter="RealtimePath" DockPanel.Dock="Right" HorizontalAlignment="Right" /> <Button Content="..." Command="{Binding FilePathSaveCommand}" CommandParameter="RealtimePath" DockPanel.Dock="Right" HorizontalAlignment="Right" />
<TextBox Text="{Binding RealtimePath}" IsReadOnly="True" DockPanel.Dock="Right" FontSize="10"/> <TextBox Text="{Binding RealtimePath}" IsReadOnly="True" DockPanel.Dock="Right" FontSize="10"/>
</DockPanel> </DockPanel>
<DockPanel Grid.Row="3"> <DockPanel Grid.Row="3">
<CheckBox Content="后处理结果" IsChecked="{Binding IsUploadPostPath}" Grid.Row="4" Grid.Column="0" Style="{StaticResource ToggleButtonSwitchBaseStyle}" Width="110"/> <CheckBox Content="后处理结果" IsChecked="{Binding IsUploadPostPath}" Grid.Row="4" Grid.Column="0" Style="{StaticResource ToggleButtonSwitchBaseStyle}" Width="110"/>
<Button Content="..." Command="{Binding FilePathSaveCommand}" IsEnabled="{Binding ElementName=btnStop,Path=IsChecked}" CommandParameter="PostPath" DockPanel.Dock="Right" HorizontalAlignment="Right" /> <Button Content="..." Command="{Binding FilePathSaveCommand}" CommandParameter="PostPath" DockPanel.Dock="Right" HorizontalAlignment="Right" />
<TextBox Text="{Binding PostPath}" IsReadOnly="True" DockPanel.Dock="Right" FontSize="10" /> <TextBox Text="{Binding PostPath}" IsReadOnly="True" DockPanel.Dock="Right" FontSize="10" />
</DockPanel> </DockPanel>
</Grid> </Grid>
@ -93,7 +109,30 @@
<ComboBox DockPanel.Dock="Right" ItemsSource="{Binding IntervalTimesSource}" SelectedIndex="{Binding selectedIndex}" Text="{Binding ProMonInterval}" VerticalAlignment="Center"/> <ComboBox DockPanel.Dock="Right" ItemsSource="{Binding IntervalTimesSource}" SelectedIndex="{Binding selectedIndex}" Text="{Binding ProMonInterval}" VerticalAlignment="Center"/>
<TextBlock Text="监隔间隔(s):" DockPanel.Dock="Right" VerticalAlignment="Center"/> <TextBlock Text="监隔间隔(s):" DockPanel.Dock="Right" VerticalAlignment="Center"/>
</DockPanel>--> </DockPanel>-->
<ProgressBar Grid.Row="7" Grid.ColumnSpan="3" VerticalAlignment="Bottom" IsIndeterminate="{Binding IsIndeterminate}" Foreground="Green" Value="0"/> <StackPanel Grid.Row="6"
Grid.Column="0"
Grid.ColumnSpan="2">
<GroupBox Header="数据处理" Style="{StaticResource GroupBoxOriginal}" >
<DockPanel Grid.Row="3" IsEnabled="{Binding StartEnable}">
<CheckBox Content="结果处理" IsChecked="{Binding IsEnableToolPath}" Grid.Row="4" Grid.Column="0" Style="{StaticResource ToggleButtonSwitchBaseStyle}" Width="110"/>
<Button HorizontalAlignment="Right"
Content="..."
Command="{Binding FilePathSaveCommand}"
CommandParameter="ToolPath"
DockPanel.Dock="Right" />
<TextBox Text="{Binding ToolPath}"
IsReadOnly="True"
DockPanel.Dock="Right"
FontSize="10" />
</DockPanel>
</GroupBox>
</StackPanel>
<ProgressBar Grid.Row="7"
Grid.ColumnSpan="3"
VerticalAlignment="Bottom"
IsIndeterminate="{Binding IsIndeterminate}"
Foreground="Green"
Value="0" />
</Grid> </Grid>
</GroupBox> </GroupBox>
<UniformGrid Columns="1" Grid.Column="1"> <UniformGrid Columns="1" Grid.Column="1">

@ -0,0 +1,62 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Txgy.FilesWatcher.model
{
public class ProcessInfo
{
private string proName;
/// <summary>
/// 程序路径
/// </summary>
public string ProName
{
get { return proName; }
set { proName = value; }
}
private string proTitle;
/// <summary>
/// 程序路径
/// </summary>
public string ProTitle
{
get { return proTitle; }
set { proTitle = value; }
}
private string proPath;
/// <summary>
/// 程序路径
/// </summary>
public string ProPath
{
get { return proPath; }
set { proPath = value; }
}
private string proParams;
/// <summary>
/// 启动参数
/// </summary>
public string ProParams
{
get { return proParams; }
set { proParams = value; }
}
/// <summary>
/// 配置文件路径
/// </summary>
public string JsonPath { get; set; }
private int pid;
public int Pid
{
get { return pid; }
set { pid = value; }
}
}
}

@ -13,7 +13,10 @@ namespace Txgy.FilesWatcher.model
public string postpath { get; set; } public string postpath { get; set; }
public string mseedpath { get; set; } public string mseedpath { get; set; }
public string toolpath { get; set; }
public MQTTConfig mQTTConfig { get; set; } public MQTTConfig mQTTConfig { get; set; }
public DBConfig dBConfig { get; set; } public DBConfig dBConfig { get; set; }
public ProcessInfo proTools { get; set; }
} }
} }

@ -67,7 +67,7 @@ namespace Txgy.FilesWatcher.model
} }
catch (Exception ex) catch (Exception ex)
{ {
System.Windows.MessageBox.Show(ex.ToString()); // System.Windows.MessageBox.Show(ex.ToString());
} }
} }

@ -17,7 +17,7 @@ namespace Txgy.FilesWatcher.model
public class UploadPostproFile public class UploadPostproFile
{ {
public static void UploadPostproFileOnce(Action<string, string> mqAction, string path, string eventMessage, int workAreaId = 1) public static void UploadPostproFileOnce(string path, string eventMessage, int workAreaId = 1)
{ {
try try
{ {
@ -52,7 +52,7 @@ namespace Txgy.FilesWatcher.model
Byte[] mseedDatas = mbr.ReadBytes((int)fs.Length); Byte[] mseedDatas = mbr.ReadBytes((int)fs.Length);
fs.Close(); fs.Close();
//.json文件 //.json文件
string JsonPath = dFile.FullName.Replace(".mseed", "A.json"); string JsonPath = dFile.FullName.Replace(".mseed", "B.json");
fs = new FileStream(JsonPath, FileMode.Open, FileAccess.Read); fs = new FileStream(JsonPath, FileMode.Open, FileAccess.Read);
BinaryReader jbr = new BinaryReader(fs); BinaryReader jbr = new BinaryReader(fs);
Byte[] jsonDatas = jbr.ReadBytes((int)fs.Length); Byte[] jsonDatas = jbr.ReadBytes((int)fs.Length);
@ -69,7 +69,6 @@ namespace Txgy.FilesWatcher.model
sqlNumber = $"INSERT INTO {tbname} (EventTime, WorkAreaID, WaveData, JsonFile) VALUES('{EventTime}', '{workAreaId}', @mDatas, @jDatas);"; sqlNumber = $"INSERT INTO {tbname} (EventTime, WorkAreaID, WaveData, JsonFile) VALUES('{EventTime}', '{workAreaId}', @mDatas, @jDatas);";
MySqlCommand mycomm = new MySqlCommand(sqlNumber, conn); MySqlCommand mycomm = new MySqlCommand(sqlNumber, conn);
res = conn.Execute(sqlNumber, new { mDatas = mseedDatas, jDatas = jsonDatas }); res = conn.Execute(sqlNumber, new { mDatas = mseedDatas, jDatas = jsonDatas });
mqAction($"/watcherdata/post", JsonSerializer.Serialize(new { jsonFile = jsonString, eventMessage = eventMessage }, options));
sqlNumber = $"INSERT INTO {uploadedtbname}(filename, uploadtime) VALUES('{file}', '{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}')"; sqlNumber = $"INSERT INTO {uploadedtbname}(filename, uploadtime) VALUES('{file}', '{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}')";
res = conn.Execute(sqlNumber); res = conn.Execute(sqlNumber);
} }
@ -82,6 +81,44 @@ namespace Txgy.FilesWatcher.model
} }
} }
public static void UploadPostproFileMQ(Action<string, string> mqAction, string path, string eventMessage)
{
try
{
var currentTime = DateTime.Now;
var mseedFile = new DirectoryInfo(path).GetFiles("*.mseed");
var Dfiles = mseedFile.Where(f => eventMessage.Contains($"{f.Name.Substring(3, 4)}-{f.Name.Substring(7, 2)}-{f.Name.Substring(9, 2)}T{f.Name.Substring(12, 2)}:{f.Name.Substring(14, 2)}:{f.Name.Substring(16, 2)}"));
var files = Directory.GetFiles(path);
foreach (var dFile in Dfiles)
{
string file = dFile.Name;
string[] index_file_line = eventMessage.Split(" ");
string EventTime = index_file_line[0].Substring(0, 23);
string OriginTime = EventTime;
//.json文件
string JsonPath = dFile.FullName.Replace(".mseed", "B.json");
FileStream fs = new FileStream(JsonPath, FileMode.Open, FileAccess.Read);
BinaryReader jbr = new BinaryReader(fs);
Byte[] jsonDatas = jbr.ReadBytes((int)fs.Length);
string jsonString = Encoding.Default.GetString(jsonDatas);
fs.Close();
var options = new JsonSerializerOptions
{
// 整齐打印
WriteIndented = true,
//重新编码,解决中文乱码问题
Encoder = JavaScriptEncoder.Create(UnicodeRanges.All)
};
mqAction($"/watcherdata/post", JsonSerializer.Serialize(new { jsonFile = jsonString, eventMessage = eventMessage }, options));
}
}
catch (Exception ex)
{
// System.Windows.MessageBox.Show(ex.ToString());
}
}
} }
} }

@ -23,7 +23,7 @@ namespace Txgy.FilesWatcher.model
{ {
public class UploadRealtimeFile public class UploadRealtimeFile
{ {
public static void UploadRealtimeFileOnce(Action<string,string> mqAction, string path, string eventMessage, int workAreaId= 1) public static void UploadRealtimeFileOnce(string path, string eventMessage, int workAreaId= 1)
{ {
try try
{ {
@ -75,7 +75,6 @@ namespace Txgy.FilesWatcher.model
sqlNumber = $"INSERT INTO {tbname} (EventTime, WorkAreaID, WaveData, JsonFile) VALUES('{EventTime}', '{workAreaId}', @mDatas, @jDatas);"; sqlNumber = $"INSERT INTO {tbname} (EventTime, WorkAreaID, WaveData, JsonFile) VALUES('{EventTime}', '{workAreaId}', @mDatas, @jDatas);";
MySqlCommand mycomm = new MySqlCommand(sqlNumber,conn); MySqlCommand mycomm = new MySqlCommand(sqlNumber,conn);
res = conn.Execute(sqlNumber, new { mDatas = mseedDatas, jDatas = jsonDatas }); res = conn.Execute(sqlNumber, new { mDatas = mseedDatas, jDatas = jsonDatas });
mqAction($"/watcherdata/realtime", JsonSerializer.Serialize(new { jsonFile = jsonString, eventMessage = eventMessage }, options));
sqlNumber = $"INSERT INTO {uploadedtbname}(filename, uploadtime) VALUES('{file}', '{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}')"; sqlNumber = $"INSERT INTO {uploadedtbname}(filename, uploadtime) VALUES('{file}', '{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}')";
res = conn.Execute(sqlNumber); res = conn.Execute(sqlNumber);
} }
@ -88,5 +87,41 @@ namespace Txgy.FilesWatcher.model
} }
} }
public static void UploadRealtimeFileMQ(Action<string, string> mqAction, string path, string eventMessage)
{
try
{
var currentTime = DateTime.Now;
var mseedFile = new DirectoryInfo(path).GetFiles("*.mseed");
var Dfiles = mseedFile.Where(f => eventMessage.Contains($"{f.Name.Substring(3, 4)}-{f.Name.Substring(7, 2)}-{f.Name.Substring(9, 2)}T{f.Name.Substring(12, 2)}:{f.Name.Substring(14, 2)}:{f.Name.Substring(16, 2)}"));
var files = Directory.GetFiles(path);
foreach (var dFile in Dfiles)
{
string file = dFile.Name;
//.json文件
string JsonPath = dFile.FullName.Replace(".mseed", "A.json");
FileStream fs = new FileStream(JsonPath, FileMode.Open, FileAccess.Read);
BinaryReader jbr = new BinaryReader(fs);
Byte[] jsonDatas = jbr.ReadBytes((int)fs.Length);
string jsonString = Encoding.Default.GetString(jsonDatas);
fs.Close();
var options = new JsonSerializerOptions
{
// 整齐打印
WriteIndented = true,
//重新编码,解决中文乱码问题
Encoder = JavaScriptEncoder.Create(UnicodeRanges.All)
};
mqAction($"/watcherdata/realtime", JsonSerializer.Serialize(new { jsonFile = jsonString, eventMessage = eventMessage }, options));
}
}
catch (Exception ex)
{
//MessageBox.Show(ex.ToString());
}
}
} }
} }

@ -1,10 +1,12 @@
{ {
// //
"mainpath": "Y:\\YuwuN2107", "mainpath": "I:\\yuwuN3102mseed",
// //
"realtimepath": "EVT2023", "realtimepath": "EVT2023",
// //
"postpath": "post\\EVT2023", "postpath": "post20231119",
//
"toolpath": "post20231119",
// //
"mseedpath": "NET2023", "mseedpath": "NET2023",
"mQTTConfig": { "mQTTConfig": {
@ -12,7 +14,7 @@
"port": 1883, "port": 1883,
"userName": "23101052539", "userName": "23101052539",
"password": "23101052539", "password": "23101052539",
"clientID": "119" "clientID": "1006"
}, },
"dBConfig": { "dBConfig": {
"dbms": "mysql", "dbms": "mysql",
@ -21,5 +23,14 @@
"database": "yuwu2021", "database": "yuwu2021",
"userName": "yuwudba", "userName": "yuwudba",
"password": "Yw123456" "password": "Yw123456"
},
"proTools": {
"ProName": "gw.tools",
"ProTitle": "后处理",
"ProPath": "ampstools\\",
"ProParams": "-cfg gw.apms.json -wave ",
"JsonPath": "gw.apms.json",
"Pid": 0,
"ShowState": 0
} }
} }

Loading…
Cancel
Save