public void AddOutputNode(PanelOutputNode node) { if (Outputs.Any(x => x.Id == node.Id)) return; var output = new Output { Id = node.Id, Name = GenerateOutputName() }; node.Settings["Name"].Value = output.Name; AddOutput(output); UpdateMeInEditor(); UpdateMeInDb(); }
public Node GetOutputOwner(Output output) { lock (nodesLock) return nodes.FirstOrDefault(node => node.Outputs.Contains(output)); }
public Link GetLink(Output output, Input input) { lock (linksLock) return links.FirstOrDefault(x => x.InputId == input.Id && x.OutputId == output.Id); }
public List<Link> GetLinksForOutput(Output output) { lock (linksLock) return links.Where(x => x.OutputId == output.Id).ToList(); }
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; }
public void RemoveLink(Output output, Input input, bool writeInDb) { Link link = GetLink(output, input); if (link == null) { LogEngineError($"Can`t remove link from [{output.Id}] to [{input.Id}]. Does not exist."); return; } lock (linksLock) links.Remove(link); if (writeInDb) nodesDb?.RemoveLink(link.Id); Node inputNode = GetInputOwner(input); Node outputNode = GetOutputOwner(output); if (inputNode != null && outputNode != null) LogEngineInfo($"Remove link from [{outputNode.GetType().Name}] to [{inputNode.GetType().Name}]"); else LogEngineInfo($"Remove link."); input.Value = null; OnRemoveLink?.Invoke(link); }
public void OnOutputChange(Output output) { if (!started) return; Node node = GetOutputOwner(output); if (node == null) return; ShowNodeActivity(node); OnOutputStateUpdated?.Invoke(output); node.OnOutputChange(output); }
public void UpdateBattery(int? batteryLevel) { Output output = Outputs.FirstOrDefault(x => x.Name == "Battery"); if (output == null) { output = new Output { Name = "Battery" }; output.SlotIndex = Int32.MaxValue; AddOutput(output); UpdateMeInEditor(); } output.Value = batteryLevel.ToString(); UpdateMeInDb(); }
public virtual void OnOutputChange(Output output) { if (options.LogOutputChanges) LogInfo($"{output.Name}: [{output.Value ?? "NULL"}]"); //send state to linked nodes List<Link> list = engine?.GetLinksForOutput(output); foreach (var link in list) { Input input = engine?.GetInput(link.InputId); if (input != null) { input.Value = output.Value; } } }
public void RemoveOutput(Output output) { if (output == null || !Outputs.Contains(output)) { LogError("Can`t remove output. Does not exist."); return; } var links = engine.GetLinksForOutput(output); engine.RemoveLinks(links,true); Outputs.Remove(output); }
public void AddOutput(Output output) { Outputs.Add(output); if (engine != null) output.OnOutputChange += engine.OnOutputChange; }