/// <summary>
 /// 开始节点的构造执行上下文对象
 /// </summary>
 /// <param name="processModel"></param>
 /// <param name="processInstance"></param>
 /// <param name="activity"></param>
 /// <param name="activityResource"></param>
 private ActivityForwardContext(ProcessModel processModel,
     ProcessInstanceEntity processInstance,
     ActivityEntity activity,
     ActivityResource activityResource)
 {
     ProcessModel = processModel;
     ProcessInstance = processInstance;
     Activity = activity;
     ActivityResource = activityResource;
 }
        /// <summary>
        /// 任务执行的上下文对象
        /// </summary>
        /// <param name="task"></param>
        /// <param name="processModel"></param>
        /// <param name="activityResource"></param>
        private ActivityForwardContext(TaskViewEntity task,
            ProcessModel processModel,
            ActivityResource activityResource)
        {
            this.TaskView = task;

            //check task condition has load activity instance
            this.FromActivityInstance = (new ActivityInstanceManager()).GetById(task.ActivityInstanceID);
            this.ProcessInstance = (new ProcessInstanceManager()).GetById(task.ProcessInstanceID);
            this.Activity = processModel.GetActivity(task.ActivityGUID);
            this.ProcessModel = processModel;
            this.ActivityResource = activityResource;
        }
        /// <summary>
        /// 获取下一步节点列表(伴随条件和资源)
        /// </summary>
        /// <param name="currentActivity"></param>
        /// <param name="conditionKeyValuePair"></param>
        /// <returns></returns>
        internal NextActivityMatchedResult GetNextActivityList(string currentActivityGUID,
                                                               IDictionary <string, string> conditionKeyValuePair,
                                                               ActivityResource activityResource,
                                                               Expression <Func <ActivityResource, ActivityEntity, bool> > expression)
        {
            NextActivityComponent newRoot = NextActivityComponentFactory.CreateNextActivityComponent();

            //先获取未加运行时表达式过滤的下一步节点列表
            NextActivityMatchedResult result = GetNextActivityList(currentActivityGUID,
                                                                   conditionKeyValuePair);

            foreach (NextActivityComponent c in result.Root)
            {
                if (c.HasChildren)
                {
                    NextActivityComponent child = GetNextActivityListByExpressionRecurisivly(c, activityResource, expression);
                    if (child != null)
                    {
                        newRoot.Add(child);
                    }
                }
                else
                {
                    if (expression.Compile().Invoke(activityResource, c.Activity))///TODO
                    {
                        newRoot.Add(c);
                    }
                }
            }

            NextActivityMatchedResult newResult = null;

            if (newRoot.HasChildren)
            {
                newResult = NextActivityMatchedResult.CreateNextActivityMatchedResultObject(result.MatchedType, newRoot);
            }
            else
            {
                newResult = NextActivityMatchedResult.CreateNextActivityMatchedResultObject(NextActivityMatchedType.NoneTransitionFilteredByCondition,
                                                                                            newRoot);
            }
            return(newResult);
        }
        /// <summary>
        /// 递归获取满足条件的下一步节点列表
        /// </summary>
        /// <param name="root"></param>
        /// <param name="activityResource"></param>
        /// <param name="expression"></param>
        /// <returns></returns>
        private NextActivityComponent GetNextActivityListByExpressionRecurisivly(NextActivityComponent root,
                                                                                 ActivityResource activityResource,
                                                                                 Expression <Func <ActivityResource, ActivityEntity, bool> > expression)
        {
            NextActivityComponent r1 = null;

            foreach (NextActivityComponent c in root)
            {
                if (c.HasChildren)
                {
                    NextActivityComponent child = GetNextActivityListByExpressionRecurisivly(c, activityResource, expression);
                    r1 = AddChildToNewGatewayComponent(r1, c, child);
                }
                else
                {
                    if (expression.Compile().Invoke(activityResource, c.Activity))
                    {
                        r1 = AddChildToNewGatewayComponent(r1, root, c);
                    }
                }
            }
            return(r1);
        }
 /// <summary>
 /// 启动流程的上下文对象
 /// </summary>
 /// <param name="processModel"></param>
 /// <param name="processInstance"></param>
 /// <param name="activity"></param>
 /// <param name="activityResource"></param>
 /// <returns></returns>
 internal static ActivityForwardContext CreateStartupContext(ProcessModel processModel,
     ProcessInstanceEntity processInstance,
     ActivityEntity activity,
     ActivityResource activityResource)
 {
     return new ActivityForwardContext(processModel, processInstance, activity, activityResource);
 }
 /// <summary>
 /// 创建任务执行上下文对象
 /// </summary>
 /// <param name="task"></param>
 /// <param name="processModel"></param>
 /// <param name="activityResource"></param>
 /// <returns></returns>
 internal static ActivityForwardContext CreateRunningContext(TaskViewEntity task,
     ProcessModel processModel,
     ActivityResource activityResource)
 {
     return new ActivityForwardContext(task, processModel, activityResource);
 }
 /// <summary>
 /// 创建流程跳转上下文对象
 /// </summary>
 /// <param name="jumpforwardActivity"></param>
 /// <param name="processModel"></param>
 /// <param name="processInstance"></param>
 /// <param name="activityResource"></param>
 /// <returns></returns>
 internal static ActivityForwardContext CreateJumpforwardContext(ActivityEntity jumpforwardActivity,
     ProcessModel processModel,
     ProcessInstanceEntity processInstance,
     ActivityResource activityResource)
 {
     return new ActivityForwardContext(processModel, processInstance, jumpforwardActivity, activityResource);
 }