Exemplo n.º 1
0
        public void CanCopyAndPasteDSVarArgFunctionNode()
        {
            Assert.AreEqual(0, CurrentDynamoModel.CurrentWorkspace.Nodes.Count());

            const string dsVarArgFunctionName = "[email protected],string[]";
            var node = new DSVarArgFunction(CurrentDynamoModel.LibraryServices.GetFunctionDescriptor(dsVarArgFunctionName));
            CurrentDynamoModel.CurrentWorkspace.AddAndRegisterNode(node, false);

            // Here we check to see if we do get a DSVarArgFunction node (which
            // is what this test case is written for, other nodes will render the 
            // test case meaningless).
            // 
            Assert.AreEqual(1, CurrentDynamoModel.CurrentWorkspace.Nodes.Count());

            CurrentDynamoModel.AddToSelection(node); // Select the only DSVarArgFunction node.
            CurrentDynamoModel.Copy(); // Copy the only DSVarArgFunction node.

            Assert.DoesNotThrow(() =>
            {
                CurrentDynamoModel.Paste(); // Nope, paste should not crash Dynamo.
            });
        }
Exemplo n.º 2
0
        public void Defect_MAGN_3166()
        {
            // Create the node with given information.
            NodeModel node =
                new DSVarArgFunction(CurrentDynamoModel.LibraryServices.GetFunctionDescriptor("[email protected][]..[]"));
            CurrentDynamoModel.ExecuteCommand(new DynCmd.CreateNodeCommand(node, 0, 0, true, false));

            var nodeGuid = node.GUID;

            // The node sound be found, and it should be a DSVarArgFunction.
            var workspace = CurrentDynamoModel.CurrentWorkspace;
            Assert.IsNotNull(node);

            // Delete the node and ensure it is gone.
            CurrentDynamoModel.ExecuteCommand(new DynCmd.DeleteModelCommand(nodeGuid));
            node = workspace.NodeFromWorkspace(nodeGuid);
            Assert.IsNull(node);

            // Perform undo operation.
            var undoOperation = DynCmd.UndoRedoCommand.Operation.Undo;
            CurrentDynamoModel.ExecuteCommand(new DynCmd.UndoRedoCommand(undoOperation));

            // Now that deletion is undone, ensure the node exists.
            node = workspace.NodeFromWorkspace(nodeGuid);
            Assert.IsNotNull(node);
            Assert.IsNotNull(node as DSVarArgFunction);
        }
Exemplo n.º 3
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            NodeModel node = null;

            var obj = JObject.Load(reader);
            var type = Type.GetType(obj["$type"].Value<string>());
            
            var guid = Guid.Parse(obj["Uuid"].Value<string>());
            var displayName = obj["DisplayName"].Value<string>();
            //var x = obj["X"].Value<double>();
            //var y = obj["Y"].Value<double>();

            var inPorts = obj["InputPorts"].ToArray().Select(t => t.ToObject<PortModel>()).ToArray();
            var outPorts = obj["OutputPorts"].ToArray().Select(t => t.ToObject<PortModel>()).ToArray();

            var resolver = (IdReferenceResolver)serializer.ReferenceResolver;

            if (type == typeof(Function))
            {
                var functionId = Guid.Parse(obj["FunctionUuid"].Value<string>());
                node = manager.CreateCustomNodeInstance(functionId);
                RemapPorts(node, inPorts, outPorts, resolver);
            }
            else if(type == typeof(CodeBlockNodeModel))
            {
                var code = obj["Code"].Value<string>();
                node = new CodeBlockNodeModel(code, guid, 0.0, 0.0, libraryServices, ElementResolver);
                RemapPorts(node, inPorts, outPorts, resolver);
            }
            else if(typeof(DSFunctionBase).IsAssignableFrom(type))
            {
                var mangledName = obj["FunctionName"].Value<string>();

                var description = libraryServices.GetFunctionDescriptor(mangledName);

                if(type == typeof(DSVarArgFunction))
                {
                    node = new DSVarArgFunction(description);
                    // The node syncs with the function definition.
                    // Then we need to make the inport count correct
                    var varg = (DSVarArgFunction)node;
                    varg.VarInputController.SetNumInputs(inPorts.Count());
                }
                else if(type == typeof(DSFunction))
                {
                    node = new DSFunction(description);
                    
                }
                RemapPorts(node, inPorts, outPorts, resolver);
            }
            else if (type == typeof(DSVarArgFunction))
            {
                var functionId = Guid.Parse(obj["FunctionUuid"].Value<string>());
                node = manager.CreateCustomNodeInstance(functionId);
                RemapPorts(node, inPorts, outPorts, resolver);
            }
            else
            {
                node = (NodeModel)obj.ToObject(type);
            }

            node.GUID = guid;
            node.NickName = displayName;
            //node.X = x;
            //node.Y = y;

            // Add references to the node and the ports to the reference resolver,
            // so that they are available for entities which are deserialized later.
            serializer.ReferenceResolver.AddReference(serializer.Context, node.GUID.ToString(), node);

            foreach(var p in node.InPorts)
            {
                serializer.ReferenceResolver.AddReference(serializer.Context, p.GUID.ToString(), p);
            }
            foreach (var p in node.OutPorts)
            {
                serializer.ReferenceResolver.AddReference(serializer.Context, p.GUID.ToString(), p);
            }
            return node;
        }