/// <summary> /// /// </summary> /// <returns></returns> public override ProcessingInfo ActivateLogic(ProcessingContext context_, NodeSlot slot_) { ProcessingInfo info = new ProcessingInfo(); info.State = ActionNode.LogicState.Ok; object intVal = GetValueFromSlot((int)NodeSlotId.Delay); if (intVal == null) { info.State = ActionNode.LogicState.Ok; info.ErrorMessage = "Please connect a integer variable node"; LogManager.Instance.WriteLine(LogVerbosity.Error, "{0} : {1}.", Title, info.ErrorMessage); return(info); } MemoryStackItem memoryItem = context_.CurrentFrame.GetValueFromID(Id); if (memoryItem == null) { memoryItem = context_.CurrentFrame.Allocate(Id, TimeSpan.Zero); } TimeSpan startTime = (TimeSpan)memoryItem.Value; int delay = (int)intVal; double delayDouble = ((double)delay) / 1000.0; TimeSpan t = DateTime.Now.TimeOfDay.Subtract(startTime); double totalSecs = t.TotalSeconds; //this is the first time, so we set the current time if (startTime == TimeSpan.Zero) { totalSecs = 0.0; startTime = DateTime.Now.TimeOfDay; memoryItem.Value = startTime; } else if (totalSecs >= delayDouble) { startTime = TimeSpan.Zero; memoryItem.Value = startTime; ActivateOutputLink(context_, (int)NodeSlotId.Out); CustomText = String.Empty; return(info); } CustomText = string.Format("Delay ({0:0.000} seconds left)", delayDouble - totalSecs); context_.RegisterNextExecution(GetSlotById((int)NodeSlotId.In)); return(info); }
/// <summary> /// Used to activate the nodes in the next step, see Sequence.Run() /// </summary> /// <param name="context_"></param> public void RegisterNodes(ProcessingContext context_) { foreach (NodeSlot slot in ConnectedNodes) { if (slot.Node is ActionNode) { context_.RegisterNextExecution(slot); } } if (Activated != null) { Activated.Invoke(this, EventArgs.Empty); } }
/// <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); }