Esempio n. 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);
        }
Esempio n. 2
0
        public void BackUpTasks(Definitions def, List <BPMTaskInstanceEntity> DBTasks)
        {
            #region Tasks

            foreach (var task in DBTasks)
            {
                TaskInstance taskInstance = null;
                var          taskID       = task.ID.ToString().ToUpper();

                switch (task.Type)
                {
                case (int)TaskType.Start:
                {
                    taskInstance = new StartTaskInstance()
                    {
                        Name     = task.Name,
                        ID       = taskID,
                        SourceID = task.SourceID,
                        From     = task.Source.ToString().ToUpper(),
                        To       = task.Target.ToString().ToUpper(),
                        Status   = (TaskStatus)task.Status,
                        Type     = TaskType.Start
                    };
                    break;
                }

                case (int)TaskType.CallApi:
                {
                    taskInstance = new AutoTaskInstance(UnityContainerHelper.GetServer <IAutoTaskExcute>(task.Name))
                    {
                        Name     = task.Name,
                        ID       = taskID,
                        SourceID = task.SourceID,
                        From     = task.Source.ToString().ToUpper(),
                        To       = task.Target.ToString().ToUpper(),
                        Status   = (TaskStatus)task.Status,
                        Type     = TaskType.CallApi
                    };

                    break;
                }

                case (int)TaskType.Manual:
                {
                    var mTask = new ManualTaskInstance()
                    {
                        Name     = task.Name,
                        ID       = taskID,
                        SourceID = task.SourceID,
                        From     = task.Source.ToString().ToUpper(),
                        To       = task.Target.ToString().ToUpper(),
                        Status   = (TaskStatus)task.Status,
                        Type     = TaskType.Manual,
                        UserID   = task.UserID
                    };

                    mTask.IsDone = mTask.Status == TaskStatus.Done;

                    foreach (var item in this.ModelInstanceIDMaps)
                    {
                        if (item.Value.ToUpper() == taskID)
                        {
                            mTask.Owner = def.Process.UserTasks.SingleOrDefault(t => t.ID == item.Key).PotentialOwner;
                            break;
                        }
                    }

                    if (this.OB != null)
                    {
                        mTask.SetObservation(this.OB);
                    }

                    taskInstance = mTask;
                    break;
                }

                case (int)TaskType.Sign:
                {
                    var mTask = new JointlySignTaskInstance()
                    {
                        Name     = task.Name,
                        ID       = taskID,
                        SourceID = task.SourceID,
                        From     = task.Source.ToString().ToUpper(),
                        To       = task.Target.ToString().ToUpper(),
                        Status   = (TaskStatus)task.Status,
                        Type     = TaskType.Manual,
                        UserID   = task.UserID,
                        Users    = task.Users
                    };

                    mTask.IsDone = mTask.Status == TaskStatus.Done;

                    foreach (var item in this.ModelInstanceIDMaps)
                    {
                        if (item.Value.ToUpper() == taskID)
                        {
                            mTask.Owner = def.Process.JointlySigns.SingleOrDefault(t => t.ID == item.Key).PotentialOwner;
                            break;
                        }
                    }

                    if (this.OB != null)
                    {
                        mTask.SetObservation(this.OB);
                    }

                    taskInstance = mTask;
                    break;
                }

                case (int)TaskType.Empty:
                {
                    break;
                }

                case (int)TaskType.End:
                {
                    taskInstance = new EndTaskInstance()
                    {
                        Name     = task.Name,
                        ID       = taskID,
                        SourceID = task.SourceID,
                        From     = task.Source.ToString().ToUpper(),
                        To       = task.Target.ToString().ToUpper(),
                        Status   = (TaskStatus)task.Status,
                        Type     = TaskType.End
                    };
                    break;
                }
                }

                if (taskInstance.Status == TaskStatus.Waiting)
                {
                    var token = new TaskToken();
                    taskInstance.Token = token;
                    this.Tokens.Add(token);
                }

                this.Tasks.Add(taskID, taskInstance);
            }
            #endregion

            // 连接线
            def.Process.SequenceFlows.ForEach(s =>
            {
                var taskID = generatIds(s.ID);
                var fromID = generatIds(s.SourceRef);
                var toID   = generatIds(s.TargetRef);

                this.Sequences.Add(taskID, new SequenceInstance()
                {
                    Name      = s.ID,
                    ID        = taskID,
                    To        = toID,
                    From      = fromID,
                    Condition = s.Condition
                });
            });

            // 独立网关
            def.Process.ExclusiveGateways.ForEach(g =>
            {
                var gid = generatIds(g.ID);

                this.Gateways.Add(gid, new ExclusiveGatewayInstance()
                {
                    ID      = gid,
                    Froms   = generatIds(g.Incoming),
                    Tos     = generatIds(g.Outgoing),
                    Default = generatIds(g.Default),
                    Type    = GatewayType.Exclusive
                });
            });

            // 并行网关
            def.Process.ParallelGateways.ForEach(g =>
            {
                var gid = generatIds(g.ID);

                this.Gateways.Add(gid, new ParallelGatewayInstance()
                {
                    ID    = gid,
                    Froms = generatIds(g.Incoming),
                    Tos   = generatIds(g.Outgoing),
                    Type  = GatewayType.Parallel,
                    IsJointlySignBegin = g.Type != null && g.Type.Equals("JointlySignBegin"),
                    IsJointlySignEnd   = g.Type != null && g.Type.Equals("JointlySignEnd")
                });
            });
        }