WF4 子流程的实现

using  System;
using  System.Linq;
using  System.Activities;
using  System.Activities.Statements;
using  System.Collections.Generic;

namespace  WorkflowConsoleApplication2
{

    
class  Program
    {
        
public   static  WorkflowApplication Instance  =   null ;
        
static   void  Main( string [] args)
        {
         
//    WorkflowInvoker.Invoke(new Workflow1());
            Instance  =   new  WorkflowApplication( new  Workflow1());
            Instance.Run();
            System.Console.Read(); 
        }
    }

    
public   class  MyActivity : NativeActivity
    {
        
public   static   string  bookmark  =   " AAAAAAAA " ;
        
public   static  Guid InstanceId  =  Guid.Empty;



        
public  List < string >  Tests {  get set ; }
        
protected   override   bool  CanInduceIdle
        {
            
get
            { 
return   true ; }
        }
        
protected   override   void  Execute(NativeActivityContext context)
        {
            Tests 
=   new  List < string > () {  " A " " B " " C " " D " " E " " F "  };
            WorkflowApplication app 
=   new  WorkflowApplication(Create(Tests));
            app.Run();
            InstanceId 
=  app.Id;

            context.CreateBookmark(bookmark, bookmarkCallback);
            Console.WriteLine(
" No " );

        }
        
protected   void  bookmarkCallback(NativeActivityContext context, Bookmark bookmark,  object  obj)
        {
            Console.WriteLine(
" OK " );
        }

        
public  Activity Create(List < string >  l)
        {
            var par 
=   new  Parallel()
            {

            };

            
foreach  (var item  in  l)
            {
                par.Branches.Add(
new  WriteLine() { Text  =  item });
            }
            var seq 
=   new  Sequence();
            seq.Activities.Add(par);
            seq.Activities.Add(
new  BackActivity());
            
return  seq;
        }

    }

    
public   class  BackActivity : NativeActivity
    {
        
protected   override   void  Execute(NativeActivityContext context)
        {
            
//  MyActivity.mainInstance.ResumeBookmark(MyActivity.bookmark, null);
            Program.Instance.ResumeBookmark(MyActivity.bookmark,  null );
        }
    }
}

你可能感兴趣的:(实现)