示例#1
0
		public Node ProcessElement(XElement startEl)
		{
			if (IsComplex(startEl))
			{
				CompositeNode top = new CompositeNode(startEl.Name.LocalName);
				foreach (var attr in startEl.Attributes())
				{
					var leaf = new LeafNode(typeof(String), attr.Name.LocalName, attr.Value);
					top.AddChildNode(leaf);
				}
				foreach (var childEl in startEl.Elements())
				{
					var childNode = ProcessElement(childEl);
					top.AddChildNode(childNode);
				}

				return top;
			}
			else
			{
				LeafNode top = new LeafNode(typeof(String), "", "");
				return top;
			}

			
		}
		/// <summary>
		/// 
		/// </summary>
		/// <param name="root"></param>
		/// <param name="reader"></param>
		/// <param name="prefix"></param>
		public void PopulateTree(CompositeNode root, IDataReader reader, String prefix)
		{
			string[] fields = GetFields(reader);

			int[] indexesToSkip = FindDuplicateFields(fields);
			
			IndexedNode indexNode = new IndexedNode(prefix);
			
			int row = 0;

			while(reader.Read())
			{
				CompositeNode node = new CompositeNode(row.ToString());

				for(int i=0; i<reader.FieldCount; i++)
				{
					// Is in the skip list?
					if (Array.IndexOf(indexesToSkip, i) >= 0) continue;
					
					// Is null?
					if (reader.IsDBNull(i)) continue;
					
					Type fieldType = reader.GetFieldType(i);
					
					node.AddChildNode(new LeafNode(fieldType, fields[i], reader.GetValue(i)));
				}

				indexNode.AddChildNode(node);
			
				row++;
			}
			
			root.AddChildNode(indexNode);
		}
示例#3
0
		public CompositeNode BuildNode(XDocument doc)
		{
			var rootNode = new CompositeNode("root");
			rootNode.AddChildNode(ProcessElement(doc.Root));
			return rootNode;

		}
		private static CompositeNode GetParamsNode(int expectedValue)
		{
			CompositeNode paramsNode = new CompositeNode("root");
			IndexedNode listNode = new IndexedNode("myList");
			paramsNode.AddChildNode(listNode);
			listNode.AddChildNode(new LeafNode(typeof(int), "", expectedValue));
			return paramsNode;
		}
示例#5
0
        private IndexedNode GetOrCreateIndexedNode(CompositeNode parent, string nodeName)
        {
            Node node = parent.GetChildNode(nodeName);

            if (node != null && node.NodeType != NodeType.Indexed)
            {
                throw new BindingException("Attempt to create or obtain an indexed node " +
                                           "named {0}, but a node with the same exists with the type {1}", nodeName, node.NodeType);
            }

            if (node == null)
            {
                node = new IndexedNode(nodeName);
                parent.AddChildNode(node);
            }

            return((IndexedNode)node);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="root"></param>
        /// <param name="reader"></param>
        /// <param name="prefix"></param>
        public void PopulateTree(CompositeNode root, IDataReader reader, String prefix)
        {
            string[] fields = GetFields(reader);

            int[] indexesToSkip = FindDuplicateFields(fields);

            var indexNode = new IndexedNode(prefix);

            int row = 0;

            while (reader.Read())
            {
                var node = new CompositeNode(row.ToString());

                for (int i = 0; i < reader.FieldCount; i++)
                {
                    // Is in the skip list?
                    if (Array.IndexOf(indexesToSkip, i) >= 0)
                    {
                        continue;
                    }

                    // Is null?
                    if (reader.IsDBNull(i))
                    {
                        continue;
                    }

                    Type fieldType = reader.GetFieldType(i);

                    node.AddChildNode(new LeafNode(fieldType, fields[i], reader.GetValue(i)));
                }

                indexNode.AddChildNode(node);

                row++;
            }

            root.AddChildNode(indexNode);
        }
示例#7
0
		private IndexedNode GetOrCreateIndexedNode(CompositeNode parent, string nodeName)
		{
			Node node = parent.GetChildNode(nodeName);

			if (node != null && node.NodeType != NodeType.Indexed)
			{
				throw new BindingException("Attempt to create or obtain an indexed node " +
				                           "named {0}, but a node with the same exists with the type {1}", nodeName, node.NodeType);
			}

			if (node == null)
			{
				node = new IndexedNode(nodeName);
				parent.AddChildNode(node);
			}

			return (IndexedNode) node;
		}
示例#8
0
		private void AddLeafNode(CompositeNode parent, Type type, String nodeName, object value)
		{
			parent.AddChildNode(new LeafNode(type, nodeName, value));
		}
示例#9
0
 private void AddLeafNode(CompositeNode parent, Type type, String nodeName, object value)
 {
     parent.AddChildNode(new LeafNode(type, nodeName, value));
 }
示例#10
0
		public void AddToRoot(CompositeNode rootNode, XDocument doc)
		{
			var top = ProcessElement(doc.Root);
			rootNode.AddChildNode(top);
		}