Exemplo n.º 1
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(List <Nodes.Node.ErrorCheck> result, 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(result, xml, attach, properties[p]);
                }

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

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

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

            return(null);
        }
Exemplo n.º 2
0
        private void ExportProperties(BsonSerializer file, Attachments.Attachment a)
        {
            file.WriteStartElement("properties");
            IList <DesignerPropertyInfo> properties = a.GetDesignerProperties();

            foreach (DesignerPropertyInfo p in properties)
            {
                // we skip properties which are not marked to be exported
                if (p.Attribute.HasFlags(DesignerProperty.DesignerFlags.NoExport))
                {
                    continue;
                }

                WriteProperty(file, p, a);
            }
            file.WriteEndElement();
        }
Exemplo n.º 3
0
        private void ExportProperties(Attachments.Attachment a, int indent)
        {
            //DesignerPropertyInfo propertyEffector = new DesignerPropertyInfo();
            IList <DesignerPropertyInfo> properties = a.GetDesignerProperties(true);

            foreach (DesignerPropertyInfo p in properties)
            {
                if (p.Attribute.HasFlags(DesignerProperty.DesignerFlags.NoExport))
                {
                    continue;
                }

                object v       = p.Property.GetValue(a, null);
                bool   bExport = !Plugin.IsExportArray(v);

                if (bExport)
                {
                    if (p.Property.Name != "Effectors")
                    {
                        string propValue = p.GetExportValue(a);
                        string name      = p.Property.Name;

                        if (propValue != string.Empty && propValue != "\"\"")
                        {
                            if (!ExportTypeMap.ContainsKey(name))
                            {
                                _err(String.Format("not support property!!! name:{0} value:{0}", name, propValue));
                            }
                            else if (ExportTypeMap[name] == PropertyType.Method)
                            {
                                ExportMethod(name, propValue, indent);
                            }
                            else if (ExportTypeMap[name] == PropertyType.Property)
                            {
                                ExportProperty(name, propValue, indent);
                            }
                            else
                            {
                                AddContent(String.Format("{0} = {1},", p.Property.Name, _quota(propValue)), indent);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 4
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)
        {
            // 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);

            return(attach);
        }
Exemplo n.º 5
0
        private void ExportProperties(XmlWriter file, Attachments.Attachment a)
        {
            IList <DesignerPropertyInfo> properties = a.GetDesignerProperties();

            foreach (DesignerPropertyInfo p in properties)
            {
                // we skip properties which are not marked to be exported
                if (p.Attribute.HasFlags(DesignerProperty.DesignerFlags.NoExport))
                {
                    continue;
                }

                // create the code which assigns the value to the node's property
                //file.Write(string.Format("{0}\t{1}.{2} = {3};\r\n", indent, nodeName, properties[p].Property.Name, properties[p].GetExportValue(node)));
                file.WriteStartElement("property");
                file.WriteAttributeString(p.Property.Name, p.GetExportValue(a));
                file.WriteEndElement();
            }
        }
Exemplo n.º 6
0
        private void ExportProperties(BsonSerializer file, Attachments.Attachment a)
        {
            DesignerPropertyInfo propertyEffector = new DesignerPropertyInfo();

            file.WriteStartElement("properties");
            IList <DesignerPropertyInfo> properties = a.GetDesignerProperties(true);

            foreach (DesignerPropertyInfo p in properties)
            {
                // we skip properties which are not marked to be exported
                if (p.Attribute.HasFlags(DesignerProperty.DesignerFlags.NoExport))
                {
                    continue;
                }

                object v       = p.Property.GetValue(a, null);
                bool   bExport = !Plugin.IsExportArray(v);

                if (bExport)
                {
                    if (p.Property.Name == "Effectors")
                    {
                        propertyEffector = p;
                    }
                    else
                    {
                        WriteProperty(file, p, a);
                    }
                }
            }

            file.WriteEndElement();

            if (propertyEffector.Property != null)
            {
                List <TransitionEffector> listV = (List <TransitionEffector>)propertyEffector.Property.GetValue(a, null);

                if (listV != null)
                {
                    file.WriteStartElement("attachments");
                    foreach (TransitionEffector te in listV)
                    {
                        file.WriteStartElement("attachment");
                        file.WriteStartElement("properties");
                        IList <DesignerPropertyInfo> effectorProperties = te.GetDesignerProperties();
                        foreach (DesignerPropertyInfo p in effectorProperties)
                        {
                            // we skip properties which are not marked to be exported
                            if (p.Attribute.HasFlags(DesignerProperty.DesignerFlags.NoExport))
                            {
                                continue;
                            }

                            WriteProperty(file, p, te);
                        }

                        file.WriteEndElement();
                        file.WriteEndElement();
                    }

                    file.WriteEndElement();
                }
            }
        }
Exemplo n.º 7
0
        private void ExportProperties(XmlWriter file, Attachments.Attachment a)
        {
            DesignerPropertyInfo         propertyEffector = new DesignerPropertyInfo();
            IList <DesignerPropertyInfo> properties       = a.GetDesignerProperties(true);

            foreach (DesignerPropertyInfo p in properties)
            {
                // we skip properties which are not marked to be exported
                if (p.Attribute.HasFlags(DesignerProperty.DesignerFlags.NoExport))
                {
                    continue;
                }

                object v       = p.Property.GetValue(a, null);
                bool   bExport = !Plugin.IsExportArray(v);

                if (bExport)
                {
                    if (p.Property.Name == "Effectors")
                    {
                        propertyEffector = p;
                    }
                    else
                    {
                        // create the code which assigns the value to the node's property
                        //file.Write(string.Format("{0}\t{1}.{2} = {3};\r\n", indent, nodeName, properties[p].Property.Name, properties[p].GetExportValue(node)));
                        string propValue = p.GetExportValue(a);

                        if (propValue != string.Empty && propValue != "\"\"")
                        {
                            file.WriteStartElement("property");
                            file.WriteAttributeString(p.Property.Name, propValue);
                            file.WriteEndElement();
                        }
                    }
                }
            }

            if (propertyEffector.Property != null)
            {
                List <TransitionEffector> listV = (List <TransitionEffector>)propertyEffector.Property.GetValue(a, null);

                if (listV != null)
                {
                    foreach (TransitionEffector te in listV)
                    {
                        IList <DesignerPropertyInfo> effectorProperties = te.GetDesignerProperties();
                        file.WriteStartElement("attachment");

                        foreach (DesignerPropertyInfo p in effectorProperties)
                        {
                            // we skip properties which are not marked to be exported
                            if (p.Attribute.HasFlags(DesignerProperty.DesignerFlags.NoExport))
                            {
                                continue;
                            }

                            string propValue = p.GetExportValue(te);

                            if (propValue != string.Empty && propValue != "\"\"")
                            {
                                file.WriteStartElement("property");
                                file.WriteAttributeString(p.Property.Name, propValue);
                                file.WriteEndElement();
                            }
                        }

                        file.WriteEndElement();
                    }
                }
            }
        }
Exemplo n.º 8
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);
        }