/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void OnLoopBodyFinished(object sender, EventArgs e) { ProcessingContext context = sender as ProcessingContext; context.Finished -= new EventHandler(OnLoopBodyFinished); MemoryStackItem memoryItem = context.Parent.CurrentFrame.GetValueFromID(Id); ForLoopNodeInfo memoryInfo = (ForLoopNodeInfo)memoryItem.Value; memoryInfo.IsWaitingLoopBody = false; memoryItem.Value = memoryInfo; }
/// <summary> /// /// </summary> /// <returns></returns> public override ProcessingInfo ActivateLogic(ProcessingContext context_, NodeSlot slot_) { ProcessingInfo info = new ProcessingInfo(); info.State = ActionNode.LogicState.Ok; if (slot_.ID == (int)NodeSlotId.In) { int firstIndex = 0, lastIndex = -1; #region first index object objFirstIndex = GetValueFromSlot((int)NodeSlotId.VarInFirstIndex); if (objFirstIndex == null) { info.State = ActionNode.LogicState.Warning; info.ErrorMessage = "Please connect a variable node into the slot First Index"; LogManager.Instance.WriteLine(LogVerbosity.Warning, "{0} : For Loop failed. {1}.", Title, info.ErrorMessage); return(info); } if (objFirstIndex != null) { firstIndex = (int)objFirstIndex; } #endregion // first index #region last index object objLastIndex = GetValueFromSlot((int)NodeSlotId.VarInLastIndex); if (objLastIndex == null) { info.State = ActionNode.LogicState.Warning; info.ErrorMessage = "Please connect a variable node into the slot Last Index"; LogManager.Instance.WriteLine(LogVerbosity.Warning, "{0} : For Loop failed. {1}.", Title, info.ErrorMessage); return(info); } if (objLastIndex != null) { lastIndex = (int)objLastIndex; } #endregion last index MemoryStackItem memoryItem = context_.CurrentFrame.GetValueFromID(Id); if (memoryItem == null) { memoryItem = context_.CurrentFrame.Allocate(Id, new ForLoopNodeInfo { Counter = firstIndex, IsWaitingLoopBody = false }); } ForLoopNodeInfo memoryInfo = (ForLoopNodeInfo)memoryItem.Value; if (memoryInfo.IsWaitingLoopBody == false) { SetValueInSlot((int)NodeSlotId.VarOutIndex, memoryInfo.Counter); if (memoryInfo.Counter <= lastIndex) { memoryInfo.IsWaitingLoopBody = true; memoryInfo.Counter++; // register again this node in order to active itself // after the sequence activated by the loop body slot // is finished memoryInfo.Step = context_.RegisterNextExecution(GetSlotById((int)NodeSlotId.In)); memoryItem.Value = memoryInfo; ProcessingContext newContext = context_.PushNewContext(); newContext.Finished += new EventHandler(OnLoopBodyFinished); ActivateOutputLink(newContext, (int)NodeSlotId.OutLoop); } else { context_.CurrentFrame.Deallocate(Id); ActivateOutputLink(context_, (int)NodeSlotId.OutCompleted); } } } else if (slot_.ID == (int)NodeSlotId.InBreak) { MemoryStackItem memoryItem = context_.CurrentFrame.GetValueFromID(Id); ForLoopNodeInfo memoryInfo = (ForLoopNodeInfo)memoryItem.Value; context_.RemoveExecution(context_, memoryInfo.Step); context_.CurrentFrame.Deallocate(Id); ActivateOutputLink(context_, (int)NodeSlotId.OutCompleted); } return(info); }