Commit 747892a9 by liulongfei

1. 添加算法进程检测

parent d9a15b44
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
...@@ -12,6 +13,33 @@ namespace VIZ.H2V.Domain ...@@ -12,6 +13,33 @@ namespace VIZ.H2V.Domain
/// </summary> /// </summary>
public class AlgorithmProcessModel : ModelBase public class AlgorithmProcessModel : ModelBase
{ {
public AlgorithmProcessModel()
{
lock (AllProcessModelList)
{
AllProcessModelList.Add(this);
}
}
/// <summary>
/// 所有的算法进程模型
/// </summary>
public static List<AlgorithmProcessModel> AllProcessModelList { get; private set; } = new List<AlgorithmProcessModel>();
#region ViewKey -- 视图键
private string viewKey;
/// <summary>
/// 视图键
/// </summary>
public string ViewKey
{
get { return viewKey; }
set { viewKey = value; this.RaisePropertyChanged(nameof(ViewKey)); }
}
#endregion
#region ProcessID -- 进程ID #region ProcessID -- 进程ID
private int processID; private int processID;
...@@ -53,5 +81,19 @@ namespace VIZ.H2V.Domain ...@@ -53,5 +81,19 @@ namespace VIZ.H2V.Domain
} }
#endregion #endregion
#region Process -- 进程信息
private Process process;
/// <summary>
/// 进程信息
/// </summary>
public Process Process
{
get { return process; }
set { process = value; this.RaisePropertyChanged(nameof(Process)); }
}
#endregion
} }
} }
...@@ -60,6 +60,7 @@ ...@@ -60,6 +60,7 @@
<Reference Include="System.Data" /> <Reference Include="System.Data" />
<Reference Include="System.Net.Http" /> <Reference Include="System.Net.Http" />
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
<Reference Include="WindowsBase" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="ApplicationDomainEx.cs" /> <Compile Include="ApplicationDomainEx.cs" />
......
...@@ -76,7 +76,7 @@ namespace VIZ.H2V.Module ...@@ -76,7 +76,7 @@ namespace VIZ.H2V.Module
service = ApplicationDomainEx.ServiceManager.GetService<INDIViewService>(NDIViewKeys.CAM_4); service = ApplicationDomainEx.ServiceManager.GetService<INDIViewService>(NDIViewKeys.CAM_4);
} }
if (service == null) if (service == null || service.StrategyMode == AlgorithmStrategyMode.auto_mode)
return false; return false;
ChangeStrategyContext context = new ChangeStrategyContext(); ChangeStrategyContext context = new ChangeStrategyContext();
...@@ -115,7 +115,7 @@ namespace VIZ.H2V.Module ...@@ -115,7 +115,7 @@ namespace VIZ.H2V.Module
service = ApplicationDomainEx.ServiceManager.GetService<INDIViewService>(NDIViewKeys.CAM_4); service = ApplicationDomainEx.ServiceManager.GetService<INDIViewService>(NDIViewKeys.CAM_4);
} }
if (service == null) if (service == null || service.StrategyMode == AlgorithmStrategyMode.center_mode)
return false; return false;
ChangeStrategyContext context = new ChangeStrategyContext(); ChangeStrategyContext context = new ChangeStrategyContext();
...@@ -135,21 +135,6 @@ namespace VIZ.H2V.Module ...@@ -135,21 +135,6 @@ namespace VIZ.H2V.Module
/// <returns>是否处理完成</returns> /// <returns>是否处理完成</returns>
private bool ExecuteManual(string hotkey) private bool ExecuteManual(string hotkey)
{ {
// Step 1. 先将当前手动模式的视图切换为自动模式
ApplicationDomainEx.ServiceManager.GetServiceList<INDIViewService>()
.Where(p => p.StrategyMode == AlgorithmStrategyMode.manual_mode)
.ToList()
.ForEach(p =>
{
ChangeStrategyContext cxt = new ChangeStrategyContext();
cxt.Mode = AlgorithmStrategyMode.auto_mode;
cxt.IsNeedRestart = false;
cxt.TriggerScene = NDIViewScene.Hotkey;
p.ChangeStrategyMode(cxt);
});
// Step 2. 将目标视图切换为手动模式
INDIViewService service = null; INDIViewService service = null;
if (string.Equals(this.Support.HotkeyConfig.ManualCAM1, hotkey)) if (string.Equals(this.Support.HotkeyConfig.ManualCAM1, hotkey))
...@@ -169,9 +154,23 @@ namespace VIZ.H2V.Module ...@@ -169,9 +154,23 @@ namespace VIZ.H2V.Module
service = ApplicationDomainEx.ServiceManager.GetService<INDIViewService>(NDIViewKeys.CAM_4); service = ApplicationDomainEx.ServiceManager.GetService<INDIViewService>(NDIViewKeys.CAM_4);
} }
if (service == null) if (service == null || service.StrategyMode == AlgorithmStrategyMode.manual_mode)
return false; return false;
// 先将出自身外手动模式的视图切换为自动模式
ApplicationDomainEx.ServiceManager.GetServiceList<INDIViewService>()
.Where(p => p.StrategyMode == AlgorithmStrategyMode.manual_mode && p != service)
.ToList()
.ForEach(p =>
{
ChangeStrategyContext cxt = new ChangeStrategyContext();
cxt.Mode = AlgorithmStrategyMode.auto_mode;
cxt.IsNeedRestart = false;
cxt.TriggerScene = NDIViewScene.Hotkey;
p.ChangeStrategyMode(cxt);
});
ChangeStrategyContext context = new ChangeStrategyContext(); ChangeStrategyContext context = new ChangeStrategyContext();
context.Mode = AlgorithmStrategyMode.manual_mode; context.Mode = AlgorithmStrategyMode.manual_mode;
context.IsNeedRestart = false; context.IsNeedRestart = false;
......
...@@ -286,16 +286,19 @@ namespace VIZ.H2V.Module ...@@ -286,16 +286,19 @@ namespace VIZ.H2V.Module
if (this.hotkeyController == null) if (this.hotkeyController == null)
return; return;
Window window = Window.GetWindow(this.GetView<NDIMainView>()); WPFHelper.BeginInvoke(() =>
if (window == null) {
return; Window window = Window.GetWindow(this.GetView<NDIMainView>());
if (window == null)
return;
if (!window.IsActive) if (!window.IsActive)
return; return;
string hotkey = HotkeyHelper.GetHotkey(e); string hotkey = HotkeyHelper.GetHotkey(e);
this.hotkeyController.Execute(hotkey); this.hotkeyController.Execute(hotkey);
});
} }
} }
} }
...@@ -366,7 +366,10 @@ namespace VIZ.H2V.Module ...@@ -366,7 +366,10 @@ namespace VIZ.H2V.Module
return false; return false;
} }
// 记录进程模型
this.Support.ProcessModel.ViewKey = this.Support.ViewKey;
this.Support.ProcessModel.ProcessID = proc.Id; this.Support.ProcessModel.ProcessID = proc.Id;
this.Support.ProcessModel.Process = proc;
// 更新缓存 // 更新缓存
this.Support.ViewConfig.ProcessID = this.Support.ProcessModel.ProcessID; this.Support.ViewConfig.ProcessID = this.Support.ProcessModel.ProcessID;
......
...@@ -42,7 +42,7 @@ namespace VIZ.H2V.Module ...@@ -42,7 +42,7 @@ namespace VIZ.H2V.Module
/// <summary> /// <summary>
/// NDI视图状态 /// NDI视图状态
/// </summary> /// </summary>
NDIViewStatus ViewStatus { get; } NDIViewStatus ViewStatus { get; set; }
/// <summary> /// <summary>
/// 加载样式 /// 加载样式
......
...@@ -16,14 +16,14 @@ using VIZ.H2V.Connection; ...@@ -16,14 +16,14 @@ using VIZ.H2V.Connection;
namespace VIZ.H2V.Module namespace VIZ.H2V.Module
{ {
/// <summary> /// <summary>
/// 应用程序启动 -- 停止算法 /// 应用程序启动 -- 算法进程
/// </summary> /// </summary>
public class AppSetup_StopAlgorithm : AppSetupBase public class AppSetup_Algorithm : AppSetupBase
{ {
/// <summary> /// <summary>
/// 日志 /// 日志
/// </summary> /// </summary>
private static ILog log = LogManager.GetLogger(typeof(AppSetup_StopAlgorithm)); private static ILog log = LogManager.GetLogger(typeof(AppSetup_Algorithm));
/// <summary> /// <summary>
/// 描述 /// 描述
...@@ -37,6 +37,8 @@ namespace VIZ.H2V.Module ...@@ -37,6 +37,8 @@ namespace VIZ.H2V.Module
/// <returns>是否成功执行</returns> /// <returns>是否成功执行</returns>
public override bool Setup(AppSetupContext context) public override bool Setup(AppSetupContext context)
{ {
ApplicationDomainEx.LoopManager.Register("AppSetup_Algorithm", 3, this.processCheck);
return true; return true;
} }
...@@ -67,5 +69,35 @@ namespace VIZ.H2V.Module ...@@ -67,5 +69,35 @@ namespace VIZ.H2V.Module
Task.WaitAll(list.ToArray()); Task.WaitAll(list.ToArray());
} }
/// <summary>
/// 进程检测
/// </summary>
private void processCheck()
{
lock (AlgorithmProcessModel.AllProcessModelList)
{
foreach (AlgorithmProcessModel model in AlgorithmProcessModel.AllProcessModelList)
{
if (model.ProcessID <= 0 || model.Process == null)
continue;
if (!model.Process.HasExited)
continue;
model.ProcessID = 0;
model.Process = null;
WPFHelper.BeginInvoke(() =>
{
INDIViewService service = ApplicationDomainEx.ServiceManager.GetService<INDIViewService>(model.ViewKey);
if (service == null)
return;
service.ViewStatus = NDIViewStatus.Stop;
});
}
}
}
} }
} }
...@@ -194,7 +194,7 @@ ...@@ -194,7 +194,7 @@
<Compile Include="NDIView\VieweModel\NDIViewModel.Message.cs" /> <Compile Include="NDIView\VieweModel\NDIViewModel.Message.cs" />
<Compile Include="NDIView\VieweModel\NDIViewModel.Property.cs" /> <Compile Include="NDIView\VieweModel\NDIViewModel.Property.cs" />
<Compile Include="NDIView\VieweModel\NDIViewModel.cs" /> <Compile Include="NDIView\VieweModel\NDIViewModel.cs" />
<Compile Include="Setup\Provider\AppSetup_StopAlgorithm.cs" /> <Compile Include="Setup\Provider\AppSetup_Algorithm.cs" />
<Compile Include="Setup\Provider\AppSetup_InitUDP.cs" /> <Compile Include="Setup\Provider\AppSetup_InitUDP.cs" />
<Compile Include="SystemSetting\ViewModel\HotkeySettingPanelViewModel.cs" /> <Compile Include="SystemSetting\ViewModel\HotkeySettingPanelViewModel.cs" />
<Compile Include="SystemSetting\ViewModel\AboutPanelViewModel.cs" /> <Compile Include="SystemSetting\ViewModel\AboutPanelViewModel.cs" />
......
...@@ -28,8 +28,8 @@ namespace VIZ.H2V ...@@ -28,8 +28,8 @@ namespace VIZ.H2V
AppSetup.AppendSetup(new AppSetup_InitExcel()); AppSetup.AppendSetup(new AppSetup_InitExcel());
// 初始化NDI // 初始化NDI
AppSetup.AppendSetup(new AppSetup_InitNDI()); AppSetup.AppendSetup(new AppSetup_InitNDI());
// 停止算法 // 初始化算法进程
AppSetup.AppendSetup(new AppSetup_StopAlgorithm()); AppSetup.AppendSetup(new AppSetup_Algorithm());
// 初始化UDP // 初始化UDP
AppSetup.AppendSetup(new AppSetup_InitUDP()); AppSetup.AppendSetup(new AppSetup_InitUDP());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment