Esempio n. 1
0
        // Callers of this method should acquire the executor lock only if they 
        // are not being called in the runtime thread.(
        private void LoadExistingInstance(WorkflowInstance instance, bool attaching)
        {
            WorkflowExecutor executor = instance.GetWorkflowResourceUNSAFE();
            if (!executor.IsInstanceValid)
                return;
            IWorkflowCoreRuntime runtimeService = (IWorkflowCoreRuntime)executor;
            Activity rootActivity = runtimeService.RootActivity;
            Guid scheduleTypeId = GetScheduleTypeId(runtimeService);

            // If we are just attaching, need to LoadExistingScheduleType with the dynamic definition and type
            // since the OnDynamicUpdateEvent has never been executed.
            if (attaching && runtimeService.IsDynamicallyUpdated)
                LoadExistingScheduleType(scheduleTypeId, rootActivity.GetType(), true, rootActivity);

            // Add to the InstanceTable before firing the DE event !
            this.instanceTable.AddInstance(instance.InstanceId, rootActivity);

            this.controllerConduit.InstanceCreated(this.programId, instance.InstanceId, scheduleTypeId);

            // Take a lock so that SetInitialActivityStatus is always called before next status events.
            lock (this.eventLock)
            {
                executor.WorkflowExecutionEvent += OnInstanceEvent;
                foreach (Activity activity in DebugController.WalkActivityTree(rootActivity))
                {
#if false
                    //
                    ReplicatorActivity replicator = activity as ReplicatorActivity;
                    if (replicator != null)
                    {
                        foreach (Activity queuedChildActivity in replicator.DynamicActivities)
                            activityQueue.Enqueue(queuedChildActivity);
                    }
                    else
#endif
                    UpdateActivityStatus(scheduleTypeId, instance.InstanceId, activity);

                }

                ActivityExecutionContext rootExecutionContext = new ActivityExecutionContext(rootActivity);
                foreach (ActivityExecutionContext executionContext in DebugController.WalkExecutionContextTree(rootExecutionContext))
                {
                    Activity instanceActivity = executionContext.Activity;
                    foreach (Activity childInstance in DebugController.WalkActivityTree(instanceActivity))
                    {
                        UpdateActivityStatus(scheduleTypeId, instance.InstanceId, childInstance);
                    }
                }
            }
        }
 private void LoadExistingInstance(WorkflowInstance instance, bool attaching)
 {
     WorkflowExecutor workflowResourceUNSAFE = instance.GetWorkflowResourceUNSAFE();
     if (workflowResourceUNSAFE.IsInstanceValid)
     {
         IWorkflowCoreRuntime workflowCoreRuntime = workflowResourceUNSAFE;
         Activity rootActivity = workflowCoreRuntime.RootActivity;
         Guid scheduleTypeId = this.GetScheduleTypeId(workflowCoreRuntime);
         if (attaching && workflowCoreRuntime.IsDynamicallyUpdated)
         {
             this.LoadExistingScheduleType(scheduleTypeId, rootActivity.GetType(), true, rootActivity);
         }
         this.instanceTable.AddInstance(instance.InstanceId, rootActivity);
         this.controllerConduit.InstanceCreated(this.programId, instance.InstanceId, scheduleTypeId);
         lock (this.eventLock)
         {
             workflowResourceUNSAFE.WorkflowExecutionEvent += new EventHandler<WorkflowExecutor.WorkflowExecutionEventArgs>(this.OnInstanceEvent);
             foreach (Activity activity2 in WalkActivityTree(rootActivity))
             {
                 this.UpdateActivityStatus(scheduleTypeId, instance.InstanceId, activity2);
             }
             ActivityExecutionContext rootContext = new ActivityExecutionContext(rootActivity);
             foreach (ActivityExecutionContext context2 in WalkExecutionContextTree(rootContext))
             {
                 foreach (Activity activity4 in WalkActivityTree(context2.Activity))
                 {
                     this.UpdateActivityStatus(scheduleTypeId, instance.InstanceId, activity4);
                 }
             }
         }
     }
 }