예제 #1
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();
            }
        }
        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);
            }
        }
예제 #3
0
        /// <summary>
        /// 处理进入下一个活动的操作
        /// </summary>
        /// <param name="nextActivity"></param>
        internal static void EnterActivity(SysTaskActivity nextActivity, DateTime now)
        {
            nextActivity.StartTime = now;

            if (nextActivity.CanMoveTo())
            {
                nextActivity.Status = SysTaskActivityStatus.Running;
            }
            else
            {
                nextActivity.Status = SysTaskActivityStatus.Pending;
            }

            foreach (SysTaskProcess branch in nextActivity.Branches)
            {
                if (branch.Activities.Count == 0)
                {
                    branch.Status = SysTaskProcessStatus.Completed;
                }
                else
                if (branch.Activities.Count > 0)
                {
                    ExecuteSysTaskActivityTask.SendTask(branch.Activities[0]);
                }
            }

            SysTaskProcessRuntime.ProcessContext.AffectedActivities.AddOrReplace(nextActivity);
        }
        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);
        }
        /// <summary>
        /// 发送执行任务流程活动的任务
        /// </summary>
        /// <param name="sysTaskActivity"></param>
        /// <returns></returns>
        public static ExecuteSysTaskActivityTask SendTask(SysTaskActivity sysTaskActivity)
        {
            ExecuteSysTaskActivityTask task = ExecuteSysTaskActivityTask.CreateTask(sysTaskActivity);

            SysTaskAdapter.Instance.Update(task);

            return(task);
        }
        /// <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);
                }
            }
        }
        public static ExecuteSysTaskActivityTask CreateTask(SysTaskActivity sysTaskActivity)
        {
            sysTaskActivity.NullCheck("sysTaskActivity");

            ExecuteSysTaskActivityTask task = new ExecuteSysTaskActivityTask(sysTaskActivity.ID);

            task.TaskID     = UuidHelper.NewUuidString();
            task.ResourceID = sysTaskActivity.ID;

            if (sysTaskActivity.Task != null && sysTaskActivity.Task.TaskTitle.IsNotEmpty())
            {
                task.TaskTitle = string.Format("执行任务流程活动,任务ID为{0},名称为{1}",
                                               sysTaskActivity.Task.TaskID,
                                               sysTaskActivity.Task.TaskTitle);
            }
            else
            {
                task.TaskTitle = string.Format("执行任务流程活动{0}", sysTaskActivity.ID);
            }

            return(task);
        }
		public static ExecuteSysTaskActivityTask CreateTask(SysTaskActivity sysTaskActivity)
		{
			sysTaskActivity.NullCheck("sysTaskActivity");

			ExecuteSysTaskActivityTask task = new ExecuteSysTaskActivityTask(sysTaskActivity.ID);

			task.TaskID = UuidHelper.NewUuidString();
			task.ResourceID = sysTaskActivity.ID;

			if (sysTaskActivity.Task != null && sysTaskActivity.Task.TaskTitle.IsNotEmpty())
			{
				task.TaskTitle = string.Format("执行任务流程活动,任务ID为{0},名称为{1}",
					sysTaskActivity.Task.TaskID,
					sysTaskActivity.Task.TaskTitle);
			}
			else
			{
				task.TaskTitle = string.Format("执行任务流程活动{0}", sysTaskActivity.ID);
			}

			return task;
		}