I need to build an app that gets files from a server and moves to another server. It was suggested that I look into using Windows Workflow Foundation (WF).
我需要构建一个从服务器获取文件并移动到另一台服务器的应用程序。有人建议我考虑使用Windows Workflow Foundation(WF)。
I started to build the workflow but it is getting messy and I'm not sure I'm doing it the best way possible.
我开始构建工作流程,但它变得混乱,我不确定我是以最好的方式做到这一点。
Here is the basic worklow activities:
这是基本的worklow活动:
Get a list of sources Determine if source is ftp or disk drive Get a list of files from the server If source is ftp then get the file with ftp get else if source is drive then read file from drive If target is ftp then ftp file to server else if target is drive then write to a drive else if target is web service then post to web service If source is ftp then delete file with ftp commands else if source is drive then delete file
获取源列表确定源是ftp还是磁盘驱动器从服务器获取文件列表如果source是ftp然后使用ftp获取文件如果source是drive则获取else然后从驱动器读取文件如果target是ftp则ftp文件到服务器如果目标是驱动器然后写入驱动器,如果目标是Web服务然后发布到Web服务如果源是ftp然后删除文件与ftp命令否则如果源是驱动器然后删除文件
With one workflow it gets a little busy. I need 2 while loops, one around the integrations and one after I get a file list.
通过一个工作流程,它会变得有点繁忙。我需要2个while循环,一个在集成周围,一个在我得到文件列表之后。
The other thing I thought of was to build multiple workflows. One for FTPtoFTP, FTPtoDrive, FTPtoWebServie, DriveToFTP, DrivetoDrive, DriveToWebService.
我想到的另一件事是构建多个工作流程。一个用于FTPtoFTP,FTPtoDrive,FTPtoWebServie,DriveToFTP,DrivetoDrive,DriveToWebService。
Any suggestions?
4 个解决方案
#1
First, you should consider creating custom Activities for each of the major sections. The custom activities will be Composite Activities that can be composed of many steps. This will help de-clutter things a bit and allow you to continue working with the workflows at a relatively high-level.
首先,您应该考虑为每个主要部分创建自定义活动。自定义活动将是复合活动,可以由许多步骤组成。这将有助于解决一些问题,并允许您继续使用相对较高级别的工作流程。
The Workflow Designer, while handy, is not really designed to scale very large. As of VS 2008, the best way to work with XAML-based technologies is to use the text editor and read/write the XML directly.
工作流设计器虽然很方便,但实际上并不是为了扩展而设计的。从VS 2008开始,使用基于XAML的技术的最佳方法是使用文本编辑器并直接读/写XML。
Breaking it down into several workflows might not be the best approach unless you can break it down into a few high-level activities and are working at the XAML level. Keep in mind that if the logic and flow is nearly identical for all of these, you will now have to maintain 6 different workflows. This is a bigger nightmare if your workflows are complex and you need to fix a common logic error across all of them.
将其分解为多个工作流可能不是最佳方法,除非您可以将其分解为几个高级活动并且正在XAML级别工作。请记住,如果所有这些逻辑和流程几乎相同,那么您现在必须维护6个不同的工作流程。如果您的工作流程很复杂并且您需要修复所有这些工作流程中的常见逻辑错误,那么这是一个更大的噩梦。
You should also consider the use of the Services. This may allow you to have ONE workflow and ONE set of activities, but the implementation of each step can be isolated into a service. In this case, you would need to instantiate one workflow per combination, load the same workflow into each, and inject different activities. Not necessarily the best approach, but something to consider.
您还应该考虑使用服务。这可能允许您拥有一个工作流程和一组活动,但每个步骤的实施可以分离到一个服务中。在这种情况下,您需要为每个组合实例化一个工作流,将相同的工作流加载到每个工作流中,并注入不同的活动。不一定是最好的方法,但需要考虑的事情。
#2
First of all, this sounds to me like using WF is adding extra complications to what should be a fairly straightforward process. Although WF can be used to model execution flow, its purpose is to model business flow, and include business rules and logic without putting those into your implementations.
首先,这对我来说听起来像使用WF会给应该是一个相当简单的过程增加额外的复杂性。尽管WF可用于建模执行流程,但其目的是对业务流程进行建模,并包含业务规则和逻辑,而无需将其纳入您的实现。
In your example, the business rules seem largely like things which should be dealt with by an app.config file.
在您的示例中,业务规则看起来很像应该由app.config文件处理的事情。
However, on the broader question of using one workflow or many. You want each of your workflow tasks to be approximately the same 'broad scope'
但是,关于使用一个或多个工作流程的更广泛问题。您希望每个工作流任务与“广泛范围”大致相同
For instance WF for building a table
例如用于构建表的WF
- purchase wood
- cut wood
- cut wood for legs
- bevel edges
- round cornices
- sand twice with different coarseness
- assemble table
为木腿切割
沙子两次,粗糙度不同
The steps in the middle are all much more detailed than the steps around them. So you would consider splitting it up into two separate workflows: a high level workflow that contains the broads steps, and lower level workflows that contain the particulars.
中间的步骤比周围的步骤更详细。因此,您可以考虑将其拆分为两个单独的工作流程:包含广泛步骤的高级工作流程,以及包含详细信息的较低级别工作流程。
So the 'GetDatasource' workflow step would not care (externally) what type of datasource it is gathering from, it just returns to the next step in the workflow a set of data.
因此,“GetDatasource”工作流程步骤不关心(外部)它从哪个类型的数据源收集,它只是返回工作流程中的下一步一组数据。
Same goes for target, it doesn't care what type of datasource it had, it only cares what it has to do with the data. So that should be encapsulated as well.
同样适用于目标,它不关心它具有什么类型的数据源,它只关心它与数据有什么关系。所以这也应该被封装。
So your Workflow could be three workflows
因此,您的工作流程可能是三个工作流程
Highest WF
- GetDataSourceWF
- DoThingsWithDataWF
Then your DoThingsWithDataWF and GetDataSourceWF Workflows can each be concerned with only the execution context that they need.
然后,您的DoThingsWithDataWF和GetDataSourceWF工作流都可以只关注它们所需的执行上下文。
EDIT
As pointed out by the commenter James Schek. You can use the higher level workflow to actually kick off your lower level workflows and manage their execution into each other.
正如评论者James Schek所指出的那样。您可以使用更高级别的工作流程来实际启动较低级别的工作流程并相互管理它们的执行。
#3
Well personally I have not used WWF yet. I have done quite a bit of workflows before though. To me breaking them up into smaller workflows would seem to be the best way. When you're working with workflows you should try to limit each workflow to a specific task so that you have a definitive start action and at least one successful route and at least one failure route. Workflows in general can be very tricky things and it's best to keep each as simple as possible.
我个人还没有使用WWF。我之前做过很多工作流程。对我来说,将它们分解为更小的工作流程似乎是最好的方法。当您使用工作流时,您应该尝试将每个工作流限制为特定任务,以便您具有明确的启动操作以及至少一个成功路由和至少一个故障路由。一般来说,工作流程可能是非常棘手的事情,最好保持每个工作流程尽可能简单。
#4
As a general rule, anytime things get "messy", you should break them down into smaller parts. I'd definitely recommend breaking it down into several workflows.
作为一般规则,任何时候事情变得“混乱”,你应该把它们分解成更小的部分。我绝对建议将其分解为几个工作流程。
#1
First, you should consider creating custom Activities for each of the major sections. The custom activities will be Composite Activities that can be composed of many steps. This will help de-clutter things a bit and allow you to continue working with the workflows at a relatively high-level.
首先,您应该考虑为每个主要部分创建自定义活动。自定义活动将是复合活动,可以由许多步骤组成。这将有助于解决一些问题,并允许您继续使用相对较高级别的工作流程。
The Workflow Designer, while handy, is not really designed to scale very large. As of VS 2008, the best way to work with XAML-based technologies is to use the text editor and read/write the XML directly.
工作流设计器虽然很方便,但实际上并不是为了扩展而设计的。从VS 2008开始,使用基于XAML的技术的最佳方法是使用文本编辑器并直接读/写XML。
Breaking it down into several workflows might not be the best approach unless you can break it down into a few high-level activities and are working at the XAML level. Keep in mind that if the logic and flow is nearly identical for all of these, you will now have to maintain 6 different workflows. This is a bigger nightmare if your workflows are complex and you need to fix a common logic error across all of them.
将其分解为多个工作流可能不是最佳方法,除非您可以将其分解为几个高级活动并且正在XAML级别工作。请记住,如果所有这些逻辑和流程几乎相同,那么您现在必须维护6个不同的工作流程。如果您的工作流程很复杂并且您需要修复所有这些工作流程中的常见逻辑错误,那么这是一个更大的噩梦。
You should also consider the use of the Services. This may allow you to have ONE workflow and ONE set of activities, but the implementation of each step can be isolated into a service. In this case, you would need to instantiate one workflow per combination, load the same workflow into each, and inject different activities. Not necessarily the best approach, but something to consider.
您还应该考虑使用服务。这可能允许您拥有一个工作流程和一组活动,但每个步骤的实施可以分离到一个服务中。在这种情况下,您需要为每个组合实例化一个工作流,将相同的工作流加载到每个工作流中,并注入不同的活动。不一定是最好的方法,但需要考虑的事情。
#2
First of all, this sounds to me like using WF is adding extra complications to what should be a fairly straightforward process. Although WF can be used to model execution flow, its purpose is to model business flow, and include business rules and logic without putting those into your implementations.
首先,这对我来说听起来像使用WF会给应该是一个相当简单的过程增加额外的复杂性。尽管WF可用于建模执行流程,但其目的是对业务流程进行建模,并包含业务规则和逻辑,而无需将其纳入您的实现。
In your example, the business rules seem largely like things which should be dealt with by an app.config file.
在您的示例中,业务规则看起来很像应该由app.config文件处理的事情。
However, on the broader question of using one workflow or many. You want each of your workflow tasks to be approximately the same 'broad scope'
但是,关于使用一个或多个工作流程的更广泛问题。您希望每个工作流任务与“广泛范围”大致相同
For instance WF for building a table
例如用于构建表的WF
- purchase wood
- cut wood
- cut wood for legs
- bevel edges
- round cornices
- sand twice with different coarseness
- assemble table
为木腿切割
沙子两次,粗糙度不同
The steps in the middle are all much more detailed than the steps around them. So you would consider splitting it up into two separate workflows: a high level workflow that contains the broads steps, and lower level workflows that contain the particulars.
中间的步骤比周围的步骤更详细。因此,您可以考虑将其拆分为两个单独的工作流程:包含广泛步骤的高级工作流程,以及包含详细信息的较低级别工作流程。
So the 'GetDatasource' workflow step would not care (externally) what type of datasource it is gathering from, it just returns to the next step in the workflow a set of data.
因此,“GetDatasource”工作流程步骤不关心(外部)它从哪个类型的数据源收集,它只是返回工作流程中的下一步一组数据。
Same goes for target, it doesn't care what type of datasource it had, it only cares what it has to do with the data. So that should be encapsulated as well.
同样适用于目标,它不关心它具有什么类型的数据源,它只关心它与数据有什么关系。所以这也应该被封装。
So your Workflow could be three workflows
因此,您的工作流程可能是三个工作流程
Highest WF
- GetDataSourceWF
- DoThingsWithDataWF
Then your DoThingsWithDataWF and GetDataSourceWF Workflows can each be concerned with only the execution context that they need.
然后,您的DoThingsWithDataWF和GetDataSourceWF工作流都可以只关注它们所需的执行上下文。
EDIT
As pointed out by the commenter James Schek. You can use the higher level workflow to actually kick off your lower level workflows and manage their execution into each other.
正如评论者James Schek所指出的那样。您可以使用更高级别的工作流程来实际启动较低级别的工作流程并相互管理它们的执行。
#3
Well personally I have not used WWF yet. I have done quite a bit of workflows before though. To me breaking them up into smaller workflows would seem to be the best way. When you're working with workflows you should try to limit each workflow to a specific task so that you have a definitive start action and at least one successful route and at least one failure route. Workflows in general can be very tricky things and it's best to keep each as simple as possible.
我个人还没有使用WWF。我之前做过很多工作流程。对我来说,将它们分解为更小的工作流程似乎是最好的方法。当您使用工作流时,您应该尝试将每个工作流限制为特定任务,以便您具有明确的启动操作以及至少一个成功路由和至少一个故障路由。一般来说,工作流程可能是非常棘手的事情,最好保持每个工作流程尽可能简单。
#4
As a general rule, anytime things get "messy", you should break them down into smaller parts. I'd definitely recommend breaking it down into several workflows.
作为一般规则,任何时候事情变得“混乱”,你应该把它们分解成更小的部分。我绝对建议将其分解为几个工作流程。