public static IVisualNode Create(IGraphController graphController, IStorage storage) { if (graphController == null || storage == null) { throw new ArgumentNullException("graphcontroller, storage"); } storage.Seek(12, SeekOrigin.Current); //Skip NodeSignature NodeType type = (NodeType)storage.ReadInteger(FieldCode.NodeType); storage.Seek(-24, SeekOrigin.Current); //Shift cursor back to the start point of reading NodeSignature VisualNode node = null; switch (type) { case NodeType.CodeBlock: node = new CodeBlockNode(graphController); node.Deserialize(storage); break; case NodeType.Condensed: node = new CondensedNode(graphController); node.Deserialize(storage); break; case NodeType.Driver: node = new DriverNode(graphController); node.Deserialize(storage); break; case NodeType.Function: node = new FunctionNode(graphController); node.Deserialize(storage); break; case NodeType.Identifier: node = new IdentifierNode(graphController); node.Deserialize(storage); break; case NodeType.Property: node = new PropertyNode(graphController); node.Deserialize(storage); break; case NodeType.Render: node = new RenderNode(graphController); node.Deserialize(storage); break; default: throw new ArgumentException("Invalid 'nodeType'"); } return(node); }
private bool HandleCreateDriverNode(GraphCommand command) { double mouseX = ((double)command.GetArgument(0)); double mouseY = ((double)command.GetArgument(1)); DriverNode node = new DriverNode(this, Configurations.DriverInitialTextValue); this.CreateNodeInternal(node, mouseX, mouseY); return(true); }
public void TestHandleSaveGraphAndLoadGraph() { try { GraphController graphController1 = new GraphController(null); IVisualNode node1 = new CodeBlockNode(graphController1, "Double Click and Type"); IVisualNode node2 = new DriverNode(graphController1, Configurations.DriverInitialTextValue); IVisualNode node3 = new FunctionNode(graphController1, "", "-", "double,double"); IVisualNode node4 = new IdentifierNode(graphController1, "c"); string filePath = Path.GetTempPath() + "test.bin"; graphController1.DoSaveGraph(filePath); GraphController graphController2 = new GraphController(null, filePath); Assert.AreEqual(4, graphController2.GetVisualNodes().Count); } finally { File.Delete(Path.GetTempPath() + "test.bin"); } }
public static IVisualNode Create(IGraphController graphController, IStorage storage) { if (graphController == null || storage == null) throw new ArgumentNullException("graphcontroller, storage"); storage.Seek(12, SeekOrigin.Current); //Skip NodeSignature NodeType type = (NodeType)storage.ReadInteger(FieldCode.NodeType); storage.Seek(-24, SeekOrigin.Current); //Shift cursor back to the start point of reading NodeSignature VisualNode node = null; switch (type) { case NodeType.CodeBlock: node = new CodeBlockNode(graphController); node.Deserialize(storage); break; case NodeType.Condensed: node = new CondensedNode(graphController); node.Deserialize(storage); break; case NodeType.Driver: node = new DriverNode(graphController); node.Deserialize(storage); break; case NodeType.Function: node = new FunctionNode(graphController); node.Deserialize(storage); break; case NodeType.Identifier: node = new IdentifierNode(graphController); node.Deserialize(storage); break; case NodeType.Property: node = new PropertyNode(graphController); node.Deserialize(storage); break; case NodeType.Render: node = new RenderNode(graphController); node.Deserialize(storage); break; default: throw new ArgumentException("Invalid 'nodeType'"); } return node; }
public void TestSerializeNullException() { IGraphController graphController = new GraphController(null); IStorage storage = null; IVisualNode node = new DriverNode(graphController, Configurations.DriverInitialTextValue); Assert.Throws<ArgumentNullException>(() => { node.Serialize(storage); }); }
public void TestSerializeDeserialize() { IGraphController graphController = new GraphController(null); IStorage storage = new BinaryStorage(); IVisualNode node1 = new DriverNode(graphController, Configurations.DriverInitialTextValue); IVisualNode node2 = new DriverNode(graphController, Configurations.DriverInitialTextValue); node1.Serialize(storage); storage.Seek(0, SeekOrigin.Begin); node2.Deserialize(storage); Assert.AreEqual(NodeType.Driver, node2.VisualType); Assert.AreEqual(node1.NodeId, node2.NodeId); Assert.AreEqual(true, ((DriverNode)node2).Dirty); Assert.AreEqual(((DriverNode)node1).Text, ((DriverNode)node2).Text); Assert.AreEqual(((DriverNode)node1).Caption, ((DriverNode)node2).Caption); Assert.AreEqual(node1.X, node2.X); Assert.AreEqual(node1.Y, node2.Y); Assert.Null(node2.GetInputSlots()); Assert.AreEqual(1, node2.GetOutputSlots().Length); }
public void TestDeserilaizeOperationException() { IGraphController graphController = new GraphController(null); IStorage storage = new BinaryStorage(); IVisualNode node = new DriverNode(graphController, Configurations.DriverInitialTextValue); ulong signature = Utilities.MakeEightCC('T', 'E', 'S', 'T', ' ', ' ', ' ', ' '); storage.WriteUnsignedInteger(signature, 21); storage.Seek(0, SeekOrigin.Begin); bool result = node.Deserialize(storage); Assert.AreEqual(result, false); }
public void TestRecordNodeModficationForUndo00() { GraphController graphController = new GraphController(null); UndoRedoRecorder urr = new UndoRedoRecorder(graphController); List<IVisualNode> nodeList = new List<IVisualNode>(); DriverNode node = new DriverNode(graphController); nodeList.Add(node); Assert.Throws<InvalidOperationException>(() => { urr.RecordNodeModificationForUndo(nodeList); }); }