MyNodes.Nodes.NodesEngine.AddLink C# (CSharp) Method

AddLink() public method

public AddLink ( MyNodes.Nodes.Output output, MyNodes.Nodes.Input input, bool writeInDb = true ) : MyNodes.Nodes.Link
output MyNodes.Nodes.Output
input MyNodes.Nodes.Input
writeInDb bool
return MyNodes.Nodes.Link
        public Link AddLink(Output output, Input input, bool writeInDb = true)
        {
            Node inputNode = GetInputOwner(input);
            Node outputNode = GetOutputOwner(output);

            if (inputNode == null || outputNode == null)
            {
                LogEngineError($"Can`t create link from [{output.Id}] to [{input.Id}]. Does not exist.");
                return null;
            }

            if (inputNode == outputNode)
            {
                LogEngineError($"Can`t create link from [{output.Id}] to [{input.Id}]. Input and output belong to the same node.");
                return null;
            }

            if (inputNode.PanelId != outputNode.PanelId)
            {
                LogEngineError($"Can`t create link from {outputNode.GetType().Name} to {inputNode.GetType().Name}. Nodes are on different panels.");
                return null;
            }


            Link link = new Link(output.Id, input.Id, inputNode.PanelId);

            //prevent two links to one input
            Link oldLink = GetLinkForInput(input);
            if (oldLink != null)
                RemoveLink(oldLink, true);

            LogEngineInfo($"New link from [{outputNode.GetType().Name}] to [{inputNode.GetType().Name}]");

            lock (linksLock)
                links.Add(link);


            if (writeInDb)
                nodesDb?.AddLink(link);

            OnNewLink?.Invoke(link);

            if (started)
                input.Value = output.Value;

            return link;
        }

Same methods

NodesEngine::AddLink ( string outputId, string inputId, bool writeInDb = true ) : MyNodes.Nodes.Link