예제 #1
0
        public void TestGuidAttributes()
        {
            XmlElement element = xmlDocument.CreateElement("element");

            // Test attribute writing.
            System.Guid      guidValue = System.Guid.NewGuid();
            XmlElementHelper writer    = new XmlElementHelper(element);

            writer.SetAttribute("ValidName", guidValue);

            // Test reading of existing attribute.
            XmlElementHelper reader = new XmlElementHelper(element);

            Assert.AreEqual(guidValue, reader.ReadGuid("ValidName"));

            // Test reading of non-existence attribute with default value.
            System.Guid defaultGuid = System.Guid.NewGuid();
            Assert.AreEqual(defaultGuid, reader.ReadGuid("InvalidName", defaultGuid));

            // Test reading of non-existence attribute without default value.
            Assert.Throws <InvalidOperationException>(() =>
            {
                reader.ReadGuid("InvalidName");
            });
        }
예제 #2
0
        protected override void DeserializeCore(XmlElement element, SaveContext context)
        {
            XmlElementHelper helper = new XmlElementHelper(element);

            // Restore some information from the node attributes.
            this.GUID = helper.ReadGuid("guid", this.GUID);
            Guid     startNodeId = helper.ReadGuid("start");
            int      startIndex  = helper.ReadInteger("start_index");
            Guid     endNodeId   = helper.ReadGuid("end");
            int      endIndex    = helper.ReadInteger("end_index");
            PortType portType    = ((PortType)helper.ReadInteger("portType"));

            // Get to the start and end nodes that this connector connects to.
            NodeModel startNode = workspaceModel.GetModelInternal(startNodeId) as NodeModel;
            NodeModel endNode   = workspaceModel.GetModelInternal(endNodeId) as NodeModel;

            pStart = startNode.OutPorts[startIndex];
            PortModel endPort = null;

            if (portType == PortType.INPUT)
            {
                endPort = endNode.InPorts[endIndex];
            }

            pStart.Connect(this);
            this.Connect(endPort);
        }
예제 #3
0
        /// <summary>
        ///     Creates and initializes a ConnectorModel from its Xml representation.
        /// </summary>
        /// <param name="connEl">XmlElement for a ConnectorModel.</param>
        /// <param name="nodes">Dictionary to be used for looking up a NodeModel by it's Guid.</param>
        /// <returns>Returns the new instance of ConnectorModel loaded from XmlElement.</returns>
        public static ConnectorModel LoadConnectorFromXml(XmlElement connEl, IDictionary <Guid, NodeModel> nodes)
        {
            var helper = new XmlElementHelper(connEl);

            var  guid       = helper.ReadGuid("guid", Guid.NewGuid());
            var  guidStart  = helper.ReadGuid("start");
            var  guidEnd    = helper.ReadGuid("end");
            int  startIndex = helper.ReadInteger("start_index");
            int  endIndex   = helper.ReadInteger("end_index");
            bool isHidden   = helper.HasAttribute(nameof(ConnectorModel.IsHidden)) ?
                              helper.ReadBoolean(nameof(ConnectorModel.IsHidden)) :
                              false;

            //find the elements to connect
            NodeModel start;

            if (nodes.TryGetValue(guidStart, out start))
            {
                NodeModel end;
                if (nodes.TryGetValue(guidEnd, out end))
                {
                    var connector = ConnectorModel.Make(start, end, startIndex, endIndex, guid);
                    if (connector != null)
                    {
                        connector.IsHidden = isHidden;
                        return(connector);
                    }
                }
            }

            return(null);
        }
예제 #4
0
        /// <summary>
        ///     Creates and initializes a ConnectorModel from its Xml representation.
        /// </summary>
        /// <param name="connEl">XmlElement for a ConnectorModel.</param>
        /// <param name="nodes">Dictionary to be used for looking up a NodeModel by it's Guid.</param>
        /// <param name="connector"></param>
        /// <returns></returns>
        public static bool LoadConnectorFromXml(XmlElement connEl, IDictionary <Guid, NodeModel> nodes, out ConnectorModel connector)
        {
            var helper = new XmlElementHelper(connEl);

            var guid       = helper.ReadGuid("guid", Guid.NewGuid());
            var guidStart  = helper.ReadGuid("start");
            var guidEnd    = helper.ReadGuid("end");
            int startIndex = helper.ReadInteger("start_index");
            int endIndex   = helper.ReadInteger("end_index");

            //find the elements to connect
            NodeModel start;

            if (nodes.TryGetValue(guidStart, out start))
            {
                NodeModel end;
                if (nodes.TryGetValue(guidEnd, out end))
                {
                    connector = ConnectorModel.Make(start, end, startIndex, endIndex, guid);
                    return(connector != null);
                }
            }
            connector = null;
            return(false);
        }
예제 #5
0
        /// <summary>
        /// Gets model by GUID which is contained in given Xml data.
        /// </summary>
        /// <param name="modelData">Xml data to find model.</param>
        /// <returns>Found <see cref="ModelBase"/> object.</returns>
        public ModelBase GetModelForElement(XmlElement modelData)
        {
            // TODO(Ben): This may or may not be true, but I guess we should be
            // using "System.Type" (given the "type" information in "modelData"),
            // and determine the matching category (e.g. is this a Node, or a
            // Connector?) instead of checking in each and every collections we
            // have in the workspace.
            //
            // System.Type type = System.Type.GetType(helper.ReadString("type"));
            // if (typeof(Dynamo.Models.NodeModel).IsAssignableFrom(type))
            //     return Nodes.First((x) => (x.GUID == modelGuid));

            var  helper    = new XmlElementHelper(modelData);
            Guid modelGuid = helper.ReadGuid("guid");

            ModelBase foundModel = GetModelInternal(modelGuid);

            if (null != foundModel)
            {
                return(foundModel);
            }

            //if we could not find a matching model
            this.Log(string.Format("Please Report: Unhandled model type: {0}, could not find a matching model with given id", helper.ReadString("type", modelData.Name)), Logging.WarningLevel.Error);
            return(null);
        }
예제 #6
0
            internal static ConvertNodesToCodeCommand DeserializeCore(XmlElement element)
            {
                XmlElementHelper helper = new XmlElementHelper(element);
                Guid             nodeId = helper.ReadGuid("NodeId");

                return(new ConvertNodesToCodeCommand(nodeId));
            }
예제 #7
0
            internal static UpdateModelValueCommand DeserializeCore(XmlElement element)
            {
                var    helper = new XmlElementHelper(element);
                string name   = helper.ReadString("Name");
                string value  = helper.ReadString("Value");

                Guid modelGuid = helper.ReadGuid("ModelGuid", Guid.Empty);

                if (modelGuid != Guid.Empty)
                {
                    // An old type of 'UpdateModelValueCommand' works for only one
                    // 'NodeModel' whose Guid is stored under 'ModelGuid' attribute.
                    return(new UpdateModelValueCommand(modelGuid, name, value));
                }
                else
                {
                    // Parsing a new type of 'UpdateModelValueCommand' that works
                    // for multiple 'NodeModel' whose Guid values are each stored
                    // as a 'ModelGuid' child element under the main element.
                    //
                    var modelGuids = (from XmlNode xmlNode in element.ChildNodes
                                      where xmlNode.Name.Equals("ModelGuid")
                                      select Guid.Parse(xmlNode.InnerText)).ToList();

                    return(new UpdateModelValueCommand(modelGuids, name, value));
                }
            }
예제 #8
0
            internal static DeleteModelCommand DeserializeCore(XmlElement element)
            {
                XmlElementHelper helper    = new XmlElementHelper(element);
                Guid             modelGuid = helper.ReadGuid("ModelGuid");

                return(new DeleteModelCommand(modelGuid));
            }
예제 #9
0
        public DummyNode(int inputCount, int outputCount, string legacyName, XmlElement originalElement, string legacyAssembly, Nature nodeNature)
        {
            InputCount = inputCount;
            OutputCount = outputCount;
            LegacyNodeName = legacyName;
            NickName = legacyName;
            OriginalNodeContent = originalElement;
            LegacyAssembly = legacyAssembly;
            NodeNature = nodeNature;

            Description = GetDescription();
            ShouldDisplayPreviewCore = false;

            UpdatePorts();

            // Take the position from the old node (because a dummy node
            // should always be created at the location of the old node).
            var helper = new XmlElementHelper(originalElement);
            X = helper.ReadDouble("x", 0.0);
            Y = helper.ReadDouble("y", 0.0);

            //Take the GUID from the old node (dummy nodes should have their
            //GUID's. This will allow the Groups to work as expected. MAGN-7568)
            GUID = helper.ReadGuid("guid", this.GUID);
        }
예제 #10
0
        public ModelBase GetModelForElement(XmlElement modelData)
        {
            // TODO(Ben): This may or may not be true, but I guess we should be
            // using "System.Type" (given the "type" information in "modelData"),
            // and determine the matching category (e.g. is this a Node, or a
            // Connector?) instead of checking in each and every collections we
            // have in the workspace.
            //
            // System.Type type = System.Type.GetType(helper.ReadString("type"));
            // if (typeof(Dynamo.Models.NodeModel).IsAssignableFrom(type))
            //     return Nodes.First((x) => (x.GUID == modelGuid));

            XmlElementHelper helper    = new XmlElementHelper(modelData);
            Guid             modelGuid = helper.ReadGuid("guid");

            ModelBase foundModel = GetModelInternal(modelGuid);

            if (null != foundModel)
            {
                return(foundModel);
            }

            throw new ArgumentException(string.Format(
                                            "Unhandled model type: {0}", helper.ReadString("type")));
        }
예제 #11
0
        public DummyNode(int inputCount, int outputCount, string legacyName, XmlElement originalElement, string legacyAssembly, Nature nodeNature)
        {
            InputCount          = inputCount;
            OutputCount         = outputCount;
            LegacyNodeName      = legacyName;
            NickName            = legacyName;
            OriginalNodeContent = originalElement;
            LegacyAssembly      = legacyAssembly;
            NodeNature          = nodeNature;

            Description = GetDescription();
            ShouldDisplayPreviewCore = false;

            UpdatePorts();

            // Take the position from the old node (because a dummy node
            // should always be created at the location of the old node).
            var helper = new XmlElementHelper(originalElement);

            X = helper.ReadDouble("x", 0.0);
            Y = helper.ReadDouble("y", 0.0);

            //Take the GUID from the old node (dummy nodes should have their
            //GUID's. This will allow the Groups to work as expected. MAGN-7568)
            GUID = helper.ReadGuid("guid", this.GUID);
        }
예제 #12
0
 protected override void DeserializeCore(XmlElement nodeElement, SaveContext context)
 {
     var helper = new XmlElementHelper(nodeElement);
     GUID = helper.ReadGuid("guid", GUID);
     Text = helper.ReadString("text", "New Note");
     X = helper.ReadDouble("x", 0.0);
     Y = helper.ReadDouble("y", 0.0);
 }
예제 #13
0
            internal static SelectModelCommand DeserializeCore(XmlElement element)
            {
                XmlElementHelper helper    = new XmlElementHelper(element);
                Guid             modelGuid = helper.ReadGuid("ModelGuid");
                ModifierKeys     modifiers = ((ModifierKeys)helper.ReadInteger("Modifiers"));

                return(new SelectModelCommand(modelGuid, modifiers));
            }
예제 #14
0
 protected override void DeserializeCore(XmlElement element, SaveContext context)
 {
     XmlElementHelper helper = new XmlElementHelper(element);
     this.GUID = helper.ReadGuid("guid", this.GUID);
     this.Text = helper.ReadString("text", "New Note");
     this.X = helper.ReadDouble("x", 0.0);
     this.Y = helper.ReadDouble("y", 0.0);
 }
예제 #15
0
            internal static ModelEventCommand DeserializeCore(XmlElement element)
            {
                XmlElementHelper helper    = new XmlElementHelper(element);
                Guid             modelGuid = helper.ReadGuid("ModelGuid");
                string           eventName = helper.ReadString("EventName");

                return(new ModelEventCommand(modelGuid, eventName));
            }
예제 #16
0
        protected override void DeserializeCore(XmlElement element, SaveContext context)
        {
            XmlElementHelper helper = new XmlElementHelper(element);

            this.GUID = helper.ReadGuid("guid", this.GUID);
            this.Text = helper.ReadString("text", "New Note");
            this.X    = helper.ReadDouble("x", 0.0);
            this.Y    = helper.ReadDouble("y", 0.0);
        }
예제 #17
0
        /// <summary>
        /// Method used to reconstruct a pin from xml when it has been deleted (undo/redo operations).
        /// </summary>
        /// <param name="pin">The xml representation of a ConnectorPinModel</param>
        /// <returns>A reconstructed instance of type ConnectorPinModel</returns>
        internal static ConnectorPinModel LoadPinFromXml(XmlElement pin)
        {
            var helper   = new XmlElementHelper(pin);
            var guid     = helper.ReadGuid("guid", Guid.NewGuid());
            var instance = new ConnectorPinModel(0, 0, guid, Guid.Empty);

            instance.Deserialize(pin as XmlElement, SaveContext.Save);
            return(instance);
        }
예제 #18
0
            internal static UpdateModelValueCommand DeserializeCore(XmlElement element)
            {
                XmlElementHelper helper    = new XmlElementHelper(element);
                Guid             modelGuid = helper.ReadGuid("ModelGuid");
                string           name      = helper.ReadString("Name");
                string           value     = helper.ReadString("Value");

                return(new UpdateModelValueCommand(modelGuid, name, value));
            }
예제 #19
0
파일: NoteModel.cs 프로젝트: Steell/Dynamo
        protected override void DeserializeCore(XmlElement nodeElement, SaveContext context)
        {
            var helper = new XmlElementHelper(nodeElement);

            GUID = helper.ReadGuid("guid", GUID);
            Text = helper.ReadString("text", "New Note");
            X    = helper.ReadDouble("x", 0.0);
            Y    = helper.ReadDouble("y", 0.0);
        }
예제 #20
0
            internal static MakeConnectionCommand DeserializeCore(XmlElement element)
            {
                XmlElementHelper helper = new XmlElementHelper(element);
                Guid             nodeId = helper.ReadGuid("NodeId");
                int      portIndex      = helper.ReadInteger("PortIndex");
                PortType portType       = ((PortType)helper.ReadInteger("Type"));
                Mode     mode           = ((Mode)helper.ReadInteger("ConnectionMode"));

                return(new MakeConnectionCommand(nodeId, portIndex, portType, mode));
            }
예제 #21
0
        protected override void DeserializeCore(XmlElement nodeElement, SaveContext context)
        {
            var helper = new XmlElementHelper(nodeElement);

            GUID = helper.ReadGuid("guid", GUID);
            Text = helper.ReadString("text", "New Note");
            X    = helper.ReadDouble("x", 0.0);
            Y    = helper.ReadDouble("y", 0.0);

            if (pinnedNode != null)
            {
                pinnedNode.GUID = helper.ReadGuid("pinnedNode");
            }

            // Notify listeners that the position of the note has changed,
            // then parent group will also redraw itself.
            ReportPosition();
            TryToSubscribeUndoNote();
        }
예제 #22
0
            internal static CreateNoteCommand DeserializeCore(XmlElement element)
            {
                XmlElementHelper helper   = new XmlElementHelper(element);
                Guid             nodeId   = helper.ReadGuid("NodeId");
                string           noteText = helper.ReadString("NoteText");
                double           x        = helper.ReadDouble("X");
                double           y        = helper.ReadDouble("Y");

                return(new CreateNoteCommand(nodeId, noteText, x, y,
                                             helper.ReadBoolean("DefaultPosition")));
            }
예제 #23
0
            internal static CreateCustomNodeCommand DeserializeCore(XmlElement element)
            {
                XmlElementHelper helper = new XmlElementHelper(element);

                return(new CreateCustomNodeCommand(
                           helper.ReadGuid("NodeId"),
                           helper.ReadString("Name"),
                           helper.ReadString("Category"),
                           helper.ReadString("Description"),
                           helper.ReadBoolean("MakeCurrent")));
            }
예제 #24
0
        protected override void DeserializeCore(XmlElement nodeElement, SaveContext context)
        {
            var helper = new XmlElementHelper(nodeElement);
            GUID = helper.ReadGuid("guid", GUID);
            Text = helper.ReadString("text", "New Note");
            X = helper.ReadDouble("x", 0.0);
            Y = helper.ReadDouble("y", 0.0);

            // Notify listeners that the position of the note has changed, 
            // then parent group will also redraw itself.
            ReportPosition();
        }
예제 #25
0
            internal static CreateNodeCommand DeserializeCore(XmlElement element)
            {
                XmlElementHelper helper = new XmlElementHelper(element);

                System.Guid nodeId   = helper.ReadGuid("NodeId");
                string      nodeName = helper.ReadString("NodeName");
                double      x        = helper.ReadDouble("X");
                double      y        = helper.ReadDouble("Y");

                return(new CreateNodeCommand(nodeId, nodeName, x, y,
                                             helper.ReadBoolean("DefaultPosition"),
                                             helper.ReadBoolean("TransformCoordinates")));
            }
예제 #26
0
        /// <summary>
        ///     Creates and initializes a ConnectorModel from its Xml representation.
        /// </summary>
        /// <param name="connEl">XmlElement for a ConnectorModel.</param>
        /// <param name="nodes">Dictionary to be used for looking up a NodeModel by it's Guid.</param>
        /// <returns>Returns the new instance of ConnectorModel loaded from XmlElement.</returns>
        public static ConnectorModel LoadConnectorFromXml(XmlElement connEl, IDictionary<Guid, NodeModel> nodes)
        {
            var helper = new XmlElementHelper(connEl);

            var guid = helper.ReadGuid("guid", Guid.NewGuid());
            var guidStart = helper.ReadGuid("start");
            var guidEnd = helper.ReadGuid("end");
            int startIndex = helper.ReadInteger("start_index");
            int endIndex = helper.ReadInteger("end_index");

            //find the elements to connect
            NodeModel start;
            if (nodes.TryGetValue(guidStart, out start))
            {
                NodeModel end;
                if (nodes.TryGetValue(guidEnd, out end))
                {
                    return ConnectorModel.Make(start, end, startIndex, endIndex, guid);
                }
            }

            return null;
        }
예제 #27
0
        protected override void DeserializeCore(XmlElement element, SaveContext context)
        {
            XmlElementHelper helper = new XmlElementHelper(element);

            this.GUID           = helper.ReadGuid("guid", this.GUID);
            this.annotationText = helper.ReadString("annotationText", Resources.GroupDefaultText);
            this.X               = helper.ReadDouble("left", DoubleValue);
            this.Y               = helper.ReadDouble("top", DoubleValue);
            this.width           = helper.ReadDouble("width", DoubleValue);
            this.height          = helper.ReadDouble("height", DoubleValue);
            this.background      = helper.ReadString("backgrouund", "");
            this.fontSize        = helper.ReadDouble("fontSize", fontSize);
            this.textBlockHeight = helper.ReadDouble("TextblockHeight", DoubleValue);
            this.InitialTop      = helper.ReadDouble("InitialTop", DoubleValue);
            this.InitialHeight   = helper.ReadDouble("InitialHeight", DoubleValue);
            //Deserialize Selected models
            if (element.HasChildNodes)
            {
                var listOfModels = new List <ModelBase>();
                if (Nodes != null)
                {
                    foreach (var childnode in element.ChildNodes)
                    {
                        var mhelper = new XmlElementHelper(childnode as XmlElement);
                        var result  = mhelper.ReadGuid("ModelGuid", new Guid());
                        var model   = ModelBaseRequested != null
                            ? ModelBaseRequested(result)
                            : Nodes.FirstOrDefault(x => x.GUID == result);

                        if (model != null)
                        {
                            listOfModels.Add(model);
                        }
                    }
                }

                Nodes = listOfModels;
            }

            //On any Undo Operation, current values are restored to previous values.
            //These properties should be Raised, so that they get the correct value on Undo.
            RaisePropertyChanged("Background");
            RaisePropertyChanged("FontSize");
            RaisePropertyChanged("AnnotationText");
            RaisePropertyChanged("Nodes");
        }
예제 #28
0
            internal static CreateNodeCommand DeserializeCore(XmlElement element)
            {
                var    helper          = new XmlElementHelper(element);
                double x               = helper.ReadDouble("X");
                double y               = helper.ReadDouble("Y");
                bool   defaultPos      = helper.ReadBoolean("DefaultPosition");
                bool   transformCoords = helper.ReadBoolean("TransformCoordinates");

                var nodeElement = element.ChildNodes.OfType <XmlElement>().FirstOrDefault();

                if (nodeElement == null)
                {
                    // Get the old NodeId and NodeName attributes
                    Guid   nodeId = helper.ReadGuid("NodeId");
                    string name   = helper.ReadString("NodeName");

                    return(new CreateNodeCommand(nodeId, name, x, y, defaultPos, transformCoords));
                }

                return(new CreateNodeCommand(nodeElement, x, y, defaultPos, transformCoords));
            }
예제 #29
0
 internal static ConvertNodesToCodeCommand DeserializeCore(XmlElement element)
 {
     XmlElementHelper helper = new XmlElementHelper(element);
     Guid nodeId = helper.ReadGuid("NodeId");
     return new ConvertNodesToCodeCommand(nodeId);
 }
예제 #30
0
 internal static UpdateModelValueCommand DeserializeCore(XmlElement element)
 {
     XmlElementHelper helper = new XmlElementHelper(element);
     Guid modelGuid = helper.ReadGuid("ModelGuid");
     string name = helper.ReadString("Name");
     string value = helper.ReadString("Value");
     return new UpdateModelValueCommand(modelGuid, name, value);
 }
예제 #31
0
 internal static ModelEventCommand DeserializeCore(XmlElement element)
 {
     XmlElementHelper helper = new XmlElementHelper(element);
     Guid modelGuid = helper.ReadGuid("ModelGuid");
     string eventName = helper.ReadString("EventName");
     return new ModelEventCommand(modelGuid, eventName);
 }
예제 #32
0
 internal static DeleteModelCommand DeserializeCore(XmlElement element)
 {
     XmlElementHelper helper = new XmlElementHelper(element);
     Guid modelGuid = helper.ReadGuid("ModelGuid");
     return new DeleteModelCommand(modelGuid);
 }
예제 #33
0
 internal static MakeConnectionCommand DeserializeCore(XmlElement element)
 {
     XmlElementHelper helper = new XmlElementHelper(element);
     Guid nodeId = helper.ReadGuid("NodeId");
     int portIndex = helper.ReadInteger("PortIndex");
     PortType portType = ((PortType)helper.ReadInteger("Type"));
     Mode mode = ((Mode)helper.ReadInteger("ConnectionMode"));
     return new MakeConnectionCommand(nodeId, portIndex, portType, mode);
 }
예제 #34
0
파일: NodeModel.cs 프로젝트: w-fish/Dynamo
        protected override void DeserializeCore(XmlElement nodeElement, SaveContext context)
        {
            var helper = new XmlElementHelper(nodeElement); 
            
            if (context != SaveContext.Copy)
                GUID = helper.ReadGuid("guid", GUID);

            // Resolve node nick name.
            string name = helper.ReadString("nickname", string.Empty);
            if (!string.IsNullOrEmpty(name))
                nickName = name;
            else
            {
                Type type = GetType();
                object[] attribs = type.GetCustomAttributes(typeof(NodeNameAttribute), true);
                var attrib = attribs[0] as NodeNameAttribute;
                if (null != attrib)
                    nickName = attrib.Name;
            }

            X = helper.ReadDouble("x", 0.0);
            Y = helper.ReadDouble("y", 0.0);
            isVisible = helper.ReadBoolean("isVisible", true);
            isUpstreamVisible = helper.ReadBoolean("isUpstreamVisible", true);
            argumentLacing = helper.ReadEnum("lacing", LacingStrategy.Disabled);

            var portInfoProcessed = new HashSet<int>();

            //read port information
            foreach (XmlNode subNode in nodeElement.ChildNodes)
            {
                if (subNode.Name == "PortInfo")
                {
                    int index = int.Parse(subNode.Attributes["index"].Value);
                    if (index < InPorts.Count)
                    {
                        portInfoProcessed.Add(index);
                        bool def = bool.Parse(subNode.Attributes["default"].Value);
                        inPorts[index].UsingDefaultValue = def;
                    }
                }
            }

            //set defaults
            foreach (
                var port in
                    inPorts.Select((x, i) => new { x, i }).Where(x => !portInfoProcessed.Contains(x.i)))
                port.x.UsingDefaultValue = false;

            if (context == SaveContext.Undo)
            {
                // Fix: MAGN-159 (nodes are not editable after undo/redo).
                //interactionEnabled = helper.ReadBoolean("interactionEnabled", true);
                state = helper.ReadEnum("nodeState", ElementState.Active);

                // We only notify property changes in an undo/redo operation. Normal
                // operations like file loading or copy-paste have the models created
                // in different ways and their views will always be up-to-date with 
                // respect to their models.
                RaisePropertyChanged("InteractionEnabled");
                RaisePropertyChanged("State");
                RaisePropertyChanged("NickName");
                RaisePropertyChanged("ArgumentLacing");
                RaisePropertyChanged("IsVisible");
                RaisePropertyChanged("IsUpstreamVisible");

                // Notify listeners that the position of the node has changed,
                // then all connected connectors will also redraw themselves.
                ReportPosition();
            }
        }
예제 #35
0
        protected override void DeserializeCore(XmlElement element, SaveContext context)
        {         
            XmlElementHelper helper = new XmlElementHelper(element);
            this.GUID = helper.ReadGuid("guid", this.GUID);
            this.annotationText = helper.ReadString("annotationText", Resources.GroupDefaultText);
            this.X = helper.ReadDouble("left", DoubleValue);
            this.Y = helper.ReadDouble("top", DoubleValue);
            this.width = helper.ReadDouble("width", DoubleValue);
            this.height = helper.ReadDouble("height", DoubleValue);
            this.background = helper.ReadString("backgrouund", "");
            this.fontSize = helper.ReadDouble("fontSize", fontSize);
            this.textBlockHeight = helper.ReadDouble("TextblockHeight", DoubleValue);
            this.InitialTop = helper.ReadDouble("InitialTop", DoubleValue);
            this.InitialHeight = helper.ReadDouble("InitialHeight", DoubleValue);
            //Deserialize Selected models
            if (element.HasChildNodes) 
            {
                var listOfModels = new List<ModelBase>();
                foreach (var childnode in element.ChildNodes)
                {
                    XmlElementHelper mhelper = new XmlElementHelper(childnode as XmlElement);
                     if (SelectedModels != null)
                     {
                         var result = mhelper.ReadGuid("ModelGuid", new Guid());
                         ModelBase model = null;
                         model = ModelBaseRequested != null ? ModelBaseRequested(result) : 
                             SelectedModels.FirstOrDefault(x => x.GUID == result);

                        listOfModels.Add(model);
                    }                  
                }
                SelectedModels = listOfModels;        
            }

            //On any Undo Operation, current values are restored to previous values.
            //These properties should be Raised, so that they get the correct value on Undo.
            RaisePropertyChanged("Background");
            RaisePropertyChanged("FontSize");
            RaisePropertyChanged("AnnotationText");
            RaisePropertyChanged("SelectedModels");
        }
예제 #36
0
            internal static CreateNodeCommand DeserializeCore(XmlElement element)
            {
                XmlElementHelper helper = new XmlElementHelper(element);
                Guid nodeId = helper.ReadGuid("NodeId");
                string nodeName = helper.ReadString("NodeName");
                double x = helper.ReadDouble("X");
                double y = helper.ReadDouble("Y");

                return new CreateNodeCommand(nodeId, nodeName, x, y,
                    helper.ReadBoolean("DefaultPosition"),
                    helper.ReadBoolean("TransformCoordinates"));
            }
예제 #37
0
        protected override void DeserializeCore(XmlElement element, SaveContext context)
        {
            XmlElementHelper helper = new XmlElementHelper(element);
            this.GUID = helper.ReadGuid("guid", Guid.NewGuid());

            // Resolve node nick name.
            string nickName = helper.ReadString("nickname", string.Empty);
            if (!string.IsNullOrEmpty(nickName))
                this.nickName = nickName;
            else
            {
                System.Type type = this.GetType();
                var attribs = type.GetCustomAttributes(typeof(NodeNameAttribute), true);
                NodeNameAttribute attrib = attribs[0] as NodeNameAttribute;
                if (null != attrib)
                    this.nickName = attrib.Name;
            }

            this.X = helper.ReadDouble("x", 0.0);
            this.Y = helper.ReadDouble("y", 0.0);
            this.isVisible = helper.ReadBoolean("isVisible", true);
            this.isUpstreamVisible = helper.ReadBoolean("isUpstreamVisible", true);
            this.argumentLacing = helper.ReadEnum("lacing", LacingStrategy.Disabled);

            if (context == SaveContext.Undo)
            {
                // Fix: MAGN-159 (nodes are not editable after undo/redo).
                interactionEnabled = helper.ReadBoolean("interactionEnabled", true);
                this.state = helper.ReadEnum("nodeState", ElementState.ACTIVE);

                // We only notify property changes in an undo/redo operation. Normal
                // operations like file loading or copy-paste have the models created
                // in different ways and their views will always be up-to-date with
                // respect to their models.
                RaisePropertyChanged("InteractionEnabled");
                RaisePropertyChanged("State");
                RaisePropertyChanged("NickName");
                RaisePropertyChanged("ArgumentLacing");
                RaisePropertyChanged("IsVisible");
                RaisePropertyChanged("IsUpstreamVisible");

                // Notify listeners that the position of the node has changed,
                // then all connected connectors will also redraw themselves.
                this.ReportPosition();
            }
        }
예제 #38
0
            protected static IEnumerable<Guid> DeserializeGuid(XmlElement element, XmlElementHelper helper)
            {
                // Deserialize old type of commands
                if (helper.HasAttribute("ModelGuid"))
                {
                    Guid modelGuid = helper.ReadGuid("ModelGuid", Guid.Empty);
                    return new[] { modelGuid };
                }

                if (helper.HasAttribute("NodeId"))
                {
                    Guid modelGuid = helper.ReadGuid("NodeId", Guid.Empty);
                    return new[] { modelGuid };
                }

                return (from XmlNode xmlNode in element.ChildNodes
                        where xmlNode.Name.Equals("ModelGuid")
                        select Guid.Parse(xmlNode.InnerText)).ToArray();
            }
예제 #39
0
        protected override void DeserializeCore(XmlElement element, SaveContext context)
        {
            XmlElementHelper helper = new XmlElementHelper(element);

            // Restore some information from the node attributes.
            this.GUID = helper.ReadGuid("guid", this.GUID);
            Guid startNodeId = helper.ReadGuid("start");
            int startIndex = helper.ReadInteger("start_index");
            Guid endNodeId = helper.ReadGuid("end");
            int endIndex = helper.ReadInteger("end_index");
            PortType portType = ((PortType)helper.ReadInteger("portType"));

            // Get to the start and end nodes that this connector connects to.
            WorkspaceModel workspace = dynSettings.Controller.DynamoModel.CurrentWorkspace;
            NodeModel startNode = workspace.GetModelInternal(startNodeId) as NodeModel;
            NodeModel endNode = workspace.GetModelInternal(endNodeId) as NodeModel;

            pStart = startNode.OutPorts[startIndex];
            PortModel endPort = null;
            if (portType == PortType.INPUT)
                endPort = endNode.InPorts[endIndex];

            pStart.Connect(this);
            this.Connect(endPort);
        }
예제 #40
0
            internal static ApplyPresetCommand DeserializeCore(XmlElement element)
            {
                var helper = new XmlElementHelper(element);

                return new ApplyPresetCommand(helper.ReadGuid("WorkspaceID"), helper.ReadGuid("StateID"));
            }
예제 #41
0
            internal static CreateCustomNodeCommand DeserializeCore(XmlElement element)
            {
                XmlElementHelper helper = new XmlElementHelper(element);

                return new CreateCustomNodeCommand(
                    helper.ReadGuid("NodeId"),
                    helper.ReadString("Name"),
                    helper.ReadString("Category"),
                    helper.ReadString("Description"),
                    helper.ReadBoolean("MakeCurrent"));
            }
예제 #42
0
            internal static CreateNoteCommand DeserializeCore(XmlElement element)
            {
                XmlElementHelper helper = new XmlElementHelper(element);
                Guid nodeId = helper.ReadGuid("NodeId");
                string noteText = helper.ReadString("NoteText");
                double x = helper.ReadDouble("X");
                double y = helper.ReadDouble("Y");

                return new CreateNoteCommand(nodeId, noteText, x, y,
                    helper.ReadBoolean("DefaultPosition"));
            }
예제 #43
0
        public ModelBase GetModelForElement(XmlElement modelData)
        {
            // TODO(Ben): This may or may not be true, but I guess we should be 
            // using "System.Type" (given the "type" information in "modelData"),
            // and determine the matching category (e.g. is this a Node, or a 
            // Connector?) instead of checking in each and every collections we
            // have in the workspace.
            // 
            // System.Type type = System.Type.GetType(helper.ReadString("type"));
            // if (typeof(Dynamo.Models.NodeModel).IsAssignableFrom(type))
            //     return Nodes.First((x) => (x.GUID == modelGuid));

            var helper = new XmlElementHelper(modelData);
            Guid modelGuid = helper.ReadGuid("guid");

            ModelBase foundModel = GetModelInternal(modelGuid);
            if (null != foundModel)
                return foundModel;

            throw new ArgumentException(
                string.Format("Unhandled model type: {0}", helper.ReadString("type", modelData.Name)));
        }
예제 #44
0
 internal static SelectModelCommand DeserializeCore(XmlElement element)
 {
     XmlElementHelper helper = new XmlElementHelper(element);
     Guid modelGuid = helper.ReadGuid("ModelGuid");
     ModifierKeys modifiers = ((ModifierKeys)helper.ReadInteger("Modifiers"));
     return new SelectModelCommand(modelGuid, modifiers);
 }
예제 #45
0
            internal static UpdateModelValueCommand DeserializeCore(XmlElement element)
            {
                var helper = new XmlElementHelper(element);
                string name = helper.ReadString("Name");
                string value = helper.ReadString("Value");

                Guid workspaceGuid = helper.ReadGuid("WorkspaceGuid", Guid.Empty);

                // TODO: once recordable framework serialize workspace's GUID,
                // we should use the GUID that read from file instead of using
                // empty GUID. Empty GUID means the command will be executed on
                // the current workspace, but it may not be the desired target
                // workspace.
                workspaceGuid = Guid.Empty;

                var modelGuids = DeserializeGuid(element, helper);

                return new UpdateModelValueCommand(workspaceGuid, modelGuids, name, value);
            }
예제 #46
0
        public void TestGuidAttributes()
        {
            XmlElement element = xmlDocument.CreateElement("element");

            // Test attribute writing.
            System.Guid guidValue = System.Guid.NewGuid();
            XmlElementHelper writer = new XmlElementHelper(element);
            writer.SetAttribute("ValidName", guidValue);

            // Test reading of existing attribute.
            XmlElementHelper reader = new XmlElementHelper(element);
            Assert.AreEqual(guidValue, reader.ReadGuid("ValidName"));

            // Test reading of non-existence attribute with default value.
            System.Guid defaultGuid = System.Guid.NewGuid();
            Assert.AreEqual(defaultGuid, reader.ReadGuid("InvalidName", defaultGuid));

            // Test reading of non-existence attribute without default value.
            Assert.Throws<InvalidOperationException>(() =>
            {
                reader.ReadGuid("InvalidName");
            });
        }