Timer


Node Information
Creates a Timer each 'Tick' event will be fired on each tick.
General Information
• This node doesn't have other available options.
Visual
Visual

Ports
Text Type DataType Accepts IsList CustomAcception
Start IN RUN MULTIPLE FALSE FALSE
Stop IN RUN MULTIPLE FALSE FALSE
Tick OUT RUN MULTIPLE FALSE FALSE
Interval IN Int32 ONE FALSE FALSE

Source
namespace Korduene.KGraph.Nodes.Objects
{
    [IsNode("Timer")]
    public class ObjectTimer : Node
    {
        Port start = new Port(PortType.IN, typeof(RUN), AcceptsLinks.MULTIPLE,  "Start");
        Port stop = new Port(PortType.IN, typeof(RUN), AcceptsLinks.MULTIPLE,  "Stop");
        Port runTick = new Port(PortType.OUT, typeof(RUN), AcceptsLinks.MULTIPLE, "Tick");
        Port interval = new Port(PortType.IN, typeof(int), AcceptsLinks.ONE, "Interval");
        Variable Var1 = new Variable("bool", "", "false");
        public ObjectTimer()
        {
            this.NodeType = KGraph.NodeType.Method;
            this.Name = "Timer";
            interval.Value = "1000";
            AddPort(start);
            AddPort(stop);
            AddPort(runTick);
            AddPort(interval);
            Var1.Name = stop.ID;
            Variables.Add(Var1);
            Information = "Creates a Timer each 'Tick' event will be fired on each tick.";
        }
        public override string Code()
        {
            Var1.Name = stop.ID;
            stop.Instructions = stop.ID + "=true;";
            return "System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();\r\n" +
            "timer.Interval = " + GetValue(interval) + ";\r\n" +
             stop.ID + "= false;\r\n" + 
            "timer.Start();\r\n" + 
            "timer.Tick += delegate(object sender, EventArgs e){\r\n" + 
            "if (" + stop.ID + "){ timer.Stop();} else{\r\n" + GetValue(runTick) + "}\r\n};";
        }
    }
}