using Newtonsoft.Json.Linq; using Serein.Library.Api; using Serein.NodeFlow; using System; using System.Collections.Generic; using System.Drawing; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using Serein.Library; using Serein.Library.Utils; using Serein.Workbench.Avalonia.Api; using Serein.Workbench.Api; using System.Diagnostics; namespace Serein.Workbench.Services { internal class FlowEEForwardingService : IFlowEEForwardingService { /// /// 流程运行环境 /// private readonly IFlowEnvironment flowEnvironment; private readonly IFlowEnvironmentEvent flowEnvironmentEvent; private readonly UIContextOperation uiContextOperation; /// /// 转发流程运行环境各个事件的实现类 /// /// /// /// public FlowEEForwardingService(IFlowEnvironment flowEnvironment, IFlowEnvironmentEvent flowEnvironmentEvent, UIContextOperation uIContextOperation) { this.flowEnvironment = flowEnvironment; this.flowEnvironmentEvent = flowEnvironmentEvent; this.uiContextOperation = uIContextOperation; InitFlowEnvironmentEvent(); } #region 工作台事件转发 /// /// 加载了依赖文件事件 /// public event LoadDllHandler? DllLoad; /// /// 项目加载完成事件 /// public event ProjectLoadedHandler? ProjectLoaded; /// /// 项目保存中事件 /// public event ProjectSavingHandler? ProjectSaving; /// /// 节点连接改变事件 /// public event NodeConnectChangeHandler? NodeConnectChanged; /// /// 节点创建事件 /// public event NodeCreateHandler? NodeCreated; /// /// 节点移除事件 /// public event NodeRemoveHandler? NodeRemoved; /// /// 节点放置容器事件 /// public event NodePlaceHandler? NodePlace; /// /// 节点取出事件 /// public event NodeTakeOutHandler? NodeTakeOut; /// /// 流程起始节点改变事件 /// public event StartNodeChangeHandler? StartNodeChanged; /// /// 流程运行完毕事件 /// public event FlowRunCompleteHandler? FlowRunComplete; /// /// 被监视的对象数据改变事件 /// public event MonitorObjectChangeHandler? MonitorObjectChanged; /// /// 节点中断状态改变事件 /// public event NodeInterruptStateChangeHandler? NodeInterruptStateChanged; /// /// 表达式中断触发事件 /// public event ExpInterruptTriggerHandler? InterruptTriggered; /// /// 容器对象改变事件 /// public event IOCMembersChangedHandler? IOCMembersChanged; /// /// 节点定位事件 /// public event NodeLocatedHandler? NodeLocated; /// /// 运行环境输出事件 /// public event EnvOutHandler? EnvOutput; /// /// 添加画布事件 /// public event CanvasCreateHandler CanvasCreated; /// /// 移除了画布事件 /// public event CanvasRemoveHandler CanvasRemoved; #endregion #region 流程运行环境事件 private void InitFlowEnvironmentEvent() { flowEnvironmentEvent.DllLoad += FlowEnvironment_DllLoadEvent; flowEnvironmentEvent.ProjectSaving += FlowEnvironment_OnProjectSaving; flowEnvironmentEvent.ProjectLoaded += FlowEnvironment_OnProjectLoaded; flowEnvironmentEvent.CanvasCreated += FlowEnvironmentEvent_OnCanvasCreate; flowEnvironmentEvent.CanvasRemoved += FlowEnvironmentEvent_OnCanvasRemove; flowEnvironmentEvent.StartNodeChanged += FlowEnvironment_StartNodeChangeEvent; flowEnvironmentEvent.NodeConnectChanged += FlowEnvironment_NodeConnectChangeEvemt; flowEnvironmentEvent.NodeCreated += FlowEnvironment_NodeCreateEvent; flowEnvironmentEvent.NodeRemoved += FlowEnvironment_NodeRemoveEvent; flowEnvironmentEvent.NodePlace += FlowEnvironment_OnNodePlaceEvent; flowEnvironmentEvent.NodeTakeOut += FlowEnvironment_OnNodeTakeOutEvent; flowEnvironmentEvent.FlowRunComplete += FlowEnvironment_OnFlowRunCompleteEvent; flowEnvironmentEvent.MonitorObjectChanged += FlowEnvironment_OnMonitorObjectChangeEvent; flowEnvironmentEvent.NodeInterruptStateChanged += FlowEnvironment_OnNodeInterruptStateChangeEvent; flowEnvironmentEvent.InterruptTriggered += FlowEnvironment_OnInterruptTriggerEvent; flowEnvironmentEvent.IOCMembersChanged += FlowEnvironment_OnIOCMembersChangedEvent; flowEnvironmentEvent.NodeLocated += FlowEnvironment_OnNodeLocateEvent;; flowEnvironmentEvent.EnvOutput += FlowEnvironment_OnEnvOutEvent; } private void ResetFlowEnvironmentEvent() { flowEnvironmentEvent.DllLoad -= FlowEnvironment_DllLoadEvent; flowEnvironmentEvent.ProjectSaving -= FlowEnvironment_OnProjectSaving; flowEnvironmentEvent.ProjectLoaded -= FlowEnvironment_OnProjectLoaded; flowEnvironmentEvent.StartNodeChanged -= FlowEnvironment_StartNodeChangeEvent; flowEnvironmentEvent.NodeConnectChanged -= FlowEnvironment_NodeConnectChangeEvemt; flowEnvironmentEvent.NodeCreated -= FlowEnvironment_NodeCreateEvent; flowEnvironmentEvent.NodeRemoved -= FlowEnvironment_NodeRemoveEvent; flowEnvironmentEvent.NodePlace -= FlowEnvironment_OnNodePlaceEvent; flowEnvironmentEvent.NodeTakeOut -= FlowEnvironment_OnNodeTakeOutEvent; flowEnvironmentEvent.FlowRunComplete -= FlowEnvironment_OnFlowRunCompleteEvent; flowEnvironmentEvent.MonitorObjectChanged -= FlowEnvironment_OnMonitorObjectChangeEvent; flowEnvironmentEvent.NodeInterruptStateChanged -= FlowEnvironment_OnNodeInterruptStateChangeEvent; flowEnvironmentEvent.InterruptTriggered -= FlowEnvironment_OnInterruptTriggerEvent; flowEnvironmentEvent.IOCMembersChanged -= FlowEnvironment_OnIOCMembersChangedEvent; flowEnvironmentEvent.NodeLocated -= FlowEnvironment_OnNodeLocateEvent; flowEnvironmentEvent.EnvOutput -= FlowEnvironment_OnEnvOutEvent; } #region 运行环境事件 /// /// 环境内容输出 /// /// /// private void FlowEnvironment_OnEnvOutEvent(InfoType type, string value) { uiContextOperation.Invoke(() => { EnvOutput?.Invoke(type, value); }); } /// /// 需要保存项目 /// /// /// private void FlowEnvironment_OnProjectSaving(ProjectSavingEventArgs eventArgs) { ProjectSaving?.Invoke(eventArgs); } /// /// 加载完成 /// /// private void FlowEnvironment_OnProjectLoaded(ProjectLoadedEventArgs eventArgs) { ProjectLoaded?.Invoke(eventArgs); } /// /// 运行完成 /// /// /// private void FlowEnvironment_OnFlowRunCompleteEvent(FlowEventArgs eventArgs) { SereinEnv.WriteLine(InfoType.INFO, "-------运行完成---------\r\n"); FlowRunComplete?.Invoke(eventArgs); } /// /// 加载了DLL文件,dll内容 /// private void FlowEnvironment_DllLoadEvent(LoadDllEventArgs eventArgs) { DllLoad?.Invoke(eventArgs); } /// /// 节点连接关系变更 /// /// private void FlowEnvironment_NodeConnectChangeEvemt(NodeConnectChangeEventArgs eventArgs) { uiContextOperation.Invoke(() => { Debug.WriteLine(DateTime.Now, $"Node Connect Changed"); NodeConnectChanged?.Invoke(eventArgs); }); } /// /// 添加了画布 /// /// /// private void FlowEnvironmentEvent_OnCanvasCreate(CanvasCreateEventArgs eventArgs) { uiContextOperation?.Invoke(() => { CanvasCreated?.Invoke(eventArgs); }); } /// /// 移除了画布 /// /// /// private void FlowEnvironmentEvent_OnCanvasRemove(CanvasRemoveEventArgs eventArgs) { CanvasRemoved?.Invoke(eventArgs); } /// /// 节点移除事件 /// /// private void FlowEnvironment_NodeRemoveEvent(NodeRemoveEventArgs eventArgs) { NodeRemoved?.Invoke(eventArgs); } /// /// 添加节点事件 /// /// 添加节点事件参数 /// private void FlowEnvironment_NodeCreateEvent(NodeCreateEventArgs eventArgs) { uiContextOperation.Invoke(() => { Debug.WriteLine(DateTime.Now, $"Create Node {eventArgs.NodeModel.Guid}"); NodeCreated?.Invoke(eventArgs); }); } /// /// 放置一个节点 /// /// /// private void FlowEnvironment_OnNodePlaceEvent(NodePlaceEventArgs eventArgs) { NodePlace?.Invoke(eventArgs); } /// /// 取出一个节点 /// /// private void FlowEnvironment_OnNodeTakeOutEvent(NodeTakeOutEventArgs eventArgs) { NodeTakeOut?.Invoke(eventArgs); } /// /// 设置了流程起始控件 /// /// /// private void FlowEnvironment_StartNodeChangeEvent(StartNodeChangeEventArgs eventArgs) { StartNodeChanged?.Invoke(eventArgs); } /// /// 被监视的对象发生改变 /// /// private void FlowEnvironment_OnMonitorObjectChangeEvent(MonitorObjectEventArgs eventArgs) { MonitorObjectChanged?.Invoke(eventArgs); } /// /// 节点中断状态改变。 /// /// private void FlowEnvironment_OnNodeInterruptStateChangeEvent(NodeInterruptStateChangeEventArgs eventArgs) { NodeInterruptStateChanged?.Invoke(eventArgs); } /// /// 节点触发了中断 /// /// /// private void FlowEnvironment_OnInterruptTriggerEvent(InterruptTriggerEventArgs eventArgs) { InterruptTriggered?.Invoke(eventArgs); } /// /// IOC变更 /// /// /// private void FlowEnvironment_OnIOCMembersChangedEvent(IOCMembersChangedEventArgs eventArgs) { IOCMembersChanged?.Invoke(eventArgs); } /// /// 节点需要定位 /// /// /// private void FlowEnvironment_OnNodeLocateEvent(NodeLocatedEventArgs eventArgs) { NodeLocated?.Invoke(eventArgs); } #endregion #endregion #region 主动触发运行环境事件 public void OnDllLoad(LoadDllEventArgs eventArgs) { throw new NotImplementedException(); } public void OnProjectLoaded(ProjectLoadedEventArgs eventArgs) { throw new NotImplementedException(); } public void OnProjectSaving(ProjectSavingEventArgs eventArgs) { throw new NotImplementedException(); } public void OnNodeConnectChanged(NodeConnectChangeEventArgs eventArgs) { throw new NotImplementedException(); } public void OnCanvasCreated(CanvasCreateEventArgs eventArgs) { throw new NotImplementedException(); } public void OnCanvasRemoved(CanvasRemoveEventArgs eventArgs) { throw new NotImplementedException(); } public void OnNodeCreated(NodeCreateEventArgs eventArgs) { throw new NotImplementedException(); } public void OnNodeRemoved(NodeRemoveEventArgs eventArgs) { throw new NotImplementedException(); } public void OnNodePlace(NodePlaceEventArgs eventArgs) { throw new NotImplementedException(); } public void OnNodeTakeOut(NodeTakeOutEventArgs eventArgs) { throw new NotImplementedException(); } public void OnStartNodeChanged(StartNodeChangeEventArgs eventArgs) { throw new NotImplementedException(); } public void OnFlowRunComplete(FlowEventArgs eventArgs) { throw new NotImplementedException(); } public void OnMonitorObjectChanged(MonitorObjectEventArgs eventArgs) { throw new NotImplementedException(); } public void OnNodeInterruptStateChanged(NodeInterruptStateChangeEventArgs eventArgs) { throw new NotImplementedException(); } public void OnInterruptTriggered(InterruptTriggerEventArgs eventArgs) { throw new NotImplementedException(); } public void OnIOCMembersChanged(IOCMembersChangedEventArgs eventArgs) { throw new NotImplementedException(); } public void OnNodeLocated(NodeLocatedEventArgs eventArgs) { throw new NotImplementedException(); } public void OnEnvOutput(InfoType type, string value) { throw new NotImplementedException(); } #endregion } }