如何将右键单击断点菜单添加到重新托管的工作流设计器中

本文关键字:工作流 新托管 右键 单击 断点 添加 菜单 | 更新日期: 2023-09-27 18:18:24

重托管工作流设计器的一个缺点是,默认情况下,它不包括许多重要工作流开发所需的功能。

其中最主要的是缺乏本机调试/断点支持。

网上有一些示例显示如何启用调试,但我没有找到任何包括显示右键单击活动上下文菜单的断点部分

如何将右键单击断点菜单添加到重新托管的工作流设计器中

事实证明,将断点菜单项添加到上下文菜单中相对简单。

首先,创建一个类来实现System.Activities.Presentation.Hosting.ICommandService

public class CommandService : ICommandService
{
    private WorkflowDesigner WorkflowDesigner;
    public CommandService(WorkflowDesigner designer) { this.WorkflowDesigner = designer; }
    public bool CanExecuteCommand(int commandId)
    {
        return true;
    }
    public event EventHandler BreakpointsChanged;
    public event EventHandler ShowPropertiesRequested;
    public void ExecuteCommand(int commandId, Dictionary<string, object> parameters)
    {
        switch (commandId)
        {
            case CommandValues.InsertBreakpoint:
                WorkflowDesigner.Context.Services.GetService<IDesignerDebugView>().UpdateBreakpoint((SourceLocation)parameters["SourceLocation"], (BreakpointTypes)parameters["BreakpointTypes"] | BreakpointTypes.Enabled);
                if (BreakpointsChanged != null)
                    BreakpointsChanged(this, new EventArgs());
                break;
            case CommandValues.DeleteBreakpoint:
                WorkflowDesigner.Context.Services.GetService<IDesignerDebugView>().UpdateBreakpoint((SourceLocation)parameters["SourceLocation"], BreakpointTypes.None);
                if (BreakpointsChanged != null)
                    BreakpointsChanged(this, new EventArgs());
                break;
            case CommandValues.EnableBreakpoint:
                WorkflowDesigner.Context.Services.GetService<IDesignerDebugView>().UpdateBreakpoint((SourceLocation)parameters["SourceLocation"], BreakpointTypes.Enabled | BreakpointTypes.Bounded);
                if (BreakpointsChanged != null)
                    BreakpointsChanged(this, new EventArgs());
                break;
            case CommandValues.DisableBreakpoint:
                WorkflowDesigner.Context.Services.GetService<IDesignerDebugView>().UpdateBreakpoint((SourceLocation)parameters["SourceLocation"], BreakpointTypes.Bounded);
                if (BreakpointsChanged != null)
                    BreakpointsChanged(this, new EventArgs());
                break;
            case CommandValues.ShowProperties:
                if (ShowPropertiesRequested != null)
                    ShowPropertiesRequested(this, new EventArgs());
                break;
        }
    }
    public bool IsCommandSupported(int commandId)
    {
        switch (commandId)
        {
            case CommandValues.ShowProperties:
            case CommandValues.InsertBreakpoint:
            case CommandValues.DeleteBreakpoint:
            case CommandValues.EnableBreakpoint:
            case CommandValues.DisableBreakpoint:
                return true;
            default:
                return false;
        }
    }
}

然后创建它,注册它的事件,并将其发布到您的工作流设计器,如下所示

CommandService cmdSvc = new CommandService(WorkflowDesigner);
cmdSvc.BreakpointsChanged += CmdSvc_BreakpointsChanged;
cmdSvc.ShowPropertiesRequested+= CmdSvc_ShowPropertiesRequested;
workflowDesigner.Context.Services.Publish<ICommandService>(cmdSvc);

用于添加、删除、启用和禁用断点的上下文菜单项现在将在右键单击活动时显示。还有一个"Properties"上下文项,如果允许隐藏属性网格,您应该执行该上下文项的命令来显示属性网格