Example #1
0
        private void ExportParameters(BsonSerializer file, Attachments.Attachment attachment)
        {
            Attachments.Event evt = attachment as Attachments.Event;

            if (evt == null || evt.Pars.Count == 0)
            {
                return;
            }

            file.WriteStartElement("pars");

            for (int i = 0; i < evt.Pars.Count; ++i)
            {
                file.WriteStartElement("par");

                file.WriteString(evt.Pars[i].Name);
                file.WriteString(Plugin.GetNativeTypeName(evt.Pars[i].Type));
                file.WriteString(evt.Pars[i].DefaultValue);

                if (!string.IsNullOrEmpty(evt.Pars[i].EventParam))
                {
                    file.WriteString(evt.Pars[i].EventParam);
                }

                file.WriteEndElement();
            }

            file.WriteEndElement();
        }
Example #2
0
        /// <summary>
        /// Saves a node to the XML file.
        /// </summary>
        /// <param name="root">The XML node we want to attach the node to.</param>
        /// <param name="node">The node we want to save.</param>
        protected void SaveNode(XmlElement root, Node node)
        {
            try
            {
                // allow the node to process its attributes in preparation of the save
                node.PreSave(_behavior);

                // store the class we have to create when loading
                XmlElement elem = _xmlfile.CreateElement("Node");
                elem.SetAttribute("Class", node.GetType().FullName);

                bool isPrefabInstance = !string.IsNullOrEmpty(node.PrefabName) && !node.IsPrefabDataDirty();

                // save attributes
                IList <DesignerPropertyInfo> properties = node.GetDesignerProperties();
                for (int p = 0; p < properties.Count; ++p)
                {
                    if (!properties[p].Attribute.HasFlags(DesignerProperty.DesignerFlags.NoSave))
                    {
                        bool bDo = !isPrefabInstance || properties[p].Attribute.HasFlags(DesignerProperty.DesignerFlags.NotPrefabRelated);

                        if (bDo)
                        {
                            if (properties[p].Attribute.HasFlags(DesignerProperty.DesignerFlags.BeValid))
                            {
                                object obj = properties[p].Property.GetValue(node, null);

                                if (obj == null || obj.ToString() == "null_method")
                                {
                                    bDo = false;
                                }
                            }

                            if (bDo)
                            {
                                elem.SetAttribute(properties[p].Property.Name, properties[p].GetSaveValue(node));
                            }
                        }
                    }
                }

                // append node to root
                root.AppendChild(elem);

                // save comment
                if (node.CommentObject != null)
                {
                    XmlElement comment = _xmlfile.CreateElement("Comment");

                    properties = node.CommentObject.GetDesignerProperties();
                    for (int p = 0; p < properties.Count; ++p)
                    {
                        if (!properties[p].Attribute.HasFlags(DesignerProperty.DesignerFlags.NoSave))
                        {
                            comment.SetAttribute(properties[p].Property.Name, properties[p].GetSaveValue(node.CommentObject));
                        }
                    }

                    elem.AppendChild(comment);
                }

                if (!isPrefabInstance)
                {
                    // save parameters
                    SaveParameters(elem, node.Pars);

                    // save DescriptorRefs
                    if (node is Behavior)
                    {
#if QUERY_EANBLED
                        Behavior b = node as Behavior;
                        SaveDescriptorRefs(elem, b);
#endif//#if QUERY_EANBLED
                    }

                    // save attachments
                    foreach (Attachments.Attachment attach in node.Attachments)
                    {
                        XmlElement attelem = _xmlfile.CreateElement("Attachment");
                        attelem.SetAttribute("Class", attach.GetType().FullName);

                        // save attributes
                        properties = attach.GetDesignerProperties();
                        for (int p = 0; p < properties.Count; ++p)
                        {
                            if (!properties[p].Attribute.HasFlags(DesignerProperty.DesignerFlags.NoSave))
                            {
                                attelem.SetAttribute(properties[p].Property.Name, properties[p].GetSaveValue(attach));
                            }
                        }

                        Attachments.Event evt = attach as Attachments.Event;
                        if (evt != null)
                        {
                            SaveParameters(attelem, evt.Pars);
                        }

                        elem.AppendChild(attelem);
                    }

                    // save children if allowed. Disallowed for referenced behaviours.
                    if (node.SaveChildren)
                    {
                        // save connectors
                        foreach (Nodes.Node.Connector connector in node.Connectors)
                        {
                            // if we have no children to store we can skip the connector
                            if (connector.ChildCount < 1)
                            {
                                continue;
                            }

                            XmlElement conn = _xmlfile.CreateElement("Connector");
                            conn.SetAttribute("Identifier", connector.Identifier);
                            elem.AppendChild(conn);

                            // save their children
                            for (int i = 0; i < connector.ChildCount; ++i)
                            {
                                SaveNode(conn, (Node)connector.GetChild(i));
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, Resources.SaveError, MessageBoxButtons.OK);

                throw;
            }
        }
Example #3
0
        /// <summary>
        /// Loads an attachment which is attached to a node.
        /// </summary>
        /// <param name="node">The node the attachment is created for.</param>
        /// <param name="xml">The XML node the attachment retrieves its name and attributes from.</param>
        /// <returns>Returns the created Attachment.</returns>
        protected Attachments.Attachment CreateAttachment(Node node, XmlNode xml)
        {
            try
            {
                // get the type of the attachment and create it

                // maintain compatibility with version 1
                //string clss= GetAttribute(xml, "Class");
                string clss;
                if (!GetAttribute(xml, "Class", out clss))
                {
                    string find  = ".Events." + GetAttribute(xml, "name");
                    Type   found = Plugin.FindType(find);
                    if (found != null)
                    {
                        clss = found.FullName;
                    }
                }

                Type t = Plugin.GetType(clss);

                if (t == null)
                {
                    throw new Exception(string.Format(Resources.ExceptionUnknownEventType, clss));
                }

                Attachments.Attachment attach = Attachments.Attachment.Create(t, node);

                // initialise the attachments properties
                IList <DesignerPropertyInfo> properties = attach.GetDesignerProperties();
                for (int p = 0; p < properties.Count; ++p)
                {
                    if (properties[p].Attribute.HasFlags(DesignerProperty.DesignerFlags.NoSave))
                    {
                        continue;
                    }

                    InitProperty(xml, attach, properties[p]);
                }

                // update attacheent with attributes
                attach.OnPropertyValueChanged(false);

                Attachments.Event evt = attach as Attachments.Event;

                if (evt != null)
                {
                    foreach (XmlNode xnode in xml.ChildNodes)
                    {
                        if (xnode.NodeType == XmlNodeType.Element)
                        {
                            switch (xnode.Name.ToLowerInvariant())
                            {
                            // load parameters
                            case ("parameters"):
                                LoadParameters(xnode, node, evt.Pars);
                                break;
                            }
                        }
                    }
                }

                return(attach);
            }
            catch (Exception ex)
            {
                string msgError = string.Format("{0}\n{1}:\n{2}", ex.Message, this.Filename, "Attachment");

                //throw new Exception(msg);
                MessageBox.Show(msgError, Resources.LoadError, MessageBoxButtons.OK);
            }

            return(null);
        }