public void LoadNodes() { ClearNodes(); OpenFileDialog openFileDialog1 = new OpenFileDialog(); // Set filter options and filter index. openFileDialog1.Filter = "XML Files (.xml)|*.xml|All Files (*.*)|*.*"; openFileDialog1.FilterIndex = 1; openFileDialog1.Multiselect = true; // Call the ShowDialog method to show the dialog box. bool?userClickedOK = openFileDialog1.ShowDialog(); // Process input if the user clicked OK. if (userClickedOK == true) { List <SerializeableNodeViewModel> SerializeNodes = new List <SerializeableNodeViewModel>(); string path = openFileDialog1.FileName; XmlSerializer ser = new XmlSerializer(typeof(List <SerializeableNodeViewModel>), new Type[] { typeof(SerializeableVariableNode), typeof(SerializeableConditionNode), typeof(SerializeableDynamicNode), typeof(SerializeableRootNode) }); using (XmlReader reader = XmlReader.Create(path)) { SerializeNodes = (List <SerializeableNodeViewModel>)ser.Deserialize(reader); } //ADD NODES foreach (var serializeableNodeViewModel in SerializeNodes) { if (serializeableNodeViewModel is SerializeableRootNode) { SerializeableRootNode rootSerialized = serializeableNodeViewModel as SerializeableRootNode; RootNode newNode = new RootNode(); newNode.Populate(rootSerialized); Nodes.Add(newNode); } if (serializeableNodeViewModel is SerializeableVariableNode) { SerializeableVariableNode variableSerialized = serializeableNodeViewModel as SerializeableVariableNode; VariableNode newNode = new VariableNode(); newNode.Populate(variableSerialized); Nodes.Add(newNode); } if (serializeableNodeViewModel is SerializeableDynamicNode) { SerializeableDynamicNode dynamicSerialized = serializeableNodeViewModel as SerializeableDynamicNode; DynamicNode newNode = new DynamicNode(); newNode.Populate(dynamicSerialized); Nodes.Add(newNode); } if (serializeableNodeViewModel is SerializeableConditionNode) { SerializeableConditionNode conSerialized = serializeableNodeViewModel as SerializeableConditionNode; ConditionNode newNode = new ConditionNode(); newNode.Populate(conSerialized); Nodes.Add(newNode); } } } //Node Connections foreach (var node in Nodes) { if (node is RootNode) { //Connect output RootNode rootNode = node as RootNode; if (rootNode.OutputConnector.ConnectionNodeID <= 0) { return; } //Connect this output to the connection's input Connector connectedTo = GetInConnectorBasedOnNode(rootNode.OutputConnector.ConnectionNodeID); Connector.ConnectPins(rootNode.OutputConnector, connectedTo); } if (node is ConditionNode) { ConditionNode conNode = node as ConditionNode; //bool value Input if (conNode.boolInput.ConnectionNodeID > 0) { //we're connected to a parameter Connector connectedToVar = GetOutConnectorBasedOnNode(conNode.boolInput.ConnectionNodeID); //variable Connector.ConnectPins(conNode.boolInput, connectedToVar); } //Input if (conNode.InExecutionConnector.ConnectionNodeID > 0) { Connector connectedTo = GetOutConnectorBasedOnNode(conNode.InExecutionConnector.ConnectionNodeID); Connector.ConnectPins(conNode.InExecutionConnector, connectedTo); } //Ouput true if (conNode.OutExecutionConnectorTrue.ConnectionNodeID > 0) { Connector connectedTo = GetInConnectorBasedOnNode(conNode.OutExecutionConnectorTrue.ConnectionNodeID); Connector.ConnectPins(conNode.OutExecutionConnectorTrue, connectedTo); } //Ouput false if (conNode.OutExecutionConnectorFalse.ConnectionNodeID > 0) { Connector connectedTo = GetInConnectorBasedOnNode(conNode.OutExecutionConnectorFalse.ConnectionNodeID); Connector.ConnectPins(conNode.OutExecutionConnectorFalse, connectedTo); } } if (node is DynamicNode) { //Connect output DynamicNode dynNode = node as DynamicNode; //Connect parameters for (int i = 0; i < dynNode.ArgumentCache.Count(); i++) { Argument arg = dynNode.ArgumentCache.ElementAt(i); if (arg.ArgIsExistingVariable) { Connector conID = dynNode.GetConnectorAtIndex(i); int connectedToVar = arg.ArgumentConnectedToNodeID; Connector varConnect = GetOutConnectorBasedOnNode(connectedToVar); Connector.ConnectPins(conID, varConnect); } } if (dynNode.OutExecutionConnector.ConnectionNodeID > 0) { //Connect this output to the connection's input Connector connectedTo = GetInConnectorBasedOnNode(dynNode.OutExecutionConnector.ConnectionNodeID); Connector.ConnectPins(dynNode.OutExecutionConnector, connectedTo); //No need to connect this in to the connection's output so far. } } } }