示例#1
0
 internal void SetCurrentNode(PowerThreadNode toNode)
 {
     //  if (IsContained(toNode))
     {
         CurrentNode = toNode;
     }
 }
示例#2
0
 public Transmission(PowerThreadNode from, PowerThreadNode to)
 {
     this.FromNode     = from;
     ConditionBranches = new List <TransmissionConditionBranch>()
     {
         new TransmissionConditionBranch {
             Condition = TransmissionCondition.Default, ToNode = to
         }
     };
 }
示例#3
0
        private PowerThreadNode GetNextNode(PowerThreadContext context, PowerThreadNode fromNode)
        {
            var transmission = Transmissions.FirstOrDefault(p => p.FromNode.ObjectId == fromNode.ObjectId);

            if (transmission == null)
            {
                return(PowerThreadDefaultNodes.DefaultEndNode);
            }

            foreach (var item in transmission.ConditionBranches)
            {
                if (item.Condition.IsSatisified(context))
                {
                    return(item.ToNode);
                }
            }

            //
            return(PowerThreadDefaultNodes.MissFoundNode);
        }
示例#4
0
        public void Next(PowerThreadContext context, PowerThreadNode fromNode)
        {
            if (context.IsCurrentNode(fromNode) == false)
            {
                throw new InvalidThreadActionException("Not actived thread node!");
            }

            if (fromNode.Equals(PowerThreadDefaultNodes.DefaultEndNode))
            {
                throw new InvalidTransmissionSinceThreadAlreadyEnd();
            }

            var toNode = GetNextNode(context, fromNode);

            if (toNode != null)
            {
                context.PowerThread.SetCurrentNode(toNode);
                if (!IsEndNode(toNode))
                {
                    toNode.LoadNode();
                }

                if (toNode.IsEnd)
                {
                    context.PowerThread.SetState(PowerThreadState.End);
                }
                else if (IsUnfound(toNode))
                {
                    context.PowerThread.SetState(PowerThreadState.ErrorMissFoundNode);
                }
                else
                {
                    context.PowerThread.SetState(PowerThreadState.Processing);
                }
            }
            else
            {
                // 如果找不到下一个节点, 也认为其结束。
                context.PowerThread.SetState(PowerThreadState.End);
            }
        }
示例#5
0
        private bool IsContained(PowerThreadNode node)
        {
            bool result = this.Nodes.Any(p => p.ObjectId == node.ObjectId);

            return(result);
        }
示例#6
0
 public void TerminateThreadAtNode(PowerThreadNode fromNode)
 {
     StateMachine.TerminateThread(Context, fromNode);
 }
示例#7
0
 public void GoNextNode(PowerThreadNode fromNode)
 {
     // todo
     StateMachine.Next(Context, fromNode);
 }
示例#8
0
 public void TerminateThread(PowerThreadContext context, PowerThreadNode fromNode)
 {
     context.PowerThread.SetState(PowerThreadState.Terminated);
 }
示例#9
0
 private bool IsUnfound(PowerThreadNode toNode)
 {
     return(toNode.Name == "[UnfoundNode]");
 }
示例#10
0
 private bool IsEndNode(PowerThreadNode toNode)
 {
     return(toNode.Equals(PowerThreadDefaultNodes.DefaultEndNode));
 }
示例#11
0
 internal bool IsCurrentNode(PowerThreadNode fromNode)
 {
     return(fromNode.ObjectId == PowerThread.CurrentNode.ObjectId);
 }