private void CompleteNormalActivity(Queue <WorkflowMessage> queue, SysProcess process, SysActivity activity)
        {
            if (activity.ExecType == 0)
            {
                new ActivityRemindHandler(base.PICacheFactory, base.PI, this.AI, ActivityRemindUseTimeType.ActivityEnd, null, null).Execute();
            }
            List <SysTransition> trans = process.Transitions.Where <SysTransition>(delegate(SysTransition t) {
                long?preActivityId = t.PreActivityId;
                long activityId    = activity.ActivityId;
                return((preActivityId.GetValueOrDefault() == activityId) && preActivityId.HasValue);
            }).ToList <SysTransition>();

            if (trans.Count <= 0)
            {
                throw new ApplicationException("没有后续的转换条件");
            }
            SysTransition nextTransition = this.GetNextTransition(trans);

            if (nextTransition == null)
            {
                throw new ApplicationException("所有后续连接线均不满足条件,流程无法继续");
            }
            SysActivityInstance ai   = this.CreatePostAcitivtyInstance(base.PI, nextTransition);
            WorkflowMessage     item = base.Engine.NewActivityInstanceCreatedMessage(ai);

            queue.Enqueue(item);
        }
        public override void Execute(Queue <WorkflowMessage> queue)
        {
            if (!this.CurrentWorkItem.Status.HasValue)
            {
                this.CurrentWorkItem.Status = 0;
            }
            if (this.CurrentWorkItem.Status == 1)
            {
                throw new ApplicationException("工作项已经完成,不可重复完成");
            }
            if ((this.CurrentWorkItem.Status != 0) && (this.CurrentWorkItem.Status != 0x63))
            {
                throw new ApplicationException("该工作项已被取消");
            }
            this.CurrentWorkItem.Status  = 1;
            this.CurrentWorkItem.EndTime = new DateTime?(DateTime.Now);
            base.PICacheFactory.UpdateWorkItem(this.CurrentWorkItem, base.PI, this.AI);
            foreach (SysWorkItem item in this.AI.WorkItems.ToList <SysWorkItem>())
            {
                if (!item.Status.HasValue)
                {
                    item.Status = 0;
                }
                if ((item.Status.Value == 0) && (item.WorkItemId != this.CurrentWorkItem.WorkItemId))
                {
                    item.Status  = 3;
                    item.EndTime = new DateTime?(DateTime.Now);
                    base.PICacheFactory.UpdateWorkItem(item, base.PI, this.AI);
                }
            }
            WorkflowMessage message = base.Engine.NewCompleteActivityMessage(this.AI);

            queue.Enqueue(message);
        }
        private void InternalExecuteForApprove(Queue <WorkflowMessage> queue)
        {
            bool flag;

            this.CheckStatus();
            this.JustCompleteCurrentWorkItem();
            this.CompleteMutexWorkItems(base.CurrentWorkItem);
            base.CurrentWorkItem.AssertHasGroup();
            SysWorkItemApproveGroup currentWorkItemGroup = this.GetCurrentWorkItemGroup();

            if (this.TryCompleteGroup(currentWorkItemGroup, out flag))
            {
                bool flag3;
                this.CancelUncompletedWorkItems(currentWorkItemGroup);
                currentWorkItemGroup.ApproveResult = new int?(ConvertBoolToApproveResult(flag));
                currentWorkItemGroup.ApproveTime   = new DateTime?(DateTime.Now);
                base.PICacheFactory.UpdateWorkItemGroup(currentWorkItemGroup);
                SysActivityInstance activityInstance = base.CurrentWorkItem.ActivityInstance;
                if (this.TryCompleteActivity(activityInstance, out flag3))
                {
                    this.CancelUncompletedWorkItems(activityInstance);
                    activityInstance.ApproveResult   = new int?(ConvertBoolToApproveResult(flag3));
                    activityInstance.ExpressionValue = activityInstance.ApproveResult;
                    WorkflowMessage item = base.Engine.NewCompleteActivityMessage(base.AI);
                    queue.Enqueue(item);
                }
            }
        }
예제 #4
0
        public override void Execute(Queue <WorkflowMessage> queue)
        {
            base.JustCompleteCurrentAI();
            SysActivity         postActivity = base.PI.Process.Activities.FirstOrDefault <SysActivity>(p => p.ActivityId == this._nextActivityId);
            SysActivityInstance ai           = base.CreatePostActivityInstance(base.PI, postActivity);
            WorkflowMessage     item         = base.Engine.NewActivityInstanceCreatedMessage(ai);

            queue.Enqueue(item);
        }
        public override void Execute(Queue <WorkflowMessage> queue)
        {
            base.CheckStatus();
            base.JustCompleteCurrentWorkItem();
            SysWorkItemApproveGroup approveGroup = base.CurrentWorkItem.ApproveGroup;

            approveGroup.ApproveResult = 0;
            base.PICacheFactory.UpdateWorkItemGroup(approveGroup);
            base.CancelUncompletedWorkItems(approveGroup);
            base.AI.ApproveResult = 0;
            base.PICacheFactory.UpdateActiviyInstance(base.AI);
            base.CancelUncompletedWorkItems(base.AI);
            WorkflowMessage item = base.Engine.NewCompleteActivityWithNextActivityMessage(base.AI, this._nextActivityId);

            queue.Enqueue(item);
        }
        public override void Execute(Queue <WorkflowMessage> queue)
        {
            SysActivity activity = this.AI.Activity;
            SysProcess  process  = activity.Process;

            if (((activity.ActivityType == 3) || (activity.ActivityType == 1)) || (activity.ActivityType == 6))
            {
                if (activity.ExecType == 0)
                {
                    new ActivityRemindHandler(base.PICacheFactory, base.PI, this.AI, ActivityRemindUseTimeType.ActivityStart, null, null).Execute();
                    this.ExecuteForManual(activity, process, queue);
                }
                else
                {
                    if (activity.ExecType != 1)
                    {
                        throw new ApplicationException("未知的活动执行类型");
                    }
                    base.Manager.ExecutePython(base.PI, activity.JScriptText);
                    this.ExecuteForAuto(activity, process);
                    WorkflowMessage item = base.Engine.NewCompleteActivityMessage(this.AI);
                    queue.Enqueue(item);
                }
            }
            else if (activity.ActivityType == 2)
            {
                this.CopyActivityInstanceData();
                this.CalDecisionValue();
                WorkflowMessage message2 = base.Engine.NewCompleteActivityMessage(this.AI);
                queue.Enqueue(message2);
            }
            else
            {
                if (activity.ActivityType != 4)
                {
                    throw new ApplicationException("未知活动类型");
                }
                base.Manager.ExecutePython(base.PI, activity.JScriptText);
                this.ExecuteForAuto(activity, process);
                WorkflowMessage message3 = base.Engine.NewCompleteActivityMessage(this.AI);
                queue.Enqueue(message3);
            }
        }
예제 #7
0
        public override void Execute(Queue <WorkflowMessage> queue)
        {
            SysProcess process = base.PI.Process;

            if ((process.Activities == null) || (process.Activities.Count == 0))
            {
                throw new ApplicationException("没有任何活动");
            }
            SysActivity act = process.Activities.FirstOrDefault <SysActivity>(a => a.ActivityType == 1);

            if (act == null)
            {
                throw new ApplicationException("没有开始活动");
            }
            SysActivityInstance ai = this.CreateActivityInstance(base.PI, act);

            new ProcessRemindHandler(base.PICacheFactory, base.PI, ai, ProcessRemindUseTimeType.ProcessStart).Execute();
            WorkflowMessage item = base.Engine.NewActivityInstanceCreatedMessage(ai);

            queue.Enqueue(item);
        }
        private void CompleteApproveActivity(Queue <WorkflowMessage> queue, SysProcess process, SysActivity activity)
        {
            new ActivityRemindHandler(base.PICacheFactory, base.PI, this.AI, ActivityRemindUseTimeType.ActivityEnd, null, this.AI.ApproveResult).Execute();
            List <SysTransition> source = process.Transitions.Where <SysTransition>(delegate(SysTransition t) {
                long?preActivityId = t.PreActivityId;
                long activityId    = activity.ActivityId;
                return((preActivityId.GetValueOrDefault() == activityId) && preActivityId.HasValue);
            }).ToList <SysTransition>();

            if (source.Count < 1)
            {
                throw new ApplicationException("没有后续的转换条件");
            }
            SysTransition tran = null;

            if (this.AI.ExpressionValue.HasValue)
            {
                int direction = Convert.ToBoolean(this.AI.ExpressionValue.Value) ? 1 : 2;
                tran = source.FirstOrDefault <SysTransition>(delegate(SysTransition p) {
                    int?nullable1 = p.Direction;
                    int num       = direction;
                    return((nullable1.GetValueOrDefault() == num) && nullable1.HasValue);
                });
            }
            if (tran == null)
            {
                tran = this.GetNextTransition(source);
            }
            if (tran == null)
            {
                throw new ApplicationException("所有后续连接线均不满足条件,流程无法继续");
            }
            SysActivityInstance ai   = this.CreatePostAcitivtyInstance(base.PI, tran);
            WorkflowMessage     item = base.Engine.NewActivityInstanceCreatedMessage(ai);

            queue.Enqueue(item);
        }
        private void CompleteDecisionActivity(Queue <WorkflowMessage> queue, SysProcess process, SysActivity activity)
        {
            List <SysTransition> source = process.Transitions.Where <SysTransition>(delegate(SysTransition t) {
                long?preActivityId = t.PreActivityId;
                long activityId    = activity.ActivityId;
                return((preActivityId.GetValueOrDefault() == activityId) && preActivityId.HasValue);
            }).ToList <SysTransition>();

            if (source.Count < 1)
            {
                throw new ApplicationException("没有后续的转换条件");
            }
            if (!this.AI.ExpressionValue.HasValue)
            {
                throw new ApplicationException("未计算决策活动的值");
            }
            int           direction = Convert.ToBoolean(this.AI.ExpressionValue.Value) ? 1 : 2;
            SysTransition tran      = source.FirstOrDefault <SysTransition>(delegate(SysTransition p) {
                int?nullable1 = p.Direction;
                int num       = direction;
                return((nullable1.GetValueOrDefault() == num) && nullable1.HasValue);
            });

            if (tran == null)
            {
                throw new ApplicationException(string.Format("没有方向为{0}的后续活动", direction));
            }
            if (!tran.PostActivityId.HasValue)
            {
                throw new ApplicationException("后续活动为空");
            }
            SysActivityInstance ai   = this.CreatePostAcitivtyInstance(base.PI, tran);
            WorkflowMessage     item = base.Engine.NewActivityInstanceCreatedMessage(ai);

            queue.Enqueue(item);
        }
        private void ExecuteForManual(SysActivity activity, SysProcess process, Queue <WorkflowMessage> queue)
        {
            if ((activity.ActivityParticipants == null) || (activity.ActivityParticipants.Count == 0))
            {
                throw new ApplicationException("未指定参与人");
            }
            Dictionary <SysWorkItemApproveGroup, List <IUser> > dictionary = new Dictionary <SysWorkItemApproveGroup, List <IUser> >(20);
            List <IUser> list = new List <IUser>();

            if (this.AI.UserDefinedApproveUsers.Count > 0)
            {
                SysWorkItemApproveGroup key = this.CreateWorkItemGroup();
                IOrgProxy    orgProxy       = OrgProxyFactory.GetProxy(base.Context);
                List <IUser> users          = (from p in this.AI.UserDefinedApproveUsers select orgProxy.GetUserById(p.UserId.Value)).ToList <IUser>();
                this.RemoveRepeatedUsers(users);
                list.AddRange(users);
                dictionary.Add(key, users);
            }
            else
            {
                using (IEnumerator <SysActivityParticipant> enumerator = activity.ActivityParticipants.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        Func <SysProcessParticipant, bool> predicate     = null;
                        SysActivityParticipant             activity_part = enumerator.Current;
                        SysWorkItemApproveGroup            group         = this.CreateWorkItemGroup(activity_part);
                        if (predicate == null)
                        {
                            predicate = p => p.ParticipantId == activity_part.ParticipantId.Value;
                        }
                        SysProcessParticipant part = process.ProcessParticipants.FirstOrDefault <SysProcessParticipant>(predicate);
                        if (part == null)
                        {
                            throw new ApplicationException("参与人为空");
                        }
                        int?         wiOwnerId   = null;
                        var          users       = ParticipantHelper.GetUsers(base.Context, part, base.PI, this.AI, wiOwnerId);
                        List <IUser> targetUsers = users;
                        this.AssertGroupHasUsers(activity_part, group, targetUsers);
                        this.RemoveRepeatedUsers(targetUsers);
                        list.AddRange(targetUsers);
                        dictionary.Add(group, targetUsers);
                    }
                }
            }
            if (list.Count == 0)
            {
                bool?isPassedWithNoParticipants = this.AI.Activity.IsPassedWithNoParticipants;
                if (!(isPassedWithNoParticipants.HasValue ? isPassedWithNoParticipants.GetValueOrDefault() : false))
                {
                    throw new ApplicationException("未计算出任何参与人");
                }
                SysActivityInstance aI = this.AI;
                aI.InstanceStatus  = 10;
                aI.EndTime         = new DateTime?(DateTime.Now);
                aI.ApproveResult   = 1;
                aI.ExpressionValue = 1;
                aI.Remark          = "无人审核,自动通过";
                base.PICacheFactory.UpdateActiviyInstance(this.AI);
                WorkflowMessage item = base.Engine.NewCompleteActivityMessage(this.AI);
                queue.Enqueue(item);
            }
            else
            {
                SysActivity activity3 = this.AI.Activity;
                if (!activity3.PassType.HasValue)
                {
                    activity3.PassType = 1;
                    if (!activity3.MinPassNum.HasValue)
                    {
                        activity3.MinPassNum = 1;
                    }
                }
                foreach (KeyValuePair <SysWorkItemApproveGroup, List <IUser> > pair in dictionary)
                {
                    SysWorkItemApproveGroup group3 = pair.Key;
                    foreach (IUser user in pair.Value)
                    {
                        this.CreateWorkItem(user, group3);
                    }
                }
            }
            if (this.AI.UserDefinedApproveUsers.Count > 0)
            {
                base.PICacheFactory.ClearApproveUsers(this.AI);
            }
        }