Пример #1
0
        public async Task <bool> Start(string DefinitionID, Dictionary <string, object> InputData = null)
        {
            var token = new TaskToken();
            var pi    = _ProcessInstances[DefinitionID];

            pi.StartTask.Token = token;
            pi.Tokens.Add(token);
            pi.Status = ProcessStatus.Running;

            if (InputData != null)
            {
                pi.InputData = InputData;
            }
            if (pi.InputData == null)
            {
                pi.InputData = new Dictionary <string, object>();
            }

            while (pi.Status == ProcessStatus.Running)
            {
                foreach (var t in pi.Tokens)
                {
                    if (await t.Excute(pi))
                    {
                        //  令牌数量发生变化,集合更改,重新循环
                        break;
                    }
                }
            }

            if (pi.Status == ProcessStatus.Finish)
            {
                // 异步更新状态
                BPMDBService.ProcessDone(pi.ID);

                // 从缓存中移除已完成的流程实例
                _ProcessInstances.Remove(pi.ID);

                // 通知业务系统流程完成
                pi.OB.ProcessFinish(pi);
            }

            return(true);
        }
Пример #2
0
        public async Task Continu(string TaskID, int User, Dictionary <string, object> InputData = null)
        {
            TaskID = TaskID.ToUpper();

            var pid = getProcessInstance(TaskID);

            ProcessInstance pi = null;

            if (string.IsNullOrEmpty(pid))
            {
                // back from db
                pi = BPMDBService.BackUpInstance(TaskID);

                // 缓存流程实例
                if (!_ProcessInstances.ContainsKey(pi.ID))
                {
                    _ProcessInstances.Add(pi.ID, pi);
                }
            }
            else
            {
                pi = _ProcessInstances[pid];
            }

            pi.Status = ProcessStatus.Running;

            pi.InputData = InputData;

            // 这里不自动跳过此任务,由任务自己来执行下一步(因为会签的话需要所有的会签任务完成才执行下一步)

            //var token = pi.Tasks[TaskID].Token;

            //token.CurrentTask = null;
            //token.CurrentGateway = null;

            //var to = pi.Sequences[pi.Tasks[TaskID].To].To;

            //if (pi.Tasks.ContainsKey(to))
            //{
            //    pi.Tasks[to].Token = token;
            //}
            //else if (pi.Gateways.ContainsKey(to))
            //{
            //    pi.Gateways[to].Token = token;
            //}

            pi.Tasks[TaskID].IsDone = true;

            while (pi.Status == ProcessStatus.Running)
            {
                foreach (var t in pi.Tokens)
                {
                    if (await t.Excute(pi))
                    {
                        //  令牌数量发生变化,集合更改,重新循环
                        break;
                    }
                }
            }

            if (pi.Status == ProcessStatus.Finish)
            {
                // 更新状态
                BPMDBService.ProcessDone(pi.ID);

                // 从缓存中移除已完成的流程实例
                _ProcessInstances.Remove(pi.ID);

                // 通知业务系统流程完成
                pi.OB.ProcessFinish(pi);
            }
        }