예제 #1
0
        private static void MoveCasesAndDelete(IWorkflowNodeEntity node, Locator?locator)
        {
            if (node.CaseActivities().Any())
            {
                if (locator !.HasReplacement(node.ToLite()))
                {
                    var replacement = locator.GetReplacement(node.ToLite()) !;

                    node.CaseActivities()
                    .Where(a => a.State == CaseActivityState.Done)
                    .UnsafeUpdate()
                    .Set(ca => ca.WorkflowActivity, ca => replacement)
                    .Execute();

                    var running = node.CaseActivities().Where(a => a.State == CaseActivityState.Pending).ToList();

                    running.ForEach(a =>
                    {
                        a.Notifications().UnsafeDelete();
                        a.WorkflowActivity = replacement;
                        a.Save();
                        CaseActivityLogic.InsertCaseActivityNotifications(a);
                    });
                }
                else
                {
                    DeleteCaseActivities(node, a => true);
                }
            }
예제 #2
0
        private static void DeleteCaseActivities(IWorkflowNodeEntity node, Expression <Func <CaseEntity, bool> > filter)
        {
            if (node is WorkflowActivityEntity wa && (wa.Type == WorkflowActivityType.DecompositionWorkflow || wa.Type == WorkflowActivityType.CallWorkflow))
            {
                var sw = wa.SubWorkflow !.Workflow;
                var wb = new WorkflowBuilder(sw);
                wb.DeleteCases(c => filter.Evaluate(c.ParentCase !.Entity) && c.ParentCase.Entity !.Workflow.Is(wa.Lane.Pool.Workflow));
            }

            var caseActivities = node.CaseActivities().Where(ca => filter.Evaluate(ca.Case));

            if (caseActivities.Any())
            {
                caseActivities.SelectMany(a => a.Notifications()).UnsafeDelete();

                Database.Query <CaseActivityEntity>()
                .Where(ca => ca.Previous !.Entity.WorkflowActivity.Is(node) && filter.Evaluate(ca.Previous.Entity.Case))
                .UnsafeUpdate()
                .Set(ca => ca.Previous, ca => ca.Previous !.Entity.Previous)
                .Execute();

                var running = caseActivities.Where(a => a.State == CaseActivityState.Pending).ToList();

                running.ForEach(a => {
                    if (a.Previous == null)
                    {
                        throw new ApplicationException(CaseActivityMessage.ImpossibleToDeleteCaseActivity0OnWorkflowActivity1BecauseHasNoPreviousActivity.NiceToString(a.Id, a.WorkflowActivity));
                    }

                    a.Previous.ExecuteLite(CaseActivityOperation.Undo);
                });

                caseActivities.UnsafeDelete();
            }
        }