Ejemplo n.º 1
0
        private SysTaskProcess PrepareSysTaskProcessData(Func <DO.SysTask> getTask, string name = "测试任务流程名称")
        {
            SysTaskProcess process = new SysTaskProcess();

            process.ID        = UuidHelper.NewUuidString();
            process.Name      = name;
            process.Status    = SysTaskProcessStatus.Running;
            process.StartTime = DateTime.Now;

            SysTaskActivity activity1 = new SysTaskActivity(getTask());

            activity1.ID   = UuidHelper.NewUuidString();
            activity1.Name = "活动1";

            process.Activities.Add(activity1);

            SysTaskActivity activity2 = new SysTaskActivity(getTask());

            activity2.ID   = UuidHelper.NewUuidString();
            activity2.Name = "活动2";

            process.Activities.Add(activity2);

            return(process);
        }
Ejemplo n.º 2
0
        protected override void AfterCreateProcessInstance(SysTaskProcess sysTaskProcess)
        {
            sysTaskProcess.Name = string.Format("作废ID为{0}的流程", this.ProcessID);

            int index = 0;

            sysTaskProcess.OwnerActivityID = this.OwnerSysActivityID;

            IWfProcess process = WfRuntime.GetProcessByProcessID(this.ProcessID);

            WfProcessCurrentInfoCollection branchProcessesStatus = WfRuntime.GetProcessStatusByOwnerActivityID(process.CurrentActivity.ID, string.Empty, false);

            if (branchProcessesStatus.Count > 0 && this.CancelAllBranchProcesses)
            {
                //作废子流程
                sysTaskProcess.Activities.Add(sysTaskProcess.CreateDispatchCancelBranchesProcessActivity(process.CurrentActivity.ID, this.CancelAllBranchProcesses, index++));
            }

            if (this.CancelSelf)
            {
                sysTaskProcess.Activities.Add(sysTaskProcess.CreateCancelProcessActivity(this.ProcessID, index++));
            }

            sysTaskProcess.Activities.Add(sysTaskProcess.CreateExitMaintainingActivity(this.ProcessID, index++));
        }
Ejemplo n.º 3
0
        protected override void AfterCreateProcessInstance(SysTaskProcess sysTaskProcess)
        {
            sysTaskProcess.Name = string.Format("创建活动{0}的分支流程", this.OwnerActivityID);

            //这一步可能是很长时间的操作
            OguDataCollection <IUser> users = this.Template.Resources.ToUsers();

            int index = 0;

            if (this.Template.ExecuteSequence == WfBranchProcessExecuteSequence.SerialInSameProcess)
            {
                sysTaskProcess.Activities.Add(CreateUserActivity(sysTaskProcess, index++, users));

                SysTaskProcessRuntime.Persist();
            }
            else
            {
                foreach (IUser user in users)
                {
                    sysTaskProcess.Activities.Add(CreateUserActivity(sysTaskProcess, index++, new IUser[] { user }));

                    SysTaskProcessRuntime.Persist();
                }
            }

            if (this.AutoAddExitMaintainingStatusTask)
            {
                IWfProcess process = WfRuntime.GetProcessByActivityID(this.OwnerActivityID);

                sysTaskProcess.Activities.Add(sysTaskProcess.CreateExitMaintainingActivity(process.ID, index++));

                SysTaskProcessRuntime.Persist();
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 准备带子流程的任务流程
        /// </summary>
        /// <param name="getTask"></param>
        /// <returns></returns>
        private SysTaskProcess PrepareSysTaskProcessWithBranchData(Func <DO.SysTask> getTask)
        {
            SysTaskProcess process = PrepareSysTaskProcessData(getTask);

            process.Name = "测试带子流程的任务流程名称";

            SysTaskProcess branchA1 = PrepareSysTaskProcessData(getTask, string.Format("{0}的分支流程1", process.Activities[0].ID));

            branchA1.OwnerActivityID = process.Activities[0].ID;

            SysTaskProcess branchA2 = PrepareSysTaskProcessData(getTask, string.Format("{0}的分支流程2", process.Activities[0].ID));

            branchA2.OwnerActivityID = process.Activities[0].ID;

            SysTaskProcessRuntime.ProcessContext.AffectedProcesses.AddOrReplace(branchA1);
            SysTaskProcessRuntime.ProcessContext.AffectedProcesses.AddOrReplace(branchA2);

            SysTaskProcess branchB1 = PrepareSysTaskProcessData(getTask, string.Format("{0}的分支流程1", process.Activities[1].ID));

            branchB1.OwnerActivityID = process.Activities[1].ID;

            SysTaskProcess branchB2 = PrepareSysTaskProcessData(getTask, string.Format("{0}的分支流程2", process.Activities[1].ID));

            branchB2.OwnerActivityID = process.Activities[1].ID;

            SysTaskProcessRuntime.ProcessContext.AffectedProcesses.AddOrReplace(branchB1);
            SysTaskProcessRuntime.ProcessContext.AffectedProcesses.AddOrReplace(branchB2);

            return(process);
        }
		protected override void AfterCreateProcessInstance(SysTaskProcess sysTaskProcess)
		{
			sysTaskProcess.Name = string.Format("创建活动{0}的分支流程", this.OwnerActivityID);

			//这一步可能是很长时间的操作
			OguDataCollection<IUser> users = this.Template.Resources.ToUsers();

			int index = 0;

			if (this.Template.ExecuteSequence == WfBranchProcessExecuteSequence.SerialInSameProcess)
			{
				sysTaskProcess.Activities.Add(CreateUserActivity(sysTaskProcess, index++, users));

				SysTaskProcessRuntime.Persist();
			}
			else
			{
				foreach (IUser user in users)
				{
					sysTaskProcess.Activities.Add(CreateUserActivity(sysTaskProcess, index++, new IUser[] { user }));

					SysTaskProcessRuntime.Persist();
				}
			}

			if (this.AutoAddExitMaintainingStatusTask)
			{
				IWfProcess process = WfRuntime.GetProcessByActivityID(this.OwnerActivityID);

				sysTaskProcess.Activities.Add(sysTaskProcess.CreateExitMaintainingActivity(process.ID, index++));

				SysTaskProcessRuntime.Persist();
			}
		}
Ejemplo n.º 6
0
        public void AddOrReplace(SysTaskProcess process)
        {
            process.NullCheck("process");

            if (this.ContainsKey(process.ID) == false)
            {
                this.Add(process);
            }
        }
Ejemplo n.º 7
0
        private SysTaskProcess CreateProcessInstance()
        {
            SysTaskProcess sysProcess = new SysTaskProcess();

            sysProcess.ID        = UuidHelper.NewUuidString();
            sysProcess.Status    = SysTaskProcessStatus.NotRunning;
            sysProcess.StartTime = DateTime.Now;

            return(sysProcess);
        }
        /// <summary>
        /// 构造一个推出维护模式的任务活动
        /// </summary>
        /// <param name="sysTaskProcess"></param>
        /// <param name="processID"></param>
        /// <param name="index"></param>
        /// <returns></returns>
        public static SysTaskActivity CreateExitMaintainingActivity(this SysTaskProcess sysTaskProcess, string processID, int index)
        {
            SysTask task = ExitMaintainingStatusTask.CreateTask(string.Empty, processID, true);

            SysTaskActivity activity = CreateActivity(sysTaskProcess, index, processID, task);

            activity.Name = string.Format("退出ID为{0}流程的维护状态", processID);

            return(activity);
        }
Ejemplo n.º 9
0
        private SysTaskProcess CreateProcessInstance()
        {
            SysTaskProcess sysProcess = new SysTaskProcess();

            sysProcess.ID        = UuidHelper.NewUuidString();
            sysProcess.Status    = SysTaskProcessStatus.NotRunning;
            sysProcess.StartTime = SNTPClient.AdjustedTime;

            return(sysProcess);
        }
		private SysTaskProcess CreateProcessInstance()
		{
			SysTaskProcess sysProcess = new SysTaskProcess();

			sysProcess.ID = UuidHelper.NewUuidString();
			sysProcess.Status = SysTaskProcessStatus.NotRunning;
			sysProcess.StartTime = DateTime.Now;

			return sysProcess;
		}
Ejemplo n.º 11
0
        public int DispatchStartBranchProcessTasks(string ownerActivityID, IWfBranchProcessTemplateDescriptor template, bool autoAddExitMaintainingStatusTask)
        {
            ownerActivityID.CheckStringIsNullOrEmpty("ownerActivityID");
            template.NullCheck("template");

            StartBranchProcessSysTaskProcessBuilder builder = new StartBranchProcessSysTaskProcessBuilder(ownerActivityID, template, autoAddExitMaintainingStatusTask);

            SysTaskProcess sysTaskProcess = builder.Build();

            SysTaskProcessRuntime.StartProcess(sysTaskProcess);

            return(sysTaskProcess.Activities.Count);
        }
Ejemplo n.º 12
0
        private SysTaskActivity CreateUserActivity(SysTaskProcess sysTaskProcess, int index, IEnumerable <IUser> users)
        {
            SysTask task = CreateUserTaskInActivity(users);

            SysTaskActivity activity = WfSysTaskActivityHelper.CreateActivity(
                sysTaskProcess,
                index,
                string.Format("创建活动{0}的分支流程的任务流程活动{1}",
                              this.OwnerActivityID, index), task);

            SysTaskProcessRuntime.ProcessContext.AffectedActivities.AddOrReplace(activity);

            return(activity);
        }
        /// <summary>
        /// 创建一个包含了作废流程任务的任务流程活动
        /// </summary>
        /// <param name="sysTaskProcess"></param>
        /// <param name="processID"></param>
        /// <param name="index"></param>
        /// <returns></returns>
        public static SysTaskActivity CreateCancelProcessActivity(this SysTaskProcess sysTaskProcess, string processID, int index)
        {
            CancelProcessTask task = CancelProcessTask.CreateTask(processID, false);

            SysTaskActivity activity = WfSysTaskActivityHelper.CreateActivity(
                sysTaskProcess,
                index,
                string.Format("作废ID为{0}的流程的任务流程活动",
                              processID, index), task);

            SysTaskProcessRuntime.ProcessContext.AffectedActivities.AddOrReplace(activity);

            return(activity);
        }
		private SysTaskActivity CreateUserActivity(SysTaskProcess sysTaskProcess, int index, IEnumerable<IUser> users)
		{
			SysTask task = CreateUserTaskInActivity(users);

			SysTaskActivity activity = WfSysTaskActivityHelper.CreateActivity(
				sysTaskProcess,
				index,
				string.Format("创建活动{0}的分支流程的任务流程活动{1}",
				this.OwnerActivityID, index), task);

			SysTaskProcessRuntime.ProcessContext.AffectedActivities.AddOrReplace(activity);

			return activity;
		}
Ejemplo n.º 15
0
        public SysTaskProcess Build()
        {
            SysTaskProcess sysTaskProcess = CreateProcessInstance();

            SysTaskProcessRuntime.ProcessContext.AffectedProcesses.AddOrReplace(sysTaskProcess);

            this.AfterCreateProcessInstance(sysTaskProcess);

            SysTaskProcessRuntime.Persist();

            sysTaskProcess = SysTaskProcessRuntime.GetProcessByID(sysTaskProcess.ID);

            return(sysTaskProcess);
        }
Ejemplo n.º 16
0
        public void StartSysTaskProcessWithBranchesAndMoveToCompleteTest()
        {
            SysTaskAdapter.Instance.ClearAll();

            SysTaskProcess process = PrepareSysTaskProcessWithBranchData(() => PrepareInvokeServiceTask());

            SysTaskProcessRuntime.StartProcess(process);

            SysTaskCommon.ExecuteAllTasks();

            SysTaskProcessRuntime.ClearCache();
            process = SysTaskProcessRuntime.GetProcessByID(process.ID);
            Assert.AreEqual(SysTaskProcessStatus.Completed, process.Status);
        }
        /// <summary>
        /// 构造一个任务活动
        /// </summary>
        /// <param name="sysTaskProcess"></param>
        /// <param name="index"></param>
        /// <param name="name"></param>
        /// <param name="task"></param>
        /// <returns></returns>
        public static SysTaskActivity CreateActivity(this SysTaskProcess sysTaskProcess, int index, string name, SysTask task)
        {
            sysTaskProcess.NullCheck("sysTaskProcess");

            SysTaskActivity activity = new SysTaskActivity(task);

            activity.ID        = UuidHelper.NewUuidString();
            activity.ProcessID = sysTaskProcess.ID;
            activity.Sequence  = index;
            activity.Name      = name;

            SysTaskProcessRuntime.ProcessContext.AffectedActivities.AddOrReplace(activity);

            return(activity);
        }
        /// <summary>
        /// 创建一个包含了撤回流程任务的任务流程活动
        /// </summary>
        /// <param name="sysTaskProcess"></param>
        /// <param name="processID"></param>
        /// <param name="index"></param>
        /// <returns></returns>
        public static SysTaskActivity CreateWithdrawProcessActivity(this SysTaskProcess sysTaskProcess, string processID, int index)
        {
            string activityID = UuidHelper.NewUuidString();

            WithdrawProcessTask task = WithdrawProcessTask.CreateTask(processID, false);

            SysTaskActivity activity = WfSysTaskActivityHelper.CreateActivity(
                sysTaskProcess,
                index,
                string.Format("撤回ID为{0}的流程的任务流程活动",
                              processID, index), task);

            SysTaskProcessRuntime.ProcessContext.AffectedActivities.AddOrReplace(activity);

            return(activity);
        }
        /// <summary>
        /// 创建一个分发作废流程任务流程的任务活动
        /// </summary>
        /// <param name="sysTaskProcess"></param>
        /// <param name="ownerActivityID"></param>
        /// <param name="cancelAllBranchProcesses"></param>
        /// <param name="index"></param>
        /// <returns></returns>
        public static SysTaskActivity CreateDispatchCancelBranchesProcessActivity(this SysTaskProcess sysTaskProcess, string ownerActivityID, bool cancelAllBranchProcesses, int index)
        {
            string activityID = UuidHelper.NewUuidString();

            DispatchCancelBranchProcessesTask task = DispatchCancelBranchProcessesTask.CreateTask(activityID, ownerActivityID, cancelAllBranchProcesses);

            SysTaskActivity activity = WfSysTaskActivityHelper.CreateActivity(
                sysTaskProcess,
                index,
                string.Format("分派作废活动ID为{0}的分支流程的任务流程活动", ownerActivityID, index),
                task);

            activity.ID = activityID;

            SysTaskProcessRuntime.ProcessContext.AffectedActivities.AddOrReplace(activity);

            return(activity);
        }
Ejemplo n.º 20
0
        public int DispatchWithdrawProcessTask(string ownerSysActivityID, string processID, bool cancelAllBranchProcesses)
        {
            IWfProcess process = WfRuntime.GetProcessByProcessID(processID);

            IWfActivity currentActivity = process.CurrentActivity;

            process.EntrtMaintainingStatus();

            WfRuntime.PersistWorkflows();

            DispatchWithdrawProcessSysTaskProcessBuilder builder = new DispatchWithdrawProcessSysTaskProcessBuilder(ownerSysActivityID, process.ID, cancelAllBranchProcesses);

            SysTaskProcess sysTaskProcess = builder.Build();

            SysTaskProcessRuntime.StartProcess(sysTaskProcess);

            return(sysTaskProcess.Activities.Count);
        }
Ejemplo n.º 21
0
        public int DispatchCancelBranchProcessesTasks(string ownerSysActivityID, string ownerActivityID, bool cancelAllBranchProcesses)
        {
            int result = 0;

            WfProcessCurrentInfoCollection branchProcessesStatus = WfRuntime.GetProcessStatusByOwnerActivityID(ownerActivityID, string.Empty, false);

            foreach (WfProcessCurrentInfo processInfo in branchProcessesStatus)
            {
                DispatchCancelProcessSysTaskProcessBuilder builder = new DispatchCancelProcessSysTaskProcessBuilder(ownerSysActivityID, processInfo.InstanceID, true, cancelAllBranchProcesses);

                SysTaskProcess sysTaskProcess = builder.Build();

                SysTaskProcessRuntime.StartProcess(sysTaskProcess);

                result += sysTaskProcess.Activities.Count;
            }

            return(result);
        }
		protected override void AfterCreateProcessInstance(SysTaskProcess sysTaskProcess)
		{
			sysTaskProcess.Name = string.Format("撤回ID为{0}的流程", this.ProcessID);

			int index = 0;

			IWfProcess process = WfRuntime.GetProcessByProcessID(this.ProcessID);

			sysTaskProcess.OwnerActivityID = this.OwnerSysActivityID;

			WfProcessCurrentInfoCollection branchProcessesStatus = WfRuntime.GetProcessStatusByOwnerActivityID(process.CurrentActivity.ID, string.Empty, false);

			if (branchProcessesStatus.Count > 0 && this.CancelAllBranchProcesses)
			{
				sysTaskProcess.Activities.Add(sysTaskProcess.CreateDispatchCancelBranchesProcessActivity(process.CurrentActivity.ID, true, index++));
			}

			sysTaskProcess.Activities.Add(sysTaskProcess.CreateWithdrawProcessActivity(this.ProcessID, index++));
			sysTaskProcess.Activities.Add(sysTaskProcess.CreateExitMaintainingActivity(this.ProcessID, index++));
		}
Ejemplo n.º 23
0
        public void CreateSysTaskProcessAndPersist()
        {
            SysTaskAdapter.Instance.ClearAll();

            SysTaskProcess process = PrepareSysTaskProcessData(() => PrepareInvokeServiceTask());

            SysTaskProcessRuntime.ProcessContext.AffectedProcesses.AddOrReplace(process);
            SysTaskProcessRuntime.Persist();

            SysTaskProcess loadedProcess = SysTaskProcessRuntime.GetProcessByID(process.ID);

            Assert.AreNotEqual(process, loadedProcess);
            Assert.AreEqual(process.ID, loadedProcess.ID);
            Assert.AreEqual(process.Activities.Count, loadedProcess.Activities.Count);

            Assert.AreEqual(process.Activities[0].Sequence, loadedProcess.Activities[0].Sequence);
            Assert.AreEqual(process.Activities[1].Sequence, loadedProcess.Activities[1].Sequence);

            Assert.AreEqual(process.Activities[0].Task.TaskID, loadedProcess.Activities[0].Task.TaskID);
        }
Ejemplo n.º 24
0
        public void StartSysTaskProcessTest()
        {
            SysTaskAdapter.Instance.ClearAll();

            SysTaskProcess process = PrepareSysTaskProcessData(() => PrepareInvokeServiceTask());

            SysTaskProcessRuntime.StartProcess(process);

            DO.SysTask moveToTask = SysTaskAdapter.Instance.LoadByResourceID(process.Activities[0].ID).FirstOrDefault();

            Assert.IsNotNull(moveToTask);

            SysTaskCommon.ExecuteAndAssertTask(moveToTask);

            SysTaskProcessRuntime.ClearCache();

            process = SysTaskProcessRuntime.GetProcessByID(process.ID);

            Assert.AreEqual(1, process.CurrentActivityIndex);
        }
		/// <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();
            }
		}
Ejemplo n.º 26
0
        public void BuildStartBranchProcessTaskProcessTest()
        {
            IWfProcessDescriptor processDesp = CreateProcessWithAutoMaintainProperty();

            IWfProcess process = WfProcessTestCommon.StartupProcess(processDesp);

            MoveToExecutor(process);

            process = WfRuntime.GetProcessByProcessID(process.ID);
            IWfActivity ownerActivity = process.CurrentActivity;

            Console.WriteLine("OwnerActivityID: {0}", ownerActivity.ID);

            //在Template设置资源为一个组织,用于后续分发分支流程的测试
            IWfBranchProcessTemplateDescriptor template = ownerActivity.Descriptor.BranchProcessTemplates[0];

            IUser userInTemplate = template.Resources.ToUsers().FirstOrDefault();

            WfDepartmentResourceDescriptor deptResourceDesp = new WfDepartmentResourceDescriptor(userInTemplate.Parent);

            template.Resources.Clear();
            template.Resources.Add(deptResourceDesp);

            SysTaskAdapter.Instance.ClearAll();

            StartBranchProcessSysTaskProcessBuilder builder = new StartBranchProcessSysTaskProcessBuilder(ownerActivity.ID, template, true);

            SysTaskProcess sysTaskProcess = builder.Build();

            SysTaskProcessRuntime.ClearCache();

            sysTaskProcess = SysTaskProcessRuntime.GetProcessByID(sysTaskProcess.ID);

            Console.WriteLine("SysTaskProcess ID: {0}", sysTaskProcess.ID);
            Console.WriteLine("SysTaskProcess Activities: {0}", sysTaskProcess.Activities.Count);

            Assert.AreEqual(template.Resources.ToUsers().Count + 1, sysTaskProcess.Activities.Count);
        }
Ejemplo n.º 27
0
        public void BuildCancelProcessTaskProcessTest()
        {
            IWfProcessDescriptor processDesp = WfProcessTestCommon.CreateSimpleProcessDescriptorWithBranchTemplate();

            IWfProcess process = WfProcessTestCommon.StartupProcess(processDesp);

            MoveToExecutor(process);

            process = WfRuntime.GetProcessByProcessID(process.ID);

            IWfActivity ownerActivity = process.CurrentActivity;

            process.EntrtMaintainingStatus();

            WfRuntime.PersistWorkflows();

            DispatchCancelProcessSysTaskProcessBuilder builder = new DispatchCancelProcessSysTaskProcessBuilder(process.ID, true);

            SysTaskProcess sysTaskProcess = builder.Build();

            Console.WriteLine(sysTaskProcess.Activities.Count);

            Assert.AreEqual(3, sysTaskProcess.Activities.Count);
        }
		protected virtual void AfterCreateProcessInstance(SysTaskProcess process)
		{
		}
Ejemplo n.º 29
0
        private SysTaskProcess PrepareSysTaskProcessData(Func<DO.SysTask> getTask, string name = "测试任务流程名称")
        {
            SysTaskProcess process = new SysTaskProcess();

            process.ID = UuidHelper.NewUuidString();
            process.Name = name;
            process.Status = SysTaskProcessStatus.Running;
            process.StartTime = DateTime.Now;

            SysTaskActivity activity1 = new SysTaskActivity(getTask());

            activity1.ID = UuidHelper.NewUuidString();
            activity1.Name = "活动1";

            process.Activities.Add(activity1);

            SysTaskActivity activity2 = new SysTaskActivity(getTask());

            activity2.ID = UuidHelper.NewUuidString();
            activity2.Name = "活动2";

            process.Activities.Add(activity2);

            return process;
        }
Ejemplo n.º 30
0
 protected virtual void AfterCreateProcessInstance(SysTaskProcess process)
 {
 }