/// <summary>
        /// Do a single step of task execution
        /// Does not automatically persist task state
        /// </summary>
        /*public void DoOneStep()
        {
            bool enabled = false;
            log.Debug("[DoOneStep start]");
            foreach (TaskDef tsk in MyTask.Tasks)
            {
                lock (this)
                {
                    if (EnableTaskIfPossible(tsk.Id) != null)
                    {
                        _canContinue = null;
                        enabled = true;
                    }
                }
            }
            
            if (!enabled)
            {
                ContinueTaskExecution();
            }
            log.Debug("[KickTokens end. Returning {0}]", enabled);
        }*/

        /// <summary>
        /// Enable specified transition
        /// </summary>
        /// <param name="taskId"></param>
        private string EnableTransition(string taskId)
        {
            lock (this)
            {
                List<string> enablingPlaces;
                bool b = CanEnableTransition(taskId, out enablingPlaces);
                if (!b) throw new Exception("Task cannot be enabled: " + taskId);
                TaskDef tsk = MyTask.GetTask(taskId);
                TransitionInfo ti = new TransitionInfo();
                ti.Status = TransitionStatus.Enabling;
                ti.TaskId = taskId;
                ti.InstanceId = AllocateNewTaskInstanceId(ti.TaskId);
                //TODO: think about automatic handling of enable task timeout 
                //this should be handled by the framework so we don't have to do it here.
                EnableChildTask msg;
                if (tsk.IsMultiInstance)
                {
                    var data = new List<Dictionary<string, object>>(ScriptRuntime.PrepareMultiInstanceTaskInputData(this, tsk, Context));
                    msg = new EnableMultiChildTask {
                        MultiInputData = data
                    };
                }
                else
                {
                    msg = new EnableChildTask {
                        InputData = ScriptRuntime.PrepareChildTaskInputData(this, tsk, Context)
                    };
                }

                //msg.Mode = tsk.AllowSynchronousExec ? MessageHandlingMode.SameTransaction : MessageHandlingMode.AnotherTransaction;
                msg.CorrelationId = ti.InstanceId;
                msg.FromTaskInstanceId = this.InstanceId;
                msg.FromProcessInstanceId = this.ProcessInstanceId;
                msg.ToTaskInstanceId = ti.InstanceId;
                msg.ProcessDefinitionId = ProcessDefinition.DefinitionId;
                msg.TaskId = tsk.Id;
            
                AllTasks.Add(ti);
                Context.EnableChildTask(msg);
                log.Info("Child task {0} created: {1}", taskId, ti.InstanceId);
                return ti.InstanceId;
            }
        }
 /// <summary>
 /// </summary>
 /// <param name="inputData"></param>
 public void Enable(ICollection<Dictionary<string, object>> inputData)
 {
     RequireActivation(true);
     //TODO: validate the data
     if (inputData.Count == 0)
         throw new TaskDataInvalidException(TaskId, InstanceId, "No input data for multi-instance task");
     this.Status = TaskStatus.Enabling;
     foreach (Dictionary<string, object> dob in inputData)
     {
         TransitionInfo ti = new TransitionInfo();
         ti.Status = TransitionStatus.Enabling;
         ti.InstanceId = AllocateNewTaskInstanceId(TaskId);
         ChildTransitions.Add(ti);
         
         Context.EnableChildTask(new EnableChildTask {
             CorrelationId = ti.InstanceId,
             FromProcessInstanceId = this.ProcessInstanceId,
             FromTaskInstanceId = this.InstanceId,
             ToTaskInstanceId = ti.InstanceId,
             InputData = dob,
             ProcessDefinitionId = this.ProcessDefinitionId,
             TaskId = this.TaskId
         });
     }
 }