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

154 Views Asked by At

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.

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:

    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. 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. There is not very much documentation (that I can find) on setting the Viewstate in the xaml. 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.

1

There are 1 best solutions below

0
Динко Тодоров On BEST ANSWER

I just fixed such problem and I did it by taking WorkflowViewState.GetViewStateManager(builder.Implementation) before DynamicUpdateServices.PrepareForUpdate(builder). I don't know what is the problem, but after I PrepareForUpdate and the result from GetViewStateManager is null. After I do all stuff, I pass the ViewStateManager to SaveBuilderToFile() and use it there.