Beispiel #1
0
        /// <summary>
        /// Constructor</summary>
        /// <param name="input">DomNode</param>
        /// <param name="mesh">Mesh</param>
        public PrimInput(DomNode input, Mesh mesh)
        {
            AttributeInfo srcAttrib = null;
            AttributeInfo offsetAttrib = null;
            AttributeInfo semantiAttrib = null;

            if (input.Type == Schema.InputLocalOffset.Type)
            {
                srcAttrib = Schema.InputLocalOffset.sourceAttribute;
                offsetAttrib = Schema.InputLocalOffset.offsetAttribute;
                semantiAttrib = Schema.InputLocalOffset.semanticAttribute;                
            }
            else if (input.Type == Schema.InputLocal.Type)
            {
                srcAttrib = Schema.InputLocal.sourceAttribute;                
                semantiAttrib = Schema.InputLocal.semanticAttribute;                
            }
            else
            {
                throw new ArgumentException(input.Type.ToString() + " is not supported");
            }


            // find the source for this input.
            string srcId = (string)input.GetAttribute(srcAttrib);
            srcId = srcId.Replace("#", "").Trim();

            foreach (Source src in mesh.Sources)
            {
                if (src.Id == srcId)
                {
                    m_source = src;
                    break;
                }
            }

            if (offsetAttrib != null)
                m_offset = Convert.ToInt32(input.GetAttribute(offsetAttrib));
            else
                m_offset = -1;

            m_semantic = (string)input.GetAttribute(semantiAttrib);

            switch (m_semantic)
            {
                case "POSITION":
                    m_atgiName = "position";
                    break;
                case "NORMAL":
                    m_atgiName = "normal";
                    break;
                case "TEXCOORD":
                    m_atgiName = "map1";
                    break;
                case "COLOR":
                    m_atgiName = "color";
                    break;
            }      

        }
Beispiel #2
0
        public void TestDuplicateAttributeInfo()
        {
            // This would be illegal in a schema file, but it seems to be supported OK in the DOM.
            var attr1   = new AttributeInfo("foo", new AttributeType("foo", typeof(string)));
            var attr2   = new AttributeInfo("foo", new AttributeType("foo", typeof(string)));
            var domType = new DomNodeType(
                "test",
                null,
                new AttributeInfo[] { attr1, attr2 },
                EmptyEnumerable <ChildInfo> .Instance,
                EmptyEnumerable <ExtensionInfo> .Instance);

            var domNode = new DomNode(domType);

            var originalAttr1 = "setting attr1";
            var originalAttr2 = "setting attr2";

            domNode.SetAttribute(attr1, originalAttr1);
            domNode.SetAttribute(attr2, originalAttr2);

            string resultAttr1 = (string)domNode.GetAttribute(attr1);
            string resultAttr2 = (string)domNode.GetAttribute(attr2);

            Assert.IsTrue(string.Equals(resultAttr1, originalAttr1));
            Assert.IsTrue(string.Equals(resultAttr2, originalAttr2));
        }
Beispiel #3
0
        public void TestDefaultValue()
        {
            AttributeType type = new AttributeType("test", typeof(string));
            AttributeInfo test = new AttributeInfo("test", type);
            test.DefaultValue = "foo";
            Assert.AreEqual(test.DefaultValue, "foo");
            test.DefaultValue = null;
            Assert.AreEqual(test.DefaultValue, type.GetDefault());
            Assert.Throws<InvalidOperationException>(delegate { test.DefaultValue = 1; });

            AttributeType length2Type = new AttributeType("length2Type", typeof(int[]), 2);
            AttributeInfo length2Info = new AttributeInfo("length2", length2Type);
            Assert.AreEqual(length2Info.DefaultValue, length2Type.GetDefault());
            Assert.AreEqual(length2Info.DefaultValue, new int[] { default(int), default(int) });
            DomNodeType nodeType = new DomNodeType("testNodeType");
            nodeType.Define(length2Info);
            DomNode node = new DomNode(nodeType);
            Assert.AreEqual(node.GetAttribute(length2Info), length2Info.DefaultValue);
            node.SetAttribute(length2Info, new int[] { 1, 2 });
            Assert.AreEqual(node.GetAttribute(length2Info), new int[] { 1, 2 });
            node.SetAttribute(length2Info, new int[] { 1 });
            Assert.AreEqual(node.GetAttribute(length2Info), new int[] { 1 });

            AttributeType length1Type = new AttributeType("length1Type", typeof(int[]), 1);
            AttributeInfo length1Info = new AttributeInfo("length1", length1Type);
            Assert.AreEqual(length1Info.DefaultValue, length1Type.GetDefault());
            Assert.AreEqual(length1Info.DefaultValue, new int[] { default(int) });
            nodeType = new DomNodeType("testNodeType");
            nodeType.Define(length1Info);
            node = new DomNode(nodeType);
            Assert.AreEqual(node.GetAttribute(length1Info), length1Info.DefaultValue);
            node.SetAttribute(length1Info, new int[] { 1 });
            Assert.AreEqual(node.GetAttribute(length1Info), new int[] { 1 });
        }
Beispiel #4
0
        public void TestGetAttribute()
        {
            DomNodeType   type = new DomNodeType("child");
            AttributeInfo info = GetIntAttribute("int");

            type.Define(info);
            DomNode test = new DomNode(type);

            Assert.True(test.IsAttributeDefault(info));
            Assert.Null(test.GetLocalAttribute(info));
            Assert.False(test.IsAttributeSet(info));

            test.SetAttribute(info, 2);
            Assert.AreEqual(test.GetAttribute(info), 2);
            Assert.AreEqual(test.GetLocalAttribute(info), 2);
            Assert.False(test.IsAttributeDefault(info));
            Assert.True(test.IsAttributeSet(info));

            test.SetAttribute(info, null);
            Assert.True(test.IsAttributeDefault(info));
            Assert.Null(test.GetLocalAttribute(info));
            Assert.False(test.IsAttributeSet(info));

            test.SetAttribute(info, 0);
            Assert.AreEqual(test.GetAttribute(info), 0);
            Assert.True(test.IsAttributeDefault(info));
            Assert.AreEqual(test.GetLocalAttribute(info), 0);
            Assert.True(test.IsAttributeSet(info));
        }
Beispiel #5
0
        /// <summary>
        /// Performs initialization when the adapter's node is set.
        /// This method is called each time the adapter is connected to its underlying node.
        /// Typically overridden by creators of DOM adapters.</summary>
        protected override void OnNodeSet()
        {
            base.OnNodeSet();

            Geometry         = DomNode.GetAttribute(Schema.instance_geometry.urlAttribute).As <Geometry>();
            Geometry.Effects = Tools.CreateEffectDictionary(GetChild <DomNode>(Schema.instance_geometry.bind_materialChild));
        }
Beispiel #6
0
        /// <summary>
        /// Creates effects dictionary</summary>
        /// <param name="bindMtrl">Bind material DomNode</param>
        /// <returns>Effects dictionary of string/Effect pairs</returns>
        public static Dictionary <string, Effect> CreateEffectDictionary(DomNode bindMtrl)
        {
            if (bindMtrl == null)
            {
                return(null);
            }

            var result = new Dictionary <string, Effect>();

            DomNode techCommon = bindMtrl.GetChild(Schema.bind_material.technique_commonChild);

            IList <DomNode> instMtrls = techCommon.GetChildList(Schema.bind_material_technique_common.instance_materialChild);

            foreach (DomNode instMtrl in instMtrls)
            {
                DomNode material   = instMtrl.GetAttribute(Schema.instance_material.targetAttribute).As <DomNode>();
                DomNode instEffect = material.GetChild(Schema.material.instance_effectChild);
                Effect  effect     = instEffect.GetAttribute(Schema.instance_effect.urlAttribute).As <Effect>();

                string symbol = instMtrl.GetAttribute(Schema.instance_material.symbolAttribute) as string;
                if (!String.IsNullOrEmpty(symbol))
                {
                    result.Add(symbol, effect);
                }
            }

            return((result.Count > 0) ? result : null);
        }
Beispiel #7
0
        /// <summary>
        /// When overridden in a derived class, returns whether resetting an object changes its value</summary>
        /// <param name="component">The component to test for reset capability</param>
        /// <returns>True iff resetting the component changes its value</returns>
        public override bool CanResetValue(object component)
        {
            if (IsReadOnly)
            {
                return(false);
            }

            DomNode domNode = GetNode(component);

            if (domNode != null)
            {
                for (int i = 0; i < m_attributeInfos.Length; ++i)
                {
                    AttributeInfo attributeInfo  = m_attributeInfos[i];
                    object        attributeValue = domNode.GetAttribute(attributeInfo);
                    if (m_defaultValues != null && m_defaultValues.Length > i)
                    {
                        if (attributeValue != m_defaultValues[i])
                        {
                            return(true);
                        }
                    }
                    else if (attributeValue != attributeInfo.DefaultValue)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Beispiel #8
0
            private void ProcessSetterType(DomNode setter, string parentPropName,
                                           List <System.ComponentModel.PropertyDescriptor> descriptors)
            {
                string curPropName = (string)setter.GetAttribute(SkinSchema.setterType.propertyNameAttribute);

                if (string.IsNullOrWhiteSpace(curPropName))
                {
                    return;
                }
                string propName = !string.IsNullOrEmpty(parentPropName)
                    ? parentPropName + "->" + curPropName : curPropName;

                DomNode valInfo = setter.GetChild(SkinSchema.setterType.valueInfoChild);

                if (valInfo != null)
                {
                    ProcessValueInfo(valInfo, propName, descriptors);
                }

                DomNode listInfo = setter.GetChild(SkinSchema.setterType.listInfoChild);

                if (listInfo != null)
                {
                    foreach (var vInfo in listInfo.GetChildList(SkinSchema.listInfoType.valueInfoChild))
                    {
                        ProcessValueInfo(vInfo, propName, descriptors);
                    }
                }
            }
Beispiel #9
0
        protected override string Convert(DomNode node, AttributeInfo attributeInfo)
        {
            string valueString = string.Empty;
            object value       = node.GetAttribute(attributeInfo);

            if (value == null)
            {
                return(valueString);
            }

            if (attributeInfo.Type.Type == AttributeTypes.Uri)
            {
                var ur = (Uri)value;
                if (ur.IsAbsoluteUri)
                {
                    ur          = _documentRoot.MakeRelativeUri(ur);
                    ur          = new Uri(Uri.UnescapeDataString(ur.ToString()), UriKind.Relative);
                    valueString = ur.ToString();
                }
            }
            else
            {
                valueString = attributeInfo.Type.Convert(value);
            }

            return(valueString);
        }
Beispiel #10
0
        private static void WriteResource(DomNode resourceNode, StreamWriter writer)
        {
            StringBuilder lineBuilder = new StringBuilder(string.Format(
                                                              "resource type=\"{0}\", name=\"{1}\"",
                                                              resourceNode.Type.Name,
                                                              resourceNode.GetAttribute(DomTypes.resourceType.nameAttribute)));

            WriteAttribute(resourceNode, "size", lineBuilder);
            WriteAttribute(resourceNode, "compressed", lineBuilder);

            if (resourceNode.Type == DomTypes.geometryResourceType.Type)
            {
                WriteAttribute(resourceNode, "bones", lineBuilder);
                WriteAttribute(resourceNode, "vertices", lineBuilder);
                WriteAttribute(resourceNode, "primitiveType", lineBuilder);
            }
            else if (resourceNode.Type == DomTypes.animationResourceType.Type)
            {
                WriteAttribute(resourceNode, "tracks", lineBuilder);
                WriteAttribute(resourceNode, "duration", lineBuilder);
            }
            else
            {
                throw new InvalidOperationException("unknown resource type");
            }

            writer.WriteLine(lineBuilder.ToString());
        }
Beispiel #11
0
            public static LightingInfo TryCreate(DomNode domNode)
            {
                AttributeInfo diffuseInfo  = domNode.Type.GetAttributeInfo("diffuse");
                AttributeInfo ambientInfo  = domNode.Type.GetAttributeInfo("ambient");
                AttributeInfo specularInfo = domNode.Type.GetAttributeInfo("specular");

                if (diffuseInfo != null &&
                    ambientInfo != null &&
                    specularInfo != null)
                {
                    return(new LightingInfo(
                               Color.FromArgb((int)domNode.GetAttribute(ambientInfo)),
                               Color.FromArgb((int)domNode.GetAttribute(specularInfo)),
                               Color.FromArgb((int)domNode.GetAttribute(diffuseInfo))));
                }
                return(null);
            }
Beispiel #12
0
        /// <summary>
        /// Performs initialization when the adapter's node is set.
        /// This method is called each time the adapter is connected to its underlying node.
        /// Typically overridden by creators of DOM adapters.</summary>
        protected override void OnNodeSet()
        {
            base.OnNodeSet();

            DomNode instanceVisualScene = GetChild <DomNode>(Schema.COLLADA_scene.instance_visual_sceneChild);

            m_visualScene = instanceVisualScene.GetAttribute(Schema.InstanceWithExtra.urlAttribute).As <VisualScene>();
        }
Beispiel #13
0
 public void _CheckNodeName(DomNode node)
 {
     if (bitBoxSchema.nodeType.Type.IsAssignableFrom(node.Type))
     {
         string name    = (string)node.GetAttribute(bitBoxSchema.nodeType.nameAttribute);
         string newName = m_uniqueNamer.Name(name);
         node.SetAttribute(bitBoxSchema.nodeType.nameAttribute, newName);
     }
 }
Beispiel #14
0
        /// <summary>
        /// Returns a string that represents the event</summary>
        /// <returns>String that represents the event</returns>
        /// <remarks>Implemented for tooltip support in TimelineControl</remarks>
        public override string ToString()
        {
            string result = DomNode.GetAttribute(Schema.eventType.descriptionAttribute).ToString();

            if (result == string.Empty)
            {
                result = Name;
            }
            return(result);
        }
Beispiel #15
0
 /// <summary>
 /// Gets the DomNode attribute as a Sphere3F</summary>
 /// <param name="domNode">DomNode holding value</param>
 /// <param name="attribute">Attribute of the DomNode that contains the data</param>
 /// <returns>DomNode attribute as a Sphere3F</returns>
 public static Sphere3F GetSphere(DomNode domNode, AttributeInfo attribute)
 {
     Sphere3F s = new Sphere3F();
     float[] value = domNode.GetAttribute(attribute) as float[];
     if (value != null)
     {
         s.Center = new Vec3F(value[0], value[1], value[2]);
         s.Radius = value[3];
     }
     return s;
 }
Beispiel #16
0
 protected override void WriteChildElementsRecursive(DomNode node, XmlWriter writer)
 {
     // Filter out external template file references that should not be in-lined
     if (node.Is<TemplateFolder>())
     {
         var pathUri = node.GetAttribute(Schema.templateFolderType.referenceFileAttribute) as Uri;
         if (pathUri != null)
             return;
     }
     base.WriteChildElementsRecursive(node, writer);
 }
        /// <summary>
        /// Performs initialization when the adapter's node is set.
        /// This method is called each time the adapter is connected to its underlying node.
        /// Typically overridden by creators of DOM adapters.</summary>
        protected override void OnNodeSet()
        {
            base.OnNodeSet();

            DomNode controller = DomNode.GetAttribute(Schema.instance_controller.urlAttribute).As <DomNode>();
            DomNode skin       = controller.GetChild(Schema.controller.skinChild);

            Geometry = skin.GetAttribute(Schema.skin.sourceAttribute).As <Geometry>();

            Geometry.Effects = Tools.CreateEffectDictionary(GetChild <DomNode>(Schema.instance_controller.bind_materialChild));
        }
Beispiel #18
0
            private void ProcessValueInfo(DomNode valInfo, string propName,
                                          List <System.ComponentModel.PropertyDescriptor> descriptors)
            {
                string typeName = (string)valInfo.GetAttribute(SkinSchema.valueInfoType.typeAttribute);
                Type   type     = SkinUtil.GetType(typeName);


                if (type == typeof(Font))
                {
                    FontDescriptor descr
                        = new FontDescriptor(valInfo, propName, null, null, null, null);
                    descriptors.Add(descr);
                }
                else
                {
                    TypeConverter converter;
                    object        editor;
                    GetEditorAndConverter(type, out editor, out converter);
                    if (editor != null)
                    {
                        var descr = new SkinSetterAttributePropertyDescriptor(valInfo
                                                                              , propName, SkinSchema.valueInfoType.valueAttribute, null, null, false, editor, converter);
                        descriptors.Add(descr);
                    }
                    else
                    {
                        DomNode ctorParams = valInfo.GetChild(SkinSchema.valueInfoType.constructorParamsChild);
                        if (ctorParams != null)
                        {
                            var vInfoChildList = ctorParams.GetChildList(SkinSchema.constructorParamsType.valueInfoChild);
                            if (vInfoChildList.Count == 1)
                            {
                                ProcessValueInfo(vInfoChildList[0], propName, descriptors);
                            }
                            else
                            {
                                int    k         = 1;
                                string paramName = propName + " : Arg_";
                                foreach (DomNode vInfoChild in vInfoChildList)
                                {
                                    string name = paramName + k;
                                    ProcessValueInfo(vInfoChild, name, descriptors);
                                    k++;
                                }
                            }
                        }

                        foreach (DomNode setterChild in valInfo.GetChildList(SkinSchema.valueInfoType.setterChild))
                        {
                            ProcessSetterType(setterChild, propName, descriptors);
                        }
                    }
                }
            }
Beispiel #19
0
 protected override void WriteChildElementsRecursive(DomNode node, XmlWriter writer)
 {
     // Filter out external template file references that should not be in-lined
     if (node.Is<TemplateFolder>())
     {
         var pathUri = node.GetAttribute(Schema.templateFolderType.referenceFileAttribute) as Uri;
         if (pathUri != null)
             return;
     }
     base.WriteChildElementsRecursive(node, writer);
 }
Beispiel #20
0
        /// <summary>
        /// Gets the DomNode attribute as a Vec3F and returns true, or returns false if the attribute
        /// doesn't exist</summary>
        /// <param name="domNode">DomNode holding the attribute</param>
        /// <param name="attribute">Attribute of the DomNode that contains the data</param>
        /// <param name="result">The resulting Vec3F. Is (0,0,0) if the attribute couldn't be found</param>
        /// <returns>True iff the attribute was found and was converted to a Vec3F</returns>
        public static bool GetVector(DomNode domNode, AttributeInfo attribute, out Vec3F result)
        {
            float[] floats = domNode.GetAttribute(attribute) as float[];
            if (floats != null)
            {
                result = new Vec3F(floats);
                return true;
            }

            result = new Vec3F();
            return false;
        }
Beispiel #21
0
		protected override string Convert(DomNode node, AttributeInfo attributeInfo)
		{
			object value = node.GetAttribute(attributeInfo);
			if (attributeInfo.Type.Type == AttributeTypes.Reference && attributeInfo.Name == "guidRef")
			{
				// guidRef refers a template whose guid value should be persisted
				var templateNode = value as DomNode;
				return templateNode.GetAttribute(Schema.templateType.guidAttribute) as string;
			}

			return base.Convert(node, attributeInfo);
		}
Beispiel #22
0
        /// <summary>
        /// Gets the DomNode that is referenced by this attribute, adapted to type T</summary>
        /// <typeparam name="T">The class to adapt the referenced DomNode to</typeparam>
        /// <param name="attributeInfo">The attribute metadata of the adapted DomNode to look for</param>
        /// <returns>If the given attribute metadata defines a reference to a DomNode, that DomNode
        /// is adapted to type T and the result is returned. Otherwise, null is returned.</returns>
        protected T GetReference <T>(AttributeInfo attributeInfo)
            where T : class
        {
            DomNode refNode = DomNode.GetAttribute(attributeInfo) as DomNode;

            if (refNode != null)
            {
                return(refNode.As <T>());
            }

            return(null);
        }
        /// <summary>
        /// When overridden in a derived class, gets the result value of the property on a component</summary>
        /// <param name="component">The component with the property for which to retrieve the value</param>
        /// <returns>The value of a property for a given component.</returns>
        public override object GetValue(object component)
        {
            object  value = null;
            DomNode node  = GetNode(component);

            if (node != null)
            {
                value = node.GetAttribute(m_attributeInfo);
            }

            return(value);
        }
        /// <summary>
        /// Gets the DomNode attribute as a Sphere3F</summary>
        /// <param name="domNode">DomNode holding value</param>
        /// <param name="attribute">Attribute of the DomNode that contains the data</param>
        /// <returns>DomNode attribute as a Sphere3F</returns>
        public static Sphere3F GetSphere(DomNode domNode, AttributeInfo attribute)
        {
            Sphere3F s = new Sphere3F();

            float[] value = domNode.GetAttribute(attribute) as float[];
            if (value != null)
            {
                s.Center = new Vec3F(value[0], value[1], value[2]);
                s.Radius = value[3];
            }
            return(s);
        }
        /// <summary>
        /// Gets the DomNode attribute as a Vec3F and returns true, or returns false if the attribute
        /// doesn't exist</summary>
        /// <param name="domNode">DomNode holding the attribute</param>
        /// <param name="attribute">Attribute of the DomNode that contains the data</param>
        /// <param name="result">The resulting Vec3F. Is (0,0,0) if the attribute couldn't be found</param>
        /// <returns>True iff the attribute was found and was converted to a Vec3F</returns>
        public static bool GetVector(DomNode domNode, AttributeInfo attribute, out Vec3F result)
        {
            float[] floats = domNode.GetAttribute(attribute) as float[];
            if (floats != null)
            {
                result = new Vec3F(floats);
                return(true);
            }

            result = new Vec3F();
            return(false);
        }
Beispiel #26
0
 private void PrintDomNode(DomNode node)
 {
     Console.WriteLine(node.Type.Name);
     foreach (AttributeInfo attr in node.Type.Attributes)
     {
         Console.WriteLine("\t{0}: {1}", attr.Name, node.GetAttribute(attr));
     }
     foreach (DomNode child in node.Children)
     {
         PrintDomNode(child);
     }
 }
Beispiel #27
0
		protected override string Convert(DomNode node, AttributeInfo attributeInfo)
		{
			object value = node.GetAttribute(attributeInfo);
			if (attributeInfo.Type.Type == AttributeTypes.Reference && attributeInfo.Name == "guidRef")
			{
				// guidRef refers a template whose guid value should be persisted
				var templateNode = value as DomNode;
				return templateNode.GetAttribute(Schema.templateType.guidAttribute) as string;
			}

			return base.Convert(node, attributeInfo);
		}
 /// <summary>
 /// Gets the DomNode attribute as a Box</summary>
 /// <param name="domNode">DomNode holding value</param>
 /// <param name="attribute">Attribute of the DomNode that contains the data</param>
 /// <returns>DomNode attribute value as a Box</returns>
 public static Box GetBox(DomNode domNode, AttributeInfo attribute)
 {
     float[] value = domNode.GetAttribute(attribute) as float[];
     if (value != null)
     {
         return(new Box(new Vec3F(value[0], value[1], value[2]),
                        new Vec3F(value[3], value[4], value[5])));
     }
     else
     {
         return(new Box());
     }
 }
Beispiel #29
0
        public void TestDefaultValue()
        {
            AttributeType type = new AttributeType("test", typeof(string));
            AttributeInfo test = new AttributeInfo("test", type);

            test.DefaultValue = "foo";
            Assert.AreEqual(test.DefaultValue, "foo");
            test.DefaultValue = null;
            Assert.AreEqual(test.DefaultValue, type.GetDefault());
            Assert.Throws <InvalidOperationException>(delegate { test.DefaultValue = 1; });

            AttributeType length2Type = new AttributeType("length2Type", typeof(int[]), 2);
            AttributeInfo length2Info = new AttributeInfo("length2", length2Type);

            Assert.AreEqual(length2Info.DefaultValue, length2Type.GetDefault());
            Assert.AreEqual(length2Info.DefaultValue, new int[] { default(int), default(int) });
            DomNodeType nodeType = new DomNodeType("testNodeType");

            nodeType.Define(length2Info);
            DomNode node = new DomNode(nodeType);

            Assert.AreEqual(node.GetAttribute(length2Info), length2Info.DefaultValue);
            node.SetAttribute(length2Info, new int[] { 1, 2 });
            Assert.AreEqual(node.GetAttribute(length2Info), new int[] { 1, 2 });
            node.SetAttribute(length2Info, new int[] { 1 });
            Assert.AreEqual(node.GetAttribute(length2Info), new int[] { 1 });

            AttributeType length1Type = new AttributeType("length1Type", typeof(int[]), 1);
            AttributeInfo length1Info = new AttributeInfo("length1", length1Type);

            Assert.AreEqual(length1Info.DefaultValue, length1Type.GetDefault());
            Assert.AreEqual(length1Info.DefaultValue, new int[] { default(int) });
            nodeType = new DomNodeType("testNodeType");
            nodeType.Define(length1Info);
            node = new DomNode(nodeType);
            Assert.AreEqual(node.GetAttribute(length1Info), length1Info.DefaultValue);
            node.SetAttribute(length1Info, new int[] { 1 });
            Assert.AreEqual(node.GetAttribute(length1Info), new int[] { 1 });
        }
Beispiel #30
0
        private static void WriteEvent(DomNode eventNode, StreamWriter writer)
        {
            StringBuilder lineBuilder = new StringBuilder(
                "event name=\"" + eventNode.GetAttribute(DomTypes.eventType.nameAttribute) + "\"");

            WriteAttribute(eventNode, "time", lineBuilder);
            WriteAttribute(eventNode, "duration", lineBuilder);
            writer.WriteLine(lineBuilder.ToString());

            foreach (DomNode resourceNode in eventNode.GetChildren(DomTypes.eventType.resourceChild))
            {
                WriteResource(resourceNode, writer);
            }
        }
Beispiel #31
0
        /// <summary>
        /// Returns DomNode's color components in array</summary>
        /// <param name="domNode">DomNode whose color is obtained</param>
        /// <returns>Array of DomNode's color components</returns>
        public static float[] GetColor(DomNode domNode)
        {
            float[] value = null;
            if (domNode != null)
            {
                DomNode color = domNode.GetChild(Schema.common_color_or_texture_type.colorChild);
                if (color != null)
                {
                    value = DoubleToFloat(color.GetAttribute(Schema.common_color_or_texture_type_color.Attribute) as double[]);
                }
            }

            return(value);
        }
Beispiel #32
0
        public void GetInfo(object item, ItemInfo info)
        {
            info.IsLeaf = !HasChildren(item);

            DomNode node = item as DomNode;

            if (node != null)
            {
                AttributeInfo attrInfo = node.Type.GetAttributeInfo("name");
                if (attrInfo != null)
                {
                    info.Label = (string)node.GetAttribute(attrInfo);
                }
            }
        }
Beispiel #33
0
        /// <summary>
        /// Gets float value associated with DomNode</summary>
        /// <param name="domNode">DomNode whose value is obtained</param>
        /// <returns>Float value associated with DomNode</returns>
        public static float GetFloat(DomNode domNode)
        {
            float value = default(float);

            if (domNode != null)
            {
                DomNode floatChild = domNode.GetChild(Schema.common_float_or_param_type.floatChild);
                if (floatChild != null)
                {
                    double v = (double)floatChild.GetAttribute(Schema.common_float_or_param_type_float.Attribute);
                    value = (float)v;
                }
            }
            return(value);
        }
Beispiel #34
0
            void IItemView.GetInfo(object item, ItemInfo info)
            {
                DomNode node = item.Cast <DomNode>();

                info.IsLeaf = true;

                if (node.Type.Equals(SkinSchema.styleType.Type))
                {
                    info.Label = (string)node.GetAttribute(SkinSchema.styleType.nameAttribute);
                }
                else
                {
                    info.Label = node.Type.Name;
                }
            }
Beispiel #35
0
        /// <summary>
        /// Converts attribute to string.
        /// WriteAttributes(..) call this method to convert dom attribute to string
        /// before writing.
        /// </summary>
        /// <param name="node">DomNode that owns the attribute to be converted</param>
        /// <param name="attributeInfo">The attribute that need to be converted</param>
        /// <returns>the string value of the attribute</returns>
        protected override string Convert(DomNode node, AttributeInfo attributeInfo)
        {
            // if attribute is uri, then convert it to relative if it is absolute.

            string valueString = string.Empty;
            object value       = node.GetAttribute(attributeInfo);

            if (value == null)
            {
                return(valueString);
            }

            if (attributeInfo.Type.Type == AttributeTypes.Reference)
            {
                // if reference is a valid node, convert to string
                DomNode refNode = value as DomNode;
                if (refNode != null)
                {
                    valueString = GetNodeReferenceString(refNode, Root, Uri);
                }
            }
            else if (attributeInfo.Type.Type == AttributeTypes.Uri)
            {
                Uri ur = (Uri)value;
                if (ur.IsAbsoluteUri)
                {
                    // todo use schema annotation to choose between resource root and this uri
                    if (node.Type == Schema.gameReferenceType.Type ||
                        node.Type == Schema.gameObjectReferenceType.Type)
                    {// use this Uri to make it relative.
                        ur = Uri.MakeRelativeUri(ur);
                    }
                    else
                    {// use resource root to make it relative
                        ur = m_resourceRoot.MakeRelativeUri(ur);
                    }

                    ur          = new Uri(Uri.UnescapeDataString(ur.ToString()), UriKind.Relative);
                    valueString = ur.ToString();
                }
            }
            else
            {
                valueString = attributeInfo.Type.Convert(value);
            }

            return(valueString);
        }
Beispiel #36
0
        /// <summary>
        /// Gets the value of this attribute, cast to type T</summary>
        /// <typeparam name="T">Attribute type</typeparam>
        /// <param name="attributeInfo">The attribute metadata of the adapted DomNode to look for</param>
        /// <returns>The value of the attribute or null (if T is a reference type) or
        /// the default value of type T (if T is a value type)</returns>
        protected T GetAttribute <T>(AttributeInfo attributeInfo)
        {
            object value = DomNode.GetAttribute(attributeInfo);

            // if value is not null, attempt the cast; an invalid type will then cause
            //  an IllegalCastException; all value type attributes have a default
            //  value, so will return here
            if (value != null)
            {
                return((T)value);
            }

            // value is null, so it must be a reference type attribute (Uri or DomNode value)
            //  return null
            return(default(T));
        }
        /// <summary>
        /// Converts attribute to string.
        /// WriteAttributes(..) call this method to convert dom attribute to string
        /// before writing.        
        /// </summary>
        /// <param name="node">DomNode that owns the attribute to be converted</param>
        /// <param name="attributeInfo">The attribute that need to be converted</param>
        /// <returns>the string value of the attribute</returns>
        protected override string Convert(DomNode node, AttributeInfo attributeInfo)
        {
            // if attribute is uri, then convert it to relative if it is absolute.

            string valueString = string.Empty;
            object value = node.GetAttribute(attributeInfo);
            if (value == null) return valueString;

            if (attributeInfo.Type.Type == AttributeTypes.Reference)
            {
                // if reference is a valid node, convert to string
                DomNode refNode = value as DomNode;
                if (refNode != null)
                    valueString = GetNodeReferenceString(refNode, Root, Uri);
            }
            else if (attributeInfo.Type.Type == AttributeTypes.Uri)
            {
                Uri ur = (Uri)value;
                if (ur.IsAbsoluteUri)
                {
                    // todo use schema annotation to choose between resource root and this uri                    
                    if (node.Type == Schema.gameReferenceType.Type
                        || node.Type == Schema.gameObjectReferenceType.Type)
                    {// use this Uri to make it relative.
                        ur = Uri.MakeRelativeUri(ur);
                    }
                    else
                    {// use resource root to make it relative
                        ur = m_resourceRoot.MakeRelativeUri(ur);
                    }

                    ur = new Uri(Uri.UnescapeDataString(ur.ToString()), UriKind.Relative);
                    valueString = ur.ToString();
                }
            }
            else
            {
                valueString = attributeInfo.Type.Convert(value);
            }

            return valueString;
        }
Beispiel #38
0
        public void TestDuplicateAttributeInfo()
        {
            // This would be illegal in a schema file, but it seems to be supported OK in the DOM.
            var attr1 = new AttributeInfo("foo", new AttributeType("foo", typeof(string)));
            var attr2 = new AttributeInfo("foo", new AttributeType("foo", typeof(string)));
            var domType = new DomNodeType(
                "test",
                null,
                new AttributeInfo[] { attr1, attr2 },
                EmptyEnumerable<ChildInfo>.Instance,
                EmptyEnumerable<ExtensionInfo>.Instance);

            var domNode = new DomNode(domType);
            
            var originalAttr1 = "setting attr1";
            var originalAttr2 = "setting attr2";

            domNode.SetAttribute(attr1, originalAttr1);
            domNode.SetAttribute(attr2, originalAttr2);

            string resultAttr1 = (string)domNode.GetAttribute(attr1);
            string resultAttr2 = (string)domNode.GetAttribute(attr2);

            Assert.IsTrue(string.Equals(resultAttr1,originalAttr1));
            Assert.IsTrue(string.Equals(resultAttr2, originalAttr2));
        }
Beispiel #39
0
 /// <summary>
 /// Appends the attribute, if it's not the default value, in the format ", {name}={value}".
 /// If the value is an integer, then no quotes are used.
 /// If the value is a bool, then true or false are written out, without quotes.
 /// Otherwise, the value is enclosed in quotes.</summary>
 /// <param name="node">Node whose attributes is written</param>
 /// <param name="name">Attribute name</param>
 /// <param name="lineBuilder">String builder to create string attribute data</param>
 private static void WriteAttribute(DomNode node, string name, StringBuilder lineBuilder)
 {
     AttributeInfo attributeInfo = node.Type.GetAttributeInfo(name);
     if (!node.IsAttributeDefault(attributeInfo))
     {
         object attribute = node.GetAttribute(attributeInfo);
         if (attribute is int)
             lineBuilder.AppendFormat(", {0}={1}", name, ((int)attribute).ToString());
         else if (attribute is bool)
             lineBuilder.AppendFormat(", {0}={1}", name, (bool)attribute == true ? "true" : "false");
         else
             lineBuilder.AppendFormat(", {0}=\"{1}\"", name, attribute);
     }
 }
Beispiel #40
0
        private static void WriteResource(DomNode resourceNode, StreamWriter writer)
        {
            StringBuilder lineBuilder = new StringBuilder( string.Format(
                "resource type=\"{0}\", name=\"{1}\"",
                resourceNode.Type.Name,
                resourceNode.GetAttribute(DomTypes.resourceType.nameAttribute)));

            WriteAttribute(resourceNode, "size", lineBuilder);
            WriteAttribute(resourceNode, "compressed", lineBuilder);

            if (resourceNode.Type == DomTypes.geometryResourceType.Type)
            {
                WriteAttribute(resourceNode, "bones", lineBuilder);
                WriteAttribute(resourceNode, "vertices", lineBuilder);
                WriteAttribute(resourceNode, "primitiveType", lineBuilder);
            }
            else if (resourceNode.Type == DomTypes.animationResourceType.Type)
            {
                WriteAttribute(resourceNode, "tracks", lineBuilder);
                WriteAttribute(resourceNode, "duration", lineBuilder);
            }
            else
                throw new InvalidOperationException("unknown resource type");
            
            writer.WriteLine(lineBuilder.ToString());
        }
Beispiel #41
0
        private static void WriteEvent(DomNode eventNode, StreamWriter writer)
        {
            StringBuilder lineBuilder = new StringBuilder(
                "event name=\"" + eventNode.GetAttribute(DomTypes.eventType.nameAttribute) + "\"");
            WriteAttribute(eventNode, "time", lineBuilder);
            WriteAttribute(eventNode, "duration", lineBuilder);
            writer.WriteLine(lineBuilder.ToString());

            foreach (DomNode resourceNode in eventNode.GetChildren(DomTypes.eventType.resourceChild))
                WriteResource(resourceNode, writer);
        }
Beispiel #42
0
            private void ProcessSetterType(DomNode setter, string parentPropName,
                List<System.ComponentModel.PropertyDescriptor> descriptors)
            {
                string curPropName = (string)setter.GetAttribute(SkinSchema.setterType.propertyNameAttribute);
                if (string.IsNullOrWhiteSpace(curPropName)) return;
                string propName = !string.IsNullOrEmpty(parentPropName)
                    ? parentPropName + "->" + curPropName : curPropName;

                DomNode valInfo = setter.GetChild(SkinSchema.setterType.valueInfoChild);
                if (valInfo != null)
                {
                    ProcessValueInfo(valInfo, propName, descriptors);
                }

                DomNode listInfo = setter.GetChild(SkinSchema.setterType.listInfoChild);
                if (listInfo != null)
                {
                    foreach (var vInfo in listInfo.GetChildList(SkinSchema.listInfoType.valueInfoChild))
                        ProcessValueInfo(vInfo, propName, descriptors);
                }
            }
Beispiel #43
0
 /// <summary>
 /// Gets Vec4F associated with DomNode attribute</summary>
 /// <param name="domNode">DomNode</param>
 /// <param name="attribute">Attribute for Vec4F</param>
 /// <returns>Vec4F associated with DomNode attribute</returns>
 public static Vec4F GetVector4(DomNode domNode, AttributeInfo attribute)
 {
     return new Vec4F(DoubleToFloat(domNode.GetAttribute(attribute) as double[]));
 }
        /// <summary>
        /// Performs custom actions for a node that has been added to the DOM subtree</summary>
        /// <param name="node">Added node</param>
        protected override void AddNode(DomNode node)
        {
            // add all references to tracker
            foreach (AttributeInfo attributeInfo in node.Type.Attributes)
            {
                if (attributeInfo.Type.Type == AttributeTypes.Reference)
                {
                    DomNode reference = node.GetAttribute(attributeInfo) as DomNode;
                    if (reference != null)
                        AddReference(node, attributeInfo, reference);
                }
            }

            if (Validating)
            {
                // if node was previously removed it has been added back
                m_removed.Remove(node);
            }

            base.AddNode(node);
        }
Beispiel #45
0
 /// <summary>
 /// Gets Matrix4F associated with DomNode attribute</summary>
 /// <param name="domNode">DomNode</param>
 /// <param name="attribute">Attribute for Matrix4F</param>
 /// <returns>Matrix4F associated with DomNode attribute</returns>
 public static Matrix4F GetMatrix(DomNode domNode, AttributeInfo attribute)
 {
     return new Matrix4F(DoubleToFloat(domNode.GetAttribute(attribute) as double[]));
 }
Beispiel #46
0
        private static void Print(DomNode game)
        {
            Console.WriteLine("Game: {0}", game.GetAttribute(game.Type.GetAttributeInfo("name")));

            foreach (DomNode child in game.Children)
            {
                Console.WriteLine();
                Console.WriteLine("   {0}", child.Type.Name);
                foreach (AttributeInfo attr in child.Type.Attributes)
                    Console.WriteLine("      {0}: {1}",
                            attr.Name,
                            child.GetAttribute(attr));
            }
            Console.WriteLine();
        }
Beispiel #47
0
 /// <summary>
 /// Gets the DomNode attribute as a Matrix4F</summary>
 /// <param name="domNode">DomNode holding value</param>
 /// <param name="attribute">Attribute of the DomNode that contains the data</param>
 /// <returns>DomNode attribute as a Matrix4F</returns>
 public static Matrix4F GetMatrix(DomNode domNode, AttributeInfo attribute)
 {
     return new Matrix4F((float[])domNode.GetAttribute(attribute));
 }
Beispiel #48
0
 /// <summary>
 /// Gets the DomNode attribute as a Vec3F. The attribute must exist on the DomNode.</summary>
 /// <param name="domNode">DomNode holding the attribute</param>
 /// <param name="attribute">Attribute of the DomNode that contains the data</param>
 /// <returns>Attribute as a Vec3F</returns>
 public static Vec3F GetVector(DomNode domNode, AttributeInfo attribute)
 {
     return new Vec3F((float[])domNode.GetAttribute(attribute));
 }
Beispiel #49
0
 /// <summary>
 /// Gets the DomNode attribute as a Box</summary>
 /// <param name="domNode">DomNode holding value</param>
 /// <param name="attribute">Attribute of the DomNode that contains the data</param>
 /// <returns>DomNode attribute value as a Box</returns>
 public static Box GetBox(DomNode domNode, AttributeInfo attribute)
 {
     float[] value = domNode.GetAttribute(attribute) as float[];
     if (value != null)
     {
         return new Box(new Vec3F(value[0], value[1], value[2]),
                        new Vec3F(value[3], value[4], value[5]));
     }
     else return new Box();
 }
Beispiel #50
0
 public static LightingInfo TryCreate(DomNode domNode)
 {
     AttributeInfo diffuseInfo = domNode.Type.GetAttributeInfo("diffuse");
     AttributeInfo ambientInfo = domNode.Type.GetAttributeInfo("ambient");
     AttributeInfo specularInfo = domNode.Type.GetAttributeInfo("specular");
     if (diffuseInfo != null &&
         ambientInfo != null &&
         specularInfo != null)
     {
         return new LightingInfo(
             Color.FromArgb((int) domNode.GetAttribute(ambientInfo)),
             Color.FromArgb((int) domNode.GetAttribute(specularInfo)),
             Color.FromArgb((int) domNode.GetAttribute(diffuseInfo)));
     }
     return null;
 }
        /// <summary>
        /// Performs custom actions for a node that has been removed from the DOM subtree</summary>
        /// <param name="node">Removed node</param>
        protected override void RemoveNode(DomNode node)
        {
            // remove all references from tracker
            foreach (AttributeInfo attributeInfo in node.Type.Attributes)
            {
                if (attributeInfo.Type.Type == AttributeTypes.Reference)
                {
                    DomNode reference = node.GetAttribute(attributeInfo) as DomNode;
                    if (reference != null)
                        RemoveReference(node, attributeInfo, reference);
                }
            }

            if (Validating)
            {
                // add to removed set
                m_removed.Add(node);
            }

            base.RemoveNode(node);
        }
Beispiel #52
0
        public void TestSetAttribute()
        {
            DomNodeType type = new DomNodeType("child");
            AttributeInfo info = GetIntAttribute("int");
            type.Define(info);
            DomNode test = new DomNode(type);

            Assert.False(test.IsAttributeSet(info));
            test.SetAttribute(info, 2);
            Assert.AreEqual(test.GetAttribute(info), 2);
            Assert.AreEqual(test.GetLocalAttribute(info), 2);
            Assert.True(test.IsAttributeSet(info));

            test.SetAttribute(info, null);
            Assert.True(test.IsAttributeDefault(info));
            Assert.Null(test.GetLocalAttribute(info));
            Assert.False(test.IsAttributeSet(info));
        }
        public void TestMoveDomNode()
        {
            var root = new DomNode(RootType.Type, RootElement);

            root.InitializeExtensions();

            var folderChild1 = new DomNode(FolderType.Type);
            var folderChild2 = new DomNode(FolderType.Type);
            var itemChild1 = new DomNode(ItemType.Type);
            var itemChild2 = new DomNode(ItemType.Type);

            var validationContext = root.As<ValidationContext>();
            
            // Set up the tree:
            // root
            //     folder
            //         item
            //     folder1
            //         item

            validationContext.RaiseBeginning();

            root.SetAttribute(RootType.NameAttribute, "root");
            itemChild1.SetAttribute(ItemType.NameAttribute, "item");
            itemChild2.SetAttribute(ItemType.NameAttribute, "item");
            folderChild1.SetAttribute(FolderType.NameAttribute, "folder");
            folderChild2.SetAttribute(FolderType.NameAttribute, "folder");

            folderChild1.GetChildList(FolderType.ItemChild).Add(itemChild1);
            folderChild2.GetChildList(FolderType.ItemChild).Add(itemChild2);

            root.GetChildList(RootType.FolderChild).Add(folderChild1);
            root.GetChildList(RootType.FolderChild).Add(folderChild2);

            // renames all folders and items with unique paths
            validationContext.RaiseEnding();
            validationContext.RaiseEnded(); 

            // Move item from first folder to second folder
            // root
            //     folder
            //     folder1
            //         item
            //         item1

            validationContext.RaiseBeginning();

            itemChild1.RemoveFromParent();
            folderChild2.GetChildList(FolderType.ItemChild).Add(itemChild1);

            validationContext.RaiseEnding();
            validationContext.RaiseEnded();
            Assert.DoesNotThrow(() => ValidateSubtree(folderChild2));
            // Make sure that the existing child wasn't renamed. Only the moved child should be renamed.
            Assert.True((string)itemChild2.GetAttribute(ItemType.NameAttribute) == "item");

            // Rename 'item_1' to 'item'.
            validationContext.RaiseBeginning();

            itemChild1.SetAttribute(ItemType.NameAttribute, "item");

            validationContext.RaiseEnding();
            validationContext.RaiseEnded();
            Assert.DoesNotThrow(() => ValidateSubtree(folderChild2));

            // Make sure that the existing child wasn't renamed. Only the moved child should be renamed.
            Assert.True((string)itemChild2.GetAttribute(ItemType.NameAttribute) == "item");

            // Rename the root.
            validationContext.RaiseBeginning();

            root.SetAttribute(RootType.NameAttribute, "new_root");

            validationContext.RaiseEnding();
            validationContext.RaiseEnded();
            Assert.DoesNotThrow(() => ValidateSubtree(root));
            Assert.True((string)root.GetAttribute(RootType.NameAttribute) == "new_root");
        }
Beispiel #54
0
        public void TestAttributeChangedEvents()
        {
            DomNodeType type = new DomNodeType("type");
            AttributeInfo stringTypeInfo = GetStringAttribute("string");
            AttributeInfo intTypeInfo = GetIntAttribute("int");
            type.Define(stringTypeInfo);
            type.Define(intTypeInfo);
            DomNode test = new DomNode(type);
            test.AttributeChanging += new EventHandler<AttributeEventArgs>(test_AttributeChanging);
            test.AttributeChanged += new EventHandler<AttributeEventArgs>(test_AttributeChanged);
            AttributeEventArgs expected;

            // test for no value change if setting to the default value and attribute is already the default
            AttributeChangingArgs = null;
            AttributeChangedArgs = null;
            test.SetAttribute(stringTypeInfo, stringTypeInfo.DefaultValue);
            Assert.Null(AttributeChangingArgs);
            Assert.Null(AttributeChangedArgs);
            test.SetAttribute(intTypeInfo, intTypeInfo.DefaultValue);
            Assert.Null(AttributeChangingArgs);
            Assert.Null(AttributeChangedArgs);

            // test for value change, string type
            test = new DomNode(type);
            test.AttributeChanging += new EventHandler<AttributeEventArgs>(test_AttributeChanging);
            test.AttributeChanged += new EventHandler<AttributeEventArgs>(test_AttributeChanged);
            AttributeChangingArgs = null;
            AttributeChangedArgs = null;
            object oldValue = test.GetAttribute(stringTypeInfo);
            test.SetAttribute(stringTypeInfo, "foo");
            expected = new AttributeEventArgs(test, stringTypeInfo, oldValue, "foo");
            Assert.True(Equals(AttributeChangingArgs, expected));
            Assert.True(Equals(AttributeChangedArgs, expected));

            oldValue = test.GetAttribute(stringTypeInfo);
            test.SetAttribute(stringTypeInfo, "foobar");
            expected = new AttributeEventArgs(test, stringTypeInfo, oldValue, "foobar");
            Assert.True(Equals(AttributeChangingArgs, expected));
            Assert.True(Equals(AttributeChangedArgs, expected));

            // test for value change, int type
            AttributeChangingArgs = null;
            AttributeChangedArgs = null;
            oldValue = test.GetAttribute(intTypeInfo);
            test.SetAttribute(intTypeInfo, 5);
            expected = new AttributeEventArgs(test, intTypeInfo, oldValue, 5);
            Assert.True(Equals(AttributeChangingArgs, expected));
            Assert.True(Equals(AttributeChangedArgs, expected));

            oldValue = test.GetAttribute(intTypeInfo);
            test.SetAttribute(intTypeInfo, 7);
            expected = new AttributeEventArgs(test, intTypeInfo, oldValue, 7);
            Assert.True(Equals(AttributeChangingArgs, expected));
            Assert.True(Equals(AttributeChangedArgs, expected));

            // test for no value change
            test.SetAttribute(stringTypeInfo, "foo");
            AttributeChangingArgs = null;
            AttributeChangedArgs = null;
            test.SetAttribute(stringTypeInfo, "foo");
            Assert.Null(AttributeChangingArgs);
            Assert.Null(AttributeChangedArgs);

            test.SetAttribute(intTypeInfo, 9);
            AttributeChangingArgs = null;
            AttributeChangedArgs = null;
            test.SetAttribute(intTypeInfo, 9);
            Assert.Null(AttributeChangingArgs);
            Assert.Null(AttributeChangedArgs);
        }
Beispiel #55
0
        /// <summary>
        /// Writes the element corresponding to the DomNode</summary>
        /// <param name="node">DomNode to write</param>
        protected virtual void WriteElement(DomNode node, XmlWriter writer)
        {
            string elementNS = m_typeCollection.TargetNamespace;
            int index = node.ChildInfo.Name.LastIndexOf(':');
            if (index >= 0)
                elementNS = node.ChildInfo.Name.Substring(0, index);

            string elementPrefix = string.Empty;

            // is this the root DomNode?
            if (node.Parent == null)
            {
                elementPrefix = m_typeCollection.GetPrefix(elementNS);
                if (elementPrefix == null)
                    elementPrefix = GeneratePrefix(elementNS);

                writer.WriteStartElement(elementPrefix, node.ChildInfo.Name, elementNS);

                // define the xsi namespace
                writer.WriteAttributeString("xmlns", "xsi", null, XmlSchema.InstanceNamespace);

                // define schema namespaces
                foreach (XmlQualifiedName name in m_typeCollection.Namespaces)
                    if (name.Name != elementPrefix) // don't redefine the element namespace
                        writer.WriteAttributeString("xmlns", name.Name, null, name.Namespace);
            }
            else
            {
                // not the root, so all schema namespaces have been defined
                elementPrefix = writer.LookupPrefix(elementNS);
                if (elementPrefix == null)
                    elementPrefix = GeneratePrefix(elementNS);

                writer.WriteStartElement(elementPrefix, node.ChildInfo.Name, elementNS);
            }

            // write type name if this is a polymorphic type
            DomNodeType type = node.Type;
            if (node.ChildInfo.Type != type)
            {
                string name = type.Name;
                index = name.LastIndexOf(':');
                if (index >= 0)
                {
                    string typeName = name.Substring(index + 1, type.Name.Length - index - 1);
                    string typeNS = name.Substring(0, index);
                    string typePrefix = writer.LookupPrefix(typeNS);
                    if (typePrefix == null)
                    {
                        typePrefix = GeneratePrefix(typeNS);
                        writer.WriteAttributeString("xmlns", typePrefix, null, typeNS);
                    }

                    name = typeName;
                    if (typePrefix != string.Empty)
                        name = typePrefix + ":" + typeName;
                }

                writer.WriteAttributeString("xsi", "type", XmlSchema.InstanceNamespace, name);
            }

            // write attributes
            AttributeInfo valueAttribute = null;
            foreach (AttributeInfo attributeInfo in type.Attributes)
            {
                // if attribute is required, or not the default, write it
                if (/*attributeInfo.Required ||*/ !node.IsAttributeDefault(attributeInfo))
                {
                    if (attributeInfo.Name == string.Empty)
                    {
                        valueAttribute = attributeInfo;
                    }
                    else
                    {
                        object value = node.GetAttribute(attributeInfo);
                        string valueString = null;
                        if (attributeInfo.Type.Type == AttributeTypes.Reference)
                        {
                            // if reference is a valid node, convert to string
                            DomNode refNode = value as DomNode;
                            if (refNode != null)
                                valueString = GetNodeReferenceString(refNode, m_root, m_uri);
                        }
                        if (valueString == null)
                            valueString = attributeInfo.Type.Convert(value);

                        writer.WriteAttributeString(attributeInfo.Name, valueString);
                    }
                }
            }

            // write value if not the default
            if (valueAttribute != null)
            {
                object value = node.GetAttribute(valueAttribute);
                writer.WriteString(valueAttribute.Type.Convert(value));
            }

            // write child elements
            foreach (ChildInfo childInfo in type.Children)
            {
                if (childInfo.IsList)
                {
                    foreach (DomNode child in node.GetChildList(childInfo))
                        WriteElement(child, writer);
                }
                else
                {
                    DomNode child = node.GetChild(childInfo);
                    if (child != null)
                        WriteElement(child, writer);
                }
            }

            writer.WriteEndElement();
        }
Beispiel #56
0
        /// <summary>
        /// Converts attribute to string.
        /// WriteAttributes(..) call this method to convert dom attribute to string before writing.</summary>
        /// <param name="node">DomNode that owns the attribute to be converted</param>
        /// <param name="attributeInfo">The attribute that need to be converted</param>
        /// <returns>the string value of the attribute</returns>
        protected virtual string Convert(DomNode node, AttributeInfo attributeInfo)
        {
            string valueString = null;
            object value = node.GetAttribute(attributeInfo);
            if (attributeInfo.Type.Type == AttributeTypes.Reference)
            {
                // if reference is a valid node, convert to string
                DomNode refNode = value as DomNode;
                if (refNode != null)
                    valueString = GetNodeReferenceString(refNode, m_root, m_uri);
            }
            if (valueString == null)
                valueString = attributeInfo.Type.Convert(value);

            return valueString;
        }
Beispiel #57
0
        private void WriteElement(DomNode node, XmlWriter writer)
        {
            // If writing the project settings file...
            if (!m_bWritingUserSettings)
            {
                // Don't save types that are not supposed to be saved
                if (s_lstExcludeDomNodeTypes.Contains(node.Type))
                    return;
            }

            var elementNs = m_typeCollection.TargetNamespace;
            var index = node.ChildInfo.Name.LastIndexOf(':');
            if (index >= 0)
                elementNs = node.ChildInfo.Name.Substring(0, index);

            string elementPrefix;

            // is this the root DomNode (the one passed Write, above)?
            if (node == m_root)
            {
                elementPrefix = m_typeCollection.GetPrefix(elementNs) ?? GeneratePrefix(elementNs);

                writer.WriteStartElement(elementPrefix, node.ChildInfo.Name, elementNs);

                // define the xsi namespace
                writer.WriteAttributeString("xmlns", "xsi", null, XmlSchema.InstanceNamespace);

                // define schema namespaces
                foreach (var name in m_typeCollection.Namespaces)
                {
                    if (string.Compare(name.Name, elementPrefix) != 0)
                        writer.WriteAttributeString("xmlns", name.Name, null, name.Namespace);
                }
            }
            else
            {
                // not the root, so all schema namespaces have been defined
                elementPrefix = writer.LookupPrefix(elementNs) ?? GeneratePrefix(elementNs);

                writer.WriteStartElement(elementPrefix, node.ChildInfo.Name, elementNs);
            }

            // write type name if this is a polymorphic type
            var type = node.Type;
            if (node.ChildInfo.Type != type)
            {
                var name = type.Name;
                index = name.LastIndexOf(':');
                if (index >= 0)
                {
                    var typeName = name.Substring(index + 1, type.Name.Length - index - 1);
                    var typeNs = name.Substring(0, index);
                    var typePrefix = writer.LookupPrefix(typeNs);
                    if (typePrefix == null)
                    {
                        typePrefix = GeneratePrefix(typeNs);
                        writer.WriteAttributeString("xmlns", typePrefix, null, typeNs);
                    }

                    name = typeName;
                    if (typePrefix != string.Empty)
                        name = typePrefix + ":" + typeName;
                }

                writer.WriteAttributeString("xsi", "type", XmlSchema.InstanceNamespace, name);
            }

            // write attributes
            AttributeInfo valueAttribute = null;
            foreach (var attributeInfo in type.Attributes)
            {
                // if attribute is required, or not the default, write it
                if (/*attributeInfo.Required ||*/ !node.IsAttributeDefault(attributeInfo))
                {
                    if (attributeInfo.Name == string.Empty)
                    {
                        valueAttribute = attributeInfo;
                    }
                    else
                    {
                        var value = node.GetAttribute(attributeInfo);
                        string valueString = null;
                        if (attributeInfo.Type.Type == AttributeTypes.Reference)
                        {
                            // if reference is a valid node, convert to string
                            var refNode = value as DomNode;
                            if (refNode != null)
                                valueString = GetNodeReferenceString(refNode, m_root);
                        }
                        if (valueString == null)
                            valueString = attributeInfo.Type.Convert(value);

                        var bWriteAttribute = true;
                        if (!m_bWritingUserSettings)
                            bWriteAttribute = !s_lstExcludeAttributes.Contains(attributeInfo.Name);

                        if (bWriteAttribute)
                            writer.WriteAttributeString(attributeInfo.Name, valueString);
                    }
                }
            }

            // write value if not the default
            if (valueAttribute != null)
            {
                var value = node.GetAttribute(valueAttribute);
                writer.WriteString(valueAttribute.Type.Convert(value));
            }

            // write child elements
            foreach (var childInfo in type.Children)
            {
                if (childInfo.IsList)
                {
                    foreach (var child in node.GetChildList(childInfo))
                        WriteElement(child, writer);
                }
                else
                {
                    var child = node.GetChild(childInfo);
                    if (child != null)
                        WriteElement(child, writer);
                }
            }

            writer.WriteEndElement();
        }
Beispiel #58
0
            private void ProcessValueInfo(DomNode valInfo, string propName,
                List<System.ComponentModel.PropertyDescriptor> descriptors)
            {
                string typeName = (string)valInfo.GetAttribute(SkinSchema.valueInfoType.typeAttribute);
                Type type = SkinUtil.GetType(typeName);


                if (type == typeof(Font))
                {
                    FontDescriptor descr
                        = new FontDescriptor(valInfo, propName, null, null, null, null);
                    descriptors.Add(descr);
                }
                else
                {

                    TypeConverter converter;
                    object editor;
                    GetEditorAndConverter(type, out editor, out converter);
                    if (editor != null)
                    {
                        var descr = new SkinSetterAttributePropertyDescriptor(valInfo
                            , propName, SkinSchema.valueInfoType.valueAttribute, null, null, false, editor, converter);
                        descriptors.Add(descr);
                    }
                    else
                    {
                        DomNode ctorParams = valInfo.GetChild(SkinSchema.valueInfoType.constructorParamsChild);
                        if (ctorParams != null)
                        {
                            var vInfoChildList = ctorParams.GetChildList(SkinSchema.constructorParamsType.valueInfoChild);
                            if (vInfoChildList.Count == 1)
                            {
                                ProcessValueInfo(vInfoChildList[0], propName, descriptors);
                            }
                            else
                            {

                                // special handling for SyntaxEditorControl
                                if (typeName == "Sce.Atf.Controls.SyntaxEditorControl.TextHighlightStyle")
                                {
                                    string argName =
                                    (string)vInfoChildList[0].GetAttribute(SkinSchema.valueInfoType.valueAttribute);

                                    string name = propName + "->" + argName;
                                    ProcessValueInfo(vInfoChildList[1], name, descriptors);
                                }
                                else
                                {
                                    int k = 1;
                                    string paramName = propName + " : Arg_";
                                    foreach (DomNode vInfoChild in vInfoChildList)
                                    {
                                        string name = paramName + k;
                                        ProcessValueInfo(vInfoChild, name, descriptors);
                                        k++;
                                    }
                                }
                            }
                        }

                        foreach (DomNode setterChild in valInfo.GetChildList(SkinSchema.valueInfoType.setterChild))
                        {
                            ProcessSetterType(setterChild, propName, descriptors);
                        }
                    }
                }
            }