private async Task ConnectNodes() { var schema = new GraphSchema(); var connections = RandomNodesGenerator.GenerateConnections(GraphViewModel.Nodes); if (Settings.AsyncLoading) { await Task.Run(() => { for (int i = 0; i < connections.Count; i++) { var con = connections[i]; schema.TryAddConnection(con.Input, con.Output); } }); } else { for (int i = 0; i < connections.Count; i++) { var con = connections[i]; schema.TryAddConnection(con.Input, con.Output); } } }
public NodifyEditorViewModel() { DeleteSelectionCommand = new DelegateCommand(DeleteSelection, () => SelectedNodes.Count > 0); CommentSelectionCommand = new DelegateCommand(() => Schema.AddCommentAroundNodes(SelectedNodes, "New comment"), () => SelectedNodes.Count > 0); DisconnectConnectorCommand = new DelegateCommand <ConnectorViewModel>(c => c.Disconnect()); CreateConnectionCommand = new DelegateCommand <object>(target => Schema.TryAddConnection(PendingConnection.Source !, target), target => PendingConnection.Source != null && target != null); PendingConnection = new PendingConnectionViewModel { Graph = this }; Schema = new GraphSchema(); Connections.WhenAdded(c => { c.Graph = this; c.Input.Connections.Add(c); c.Output.Connections.Add(c); }) // Called when the collection is cleared .WhenRemoved(c => { c.Input.Connections.Remove(c); c.Output.Connections.Remove(c); }); Nodes.WhenAdded(x => x.Graph = this) // Not called when the collection is cleared .WhenRemoved(x => { if (x is FlowNodeViewModel flow) { flow.Disconnect(); } else if (x is KnotNodeViewModel knot) { knot.Connector.Disconnect(); } }) .WhenCleared(x => Connections.Clear()); }