Example #1
0
        public static IEnumerable <FlowOperation> ParallelOperations(this TargetStateWrapper tsw)
        {
            var parallelOwnerTargetState = tsw.Owner.TargetState();
            var parallelOwnerState       = parallelOwnerTargetState.State;
            var ops       = tsw.Owner.StateOperations();
            var doneOpIds = tsw.TargetFlow.FlowInfo.TargetStates.Where(o => !string.IsNullOrEmpty(o.OperationId)).Select(o => o.OperationId);

            return(ops.Where(o => !doneOpIds.Contains(o.OperationId)));
        }
Example #2
0
        public static string StatusName(this TargetStateWrapper tsw)
        {
            var tstate = tsw.TargetState();

            if (tstate != null)
            {
                return(LocaleHelper.Localizer.Get("StateStatus_" + Enum.GetName(typeof(StateStatus), tstate.StateStatus), "DAF.Workflow"));
            }
            return(string.Empty);
        }
Example #3
0
        public static string Title(this TargetStateWrapper tsw)
        {
            var ts = tsw.TargetState();

            if (ts != null)
            {
                return(ts.Title);
            }
            return(string.Empty);
        }
Example #4
0
 public static TargetState TargetState(this TargetStateWrapper tsw)
 {
     if (tsw.TargetStates == null)
     {
         return(null);
     }
     if (tsw.TargetStates.Count() == 1)
     {
         return(tsw.TargetStates.First());
     }
     return(null);
 }
Example #5
0
        public static IEnumerable <FlowOperation> StateOperations(this TargetStateWrapper tsw)
        {
            var tstate = tsw.TargetState();

            if (tstate == null)
            {
                return(Enumerable.Empty <FlowOperation>());
            }
            var state = tsw.TargetFlow.FlowInfo.BizFlow.FlowStates.First(o => o.StateId == tstate.StateId);
            var opids = tsw.TargetFlow.FlowInfo.BizFlow.StateOperations.Where(o => o.StateId == state.StateId).Select(o => o.OperationId);
            var ops   = tsw.TargetFlow.FlowInfo.BizFlow.FlowOperations.Where(o => opids.Contains(o.OperationId));

            return(ops);
        }
Example #6
0
 public void Build()
 {
     FlowInfo.BuildTargetFlow();
     var bs = FlowInfo.TargetStates.FirstOrDefault(o => o.State.StateType == StateType.Begin);
     if (bs != null)
     {
         BeginState = new TargetStateWrapper(this, bs);
         Stack<TargetStateWrapper> st = new Stack<TargetStateWrapper>();
         st.Push(BeginState);
         while (st.Count > 0)
         {
             var prev = st.Pop();
             // 普通节点、并行开始节点、并行操作节点、并行结束节点等
             if (prev.TargetStates.Count() == 1)
             {
                 var nextTStateIds = FlowInfo.NextTargetStates.Where(o => o.TargetStateId == prev.TargetStates.First().TargetStateId).Select(o => o.NextTargetStateId);
                 var ntstates = FlowInfo.TargetStates.Where(o => nextTStateIds.Contains(o.TargetStateId));
                 var ntsw = new TargetStateWrapper(this, ntstates);
                 if (ntstates.Count() == 1)
                 {
                     var nstate = FlowInfo.BizFlow.FlowStates.First(o => o.StateId == ntstates.First().StateId);
                     switch (nstate.StateType)
                     {
                         case StateType.ParallelBegin:
                             prev.Next = ntsw;
                             ntsw.Previous = prev;
                             break;
                         case StateType.ParallelStop:
                             var prevStateType = prev.TargetState().State.StateType;
                             if (prevStateType == StateType.ParallelBegin)
                             {
                                 var parallel = prev.Next;
                                 if (parallel == null)
                                 {
                                     parallel = new TargetStateWrapper(this, ntstates);
                                     prev.Next = parallel;
                                     parallel.Children = new List<TargetStateWrapper>();
                                     parallel.Owner = prev;
                                     parallel.Previous = prev;
                                     prev.Next = parallel;
                                 }
                                 ntsw.Owner = prev;
                                 parallel.Children.Add(ntsw);
                             }
                             else if (prevStateType == StateType.ParallelStop)
                             {
                                 ntsw.Owner = prev.Owner;
                                 prev.Next = ntsw;
                                 ntsw.Previous = prev;
                             }
                             break;
                         case StateType.ParallelEnd:
                             prev.Owner.Next.Next = ntsw;
                             ntsw.Previous = prev.Owner.Next;
                             break;
                         default:
                             prev.Next = ntsw;
                             ntsw.Previous = prev;
                             break;
                     }
                 }
                 else if (ntstates.Count() > 1)
                 {
                     ntsw.Children = new List<TargetStateWrapper>();
                     ntsw.Owner = prev;
                     ntsw.Previous = prev;
                     prev.Next = ntsw;
                 }
                 st.Push(ntsw);
             }
             else if (prev.TargetStates.Count() > 1) // 并行虚拟节点
             {
                 foreach (var ts in prev.TargetStates)
                 {
                     var ntsw = new TargetStateWrapper(this, ts);
                     ntsw.Owner = prev.Owner;
                     prev.Children.Add(ntsw);
                     st.Push(ntsw);
                 }
             }
         }
     }
 }
Example #7
0
        public void Build()
        {
            FlowInfo.BuildTargetFlow();
            var bs = FlowInfo.TargetStates.FirstOrDefault(o => o.State.StateType == StateType.Begin);

            if (bs != null)
            {
                BeginState = new TargetStateWrapper(this, bs);
                Stack <TargetStateWrapper> st = new Stack <TargetStateWrapper>();
                st.Push(BeginState);
                while (st.Count > 0)
                {
                    var prev = st.Pop();
                    // 普通节点、并行开始节点、并行操作节点、并行结束节点等
                    if (prev.TargetStates.Count() == 1)
                    {
                        var nextTStateIds = FlowInfo.NextTargetStates.Where(o => o.TargetStateId == prev.TargetStates.First().TargetStateId).Select(o => o.NextTargetStateId);
                        var ntstates      = FlowInfo.TargetStates.Where(o => nextTStateIds.Contains(o.TargetStateId));
                        var ntsw          = new TargetStateWrapper(this, ntstates);
                        if (ntstates.Count() == 1)
                        {
                            var nstate = FlowInfo.BizFlow.FlowStates.First(o => o.StateId == ntstates.First().StateId);
                            switch (nstate.StateType)
                            {
                            case StateType.ParallelBegin:
                                prev.Next     = ntsw;
                                ntsw.Previous = prev;
                                break;

                            case StateType.ParallelStop:
                                var prevStateType = prev.TargetState().State.StateType;
                                if (prevStateType == StateType.ParallelBegin)
                                {
                                    var parallel = prev.Next;
                                    if (parallel == null)
                                    {
                                        parallel          = new TargetStateWrapper(this, ntstates);
                                        prev.Next         = parallel;
                                        parallel.Children = new List <TargetStateWrapper>();
                                        parallel.Owner    = prev;
                                        parallel.Previous = prev;
                                        prev.Next         = parallel;
                                    }
                                    ntsw.Owner = prev;
                                    parallel.Children.Add(ntsw);
                                }
                                else if (prevStateType == StateType.ParallelStop)
                                {
                                    ntsw.Owner    = prev.Owner;
                                    prev.Next     = ntsw;
                                    ntsw.Previous = prev;
                                }
                                break;

                            case StateType.ParallelEnd:
                                prev.Owner.Next.Next = ntsw;
                                ntsw.Previous        = prev.Owner.Next;
                                break;

                            default:
                                prev.Next     = ntsw;
                                ntsw.Previous = prev;
                                break;
                            }
                        }
                        else if (ntstates.Count() > 1)
                        {
                            ntsw.Children = new List <TargetStateWrapper>();
                            ntsw.Owner    = prev;
                            ntsw.Previous = prev;
                            prev.Next     = ntsw;
                        }
                        st.Push(ntsw);
                    }
                    else if (prev.TargetStates.Count() > 1) // 并行虚拟节点
                    {
                        foreach (var ts in prev.TargetStates)
                        {
                            var ntsw = new TargetStateWrapper(this, ts);
                            ntsw.Owner = prev.Owner;
                            prev.Children.Add(ntsw);
                            st.Push(ntsw);
                        }
                    }
                }
            }
        }
Example #8
0
 public static bool HasOperations(this TargetStateWrapper tsw)
 {
     return(tsw != null && tsw.Operations != null && tsw.Operations.Count() > 0);
 }
Example #9
0
 public static bool IsInParallel(this TargetStateWrapper tsw)
 {
     return(tsw != null && tsw.Children != null && tsw.Children.Count() > 0);
 }