Many years ago, the Windows Workflow Foundation was called WWF, and the literal translation of the name made many people think it was used to develop workflows or simply approval flows.
Bo Master was still a ignorant teenager, but also know that Microsoft will not vigorously push a face to such a business scenario of the technology, so specifically to find a "WF essence", when the "program is data" This assertion, was deeply shocked. Perhaps this is just the author's random write, but it was the generic method, Lamda expression, anonymous delegate what began to appear, the author of this statement to some extent coincidence the blogger's usual programming ideas. So the logic and the data, the algorithm and the structure, the boundary between them in my eyes, in my heart, began to blur in a more bizarre way.
However, after not using WF at work, bloggers are no longer interested in this technology. Now re-look, suddenly found that the official Workflow Team Blog Recent updates are two years ago, the online information is n years ago, and most of it is to teach you how to use. Why use, where to use, basically not too much introduction. Now, it seems to have been abandoned by Microsoft, I also specifically in the Bo asked the next, and no one knows the specific details.
It is rare to see scenarios where WF is used for development, and whether or not it is useful or not, and it is not reliable to sample the results in a small group. It seems that WF is used more harmoniously in a SharePoint environment, and because bloggers have not studied SharePoint, this is a bad comment. If the development in a pure code environment, with WF self-brought a set of activities can draw a seemingly clear flow chart, but the key and external interaction of the link is still not to be avoided, the need to consider most of the factors still need code to complete; And let people feel that there is no direct code to the convenience, such as IfElse, with code may be as long as in a method body can be completed, and in the flowchart is to use two activity, if there are interactive jump, the complexity of the flowchart is not necessarily under the code, and later maintenance is difficult to say.
It may be a non-malicious speculation, after several years, Microsoft slowly felt that the code between the original cryptic logic to the visible "process", for the programmer, it may not have much meaning, so that the investment is reduced. Of course you can also think that WF is mature, but even so, bloggers tend to think that the so-called maturity is because there is no direction to improve, although "mature", but not very useful.
BUT,WF is not useless, WF's bookmark (bookmark mechanism) is the most distinguished from the traditional development characteristics, the individual is considered to be the most important feature. Traditional development, we often encounter this situation: to determine whether the process to go to a specific link in order to determine the next step, in fact, is to judge a\b\c\d\ ... Permutations and combinations of variables, they may also be interrelated, as long as the process does not continue to flow, then each start will have to make the same judgment, whether the variables can meet the criteria to generate a label, when we find that the label exists, we can go to the label corresponding link, you can immediately follow the action. In practical development, we often set up a redundant identity field for this purpose. But a single field may not be able to fully identify a link, and it does not seem intuitive enough. The bookmark in WF is similar to the one above, in essence, it is an application that is highly skilled in delegating asynchronous callbacks, and a more natural description is a "Wait" when a variable has not yet met a condition, and is often used to interact with the outside, and in the process design, it is not like traditional code operations (query, Judgment, Update) tags appear to be abrupt (these operations WF are working on the lower level for us).
Beginning with the idea that Microsoft's introduction of WF is not intended to be used to develop a business workflow, we can even "WF" any piece of code that is logically sequential, but from a business scenario, many of the concepts of WF can be mapped, after all, abstract and figurative, both escape the flow of the word. So when the project is tight or time-critical, WF can help the programmer to comb the process-you'll find it useful when the [right] business process is unclear-even if you discard WF later, most of the code can be reused, and the code refactoring is easier due to the clear flow of each link. For this reason, the blogger uses WF in one of the current projects, and I'll briefly explain the key points and personal understanding.
Version control is also a highlight of it, this is not elaborate.
As I am not deep in the study of WF, said inevitably wrong, please the students criticize correct. In addition, this article does not show any project code, only in the industry general process, show Bo Master in the development process of thinking.
The backbone of this project is the first-hand room purchase process, involving the recognition, subscription, deal, leasing four links, the requirements are simplified as follows (the picture is drawn with Visio, drawing very frustrated, has not found a solid line curved arrows):
1. Link circulation
2, the circulation need to audit (can cross-level audit, if the applicant itself is the final link to the audit person directly through)
3, the audit will be returned to the initiation link; During the review process, the applicant may also revoke the application
4, a single link also has a different status, such as the subscription has been subscribed and back to subscribe two states, this type of state conversion also need to review, and content changes also need to review
5. At the same time, there can only be one audit item. For example, in the subscription content change review, you cannot initiate a Transfer transaction request.
This is a more typical workflow scenario. Just take over the project, I consider the traditional way to develop, not long I found myself in various links, states, logos, mutual exclusion between the dizzy, a group of paste. Even if the flowchart is already clearly in front of it, it seems rather difficult to give it code and data, and to run seemingly unrelated pieces of content in the expected logic. In particular, the product will be a face helpless to tell you, the recognition can also be transferred to lease, Business said, the next day, said, no need. To maintain a "hidden" logical relationship between code and quickly respond to changes in requirements, the complexity of the business increases and becomes more difficult.
Of course, this is not a very difficult task for a skilled worker, after all, we do this every day-translating the business process into layers of calling code-we can also sacrifice design patterns, AOP, IOC, ORM, and what makes the code look clearer (za). We've been receiving object-oriented, architecture-oriented, service-oriented training and lack of real-time process programming experience, and I think that's why Microsoft was promoting WF in the same year (this is wrong sentences, meaning to emphasize).
WF has three built-in processes: sequential flow, Flowchart, StateMachine. This project can consider the latter two, Bo Master selected is StateMachine, the whole out of the mainstream is as follows:
It's messy, and it's only weird that the VS comes with the WF designer that doesn't have Visio handy, which is actually the WF version of the 1th flowchart.
Then take a look at the logic of each line, in order to subscribe to the link out of the connection as an example, the trigger is as follows:
It can be seen that the process will determine the next step according to the external signal, flow to the next link (turn the deal, transfer lease), or back to the subscription, there are also changes in the picture is not released. A route is eventually selected based on the variables and parameter values in the process:
Any type of audit does not pass or the applicant is withdrawn to return to the current session, and before we use Visio painting flowchart as intuitive. However, there is a problem here. Bo Master Just contact StateMachine, choose entry or trigger place business logic is confused, at that time think both can, after all, ultimately only through condition to specify the direction of the change of state, without care condition where to generate The blogger thought that when Microsoft designed StateMachine, trigger was used as a container for the bookmark activity to facilitate interaction with external decisions, and of course we could put the bookmark in entry, which was a canonical question. No need to delve into. However, the blogger found that if the flow from one state to the same state--that state point to itself-in fact, the previous two links are not the same "instance", so the status of the variables and other states will not be saved, entry will be executed again. In order to avoid this situation, there is a situation in the current state, the business logic should be written in the entry, do not enter the trigger after the flow, because once the flow, even if the flow back to the current state, but also first out and then into. Of course, if the current state does not need to retain information, written in Trigger can also.
Let's see what happens in the audit.
I don't have to say more about this, but I'd like to say two more words. Although it is clear to restore the corresponding requirements, but not necessarily the most appropriate approach, I finally will unify these logic into one activity. As I said earlier, we can WF most of the many lines of code, but the complexity of the process requires the help of WF, a simple way to take care of the logic if it is hard to draw a few lines, it is paranoid. (in other words, most people who write programs are paranoid, black or white, I'm not wrong.)
For the 5th of the aforementioned requirements, a single WF process is inherently satisfying and does not require additional coding. Think about, if a few audit can be parallel, or flow to the next link, the previous link needs to change, how to do? Try it with a multi-process or sub-process.
Normal member variables in code activity, persistent after the bookmark is restored, value loss is not available, if you need to persist variable values before and after persistence, you should use variable, or apply the serializable feature, both of which bloggers speculate have not tried.
Some transactions can not fail to return all the back again, such as the document status from A->b, after a number of leadership approval, the result because the last step submitted unsuccessful, let the document back to a retrial? In this case, the last step can only be resubmitted, in real development, such "dirty commit" can be submitted periodically.
One activity can create multiple bookmark, and when all of the bookmark resumes execution, the process will continue down.
WF in the process of process flow, and can not return data to the caller, such as the launch of the application of the call, call Resumebookmark method, and do not know whether to pass or wait for the audit, need to check the database to get status results. Of course, you can use workflowapplication.extensions to interact with external programs, but not some scenarios, such as the client call WEBAPI, the server action initiation process, the action naturally need to know when the process is finished (pause or end) The result is what and return to the client; At this point the workflowapplication.extensions is then spat, unless the underlying is rewritten, such as allowing WF to cancel subsequent executions of the action and write the resulting data to an HTTP connection.
Process revision or external dependency changes, WF, either the old or new version of the parallel, or to explore how to migrate the old version to the new version, in many cases no pure code control to facilitate.
Blogger point of view: Synchronous SaaS is not a more applicable WF scenario, WF for asynchronous message push scenarios, such as the outside selling point meal status, courier status, bank funds flow, etc., the client does not wait for immediate results, but the matter state changes when the service-side message can be received. Of course, hard to use in a synchronous environment can also, at this time need a looser design and the bottom frame of the match to adapt to the WF "closed process" characteristics.
Points to be studied:
1, some processes are similar, can be packaged into a configurable process, in the design of a simple parameter configuration can show different process steps; For example, a state can be changed to B, C state, and B can only go to the C state, then a, a, the conversion to the next step of the judgment logic has a little difference. This seems to be possible only with metadata.
2, Instanceowner, online really can not find more about its introduction, currently known to be used in a multi-homed environment, the host to WF instance lock. Did not find the direct way to assign value to the instance Instanceowner, found on the Internet is basically the following two lines of code:
New Createworkflowownercommand (), Timespan.fromseconds (= view. Instanceowner;
Do not know is based on what factors to consider, always feel that do not understand what is meant, why and in this way to set up Defaultinstanceowner, if not set, then the following line of code run will be error:
workflowapplicationinstance instance = workflowapplication.getinstance (Guid.parse (flowinstance. InstanceID), instore);
The framework should be completely at the bottom of the automatic to us to deal with instanceowner related things, such as the following sentence in the not set Defaultinstanceowner time will not error:
Wfapp.load (Guid.parse (flowinstance. InstanceID));
How can you set your own Instanceowner, maybe can pass instanceownermetadata.
New Createworkflowownercommand () { = { new Instancevalue ( Wfinstancescopename)},} };
However, the set up, how to get another problem, interested friends can study this file, can also be found in the official Wf_wcf_ example. In short, the water is deep enough to persist this trip.
Other references:
Loading persisted workflow instances with Workflowapplication
Do you remember the Windows Workflow Foundation?