Пример #1
0
		/// <summary>
		/// Serializes AdvTree object to XmlElement object.
		/// </summary>
		/// <param name="tree">Instance of AdvTree to serialize.</param>
		/// <param name="parent">XmlElement to serialize to.</param>
		public static void Save(AdvTree tree, XmlElement parent)
		{
			NodeSerializationContext context = new NodeSerializationContext();
			context.RefXmlElement = parent;
			context.AdvTree = tree;
			context.HasSerializeNodeHandlers = tree.HasSerializeNodeHandlers;
			context.HasDeserializeNodeHandlers = tree.HasDeserializeNodeHandlers;
			
			foreach(Node node in tree.Nodes)
			{
				Save(node, context);
			}
		}
Пример #2
0
		/// <summary>
		/// Load nodes from XmlElement.
		/// </summary>
		/// <param name="tree">Reference to AdvTree to be populated.</param>
		/// <param name="parent">XmlElement that tree was serialized to.</param>
		public static void Load(AdvTree tree, XmlElement parent)
		{
			tree.BeginUpdate();
			tree.DisplayRootNode = null;
			tree.Nodes.Clear();
			
			NodeSerializationContext context = new NodeSerializationContext();
			context.AdvTree = tree;
			context.HasDeserializeNodeHandlers  = tree.HasDeserializeNodeHandlers;
			context.HasSerializeNodeHandlers = tree.HasSerializeNodeHandlers;
			
			try
			{
				foreach(XmlNode xmlNode in parent.ChildNodes)
				{
					if(xmlNode.Name==XmlNodeName && xmlNode is XmlElement)
					{
						Node node=new Node();
						tree.Nodes.Add(node);
						context.RefXmlElement = xmlNode as XmlElement;
						LoadNode(node, context);
					}
				}
			}
			finally
			{
				tree.EndUpdate();
			}
		}
Пример #3
0
		/// <summary>
		/// Load single node and it's child nodes if any.
		/// </summary>
		/// <param name="nodeToLoad">New instance of node that is populated with loaded data.</param>
		/// <param name="context">Provides deserialization context.</param>
		public static void LoadNode(Node nodeToLoad, NodeSerializationContext context)
		{
			XmlElement xmlNode = context.RefXmlElement;
			
			ElementSerializer.Deserialize(nodeToLoad, xmlNode);

			foreach(XmlNode xmlChild in xmlNode.ChildNodes)
			{
				XmlElement xmlElem = xmlChild as XmlElement;
				if(xmlElem == null)
					continue;
				if(xmlElem.Name==XmlNodeName)
				{
					Node node=new Node();
					nodeToLoad.Nodes.Add(node);
					context.RefXmlElement = xmlElem;
					LoadNode(node, context);
				}
				else if(xmlElem.Name == XmlCellsName)
				{
					LoadCells(nodeToLoad, xmlElem);
				}
				else if(xmlElem.Name == XmlCustomName)
				{
					if(context.HasDeserializeNodeHandlers)
					{
						SerializeNodeEventArgs e = new SerializeNodeEventArgs(nodeToLoad, xmlNode, xmlElem);
						context.AdvTree.InvokeDeserializeNode(e);
					}
				}
			}
			context.RefXmlElement = xmlNode;
		}
Пример #4
0
		/// <summary>
		/// Serializes Node and all child nodes to XmlElement object.
		/// </summary>
		/// <param name="node">Node to serialize.</param>
		/// <param name="context">Provides serialization context.</param>
		public static void Save(Node node, NodeSerializationContext context)
		{
			XmlElement parent = context.RefXmlElement;
			
			XmlElement xmlNode=parent.OwnerDocument.CreateElement(XmlNodeName);
			parent.AppendChild(xmlNode);
			
			ElementSerializer.Serialize(node, xmlNode);
			
			if(context.HasSerializeNodeHandlers)
			{
				XmlElement customXml = parent.OwnerDocument.CreateElement(XmlCustomName);
				SerializeNodeEventArgs e = new SerializeNodeEventArgs(node, xmlNode, customXml);
				context.AdvTree.InvokeSerializeNode(e);
				if (customXml.Attributes.Count > 0 || customXml.ChildNodes.Count > 0)
					xmlNode.AppendChild(customXml);
			}
			
			if(node.Cells.Count>1)
			{
				XmlElement xmlCells = parent.OwnerDocument.CreateElement(XmlCellsName);
				xmlNode.AppendChild(xmlCells);
				
				for(int i=1; i<node.Cells.Count;i++)
				{
					Cell cell=node.Cells[i];
					XmlElement xmlCell= parent.OwnerDocument.CreateElement(XmlCellName);
					xmlCells.AppendChild(xmlCell);
					ElementSerializer.Serialize(cell, xmlCell);
					if(cell.ShouldSerializeImages())
					{
						XmlElement xmlCellImages = parent.OwnerDocument.CreateElement(XmlCellImagesName);
						xmlCell.AppendChild(xmlCellImages);
						ElementSerializer.Serialize(cell.Images, xmlCellImages);
					}
				}
			}
			
			context.RefXmlElement = xmlNode;
			foreach(Node childNode in node.Nodes)
			{
				Save(childNode, context);
			}
			context.RefXmlElement = parent;
		}