| 
						
						
							
								
							
						
						
					 | 
				
			
			 | 
			 | 
			
				@ -28,6 +28,8 @@ using System.Windows.Markup;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				using System.Windows.Forms.VisualStyles;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				using System.Xml.Linq;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				using Prism.Services.Dialogs;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				using Microsoft.VisualBasic.Logging;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				using log4net;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				namespace Txgy.FilesWatcher.ViewModels
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				{
 | 
			
		
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
			
			 | 
			 | 
			
				@ -35,6 +37,7 @@ namespace Txgy.FilesWatcher.ViewModels
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        public MainViewModel(WebsocketClient websocketClient, SystemConfig systemConfig, IEventAggregator ea, IDialogService dialogService, ManualModeDialogViewModel manualModeDialog)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            _log = new GetLogger("MainViewModel");
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            StartCommand = new DelegateCommand(Start, StartCanExecute).ObservesProperty(() => StartEnable);
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            StopCommand= new DelegateCommand(Stop, StopCanExecute).ObservesProperty(() => StopEnable);
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            string filter = "*.index";
 | 
			
		
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
			
			 | 
			 | 
			
				@ -56,7 +59,7 @@ namespace Txgy.FilesWatcher.ViewModels
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            this._dialogService = dialogService;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            this._manualModeDialog = manualModeDialog;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        }
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        private GetLogger _log;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        private string watcherPath;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        public string PostPath
 | 
			
		
		
	
	
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
				
			
			 | 
			 | 
			
				@ -267,6 +270,7 @@ namespace Txgy.FilesWatcher.ViewModels
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        public DelegateCommand ManualCommand => new DelegateCommand(() => 
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            _log.Log.Debug("MainViewModel.ManualCommand,打开");
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            DialogParameters param = new DialogParameters
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				                { "main", this }
 | 
			
		
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
			
			 | 
			 | 
			
				@ -278,7 +282,7 @@ namespace Txgy.FilesWatcher.ViewModels
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        });
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        private void Start()
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            int res= WatchStartOrSopt(true);
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            int res = WatchStartOrSopt(true);
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            if (res == 0)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				                StartEnable = false;
 | 
			
		
		
	
	
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
				
			
			 | 
			 | 
			
				@ -434,7 +438,7 @@ namespace Txgy.FilesWatcher.ViewModels
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            mqttClient = new MqttFactory().CreateManagedMqttClient();
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            mqttClient.UseDisconnectedHandler(ee =>
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				                Debug.WriteLine($">>> 服务器断开连接,{ee}");
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				                _log.Log.Debug($">>> 服务器断开连接,{ee}");
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            });
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            mqttClient.UseApplicationMessageReceivedHandler(ee =>
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            {
 | 
			
		
		
	
	
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
				
			
			 | 
			 | 
			
				@ -514,6 +518,8 @@ 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)
 | 
			
		
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
			
			 | 
			 | 
			
				@ -531,6 +537,8 @@ namespace Txgy.FilesWatcher.ViewModels
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				                    });
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				                }), path, WorkAreaId);
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            }
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            _log.Log.Debug("MainViewModel.MseedFileChanged() < exit....");
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        }
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
	
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
				
			
			 | 
			 | 
			
				@ -605,7 +613,8 @@ namespace Txgy.FilesWatcher.ViewModels
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            var watch= sender as FileSystemWatcher;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            string lastLine = File.ReadLines(e.FullPath).Last().Trim();
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            Debug.WriteLine($"最后修改时间:{lastWriteTime},文件路径:{watch.Path}");
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            var filePath=  Path.GetDirectoryName(e.FullPath);
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            _log.Log.DebugFormat($"MainViewModel.Watcher_Changed() 最后修改时间:{lastWriteTime},文件路径:{watch.Path}");
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            var filePath =  Path.GetDirectoryName(e.FullPath);
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            if (watch != null && watch.Path == watcherArray[0].Path)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				                watcherArray[0].EnableRaisingEvents = false;
 | 
			
		
		
	
	
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
				
			
			 | 
			 | 
			
				@ -727,7 +736,6 @@ namespace Txgy.FilesWatcher.ViewModels
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        private void Watcher_Deleted(object sender, FileSystemEventArgs e)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            DateTime dt = DateTime.Now;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            string tmp = dt.Hour.ToString() + "时" + dt.Minute.ToString() + "分" + dt.Second.ToString() + "秒" + dt.Millisecond.ToString() + "毫秒,目录发生变化\r\n";
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            tmp += "改变类型 :" + e.ChangeType.ToString() + "\r\n"; ;
 | 
			
		
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
			
			 | 
			 | 
			
				@ -744,6 +752,7 @@ namespace Txgy.FilesWatcher.ViewModels
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        private void StartConnectMQ()
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            _log.Log.Debug("MainViewModel.StartConnectMQ() > enter....");
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            // 向服务端开放的端口进行服务请求
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            //    string clientID = Guid.NewGuid().ToString();
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            var mqttClientOptions = new MqttClientOptionsBuilder()
 | 
			
		
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
			
			 | 
			 | 
			
				@ -757,6 +766,7 @@ namespace Txgy.FilesWatcher.ViewModels
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				                        .Build();
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            mqttClient.StartAsync(options);
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            startTime = DateTime.Now;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            _log.Log.Debug("MainViewModel.StartConnectMQ() < exit....");
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        }
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        private void StopMQ()
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        {
 | 
			
		
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
			
			 | 
			 | 
			
				@ -764,6 +774,8 @@ namespace Txgy.FilesWatcher.ViewModels
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        }
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        private void MQPublish(string topic, string openCmd)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            _log.Log.Debug("MainViewModel.MQPublish() > enter....");
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            _log.Log.DebugFormat("MainViewModel.MQPublish() topic:{0},cmd:{1}", topic, openCmd);
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            //   byte[] cmdByte = Convert.FromHexString(openCmd.Replace(" ", ""));
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            MqttApplicationMessage message = new MqttApplicationMessageBuilder()
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				                .WithTopic(topic)
 | 
			
		
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
			
			 | 
			 | 
			
				@ -781,6 +793,7 @@ namespace Txgy.FilesWatcher.ViewModels
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				                mes = $">>>数据发送失败:{topic},{openCmd}";
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            }
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            Debug.WriteLine(mes);
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            _log.Log.Debug("MainViewModel.MQPublish() < exit....");
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        }
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
	
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
				
			
			 | 
			 | 
			
				@ -822,6 +835,9 @@ namespace Txgy.FilesWatcher.ViewModels
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        private bool CMDStartProcess(ProcessInfo proInfo, string path)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            _log.Log.Debug("MainViewModel.CMDStartProcess() > enter....");
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            _log.Log.DebugFormat("MainViewModel.CMDStartProcess() proInfo:{0},path:{1}", proInfo.ProName, path);
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            Process process = new Process();
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            process.Exited += Process_Exited;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            process.EnableRaisingEvents = true;
 | 
			
		
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
			
			 | 
			 | 
			
				@ -838,17 +854,18 @@ namespace Txgy.FilesWatcher.ViewModels
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            process.ErrorDataReceived += new DataReceivedEventHandler(OutputHandler);
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            bool res = process.Start();
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            _log.Log.Debug("MainViewModel.CMDStartProcess() < exit....");
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            return res;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        }
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        private void Process_Exited(object? sender, EventArgs e)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            _log.Log.Debug("MainViewModel.Process_Exited()");
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        }
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        void OutputHandler(object sendingProcess, DataReceivedEventArgs outLine)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            Debug.WriteLine("output*************:{0},{1}", sendingProcess.ToString(), outLine.Data);
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            _log.Log.DebugFormat("MainViewModel.OutputHandler() output:{0},{1}", sendingProcess.ToString(), outLine.Data);
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            if (string.IsNullOrEmpty(outLine.Data)) return;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        }
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        #endregion
 | 
			
		
		
	
	
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
				
			
			 | 
			 | 
			
				
 
 |