protected override void ExportConstructorAndProperties(System.IO.StreamWriter file, Node node, string indent, string nodeName, string classname)
		{
			// get all the properties that need to be exported
			IList<DesignerPropertyInfo> properties= node.GetDesignerProperties();

			// generate the list of parameters
			string parameters= string.Empty;
			for(int p= 0; p <properties.Count; ++p)
			{
				if(!properties[p].Attribute.HasFlags(DesignerProperty.DesignerFlags.NoExport))
					parameters+= properties[p].GetExportValue(node) +", ";
			}

			// remove the comma
			if(parameters !=string.Empty)
				parameters= parameters.Substring(0, parameters.Length -2);

			// create a new instance of the node
			file.Write( string.Format("{0}\t{2} {1} = new {2}({3});\r\n", indent, nodeName, classname, parameters) );
		}
示例#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)
		{
			// allow the node to process its attributes in preparation of the save
			node.PreSave(_node);

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

			// save attributes
			IList<DesignerPropertyInfo> properties= node.GetDesignerProperties();
			for(int p= 0; p <properties.Count; ++p)
			{
				if(!properties[p].Attribute.HasFlags(DesignerProperty.DesignerFlags.NoSave))
					elem.SetAttribute(properties[p].Property.Name, properties[p].GetStringValue(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].GetStringValue(node.CommentObject));
				}

				elem.AppendChild(comment);
			}

			// save events
			foreach(Nodes.Node.SubItem sub in node.SubItems)
			{
				if(sub is Nodes.Node.SubItemEvent)
				{
					Events.Event ne= ((Nodes.Node.SubItemEvent)sub).Event;

					XmlElement evnt= _xmlfile.CreateElement("Event");
					evnt.SetAttribute("Class", ne.GetType().FullName);

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

					elem.AppendChild(evnt);
				}
			}

			// 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, connector.GetChild(i));
				}
			}
		}
示例#3
0
		/// <summary>
		/// Exports all the properties of a ode and assigns them.
		/// </summary>
		/// <param name="file">The file we are exporting to.</param>
		/// <param name="nodeName">The name of the node we are setting the properties for.</param>
		/// <param name="node">The node whose properties we are exporting.</param>
		/// <param name="indent">The indent for the currently generated code.</param>
		protected void ExportProperties(StreamWriter file, string nodeName, Node node, string indent)
		{
			// export all the properties
			IList<DesignerPropertyInfo> properties= node.GetDesignerProperties();
			for(int p= 0; p <properties.Count; ++p)
			{
				// we skip properties which are not marked to be exported
				if(properties[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)) );
			}
		}
示例#4
0
        /// <summary>
        /// Exports all the properties of a node and assigns them.
        /// </summary>
        /// <param name="file">The file we are exporting to.</param>
        /// <param name="nodeName">The name of the node we are setting the properties for.</param>
        /// <param name="node">The node whose properties we are exporting.</param>
        /// <param name="indent">The indent for the currently generated code.</param>
        protected void ExportProperties(StreamWriter file, string nodeName, Node node, string indent)
        {
            //file.Write(string.Format("[id ='{1}'] ", indent, nodeName));
            // export all the properties
            IList<DesignerPropertyInfo> properties = node.GetDesignerProperties();
            for (int p = 0; p < properties.Count; ++p)
            {
                // we skip properties which are not marked to be exported
                if (properties[p].Attribute.HasFlags(DesignerProperty.DesignerFlags.NoExport))
                    continue;
                if (properties[p].Property.Name.ToLower() == "content")
                    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)));
                string expVal = properties[p].GetExportValue(node);
                if (!expVal.StartsWith("\"")) expVal = String.Format("\"{0}\"", expVal);
                file.Write(string.Format(" {2} = {3}", indent, nodeName, properties[p].Property.Name.ToLower(), expVal));
            }
        }