简体   繁体   English

使用可视化设计器进行动态更新:将流转换为代码是否可能或更好?

[英]Dynamic Update using the visual designer: is it possible, or better to convert flows to code?

Related to my earlier question about updating long-running flows with multiple child flows and custom activities , I'm working on implementing a plan as well as code for modifying workflows after they've been released to production. 与我之前关于使用多个子流和自定义活动更新长时间运行流的问题相关,我正在努力实现一个计划以及在将工作流发布到生产后修改工作流的代码。

Besides the various issues outlined in the other question, I'm trying to debug the visual designer appearing jumbled after prepping it for dynamic update. 除了在另一个问题中概述的各种问题之外,我正在尝试调试视觉设计器在准备动态更新之后出现混乱。 After running diffs on the .xaml, it appears to be an issue with the WorkflowViewState getting confused. 在.xaml上运行差异后,似乎是WorkflowViewState混淆的问题。

According to previous posts , it seems that abandoning the visual designer is one sure-fire way of solving this problem. 根据以前的帖子 ,似乎放弃视觉设计师是解决这个问题的一种可靠方法。 However, I've found code that seems to nearly get me there. 但是,我发现代码似乎几乎让我在那里。 Here is how I'm saving the MainProcessFlow.xaml back to the file, after calling the DynamicUpdateServices.PrepareForUpdate method: 以下是我在调用DynamicUpdateServices.PrepareForUpdate方法后将MainProcessFlow.xaml保存回文件的方法:

    private static void SaveBuilderToFile(ActivityBuilder builder, string filePath)
    {
        // Make sure the activity builder has the right information about the c# expressions (even though its visual basic)
        VisualBasic.SetSettings(builder, VisualBasic.GetSettings(builder));

        // Set c# as the language
        System.Activities.Presentation.Expressions.ExpressionActivityEditor.SetExpressionActivityEditor(builder, "C#");

        // This is what I was hoping would correctly set the Viewstate
        WorkflowViewState.SetViewStateManager(
            builder.Implementation, WorkflowViewState.GetViewStateManager(builder.Implementation));

        string fullPath = Path.GetFullPath(filePath);

        using (FileStream file = File.Create(fullPath))
        {
            using (XmlWriter xmlWriter = XmlWriter.Create(file, new XmlWriterSettings { Indent = true, OmitXmlDeclaration = true }))
            {
                using (XamlWriter xamlWriter = ActivityXamlServices.CreateBuilderWriter( new XamlXmlWriter(xmlWriter, new XamlSchemaContext())))
                {
                    XamlServices.Save(xamlWriter, builder);
                }
            }
        }
    }

After calling this method and opening the .xaml up in the visual designer, the activities are out of order. 在调用此方法并在可视化设计器中打开.xaml之后,活动就会出现故障。 The flows are still "correct", in that the arrows are pointing in the right direction, but the layout is jumbled. 流程仍然是“正确的”,因为箭头指向正确的方向,但布局是混乱的。 After making my changes, creating the update map, and saving the .xaml back without the dynamicupdate information, the order is still incorrect. 进行更改,创建更新映射并在没有dynamicupdate信息的情况下保存.xaml后,订单仍然不正确。 There is not very much documentation (that I can find) on setting the Viewstate in the xaml. 在xaml中设置Viewstate时,没有太多文档(我可以找到)。 Am I missing something? 我错过了什么吗?

Alternatively, is abandoning the visual designer a better option? 或者,放弃视觉设计师是一个更好的选择吗? We have nearly a years worth of Workflows, so it would be an immense undertaking, but getting DynamicUpdate working is a higher priority. 我们有近一年的工作流程,所以这将是一项巨大的任务,但让DynamicUpdate工作是一个更高的优先级。

I just fixed such problem and I did it by taking WorkflowViewState.GetViewStateManager(builder.Implementation) before DynamicUpdateServices.PrepareForUpdate(builder) . 我刚刚解决了这个问题,我在DynamicUpdateServices.PrepareForUpdate(builder)之前使用了WorkflowViewState.GetViewStateManager(builder.Implementation) DynamicUpdateServices.PrepareForUpdate(builder) I don't know what is the problem, but after I PrepareForUpdate and the result from GetViewStateManager is null. 我不知道是什么问题,但在PrepareForUpdate之后,GetViewStateManager的结果为null。 After I do all stuff, I pass the ViewStateManager to SaveBuilderToFile() and use it there. 在完成所有操作后,我将ViewStateManager传递给SaveBuilderToFile()并在那里使用它。

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

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