WorkflowMarkupSerializer 不保留状态机工作流程中的位置

发布于 2024-07-16 21:49:21 字数 1234 浏览 5 评论 0原文

我正在使用 WorkflowMarkupSerializer 保存状态机工作流程 - 它保存状态正常,但不保留其位置。 编写工作流程的代码在这里:

        using (XmlWriter xmlWriter = XmlWriter.Create(fileName))
        {
            WorkflowMarkupSerializer markupSerializer
                = new WorkflowMarkupSerializer();
            markupSerializer.Serialize(xmlWriter, workflow);
        }

读取工作流程的代码是:

            DesignerSerializationManager dsm
            = new DesignerSerializationManager();
        using (dsm.CreateSession())
        {
            using (XmlReader xmlReader
                = XmlReader.Create(fileName))
            {
                //deserialize the workflow from the XmlReader
                WorkflowMarkupSerializer markupSerializer
                    = new WorkflowMarkupSerializer();
                workflow = markupSerializer.Deserialize(
                    dsm, xmlReader) as Activity;

                if (dsm.Errors.Count > 0)
                {
                    WorkflowMarkupSerializationException error
                        = dsm.Errors[0]
                          as WorkflowMarkupSerializationException;
                    throw error;
                }
            }
         }

I am using WorkflowMarkupSerializer to save a statemachine workflow - it saves the states OK, but does not keep their positions. The code to write the workflow is here:

        using (XmlWriter xmlWriter = XmlWriter.Create(fileName))
        {
            WorkflowMarkupSerializer markupSerializer
                = new WorkflowMarkupSerializer();
            markupSerializer.Serialize(xmlWriter, workflow);
        }

The code to read the workflow is:

            DesignerSerializationManager dsm
            = new DesignerSerializationManager();
        using (dsm.CreateSession())
        {
            using (XmlReader xmlReader
                = XmlReader.Create(fileName))
            {
                //deserialize the workflow from the XmlReader
                WorkflowMarkupSerializer markupSerializer
                    = new WorkflowMarkupSerializer();
                workflow = markupSerializer.Deserialize(
                    dsm, xmlReader) as Activity;

                if (dsm.Errors.Count > 0)
                {
                    WorkflowMarkupSerializationException error
                        = dsm.Errors[0]
                          as WorkflowMarkupSerializationException;
                    throw error;
                }
            }
         }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

忘你却要生生世世 2024-07-23 21:49:22

哈,即使是 Visual Studio 2008 中托管的工作流设计器也会随机丢失状态的位置。 这告诉我这可能不是一件容易的任务,并且是组成它的活动的外部信息。 我会在主机周围挖掘更多信息; 如果我找到什么,我会回复。

Hah, even the workflow designer hosted in Visual Studio 2008 loses the positions of states randomly. This tells me it's probably not an easy task, and is information external to the Activities that comprise it. I'd dig more around the host for information; if I find something, I'll post back.

余罪 2024-07-23 21:49:21

打开控制面板-> “区域和语言选项”并将列表分隔符设置为“,”(逗号)
并且工作流序列化程序将使用“,”(逗号)作为 struct SizeF 的 X,Y 坐标的分隔符,

然后选择“;” 并且工作流序列化器将使用“;” (分号)作为分隔符。

序列化程序使用区域设置来序列化标记,这真的很愚蠢。

Open Control Panel -> "Regional and language options" and set list separator to ',' (comma)
and workflow serializer will use ',' (comma) as separator for X,Y coordinates for struct SizeF

then select ';' and workflow serializer will use ';' (semicolon) as separator.

This really stupid that serializer use regional setting for serialize markup.

最丧也最甜 2024-07-23 21:49:21

所有状态的位置都保存在单独的文件中。 您需要将其与工作流程本身的标记一起拖动。 幸运的是,它也只是 XML,因此您可以重用那里的大部分代码。 如果没记错的话,我相信它就是 NameOfYourWorkflow.layout。

我同意 x0n - Visual Studio 中的设计器真的很糟糕。

The position of all the states is kept in a separate file. You'll need to drag it around with the markup of the workflow itself. Luckily, it's just XML as well, so you might be able to reuse most of the code you have up there. If memory serves, I believe it's simply NameOfYourWorkflow.layout.

I agree with x0n - the designer is really bad in Visual Studio.

稀香 2024-07-23 21:49:21

好的,本教程提供了有关如何执行此操作的良好信息 - 尽管到目前为止,我只能保存布局,无法正确使用布局。 有问题的信息大约是 2/3(或者只是搜索 .layout)

(如何结束自己的问题?)

OK, this tutorial gives good information on how to do it - although so far I am only able to save the layout, I haven't been able to correctly use the layout. The information in question is about 2/3rds down (or just do a search for .layout)

(How does one close his own question?)

只有影子陪我不离不弃 2024-07-23 21:49:21

请注意,所创建的 XML(在示例中以扩展名 .layout 命名)的序列化或反序列化中存在错误。

它会生成以下 xml 作为文件的第一行:

<?xml version="1.0" encoding="utf-8"?><StateMachineWorkflowDesigner xmlns:ns0="clr-namespace:System.Drawing;Assembly=System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" Name="New" Location="30, 30" Size="519, 587" AutoSizeMargin="16, 24" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/workflow">

读回此内容时,< em>size 属性导致异常。 我从文件中删除了 Size="519, 587",并且工作流程已正确加载回来。 现在,我写入文件,打开它并删除大小,然后关闭它。 我需要考虑一个更优雅的解决方案,但至少我现在正在保存和恢复状态机工作流程。

Note that there is a bug in either the serialize or deserialize of the XML created (named in the example with an extension of .layout.)

It produces the following xml as the first line of the file:

<?xml version="1.0" encoding="utf-8"?><StateMachineWorkflowDesigner xmlns:ns0="clr-namespace:System.Drawing;Assembly=System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" Name="New" Location="30, 30" Size="519, 587" AutoSizeMargin="16, 24" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/workflow">

When reading this back in, the size attribute causes an exception. I removed Size="519, 587" from the file and the workflow is loaded back correctly. Right now, I write the file, open it and remove the size, then close it. I need to think about a more elegant solution, but at least I am now saving and restoring a state machine workflow.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文