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

被刻印的时光 ゝ 提交于 2020-01-02 23:13:26

问题


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


回答1:


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

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



来源:https://stackoverflow.com/questions/25363874/how-to-add-the-right-click-breakpoints-menu-to-a-rehosted-workflow-designer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!