protected override void OnExecute(SysTask task)
        {
            ExecuteSysTaskActivityTask activityTask = new ExecuteSysTaskActivityTask(task);

            SysTaskProcess process = SysTaskProcessRuntime.GetProcessByActivityID(activityTask.ActivityID);

            process.CurrentActivity.ExecuteTask();

            using (TransactionScope scope = TransactionScopeFactory.Create())
            {
                SysTaskProcessRuntime.Persist();

                //没有异常,则继续流转
                if (process.Status == SysTaskProcessStatus.Running)
                {
                    process = SysTaskProcessRuntime.GetProcessByActivityID(activityTask.ActivityID);

                    AutoMoveToNextActivity(process.CurrentActivity);

                    if (process.OwnerActivity != null)
                    {
                        AutoMoveToNextActivity(process.OwnerActivity);
                    }
                }

                scope.Complete();
            }

            if (process.Status == SysTaskProcessStatus.Aborted)
            {
                throw new ApplicationException(process.CurrentActivity.StatusText);
            }
        }
예제 #2
0
        /// <summary>
        /// 启动流程,持久化,然后发送执行活动的任务
        /// </summary>
        /// <param name="process"></param>
        public static void StartProcess(SysTaskProcess process)
        {
            process.NullCheck("process");

            process.Status = SysTaskProcessStatus.Running;

            ProcessContext.AffectedProcesses.AddOrReplace(process);

            if (process.Activities.Count == 0)
            {
                process.Status = SysTaskProcessStatus.Completed;
            }

            using (TransactionScope scope = TransactionScopeFactory.Create())
            {
                Persist();

                if (process.Activities.Count > 0)
                {
                    ExecuteSysTaskActivityTask.SendTask(process.Activities[0]);
                }

                scope.Complete();
            }
        }
예제 #3
0
        /// <summary>
        /// 根据流程ID获取任务流程,如果不存在则抛出异常
        /// </summary>
        /// <param name="processID"></param>
        /// <returns></returns>
        public static SysTaskProcess GetProcessByID(string processID)
        {
            processID.CheckStringIsNullOrEmpty(processID);

            SysTaskProcess result = ProcessContext.LoadedProcesses[processID];

            if (result == null)
            {
                result = SysTaskProcessAdapter.Instance.Load(processID);
                ProcessContext.LoadedProcesses.Add(result);
            }

            return(result);
        }
예제 #4
0
        /// <summary>
        /// 根据流程活动的ID获取任务流程,如果不存在则抛出异常
        /// </summary>
        /// <param name="activityID"></param>
        /// <returns></returns>
        public static SysTaskProcess GetProcessByActivityID(string activityID)
        {
            activityID.CheckStringIsNullOrEmpty("activityID");

            SysTaskProcess result = SysTaskProcessAdapter.Instance.LoadByActivityID(activityID);

            if (ProcessContext.LoadedProcesses.ContainsKey(result.ID))
            {
                result = ProcessContext.LoadedProcesses[result.ID];
            }
            else
            {
                ProcessContext.LoadedProcesses.Add(result);
            }

            return(result);
        }
        /// <summary>
        /// 如果能够流转,自动流转到下一个活动
        /// </summary>
        /// <param name="activity"></param>
        private static void AutoMoveToNextActivity(SysTaskActivity activity)
        {
            if (activity.CanMoveTo())
            {
                SysTaskActivity nextActivity = activity.Process.MoveToNextActivity();

                SysTaskProcessRuntime.Persist();

                if (activity.Process.Status == SysTaskProcessStatus.Running)
                {
                    ExecuteSysTaskActivityTask.SendTask(nextActivity);
                }
            }
            else
            {
                //对于第一个活动就带子流程的场景,其状态是NotRunning且有可能被阻塞不能流转,需要通过此操作启动子流程的Task
                if (activity.Status == SysTaskActivityStatus.NotRunning)
                {
                    SysTaskProcess.EnterActivity(activity, SNTPClient.AdjustedTime);
                }
            }
        }
예제 #6
0
 internal SysTaskActivityCollection(SysTaskProcess process)
 {
     this._Process = process;
 }