修改工作流时,SourceLocationProvider.CollectMapping不会更新

问题描述 投票:1回答:2

我正在为重新托管的工作流设计器实现VisualTracking。如果文件刚刚加载到WorkflowDesigner中,则视觉跟踪工作正常,并且SourceLocationProvider.CollectMapping生成的映射可以成功运行。但是,如果对工作流进行了修改并重新保存,则SourceLocationProvider仅映射原始xaml。

有没有办法强制SourceLocationProvider在引擎盖下使用的AttachedProperties更新?

如果尝试使用WorkflowDesigner.Load(..),则会创建一个全新的WorkflowDesigner对象,因为WorkflowDesigner只能加载一次文件。如果可能,我想避免这种情况,因为它丢失了已设置的任何调试数据。

c# .net workflow-foundation-4 workflow-foundation
2个回答
0
投票

对不起,我自己没试过,但你可以从设计师的ModelChanged事件中调用SourceLocationProvider.CollectMapping(...)吗?


0
投票

使用反射,可以直接从DebuggerService本身获取所需的信息。以下解决方案适用于我,并在更新工作流程后继续工作:

private static Dictionary<string, SourceLocation> CreateSourceLocationMapping(
    IDesignerDebugView debugView,
    ModelService modelService)
{
    var nonPublicInstance = BindingFlags.Instance | BindingFlags.NonPublic;
    var debuggerServiceType = typeof(DebuggerService);
    var ensureMappingMethodName = "EnsureSourceLocationUpdated";
    var mappingFieldName = "instanceToSourceLocationMapping";
    var ensureMappingMethod = debuggerServiceType.GetMethod(ensureMappingMethodName, nonPublicInstance);
    var mappingField = debuggerServiceType.GetField(mappingFieldName, nonPublicInstance);

    if (ensureMappingMethod == null)
        throw new MissingMethodException(debuggerServiceType.FullName, ensureMappingMethodName);
    if (mappingField == null)
        throw new MissingFieldException(debuggerServiceType.FullName, mappingFieldName);

    var rootActivity = modelService.Root.GetCurrentValue() as Activity;
    if (rootActivity != null) 
        WorkflowInspectionServices.CacheMetadata(rootActivity);

    ensureMappingMethod.Invoke(debugView, new object[0]);
    var mapping = (Dictionary<object, SourceLocation>) mappingField.GetValue(debugView);

    return (from pair in mapping
            let activity = pair.Key as Activity
            where activity != null
            select new {activity.Id, pair.Value})
        .ToDictionary(p => p.Id, p => p.Value);
}
© www.soinside.com 2019 - 2024. All rights reserved.