问题描述
重新托管的工作流设计器的一个缺点是,默认情况下,它不包含严肃的工作流开发所需的许多功能.
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.
首先,创建一个实现 System.Activities.Presentation.Hosting.ICommandService 的类
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
这篇关于如何将右键单击断点菜单添加到重新托管的工作流设计器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!