public void CleanWorkbenchClearsUndoStack() { var dynamoModel = Controller.DynamoModel; Assert.IsNotNull(dynamoModel.CurrentWorkspace); var workspace = dynamoModel.CurrentWorkspace; Assert.AreEqual(false, workspace.CanUndo); Assert.AreEqual(false, workspace.CanRedo); Assert.AreEqual(0, workspace.Nodes.Count); // An empty workspace var createNodeCommand = new DynamoViewModel.CreateNodeCommand( Guid.NewGuid(), "Add", 0, 0, false, false); // Create a new node in the empty workspace. Controller.DynamoViewModel.ExecuteCommand(createNodeCommand); Assert.AreEqual(1, workspace.Nodes.Count); Assert.AreEqual(true, workspace.CanUndo); Assert.AreEqual(false, workspace.CanRedo); dynamoModel.CleanWorkbench(); // Clearing current workspace. // Undo stack should be cleared. Assert.AreEqual(false, workspace.CanUndo); Assert.AreEqual(false, workspace.CanRedo); }
public Guid RunDSScriptInCBN(string dscode) { /// Method that takes the DesignScript language code and dumps into CBN. /// Then evaluate in Dynamo and return the guid of the CBN var guid = Guid.NewGuid(); var command1 = new DynamoViewModel.CreateNodeCommand(guid, "Code Block", 0, 0, false, false); ViewModel.ExecuteCommand(command1); var command2 = new DynamoViewModel.UpdateModelValueCommand(guid, "Code", dscode); ViewModel.ExecuteCommand(command2); Assert.DoesNotThrow(() => ViewModel.Model.RunExpression()); return guid; }
public override bool RunTest(NodeModel node, StreamWriter writer) { bool pass = false; var types = LoadAllTypesFromDynamoAssemblies(); foreach (Type type in types) { string nodeName = GetName(type); var firstNodeConnectors = node.AllConnectors.ToList(); double coordinatesX = node.X; double coordinatesY = node.Y; if (!string.IsNullOrEmpty(nodeName)) { DynamoViewModel.UIDispatcher.Invoke(new Action(() => { Guid guidNumber = Guid.NewGuid(); DynamoViewModel.CreateNodeCommand createCommand = new DynamoViewModel.CreateNodeCommand(guidNumber, nodeName, coordinatesX, coordinatesY, false, false); DynamoViewModel.ExecuteCommand(createCommand); })); var valueMap = new Dictionary<Guid, String>(); foreach (ConnectorModel connector in firstNodeConnectors) { Guid guid = connector.Start.Owner.GUID; Object data = connector.Start.Owner.GetValue(0).Data; String val = data != null ? data.ToString() : "null"; valueMap.Add(guid, val); writer.WriteLine(guid + " :: " + val); writer.Flush(); } int numberOfUndosNeeded = Mutate(node); Thread.Sleep(100); writer.WriteLine("### - Beginning undo"); for (int iUndo = 0; iUndo < numberOfUndosNeeded; iUndo++) { DynamoViewModel.UIDispatcher.Invoke(new Action(() => { DynamoViewModel.UndoRedoCommand undoCommand = new DynamoViewModel.UndoRedoCommand(DynamoViewModel.UndoRedoCommand.Operation.Undo); DynamoViewModel.ExecuteCommand(undoCommand); })); } Thread.Sleep(100); writer.WriteLine("### - undo complete"); writer.Flush(); DynamoViewModel.UIDispatcher.Invoke(new Action(() => { DynamoViewModel.RunCancelCommand runCancel = new DynamoViewModel.RunCancelCommand(false, false); DynamoViewModel.ExecuteCommand(runCancel); })); while (DynamoViewModel.Model.Runner.Running) { Thread.Sleep(10); } writer.WriteLine("### - Beginning test of CustomNode"); if (node.OutPorts.Count > 0) { try { NodeModel nodeAfterUndo = DynamoViewModel.Model.Nodes.ToList().FirstOrDefault((t) => { return (t.GUID == node.GUID); }); if (nodeAfterUndo != null) { var firstNodeConnectorsAfterUndo = nodeAfterUndo.AllConnectors.ToList(); foreach (ConnectorModel connector in firstNodeConnectors) { Guid guid = connector.Start.Owner.GUID; Object data = connector.Start.Owner.GetValue(0).Data; String val = data != null ? data.ToString() : "null"; if (valueMap[guid] != val) { writer.WriteLine("!!!!!!!!!!! - test of CustomNode is failed"); writer.WriteLine(node.GUID); writer.WriteLine("Was: " + val); writer.WriteLine("Should have been: " + valueMap[guid]); writer.Flush(); return pass; } } } } catch (Exception) { writer.WriteLine("!!!!!!!!!!! - test of CustomNode is failed"); writer.Flush(); return pass; } } writer.WriteLine("### - test of CustomNode complete"); writer.Flush(); } } return pass = true; }
public override int Mutate(NodeModel node) { Random rand = new Random(1); DynamoViewModel.UIDispatcher.Invoke(new Action(() => { Guid guidNumber = Guid.NewGuid(); double coordinatesX = node.X * rand.NextDouble(); double coordinatesY = node.Y * rand.NextDouble(); DynamoViewModel.CreateNodeCommand createNodeNumber1 = new DynamoViewModel.CreateNodeCommand(guidNumber, "Number", coordinatesX, coordinatesY, false, true); DynamoViewModel.ExecuteCommand(createNodeNumber1); DynamoViewModel.MakeConnectionCommand connToStart1 = new DynamoViewModel.MakeConnectionCommand(guidNumber, 0, PortType.OUTPUT, DynamoViewModel.MakeConnectionCommand.Mode.Begin); DynamoViewModel.MakeConnectionCommand connToStart2 = new DynamoViewModel.MakeConnectionCommand(node.GUID, 0, PortType.INPUT, DynamoViewModel.MakeConnectionCommand.Mode.End); DynamoViewModel.MakeConnectionCommand connToAmount1 = new DynamoViewModel.MakeConnectionCommand(guidNumber, 0, PortType.OUTPUT, DynamoViewModel.MakeConnectionCommand.Mode.Begin); DynamoViewModel.MakeConnectionCommand connToAmount2 = new DynamoViewModel.MakeConnectionCommand(node.GUID, 1, PortType.INPUT, DynamoViewModel.MakeConnectionCommand.Mode.End); DynamoViewModel.MakeConnectionCommand connToStep1 = new DynamoViewModel.MakeConnectionCommand(guidNumber, 0, PortType.OUTPUT, DynamoViewModel.MakeConnectionCommand.Mode.Begin); DynamoViewModel.MakeConnectionCommand connToStep2 = new DynamoViewModel.MakeConnectionCommand(node.GUID, 2, PortType.INPUT, DynamoViewModel.MakeConnectionCommand.Mode.End); DynamoViewModel.ExecuteCommand(connToStart1); //"Number" with "Number Sequence" on Start DynamoViewModel.ExecuteCommand(connToStart2); //"Number" with "Number Sequence" on Start DynamoViewModel.ExecuteCommand(connToAmount1); //"Number" with "Number Sequence" on Amount DynamoViewModel.ExecuteCommand(connToAmount2); //"Number" with "Number Sequence" on Amount DynamoViewModel.ExecuteCommand(connToStep1); //"Number" with "Number Sequence" on Step DynamoViewModel.ExecuteCommand(connToStep2); //"Number" with "Number Sequence" on Step })); return 4; }
public override int Mutate(NodeModel node) { Random rand = new Random(1); int countOfInPorts = 0; var nodeConnectors = node.AllConnectors.ToList(); foreach (ConnectorModel connector in nodeConnectors) { if (connector.Start.Owner.GUID != node.GUID) { Guid guidNumber = Guid.NewGuid(); double coordinatesX = node.X * rand.NextDouble(); double coordinatesYNumber1 = node.Y * rand.NextDouble(); countOfInPorts++; DynamoViewModel.UIDispatcher.Invoke(new Action(() => { //make node DynamoViewModel.CreateNodeCommand createNodeNumber1 = new DynamoViewModel.CreateNodeCommand(guidNumber, "Number", coordinatesX, coordinatesYNumber1, false, true); //create node DynamoViewModel.ExecuteCommand(createNodeNumber1); int outPortIndex = connector.Start.Index; int inPortIndex = connector.End.Index; //make connection DynamoViewModel.MakeConnectionCommand connToStart1 = new DynamoViewModel.MakeConnectionCommand(guidNumber, outPortIndex, PortType.OUTPUT, DynamoViewModel.MakeConnectionCommand.Mode.Begin); DynamoViewModel.MakeConnectionCommand connToStart2 = new DynamoViewModel.MakeConnectionCommand(node.GUID, inPortIndex, PortType.INPUT, DynamoViewModel.MakeConnectionCommand.Mode.End); //create connections DynamoViewModel.ExecuteCommand(connToStart1); DynamoViewModel.ExecuteCommand(connToStart2); })); } } return countOfInPorts * 2; }
public override int Mutate(NodeModel node) { int workspaceIndex = DynamoViewModel.CurrentWorkspaceIndex; Random rand = new Random(1); DynamoViewModel.UIDispatcher.Invoke(new Action(() => { DynamoViewModel.SwitchTabCommand switchCmd = new DynamoViewModel.SwitchTabCommand(workspaceIndex); DynamoViewModel.ExecuteCommand(switchCmd); Thread.Sleep(100); })); DynamoViewModel.UIDispatcher.Invoke(new Action(() => { DynamoViewModel.SwitchTabCommand switchCmd = new DynamoViewModel.SwitchTabCommand(workspaceIndex); DynamoViewModel.ExecuteCommand(switchCmd); Thread.Sleep(100); })); var workspaces = DynamoModel.Workspaces; var outputsInCustomNode = workspaces.FirstOrDefault((t) => { return (t.Name == ((Function)node).Definition.WorkspaceModel.Name); }).Nodes.Where(t => t.GetType() == typeof(Output)).ToList(); Guid numberGuid = Guid.NewGuid(); double coordinatesX = rand.NextDouble() * node.X; double coordinatesY = rand.NextDouble() * node.Y; DynamoViewModel.UIDispatcher.Invoke(new Action(() => { DynamoViewModel.CreateNodeCommand createCommand = new DynamoViewModel.CreateNodeCommand(numberGuid, "Number", coordinatesX, coordinatesY, false, false); DynamoViewModel.ExecuteCommand(createCommand); })); foreach (NodeModel output in outputsInCustomNode) { DynamoViewModel.UIDispatcher.Invoke(new Action(() => { DynamoViewModel.MakeConnectionCommand connToAnother1 = new DynamoViewModel.MakeConnectionCommand(numberGuid, 0, PortType.OUTPUT, DynamoViewModel.MakeConnectionCommand.Mode.Begin); DynamoViewModel.MakeConnectionCommand connToAnother2 = new DynamoViewModel.MakeConnectionCommand(output.GUID, 0, PortType.INPUT, DynamoViewModel.MakeConnectionCommand.Mode.End); DynamoViewModel.ExecuteCommand(connToAnother1); DynamoViewModel.ExecuteCommand(connToAnother2); })); } int numberOfUndosNeeded = outputsInCustomNode.Count * 2 + 1; return numberOfUndosNeeded; }