简体   繁体   English

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

[英]How to add the right-click breakpoints menu to a rehosted workflow designer

A shortcoming of the rehosted workflow designer is that it does not, by default, include many of the features necessary for serious workflow development.重新托管的工作流设计器的一个缺点是,默认情况下,它不包括严肃的工作流开发所需的许多功能。

Chief among these is the lack of native debug/breakpoint support.其中最主要的是缺乏本地调试/断点支持。

There are samples online which show how to enable debugging, but I didn't find any which included showing the breakpoint section of the right-click context menu for activities网上有一些示例显示了如何启用调试,但我没有找到任何示例,其中包括显示活动的右键单击上下文菜单的断点部分

It turns out adding the breakpoint menuitems to the context menu is relatively straightforward.事实证明,将断点菜单项添加到上下文菜单相对简单。

First, make a class which implements System.Activities.Presentation.Hosting.ICommandService首先,创建一个实现 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;
        }
    }
}

Then create it, register for its events, and publish it to your workflow designer like so然后创建它,注册其事件,然后像这样将其发布到您的工作流设计器

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

The context menu items for adding, removing, enabling and disabling breakpoints will now by shown when you right-click an activity.现在,当您右键单击活动时,将显示用于添加、删除、启用和禁用断点的上下文菜单项。 There will also be a "Properties" context item whose command you should implement to show the property grid if hiding it is allowed还将有一个“属性”上下文项,如果允许隐藏它,您应该执行其命令以显示属性网格

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM