Event


Node Information
This will get all available functions of the connected Type. Connect any object to Object Port, click on the InfoButton to see all the functions.
General Information
• This node has other options, you can view them by clicking on the info button, this also means according to the node you might be able to add more ports than what is already listed.
• Some of the ports of this node can change their types and accept types automatically.
Visual
Visual

Ports
Text Type DataType Accepts IsList CustomAcception
Create IN RUN MULTIPLE FALSE FALSE
Object IN Object ONE FALSE TRUE
Execute OUT RUN MULTIPLE FALSE FALSE

Source
namespace Korduene.KGraph.Nodes.Types
{
    [IsNode("Event")]
    public class GetEvent : Node
    {
        Port create = new Port(PortType.IN, typeof(RUN), AcceptsLinks.MULTIPLE, "Create");
        Port obj = new Port(PortType.IN, typeof(object), AcceptsLinks.ONE, "Object");
        Port run = new Port(PortType.OUT, typeof(RUN), AcceptsLinks.MULTIPLE, "Execute");
        public bool Instance
        {
            set { obj.Value = value.ToString(); }
            get
            {
                bool ret = false;
                bool.TryParse(obj.Value, out ret);
                return ret;
            }
        }
        public GetEvent()
        {
            Name = "Event";
            AddPort(create);
            AddPort(obj);
            AddPort(run);
            Instance = true;
            OptionsAvilable = true;
            obj.OnDisconnected = ObjDisconnected;
            obj.CustomAcception = ObjAcception;
            Information = "This will get all available functions of the connected Type. Connect any object to Object Port, click on the InfoButton to see all the functions.";
        }
        bool ObjAcception(Port port)
        {
            if (string.IsNullOrWhiteSpace(ReferenceName))
            {
                if (port != null && port.DataType != null)
                {
                    ReferenceName = port.ParentNode.ReferenceName;
                    ReturnType = port.DataType;
                    CreateMenu(port.DataType);
                }
            }
            else
            {
                ClearMethod();
            }
            return true;
        }
        private void ObjDisconnected(int portCount)
        {
            ClearMethod();
        }
        private void ClearMethod()
        {
            ReferenceName = string.Empty;
            List<port> prts = new List<port>();
            foreach (var item in Ports)
            {
                if (item.IsExtra)
                {
                    prts.Add(item);
                }
            }
            foreach (var item in prts)
            {
                RemovePort(item, false);
            }
            InfoContextMenu = null;
        }
        private void CreateMenu(Type type)
        {
            InfoContextMenu = GetEventsMenu(type, Instance);
        }
        public override void OnEventSelected(System.Reflection.EventInfo eventInfo)
        {
            string nm = ReferenceName;
            ClearMethod();
            ReferenceName = nm;
            Name = eventInfo.Name;
            foreach (var item in eventInfo.EventHandlerType.GetMethod("Invoke").GetParameters())
            {
                Port port = new Port(PortType.OUT, item.ParameterType, AcceptsLinks.MULTIPLE, item.Name, true);
                AddPort(port);
            }
            CreateMenu(ReturnType);
        }
        public override void UpdateResults()
        {
            string par = string.Empty;
            string setpar = string.Empty;
            Variables.Clear();
            foreach (var port in Ports)
            {
                if (port.IsExtra)
                {
                    par += GraphCore.GetFullTypeName(port.DataType) + " " + port.ID + port.Text + ", ";
                    Variables.Add(new Variable(GraphCore.GetFullTypeName(port.DataType), port.ID, port.DefaultValue()));
                    setpar += port.ID + " = " + port.ID + port.Text + ";\r\n";
                    port.Instructions = port.ID;
                }
            }
            if (par.Length > 2)
            {
                par = par.Remove(par.Length - 2, 2);
            }
            create.Instructions = GetValue(obj) + "." + Name + " += delegate (" + par + ")\r\n{\r\n" + setpar + GetValue(run) + "\r\n};\r\n";
        }
        public override void OnLoad()
        {
            if (ReturnType != null)
            {
                CreateMenu(ReturnType);
            }
        }
    }
}

</port></port>