WF Activity得到Variable and Argument

  public   sealed   class  CustomActivity1 : NativeActivity
    {
        
protected   override   void  Cancel(NativeActivityContext context)
        {
            Console.Write(
" Cancel " );
            
base .Cancel(context);
        }

        
protected   override   void  Abort(NativeActivityAbortContext context)
        {
            Console.Write(
" Abort " );
            
base .Abort(context);
        }


        
protected   override   void  CacheMetadata(NativeActivityMetadata metadata)
        {
            _locationReferences 
=
                metadata.Environment.GetLocationReferences().ToList();

            
base .CacheMetadata(metadata);
        }

        
protected   override   void  Execute(NativeActivityContext context)
        {
            LocationReference locationReference 
=
                _locationReferences.Find(
                    x 
=>  x.Name  ==   " Test "   &&  x.Type  ==   typeof ( int ));

            
if  (locationReference  !=   null )
            {
                Console.WriteLine(
                    locationReference.Name 
+   "   "   +  locationReference.Type);

                
//  Blows up here.
                Location location  =  locationReference.GetLocation(context);
                location.Value 
=   5 ;
            }
          //  var pi 
=  context.GetType().GetProperty( " AllowChainedEnvironmentAccess " , BindingFlags.NonPublic  |  BindingFlags.Instance);
          //  pi.SetValue(context, 
true null );
            
string  myVaraibleName  =   " varaibleX " ;
            
string  myArgumentName  =   " argument1 " ;

            
string  MyVariableValue  =  context.DataContext.GetProperties()[myVaraibleName].GetValue(context.DataContext).ToString();
            
string  myArgument  =  context.DataContext.GetProperties()[myArgumentName].GetValue(context.DataContext).ToString();
            Console.Write(
" Execute " );
            var extension 
=  context.GetExtension < MyExtension > ();

        }

        
private  List < LocationReference >  _locationReferences;


    }

    
class  MyExtension : IWorkflowInstanceExtension
    {
        
private  WorkflowInstanceProxy _instance;
        
public  IEnumerable < object >  GetAdditionalExtensions()
        {
            
return   null ;
        }
        
public   void  SetInstance(WorkflowInstanceProxy instance)
        {
            _instance 
=  instance;
        }
        
public   void  WaitSome(Bookmark bookmark)
        {

            
//   _instance.WorkflowDefinition

        }
    }


你可能感兴趣的:(Activity)