private static bool Equivalent(AttributePropertyDescriptor x, AttributePropertyDescriptor y)
        {
            if (!x.AttributeInfo.Equivalent(y.AttributeInfo))
            {
                return(false);
            }

            var descX = x as ChildAttributePropertyDescriptor;
            var descY = y as ChildAttributePropertyDescriptor;

            if (descX == null || descY == null)
            {
                return(false);
            }

            var xPath = descX.Path.ToArray();
            var yPath = descY.Path.ToArray();

            if (xPath.Length != yPath.Length)
            {
                return(false);
            }

            for (int i = 0; i < xPath.Length; i++)
            {
                if (!yPath[i].IsEquivalent(xPath[i]))
                {
                    return(false);
                }
            }
            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Adds OSC addresses (one for the x-coordinate and one for the y-coordinate) for a list
        /// of DOM children that have attributes that are arrays of floats. Each array of floats
        /// represents a 2D point where the first float is the x coordinate and the second float
        /// is the y coordinate.</summary>
        /// <param name="childInfo">The child info which defines the list of children of a selected DomNode</param>
        /// <param name="childAttributeDesc">The attribute on each child that defines the array of floats</param>
        /// <param name="oscAddress">The base OSC address to use. "/x" and "/y" will be appended for
        /// the x-coordinate array and the y-coordinate array, which is how Lemur sends and receives
        /// 2-D point arrays.</param>
        /// <returns>The base OSC address, with possible changes to make it legal.</returns>
        public string Add2DPointProperty(ChildInfo childInfo, AttributePropertyDescriptor childAttributeDesc, string oscAddress)
        {
            oscAddress = OscServices.FixPropertyAddress(oscAddress);

            var xCoordDesc = new ChildListFloatingPointArrayDesc(childInfo, childAttributeDesc, 0);
            AddPropertyAddress(xCoordDesc, oscAddress + "/x");

            var yCoordDesc = new ChildListFloatingPointArrayDesc(childInfo, childAttributeDesc, 1);
            AddPropertyAddress(yCoordDesc, oscAddress + "/y");

            return oscAddress;
        }
Ejemplo n.º 3
0
        public void TestEquality()
        {
            var attrType1 = new AttributeType("xkcd", typeof(string));
            var attrInfo1 = new AttributeInfo("xkcd", attrType1);
            attrInfo1.DefaultValue = "Firefly";
            var desc1 = new AttributePropertyDescriptor(
                "xkcd", attrInfo1, "Category 1", "A commonly used word or phrase in the xkcd comic", true);
            int originalHashCode = desc1.GetHashCode();

            // test if two identically created property descriptors compare as being equal
            var desc2 = new AttributePropertyDescriptor(
                "xkcd", attrInfo1, "Category 1", "A commonly used word or phrase in the xkcd comic", true);
            Assert.AreEqual(desc1, desc2);
            Assert.AreEqual(desc1.GetHashCode(), desc2.GetHashCode());

            // test category being different; oddly, although I think they should not be considered equal,
            //  the .Net PropertyDescriptor ignores the difference in category name. So, I'm guessing that
            //  the AttributePropertyDescriptor should behave the same as PropertyDescriptor.
            var desc3 = new AttributePropertyDescriptor(
                "xkcd", attrInfo1, "Category 2", "A commonly used word or phrase in the xkcd comic", true);
            Assert.AreEqual(desc1, desc3);
            Assert.AreEqual(desc1.GetHashCode(), desc3.GetHashCode());

            // test description being different; similarly here, the .Net PropertyDescriptor doesn't care.
            var desc4 = new AttributePropertyDescriptor(
                "xkcd", attrInfo1, "Category 1", "slightly different description", true);
            Assert.AreEqual(desc1, desc4);
            Assert.AreEqual(desc1.GetHashCode(), desc4.GetHashCode());

            // test readOnly being different; ditto for read-only flag!
            var desc5 = new AttributePropertyDescriptor(
                "xkcd", attrInfo1, "Category 1", "A commonly used word or phrase in the xkcd comic", false);
            Assert.AreEqual(desc1, desc5);
            Assert.AreEqual(desc1.GetHashCode(), desc5.GetHashCode());

            // test that the hash code hasn't changed after using the AttributeInfo
            var domNodeType = new DomNodeType("WebComic", DomNodeType.BaseOfAllTypes);
            var attrInfo2 = new AttributeInfo("xkcd", attrType1);
            domNodeType.Define(attrInfo2);
            Assert.AreEqual(desc1.GetHashCode(), originalHashCode);

            // test that the hash code hasn't changed after creating a derived DomNodeType
            var derivedDomNodeType = new DomNodeType("ScientificWebComic", domNodeType);
            var derivedAttrInfo = new AttributeInfo("xkcd", attrType1);
            derivedDomNodeType.Define(derivedAttrInfo);
            Assert.AreEqual(desc1.GetHashCode(), originalHashCode);

            // test that an AttributeInfo used in a derived DomNodeType doesn't change equality or hash code
            var desc6 = new AttributePropertyDescriptor(
                "xkcd", derivedAttrInfo, "Category 1", "A commonly used word or phrase in the xkcd comic", true);
            Assert.AreEqual(desc1, desc6);
            Assert.AreEqual(desc1.GetHashCode(), desc6.GetHashCode());
        }
Ejemplo n.º 4
0
        private static bool Equivalent(AttributePropertyDescriptor x, AttributePropertyDescriptor y)
        {
            if (!x.AttributeInfo.Equivalent(y.AttributeInfo))
                return false;

            var descX = x as ChildAttributePropertyDescriptor;
            var descY = y as ChildAttributePropertyDescriptor;

            if (descX == null || descY == null)
                return false;

            var xPath = descX.Path.ToArray();
            var yPath = descY.Path.ToArray();
            if (xPath.Length != yPath.Length)
                return false;

            for (int i = 0; i < xPath.Length; i++)
            {
                if (!yPath[i].IsEquivalent(xPath[i]))
                    return false;
            }
            return true;
        }
Ejemplo n.º 5
0
 // 'byteIndex' is 0 for the lowest byte (green), 1 for next lowest byte (blue),
 //  and 2 for the third byte (red).
 public ByteAttributePropertyDescriptor(AttributePropertyDescriptor original, byte byteIndex)
     : base(original.Name, original.AttributeInfo, original.Category, original.Description, original.IsReadOnly)
 {
     m_bitShift = byteIndex * 8;
 }
Ejemplo n.º 6
0
 public ChildListFloatingPointArrayDesc(ChildInfo childInfo, AttributePropertyDescriptor childAttributeDesc, int coordinateIndex)
     : base(
         childAttributeDesc.Name,
         childAttributeDesc.AttributeInfo,
         childInfo,
         childAttributeDesc.Category,
         childAttributeDesc.Description,
         childAttributeDesc.IsReadOnly,
         null, //editor
         childAttributeDesc.Converter)
 {
     m_childInfo = childInfo;
     m_childAttributeDesc = childAttributeDesc;
     m_coordinateIndex = coordinateIndex;
 }
Ejemplo n.º 7
0
        private static PropertyDescriptor GetDescriptor(
            DomNodeType type,
            XmlNode annotation,
            string name,
            string[] segments)
        {
            PropertyDescriptor desc = null;
            // Get mandatory display name
            XmlAttribute displayNameAttr = annotation.Attributes["displayName"];

            if (displayNameAttr != null)
            {
                if (string.IsNullOrEmpty(name))
                {
                    throw new AnnotationException(string.Format(
                                                      "Required name attribute is null or empty.\r\nType: {0}\r\nElement: {1}",
                                                      type.Name, annotation.Name));
                }

                string displayName = displayNameAttr.Value;
                if (string.IsNullOrEmpty(displayName))
                {
                    displayName = name;
                }

                // Get optional annotations
                string        category      = GetAnnotation(annotation, "category");
                string        description   = GetAnnotation(annotation, "description");
                bool          readOnly      = GetAnnotation(annotation, "readOnly") == "true";
                object        editor        = CreateObject <object>(type, annotation, "editor");
                TypeConverter typeConverter = CreateObject <TypeConverter>(type, annotation, "converter");

                if (annotation.Name == "scea.dom.editors.attribute")
                {
                    // Attribute annotation
                    if (segments == null)
                    {
                        throw new AnnotationException("Unnamed attribute");
                    }

                    if (segments.Length == 1) // local attribute
                    {
                        AttributeInfo metaAttr = type.GetAttributeInfo(name);
                        if (metaAttr == null)
                        {
                            throw new AnnotationException("Type doesn't have this attribute");
                        }

                        desc = new AttributePropertyDescriptor(
                            displayName, metaAttr,
                            category, description, readOnly, editor, typeConverter);
                    }
                    else // descendant attribute
                    {
                        ChildInfo[]   metaElements = GetPath(type, segments, segments.Length - 1);
                        DomNodeType   childType    = metaElements[segments.Length - 2].Type;
                        AttributeInfo metaAttr     = childType.GetAttributeInfo(segments[segments.Length - 1]);
                        if (metaAttr == null)
                        {
                            throw new AnnotationException("Descendant type doesn't have this attribute");
                        }

                        desc = new ChildAttributePropertyDescriptor(
                            displayName, metaAttr, metaElements,
                            category, description, readOnly, editor, typeConverter);
                    }
                }
                else if (annotation.Name == "scea.dom.editors.child")
                {
                    // Child value annotation
                    ChildInfo element = type.GetChildInfo(name);
                    if (element == null)
                    {
                        throw new AnnotationException("Type doesn't have this element");
                    }

                    desc = new ChildPropertyDescriptor(
                        displayName, element,
                        category, description, readOnly, editor, typeConverter);
                }
            }

            return(desc);
        }
Ejemplo n.º 8
0
        public void TestGetPropertyDescriptorKey()
        {
            // First use AttributePropertyDescriptor and MultiPropertyDescriptor
            {
                // Make sure that different property descriptor objects with the same Name, Category and Type
                //  have the same hash code, using PropertyUtils.GetPropertyDescriptorHash().
                var attrPropertyDescriptor = new AttributePropertyDescriptor(
                    "TestName", new AttributeInfo("TestAttrName", new AttributeType("TestAttrName", typeof(string))),
                    "TestCategory", "Test description", false);
                var multiPropertyDescriptor = new MultiPropertyDescriptor(attrPropertyDescriptor);
                Assert.IsTrue(IsSameHashKey(attrPropertyDescriptor, multiPropertyDescriptor));

                // Make sure that null Category names work, too.
                attrPropertyDescriptor = new AttributePropertyDescriptor(
                    "TestName", new AttributeInfo("TestAttrName", new AttributeType("TestAttrName", typeof(string))),
                    null, "Test description", false);
                multiPropertyDescriptor = new MultiPropertyDescriptor(attrPropertyDescriptor);
                Assert.IsTrue(IsSameHashKey(attrPropertyDescriptor, multiPropertyDescriptor));

                // Make sure that if the Name and Category and identical, that it works with other property
                //  descriptors who also have identical Name and Category strings. This makes sure that we
                //  are not using 'xor' between the Name and Category.
                attrPropertyDescriptor = new AttributePropertyDescriptor(
                    "SameName", new AttributeInfo("TestAttrName", new AttributeType("TestAttrName", typeof(string))),
                    "SameName", "Name and Category are the same!", false);
                multiPropertyDescriptor = new MultiPropertyDescriptor(attrPropertyDescriptor);
                Assert.IsTrue(IsSameHashKey(attrPropertyDescriptor, multiPropertyDescriptor));

                var d2 = new AttributePropertyDescriptor(
                    "AnotherSameName", new AttributeInfo("TestAttrName", new AttributeType("TestAttrName", typeof(string))),
                    "AnotherSameName", "Name and Category are the same!", false);
                var m2 = new MultiPropertyDescriptor(d2);
                Assert.IsTrue(IsSameHashKey(d2, m2));

                Assert.IsTrue(!IsSameHashKey(attrPropertyDescriptor, d2));

                // Make sure that if the Name and Category are swapped, that they yield different codes.
                attrPropertyDescriptor = new AttributePropertyDescriptor(
                    "Name1", new AttributeInfo("TestAttrName", new AttributeType("TestAttrName", typeof(string))),
                    "Name2", "Test description", false);
                d2 = new AttributePropertyDescriptor(
                    "Name2", new AttributeInfo("TestAttrName", new AttributeType("TestAttrName", typeof(string))),
                    "Name1", "Test description", false);
                Assert.IsTrue(!IsSameHashKey(attrPropertyDescriptor, d2));
            }

            // Now use a stub property descriptor and MultiPropertyDescriptor
            {
                // Make sure that different property descriptor objects with the same Name, Category and Type
                //  have the same hash code, using PropertyUtils.GetPropertyDescriptorHash().
                var stubPropertyDescriptor = new MyPropertyDescriptor("TestName", "TestCategory", typeof(string));
                var multiPropertyDescriptor = new MultiPropertyDescriptor(stubPropertyDescriptor);
                Assert.IsTrue(IsSameHashKey(stubPropertyDescriptor, multiPropertyDescriptor));

                // Make sure that null Category names work, too.
                stubPropertyDescriptor = new MyPropertyDescriptor("TestName", null, typeof(string));
                multiPropertyDescriptor = new MultiPropertyDescriptor(stubPropertyDescriptor);
                Assert.IsTrue(IsSameHashKey(stubPropertyDescriptor, multiPropertyDescriptor));

                // Make sure that if the Name and Category and identical, that it works with other property
                //  descriptors who also have identical Name and Category strings. This makes sure that we
                //  are not using 'xor' between the Name and Category.
                stubPropertyDescriptor = new MyPropertyDescriptor("SameName", "SameName", typeof(string));
                multiPropertyDescriptor = new MultiPropertyDescriptor(stubPropertyDescriptor);
                Assert.IsTrue(IsSameHashKey(stubPropertyDescriptor, multiPropertyDescriptor));

                var d2 = new MyPropertyDescriptor("AnotherSameName", "AnotherSameName", typeof(string));
                var m2 = new MultiPropertyDescriptor(d2);
                Assert.IsTrue(IsSameHashKey(d2, m2));

                Assert.IsTrue(!IsSameHashKey(stubPropertyDescriptor, d2));

                // Make sure that if the Name and Category are swapped, that they yield different codes.
                stubPropertyDescriptor = new MyPropertyDescriptor("Name1", "Name2", typeof(string));
                d2 = new MyPropertyDescriptor("Name2", "Name1", typeof(string));
                Assert.IsTrue(!IsSameHashKey(stubPropertyDescriptor, d2));
            }
        }