public static string SerializeNode(Node node) { JsonSerializerSettings settings = new JsonSerializerSettings(); settings.TypeNameHandling = TypeNameHandling.All; return JsonConvert.SerializeObject(node, settings); }
private void OnNodeUpdatedOnDashboard(Node node) { if (node is UiNode) OnUiNodeUpdated?.Invoke((UiNode)node); if (node is PanelNode) OnPanelNodeUpdated?.Invoke(node); }
private void OnNewNode(Node node) { if (!(node is UiNode)) return; UiNode n = (UiNode)node; n.OnAddToUiEngine(this); if (string.IsNullOrEmpty(n.Settings["Name"].Value)) n.Settings["Name"].Value = GenerateName(n); OnNewUiNode?.Invoke(n); engine.UpdateNodeInEditor(n); //engine.UpdateNodeOnDashboard(n); engine.UpdateNodeInDb(n); }
private void WriteUpdatedNodes() { Node[] nodes = new Node[updatedNodes.Count]; updatedNodes.CopyTo(nodes); updatedNodes.Clear(); List<SerializedNode> serializedNodes = nodes .Select(node => new SerializedNode(node)).ToList(); using (var db = new SqlConnection(connectionString)) { db.Open(); var sqlQuery = "UPDATE Nodes SET " + "JsonData = @JsonData " + "WHERE Id = @Id"; db.Execute(sqlQuery, serializedNodes); } }
private void WriteUpdatedNodes() { Node[] nodes = new Node[updatedNodes.Count]; updatedNodes.CopyTo(nodes); updatedNodes.Clear(); List<SerializedNode> serializedNodes = new List<SerializedNode>(); foreach (var node in nodes) { SerializedNode oldNode = db.SerializedNodes.FirstOrDefault(x => x.Id == node.Id); if (oldNode == null) continue; SerializedNode newNode = new SerializedNode(node); oldNode.JsonData = newNode.JsonData; serializedNodes.Add(oldNode); } db.SerializedNodes.UpdateRange(serializedNodes); db.SaveChanges(); }
private static void OnPanelNodeUpdated(Node node) { NodeEditorAPIController nodeEditorApi = new NodeEditorAPIController(); LiteGraph.Node liteGraphNode = nodeEditorApi.ConvertNodeToLiteGraphNode(node); hub.Clients.All.OnPanelNodeUpdated(liteGraphNode); }
public SerializedNode(Node node) { Id = node.Id; JsonData = NodesEngineSerializer.SerializeNode(node); }
public void ShowNodeActivity(Node node) { if (activityList.Contains(node)) return; activityList.Add(node); OnNodeActivity?.Invoke(node); }
public void GenerateNewIds(Node node) { //generate id`s for inputs foreach (var input in node.Inputs) input.Id = Guid.NewGuid().ToString(); //generate id`s for outputs foreach (var output in node.Outputs) output.Id = Guid.NewGuid().ToString(); node.Id = Guid.NewGuid().ToString(); }
public void UpdateNode(Node node) { if (writeInterval != 0) { if (!updatedNodes.Contains(node)) updatedNodes.Add(node); return; } SerializedNode oldNode = db.SerializedNodes.FirstOrDefault(x => x.Id == node.Id); if (oldNode == null) return; SerializedNode newNode = new SerializedNode(node); oldNode.JsonData = newNode.JsonData; db.SerializedNodes.Update(oldNode); db.SaveChanges(); }
public void UpdateNode(Node node) { if (writeInterval != 0) { if (!updatedNodes.Contains(node)) updatedNodes.Add(node); return; } using (var db = new SqlConnection(connectionString)) { db.Open(); var sqlQuery = "UPDATE Nodes SET " + "JsonData = @JsonData " + "WHERE Id = @Id"; SerializedNode serializedNode = new SerializedNode(node); db.Execute(sqlQuery, serializedNode); } }
public void UpdateNodeOnDashboard(Node node) { OnNodeUpdatedOnDashboard?.Invoke(node); }
public void RemoveNode(Node node) { lock (nodesLock) if (!nodes.Contains(node)) { LogEngineError($"Can`t remove node [{node.GetType().Name}]. Node [{node.Id}] does not exist."); return; } List<Node> nodesToRemove = new List<Node>(); nodesToRemove.Add(node); List<Link> linksToRemove = new List<Link>(); List<Link> links = GetLinksForNode(node); linksToRemove.AddRange(links); foreach (var link in links) { RemoveLink(link, false); } node.OnRemove(); if (node is PanelNode) { var nodesOnPanel = GetNodesForPanel(node.Id, true); nodesToRemove.AddRange(nodesOnPanel); foreach (var n in nodesOnPanel) { List<Link> li = GetLinksForNode(n); linksToRemove.AddRange(li); foreach (var link in li) { RemoveLink(link, false); } LogEngineInfo($"Remove node [{n.GetType().Name}]"); OnRemoveNode?.Invoke(n); lock (nodesLock) nodes.Remove(n); } } lock (nodesLock) nodes.Remove(node); nodesDb?.RemoveNodes(nodesToRemove); nodesDb?.RemoveLinks(linksToRemove); LogEngineInfo($"Remove node [{node.GetType().Name}]"); OnRemoveNode?.Invoke(node); }
public bool AddNode(Node node, bool writeInDb = true) { if (node.PanelId != MAIN_PANEL_ID && GetPanelNode(node.PanelId) == null) { LogEngineError($"Can`t create node [{node.GetType().Name}]. Panel [{node.PanelId}] does not exist."); return false; } bool checkNodeCanBeAdded = node.OnAddToEngine(this); if (!checkNodeCanBeAdded) { LogEngineError($"Can`t create node [{node.GetType().Name}]. Aborted by node."); return false; } lock (nodesLock) nodes.Add(node); if (writeInDb) nodesDb?.AddNode(node); LogEngineInfo($"New node [{node.GetType().Name}]"); OnNewNode?.Invoke(node); return true; }
private static void OnNewNode(Node node) { NodeEditorAPIController nodeEditorApi = new NodeEditorAPIController(); LiteGraph.Node liteGraphNode = nodeEditorApi.ConvertNodeToLiteGraphNode(node); hub.Clients.Group(node.PanelId).OnNewNode(liteGraphNode); }
private static void OnNodeActivity(Node node) { hub.Clients.Group(node.PanelId).OnNodeActivity(node.Id); }
private void OnRemoveNode(Node node) { if (node is UiNode) OnRemoveUiNode?.Invoke((UiNode)node); }
public void UpdateNodeInEditor(Node node) { OnNodeUpdatedInEditor?.Invoke(node); }
public void AddNode(Node node) { using (var db = new SqlConnection(connectionString)) { db.Open(); var sqlQuery = "INSERT INTO Nodes (Id, JsonData) " + "VALUES(@Id, @JsonData)"; SerializedNode serializedNode = new SerializedNode(node); db.Execute(sqlQuery, serializedNode); } }
public void UpdateNodeInDb(Node node) { Node oldNode = GetNode(node.Id); if (oldNode == null) { LogEngineError($"Can`t update node [{node.GetType().Name}]. Node [{node.Id}] does not exist."); return; } // LogEngineInfo($"Update node in DB [{node.GetType().Name}]"); nodesDb?.UpdateNode(node); }
public List<Link> GetLinksForNode(Node node) { List<Link> list = new List<Link>(); foreach (var input in node.Inputs) { Link link = GetLinkForInput(input); if (link != null) list.Add(link); } foreach (var output in node.Outputs) { List<Link> links = GetLinksForOutput(output); if (links != null) list.AddRange(links); } return list; }
public void AddNode(Node node) { SerializedNode serializedNode = new SerializedNode(node); db.SerializedNodes.Add(serializedNode); db.SaveChanges(); }