2024-10-07 15:15:18 +08:00
|
|
|
|
|
2024-09-30 22:20:02 +08:00
|
|
|
|
using Net462DllTest.Signal;
|
|
|
|
|
|
using Net462DllTest.ViewModel;
|
2024-09-27 10:30:19 +08:00
|
|
|
|
using Serein.Library.Api;
|
|
|
|
|
|
using Serein.Library.Attributes;
|
|
|
|
|
|
using Serein.Library.Enums;
|
2024-10-07 15:15:18 +08:00
|
|
|
|
using Serein.Library.Ex;
|
|
|
|
|
|
using Serein.Library.Framework.NodeFlow;
|
|
|
|
|
|
using Serein.Library.NodeFlow.Tool;
|
2024-09-27 10:30:19 +08:00
|
|
|
|
using Serein.Library.Utils;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
2024-10-07 15:15:18 +08:00
|
|
|
|
using System.Threading.Tasks;
|
2024-09-27 10:30:19 +08:00
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
2024-10-07 15:15:18 +08:00
|
|
|
|
namespace Net462DllTest.LogicControl
|
2024-09-30 16:36:55 +08:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 视图管理
|
|
|
|
|
|
/// </summary>
|
2024-09-30 02:45:49 +08:00
|
|
|
|
[AutoRegister]
|
2024-10-07 15:15:18 +08:00
|
|
|
|
public class ViewManagement:ChannelFlowTrigger<CommandSignal>
|
2024-09-27 10:30:19 +08:00
|
|
|
|
{
|
2024-10-07 15:15:18 +08:00
|
|
|
|
private readonly List<Form> forms = new List<Form>();
|
2024-09-30 16:36:55 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 打开窗口
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="form">要打开的窗口类型</param>
|
|
|
|
|
|
/// <param name="isTop">是否置顶</param>
|
2024-09-27 23:47:25 +08:00
|
|
|
|
public void OpenView(Form form, bool isTop)
|
2024-09-27 10:30:19 +08:00
|
|
|
|
{
|
2024-09-27 23:47:25 +08:00
|
|
|
|
form.TopMost = isTop;
|
2024-09-27 10:30:19 +08:00
|
|
|
|
form.Show();
|
|
|
|
|
|
forms.Add(form);
|
|
|
|
|
|
}
|
|
|
|
|
|
public void CloseView(Type formType)
|
|
|
|
|
|
{
|
|
|
|
|
|
var remoteForms = forms.Where(f => f.GetType() == formType).ToArray();
|
|
|
|
|
|
foreach (Form f in remoteForms)
|
|
|
|
|
|
{
|
|
|
|
|
|
f.Close();
|
|
|
|
|
|
f.Dispose();
|
|
|
|
|
|
this.forms.Remove(f);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-09-28 23:55:19 +08:00
|
|
|
|
|
2024-09-27 10:30:19 +08:00
|
|
|
|
|
2024-10-07 15:15:18 +08:00
|
|
|
|
[DynamicFlow("[View]")]
|
2024-09-27 10:30:19 +08:00
|
|
|
|
public class ViewLogicControl
|
|
|
|
|
|
{
|
2024-09-30 02:45:49 +08:00
|
|
|
|
private readonly ViewManagement ViewManagement;
|
|
|
|
|
|
public ViewLogicControl(ViewManagement ViewManagement)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.ViewManagement = ViewManagement;
|
|
|
|
|
|
}
|
2024-09-27 10:30:19 +08:00
|
|
|
|
|
|
|
|
|
|
[NodeAction(NodeType.Init)]
|
|
|
|
|
|
public void Init(IDynamicContext context)
|
|
|
|
|
|
{
|
|
|
|
|
|
context.Env.IOC.Register<ViewManagement>();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-10-07 15:15:18 +08:00
|
|
|
|
#region 触发器节点
|
2024-09-27 10:30:19 +08:00
|
|
|
|
|
2024-10-07 15:15:18 +08:00
|
|
|
|
[NodeAction(NodeType.Flipflop, "等待信号触发", ReturnType = typeof(int))]
|
|
|
|
|
|
public async Task<IFlipflopContext> WaitTask(CommandSignal command = CommandSignal.Command_1)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
TriggerData triggerData = await ViewManagement.CreateChannelWithTimeoutAsync(command, TimeSpan.FromMinutes(120), 0);
|
|
|
|
|
|
if (triggerData.Type == TriggerType.Overtime)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new FlipflopException("超时取消");
|
|
|
|
|
|
}
|
|
|
|
|
|
return new FlipflopContext(FlipflopStateType.Succeed, triggerData.Value);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (FlipflopException)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw;
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception)
|
|
|
|
|
|
{
|
|
|
|
|
|
return new FlipflopContext(FlipflopStateType.Error);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
2024-09-27 10:30:19 +08:00
|
|
|
|
[NodeAction(NodeType.Action, "打开窗体(指定枚举值)")]
|
2024-10-07 15:15:18 +08:00
|
|
|
|
public void OpenForm(IDynamicContext context, FromValue fromId = FromValue.FromWorkBenchView, bool isTop = true)
|
2024-09-27 10:30:19 +08:00
|
|
|
|
{
|
2024-09-28 23:55:19 +08:00
|
|
|
|
var fromType = EnumHelper.GetBoundValue<FromValue, Type>(fromId, attr => attr.Value);
|
2024-09-27 10:30:19 +08:00
|
|
|
|
if (fromType is null) return;
|
|
|
|
|
|
if (context.Env.IOC.Instantiate(fromType) is Form form)
|
|
|
|
|
|
{
|
2024-09-27 23:47:25 +08:00
|
|
|
|
ViewManagement.OpenView(form, isTop);
|
2024-09-27 10:30:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[NodeAction(NodeType.Action, "打开窗体(使用转换器)")]
|
2024-09-28 23:55:19 +08:00
|
|
|
|
public void OpenForm2([EnumTypeConvertor(typeof(FromValue))] Form form, bool isTop = true)
|
2024-09-27 10:30:19 +08:00
|
|
|
|
{
|
2024-09-27 23:47:25 +08:00
|
|
|
|
ViewManagement.OpenView(form, isTop);
|
2024-09-27 10:30:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-09-28 23:55:19 +08:00
|
|
|
|
|
2024-09-27 10:30:19 +08:00
|
|
|
|
[NodeAction(NodeType.Action, "关闭窗体")]
|
2024-10-07 15:15:18 +08:00
|
|
|
|
public void CloseForm(IDynamicContext context, FromValue fromId = FromValue.FromWorkBenchView)
|
2024-09-27 10:30:19 +08:00
|
|
|
|
{
|
2024-09-28 23:55:19 +08:00
|
|
|
|
var fromType = EnumHelper.GetBoundValue<FromValue, Type>(fromId, attr => attr.Value);
|
2024-09-27 10:30:19 +08:00
|
|
|
|
if (fromType is null) return;
|
|
|
|
|
|
ViewManagement.CloseView(fromType);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-09-28 23:55:19 +08:00
|
|
|
|
|
2024-09-27 10:30:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|