public static void OnConvertToXmlNode(object obj, XmlNode node)
                {
                    Gradient gradient = (Gradient)obj;

                    if (gradient != null)
                    {
                        XmlNode colorKeysXmlNode = XmlUtils.CreateXmlNode(node.OwnerDocument, XmlConverter.kXmlArrayTag);
                        for (int i = 0; i < gradient.colorKeys.Length; i++)
                        {
                            XmlNode colorKeyXmlNode = XmlUtils.CreateXmlNode(node.OwnerDocument, "ColorKey");
                            XmlConverter.AppendFieldObject(colorKeyXmlNode, gradient.colorKeys[i].color, "color");
                            XmlConverter.AppendFieldObject(colorKeyXmlNode, gradient.colorKeys[i].time, "time");
                            XmlUtils.SafeAppendChild(colorKeysXmlNode, colorKeyXmlNode);
                        }
                        XmlUtils.AddAttribute(node.OwnerDocument, colorKeysXmlNode, XmlConverter.kXmlFieldIdAttributeTag, "colorKeys");
                        XmlUtils.SafeAppendChild(node, colorKeysXmlNode);


                        XmlNode alphasKeyXmlNode = XmlUtils.CreateXmlNode(node.OwnerDocument, XmlConverter.kXmlArrayTag);
                        for (int i = 0; i < gradient.alphaKeys.Length; i++)
                        {
                            XmlNode alphaKeyXmlNode = XmlUtils.CreateXmlNode(node.OwnerDocument, "AlphaKey");
                            XmlConverter.AppendFieldObject(alphaKeyXmlNode, gradient.alphaKeys[i].alpha, "alpha");
                            XmlConverter.AppendFieldObject(alphaKeyXmlNode, gradient.alphaKeys[i].time, "time");
                            XmlUtils.SafeAppendChild(alphasKeyXmlNode, alphaKeyXmlNode);
                        }
                        XmlUtils.AddAttribute(node.OwnerDocument, alphasKeyXmlNode, XmlConverter.kXmlFieldIdAttributeTag, "alphaKeys");
                        XmlUtils.SafeAppendChild(node, alphasKeyXmlNode);
                    }
                }
Exemple #2
0
                public static void OnConvertToXmlNode(object obj, XmlNode node)
                {
                    IDictionary dictionary = (IDictionary)obj;

                    Type[] dictionaryTypes = SystemUtils.GetGenericImplementationTypes(typeof(Dictionary <,>), obj.GetType());

                    if (dictionaryTypes != null)
                    {
                        //Find keys
                        string[] keys = new string[dictionary.Keys.Count];
                        int      i    = 0;
                        foreach (object key in dictionary.Keys)
                        {
                            keys[i++] = Convert.ToString(key);
                        }

                        //Append all child nodes
                        i = 0;
                        foreach (object value in dictionary.Values)
                        {
                            XmlNode arrayItemXmlNode = XmlConverter.ToXmlNode(value, node.OwnerDocument);
                            XmlUtils.AddAttribute(node.OwnerDocument, arrayItemXmlNode, "key", keys[i++]);
                            XmlUtils.SafeAppendChild(node, arrayItemXmlNode);
                        }
                    }
                }
                public static XmlNode AppendFieldObject <T>(XmlNode parentNode, T obj, string id)
                {
                    XmlNode childXmlNode = ToXmlNode(obj, parentNode.OwnerDocument);

                    XmlUtils.AddAttribute(parentNode.OwnerDocument, childXmlNode, kXmlFieldIdAttributeTag, id);
                    XmlUtils.SafeAppendChild(parentNode, childXmlNode);
                    return(childXmlNode);
                }
 private static void AddRuntimeTypeInfoIfNecessary(Type fieldType, Type objType, XmlNode parentNode, XmlDocument xmlDoc)
 {
     //If field is abstract or generic AND node is abstract or generic, insert type node so we can convert it
     if (NeedsRuntimeTypeInfo(fieldType, objType))
     {
         XmlNode typeNode = ToXmlNode(objType, xmlDoc);
         XmlUtils.AddAttribute(xmlDoc, typeNode, kXmlNodeRuntimeTypeAttributeTag, "");
         XmlUtils.SafeAppendChild(parentNode, typeNode);
     }
 }
Exemple #5
0
                public static void OnConvertToXmlNode(object obj, XmlNode node)
                {
                    AnimationCurve curve = (AnimationCurve)obj;

                    if (curve != null)
                    {
                        XmlNode keyframesXmlNode = XmlUtils.CreateXmlNode(node.OwnerDocument, XmlConverter.kXmlArrayTag);
                        for (int i = 0; i < curve.length; i++)
                        {
                            Keyframe keyFrame        = curve[i];
                            XmlNode  keyFrameXmlNode = XmlUtils.CreateXmlNode(node.OwnerDocument, "KeyFrame");
                            XmlConverter.AppendFieldObject(keyFrameXmlNode, keyFrame.inTangent, "inTangent");
                            XmlConverter.AppendFieldObject(keyFrameXmlNode, keyFrame.outTangent, "outTangent");
                            XmlConverter.AppendFieldObject(keyFrameXmlNode, keyFrame.time, "time");
                            XmlConverter.AppendFieldObject(keyFrameXmlNode, keyFrame.value, "value");
                            XmlUtils.SafeAppendChild(keyframesXmlNode, keyFrameXmlNode);
                        }
                        XmlUtils.AddAttribute(node.OwnerDocument, keyframesXmlNode, XmlConverter.kXmlFieldIdAttributeTag, "keyFrames");
                        XmlUtils.SafeAppendChild(node, keyframesXmlNode);
                    }
                }
Exemple #6
0
                public static void OnConvertToXmlNode(object obj, XmlNode node)
                {
                    IDictionary dictionary = (IDictionary)obj;

                    Type[] dictionaryTypes = SystemUtils.GetGenericImplementationTypes(typeof(Dictionary <,>), obj.GetType());

                    if (dictionaryTypes != null)
                    {
                        //Find keys
                        string[] keys = new string[dictionary.Keys.Count];
                        int      i    = 0;
                        foreach (object key in dictionary.Keys)
                        {
                            keys[i++] = Convert.ToString(key);
                        }

                        //Create all child nodes
                        List <XmlNode> childNodes = new List <XmlNode>();
                        i = 0;
                        foreach (object value in dictionary.Values)
                        {
                            XmlNode arrayItemXmlNode = XmlConverter.ToXmlNode(value, node.OwnerDocument);
                            XmlUtils.AddAttribute(node.OwnerDocument, arrayItemXmlNode, "key", keys[i++]);
                            childNodes.Add(arrayItemXmlNode);
                        }

                        //Sort child nodes
                        childNodes.Sort((x, y) => x.Attributes["key"].Value.CompareTo(y.Attributes["key"].Value));

                        //Append child nodes in alphabetical order
                        foreach (XmlNode childNode in childNodes)
                        {
                            XmlUtils.SafeAppendChild(node, childNode);
                        }
                    }
                }
Exemple #7
0
        public static void AssetUploadDuplicateHash(User user, IEnumerable <Asset> assets)
        {
            // Get the message template and set the subject
            Email email = NotifyEngine.GetEmailTemplate("Admin.AssetUploadDuplicateHash", user.PrimaryBrand);

            email.Subject = NotifyEngine.GetSubject("Duplicate asset upload failed");

            // Add uploader name
            email.AddBodyParameter("uploader-name", user.FullName);

            // Add the superadmins as recipients
            AddSuperAdminsToEmailList(email.Recipients);

            // Add assets
            foreach (Asset asset in assets)
            {
                // Create the Asset node
                XmlNode node = email.BodyXmlDoc.CreateElement("Asset");

                // Ensure we've got a document element
                if (email.BodyXmlDoc.DocumentElement == null)
                {
                    return;
                }

                // Add the asset node
                email.BodyXmlDoc.DocumentElement.AppendChild(node);

                // Add the AssetId attribute
                XmlUtils.AddAttribute(email.BodyXmlDoc, node, "AssetId", asset.AssetId);
                XmlUtils.AddAttribute(email.BodyXmlDoc, node, "Filename", asset.Filename);
            }

            // Send it
            NotifyEngine.SendMessage(email);
        }
                public static XmlNode ToXmlNode <T>(T obj, XmlDocument xmlDoc, object defualtObject = null)
                {
                    XmlNode node = null;

                    if (obj != null)
                    {
                        Type            objType   = obj.GetType();
                        ObjectConverter converter = GetConverter(objType);

                        if (ShouldWriteObject(objType, converter, obj, defualtObject))
                        {
                            //IXmlConversionCallbackReceiver callback
                            if (obj is ISerializationCallbackReceiver)
                            {
                                ((ISerializationCallbackReceiver)obj).OnBeforeSerialize();
                            }

                            //If the object is an array create a node for the array and convert each element individually
                            if (objType.IsArray)
                            {
                                Array arrayField = obj as Array;

                                if (arrayField != null && arrayField.Length > 0)
                                {
                                    XmlNode arrayXmlNode = XmlUtils.CreateXmlNode(xmlDoc, kXmlArrayTag);

                                    //Append all child nodes
                                    for (int i = 0; i < arrayField.Length; i++)
                                    {
                                        XmlNode arrayElementXmlNode = ToXmlNode(arrayField.GetValue(i), xmlDoc);
                                        XmlUtils.SafeAppendChild(arrayXmlNode, arrayElementXmlNode);
                                    }

                                    node = arrayXmlNode;
                                }
                            }
                            else
                            {
                                string tag = GetXmlTag(objType);

                                if (!string.IsNullOrEmpty(tag))
                                {
                                    node = XmlUtils.CreateXmlNode(xmlDoc, tag);

                                    //If the object has an associated converter class, convert the object using it
                                    if (converter != null)
                                    {
                                        converter._onConvertToXmlNode(obj, node);
                                    }
                                    //Otherwise convert each field
                                    else
                                    {
                                        SerializedObjectMemberInfo[] xmlFields = SerializedObjectMemberInfo.GetSerializedFields(objType);

                                        //Create a default version of this to compare with?
                                        if (defualtObject == null)
                                        {
                                            defualtObject = CreateInstance(objType);
                                        }

                                        foreach (SerializedObjectMemberInfo xmlField in xmlFields)
                                        {
                                            object fieldObj        = xmlField.GetValue(obj);
                                            object defualtFieldObj = xmlField.GetValue(defualtObject);

                                            XmlNode fieldXmlNode = ToXmlNode(fieldObj, xmlDoc, defualtFieldObj);

                                            if (fieldXmlNode != null)
                                            {
                                                AddRuntimeTypeInfoIfNecessary(xmlField.GetFieldType(), fieldObj.GetType(), fieldXmlNode, xmlDoc);
                                                XmlUtils.AddAttribute(xmlDoc, fieldXmlNode, kXmlFieldIdAttributeTag, xmlField.GetID());
                                                XmlUtils.SafeAppendChild(node, fieldXmlNode);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

                    return(node);
                }