Example #1
0
        public void TestEnumAttributes()
        {
            XmlElement element = xmlDocument.CreateElement("element");

            // Test attribute writing.
            LacingStrategy   strategy = LacingStrategy.CrossProduct;
            XmlElementHelper writer   = new XmlElementHelper(element);

            writer.SetAttribute("ValidName", strategy.ToString());
            writer.SetAttribute("ValidName2", "UnknownEnumString");

            // Test reading of existing attributes (with valid/invalid values).
            XmlElementHelper reader = new XmlElementHelper(element);

            Assert.AreEqual(strategy, reader.ReadEnum("ValidName", LacingStrategy.Disabled));

            LacingStrategy defaultValue = LacingStrategy.First;

            Assert.AreEqual(defaultValue, reader.ReadEnum("ValidName2", defaultValue));
        }
Example #2
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();
            }
        }
Example #3
0
        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();
            }
        }
Example #4
0
        public void TestEnumAttributes()
        {
            XmlElement element = xmlDocument.CreateElement("element");

            // Test attribute writing.
            LacingStrategy strategy = LacingStrategy.CrossProduct;
            XmlElementHelper writer = new XmlElementHelper(element);
            writer.SetAttribute("ValidName", strategy.ToString());
            writer.SetAttribute("ValidName2", "UnknownEnumString");

            // Test reading of existing attributes (with valid/invalid values).
            XmlElementHelper reader = new XmlElementHelper(element);
            Assert.AreEqual(strategy, reader.ReadEnum("ValidName", LacingStrategy.Disabled));

            LacingStrategy defaultValue = LacingStrategy.First;
            Assert.AreEqual(defaultValue, reader.ReadEnum("ValidName2", defaultValue));
        }