Esempio n. 1
0
        public void CanSavePinState()
        {
            var model = CurrentDynamoModel;
            var cbn = new CodeBlockNodeModel(model.LibraryServices);
            var command = new DynamoModel.CreateNodeCommand(cbn, 0, 0, true, false);

            CurrentDynamoModel.ExecuteCommand(command);

            UpdateCodeBlockNodeContent(cbn, "42");
            cbn.PreviewPinned = true;

            DynamoSelection.Instance.Selection.Add(cbn);
            var ids = DynamoSelection.Instance.Selection.OfType<NodeModel>().Select(x => x.GUID).ToList();
            model.ExecuteCommand(new DynamoModel.AddPresetCommand("state1", "3", ids));

            UpdateCodeBlockNodeContent(cbn, "146");
            DynamoSelection.Instance.Selection.Remove(cbn);

            model.CurrentWorkspace.ApplyPreset(model.CurrentWorkspace.Presets.Where(
               x => x.Name == "state1").First());

            RunCurrentModel();

            Assert.IsTrue(cbn.PreviewPinned);
        }
Esempio n. 2
0
        public void CleanWorkbenchClearsUndoStack()
        {
            var dynamoModel = ViewModel.Model;
            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 addNode = new DSFunction(dynamoModel.LibraryServices.GetFunctionDescriptor("+"));
            var createNodeCommand = new DynamoModel.CreateNodeCommand(
                addNode, 0, 0, false, false);

            // Create a new node in the empty workspace.
            ViewModel.ExecuteCommand(createNodeCommand);
            Assert.AreEqual(1, workspace.Nodes.Count());

            Assert.AreEqual(true, workspace.CanUndo);
            Assert.AreEqual(false, workspace.CanRedo);
            dynamoModel.CurrentWorkspace.Clear(); // Clearing current workspace.

            // Undo stack should be cleared.
            Assert.AreEqual(false, workspace.CanUndo);
            Assert.AreEqual(false, workspace.CanRedo);
        }
Esempio n. 3
0
        public void CleanWorkbenchClearsUndoStack()
        {
            var dynamoModel = ViewModel.Model;
            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 DynamoModel.CreateNodeCommand(
                Guid.NewGuid(), "Add", 0, 0, false, false);

            // Create a new node in the empty workspace.
            ViewModel.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);
        }
Esempio n. 4
0
        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
                        DynamoModel.CreateNodeCommand createNodeNumber1 =
                            new DynamoModel.CreateNodeCommand(guidNumber, "Number", 
                                coordinatesX, coordinatesYNumber1, false, true);

                        //create node
                        DynamoViewModel.ExecuteCommand(createNodeNumber1);

                        int outPortIndex = connector.Start.Index;
                        int inPortIndex = connector.End.Index;

                        //make connection
                        DynamoModel.MakeConnectionCommand connToStart1 =
                            new DynamoModel.MakeConnectionCommand(guidNumber, outPortIndex, 
                                PortType.OUTPUT, DynamoModel.MakeConnectionCommand.Mode.Begin);
                        DynamoModel.MakeConnectionCommand connToStart2 =
                            new DynamoModel.MakeConnectionCommand(node.GUID, inPortIndex, 
                                PortType.INPUT, DynamoModel.MakeConnectionCommand.Mode.End);

                        //create connections
                        DynamoViewModel.ExecuteCommand(connToStart1);
                        DynamoViewModel.ExecuteCommand(connToStart2);
                    }));
                }
            }
            return countOfInPorts * 2;
        }        
        public override bool RunTest(NodeModel node, EngineController engine, 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(() =>
                    {
                        var newNode = type.GetDefaultConstructor<NodeModel>()();

                        DynamoModel.CreateNodeCommand createCommand =
                            new DynamoModel.CreateNodeCommand(
                                newNode, 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, engine).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(() =>
                        {
                            DynamoModel.UndoRedoCommand undoCommand =
                                new DynamoModel.UndoRedoCommand(DynamoModel.UndoRedoCommand.Operation.Undo);

                            DynamoViewModel.ExecuteCommand(undoCommand);
                        }));
                    }
                    Thread.Sleep(100);

                    writer.WriteLine("### - undo complete");
                    writer.Flush();

                    DynamoViewModel.UIDispatcher.Invoke(new Action(() =>
                    {
                        DynamoModel.RunCancelCommand runCancel =
                            new DynamoModel.RunCancelCommand(false, false);

                        DynamoViewModel.ExecuteCommand(runCancel);
                    }));
                    while (!DynamoViewModel.HomeSpace.RunSettings.RunEnabled)
                    {
                        Thread.Sleep(10);
                    }

                    writer.WriteLine("### - Beginning test of CustomNode");
                    if (node.OutPorts.Count > 0)
                    {
                        try
                        {
                            NodeModel nodeAfterUndo =
                                DynamoViewModel.Model.CurrentWorkspace.Nodes.FirstOrDefault(
                                    (t) => (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, engine).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;
        }
Esempio n. 6
0
        public override int Mutate(NodeModel node)
        {
            int workspaceIndex = DynamoViewModel.CurrentWorkspaceIndex;
            Random rand = new Random(1);

            DynamoViewModel.UIDispatcher.Invoke(new Action(() =>
            {
                DynamoModel.SwitchTabCommand switchCmd =
                    new DynamoModel.SwitchTabCommand(workspaceIndex);

                DynamoViewModel.ExecuteCommand(switchCmd);
                Thread.Sleep(100);
            }));

            DynamoViewModel.UIDispatcher.Invoke(new Action(() =>
            {
                DynamoModel.SwitchTabCommand switchCmd =
                    new DynamoModel.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(() =>
            {
                DynamoModel.CreateNodeCommand createCommand =
                    new DynamoModel.CreateNodeCommand(numberGuid, "Number", 
                        coordinatesX, coordinatesY, false, false);
                DynamoViewModel.ExecuteCommand(createCommand);
            }));

            foreach (NodeModel output in outputsInCustomNode)
            {
                DynamoViewModel.UIDispatcher.Invoke(new Action(() =>
                {
                    DynamoModel.MakeConnectionCommand connToAnother1 =
                        new DynamoModel.MakeConnectionCommand(numberGuid, 0, PortType.OUTPUT, 
                            DynamoModel.MakeConnectionCommand.Mode.Begin);
                    DynamoModel.MakeConnectionCommand connToAnother2 =
                        new DynamoModel.MakeConnectionCommand(output.GUID, 0, PortType.INPUT, 
                            DynamoModel.MakeConnectionCommand.Mode.End);

                    DynamoViewModel.ExecuteCommand(connToAnother1);
                    DynamoViewModel.ExecuteCommand(connToAnother2);
                }));
            }

            int numberOfUndosNeeded = outputsInCustomNode.Count * 2 + 1;

            return numberOfUndosNeeded;
        }
Esempio n. 7
0
        public override int Mutate(NodeModel node)
        {
            DynamoViewModel.UIDispatcher.Invoke(new Action(() =>
            {
                Guid guidNumber = Guid.NewGuid();

                double coordinatesX = 120;
                double coordinatesY = 180;

                DynamoModel.CreateNodeCommand createNodeCmd1 =
                    new DynamoModel.CreateNodeCommand(guidNumber, "Number", coordinatesX,
                        coordinatesY, false, true);

                DynamoViewModel.ExecuteCommand(createNodeCmd1);

                DynamoModel.MakeConnectionCommand connToStart1 =
                    new DynamoModel.MakeConnectionCommand(guidNumber, 0, PortType.OUTPUT,
                        DynamoModel.MakeConnectionCommand.Mode.Begin);
                DynamoModel.MakeConnectionCommand connToStart2 =
                    new DynamoModel.MakeConnectionCommand(node.GUID, 0, PortType.INPUT,
                        DynamoModel.MakeConnectionCommand.Mode.End);

                DynamoModel.MakeConnectionCommand connToAmount1 =
                    new DynamoModel.MakeConnectionCommand(guidNumber, 0, PortType.OUTPUT,
                        DynamoModel.MakeConnectionCommand.Mode.Begin);
                DynamoModel.MakeConnectionCommand connToAmount2 =
                    new DynamoModel.MakeConnectionCommand(node.GUID, 1, PortType.INPUT,
                        DynamoModel.MakeConnectionCommand.Mode.End);

                DynamoModel.MakeConnectionCommand connToStep1 =
                    new DynamoModel.MakeConnectionCommand(guidNumber, 0, PortType.OUTPUT,
                        DynamoModel.MakeConnectionCommand.Mode.Begin);
                DynamoModel.MakeConnectionCommand connToStep2 =
                    new DynamoModel.MakeConnectionCommand(node.GUID, 2, PortType.INPUT,
                        DynamoModel.MakeConnectionCommand.Mode.End);

                DynamoViewModel.ExecuteCommand(connToStart1); //"Number" with "Number Range" on Start
                DynamoViewModel.ExecuteCommand(connToStart2); //"Number" with "Number Range" on Start
                DynamoViewModel.ExecuteCommand(connToAmount1); //"Number" with "Number Range" on End
                DynamoViewModel.ExecuteCommand(connToAmount2); //"Number" with "Number Range" on End
                DynamoViewModel.ExecuteCommand(connToStep1); //"Number" with "Number Range" on Step
                DynamoViewModel.ExecuteCommand(connToStep2); //"Number" with "Number Range" on Step
            }));

            return 4;
        }