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

时间:2014-08-18 12:57:31

标签: c# workflow-foundation

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

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

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

1 个答案:

答案 0 :(得分:2)

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

首先,创建一个实现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);

现在,当您右键单击某个活动时,将显示用于添加,删除,启用和禁用断点的上下文菜单项。还有一个&#34;属性&#34;上下文项目,如果允许隐藏它,则应该实现其命令以显示属性网格