Exemple #1
0
		private void Load(System.Xml.XmlDocument BrowserFile)
		{
			Lookup = new System.Collections.Specialized.ListDictionary();
			DefaultLookup = new System.Collections.Specialized.ListDictionary();
			RefNodes = new List<Node>();
			System.Xml.XmlNode node;
			//I know this might allocate more nodes then needed but never less.
			Nodes = new Node[BrowserFile.DocumentElement.ChildNodes.Count];
			for (int a = 0;a <= BrowserFile.DocumentElement.ChildNodes.Count - 1;a++)
			{
				node = BrowserFile.DocumentElement.ChildNodes[a];

				if (node.NodeType == System.Xml.XmlNodeType.Comment)
				{
					continue;
				}
				Nodes[a] = new Node(node);
				Nodes[a].FileName = FileName;
				if (Nodes[a].NameType != NodeType.DefaultBrowser)
				{
					//fxcop sugguested this was faster then
					//Nodes[a].refID != string.Empty
					if (Nodes[a].RefId.Length > 0)
					{
						RefNodes.Add(Nodes[a]);
					}
					else if (Lookup.Contains(Nodes[a].Id) == false)
					{
						Lookup.Add(Nodes[a].Id, a);
					}
					else
					{
						throw new nBrowser.Exception("Duplicate ID found \"" + Nodes[a].Id + "\"");
					}
				}
				else
				{
					//fxcop sugguested this was faster then
					//Nodes[a].refID != string.Empty
					if (Nodes[a].RefId.Length > 0)
					{
						RefNodes.Add(Nodes[a]);
					}
					else if (DefaultLookup.Contains(Nodes[a].Id) == false)
					{
						DefaultLookup.Add(Nodes[a].Id, a);
					}
					else
					{
						throw new nBrowser.Exception("Duplicate ID found \"" + Nodes[a].Id + "\"");
					}
				}
			}
		}
Exemple #2
0
		/// <summary>
		/// Returns an Array of Nodes that have been built. To be used for Design/Editors of Browser
		/// files.
		/// </summary>
		/// <returns></returns>
		public Node[] Nodes()
		{
			Node[] browsers;
			nBrowser.File[] files = new nBrowser.File[Browserfiles.Count];
			Browserfiles.Values.CopyTo(files, 0);
			int count = 0;
			for (int i = 0;i <= files.Length - 1;i++)
			{
				count += files[i].Nodes.Length;
			}
			browsers = new Node[count];
			count = 0;
			for (int i = 0;i <= files.Length - 1;i++)
			{
				for (int a = 0;a <= files[i].Nodes.Length - 1;a++)
				{
					browsers[count] = files[i].Nodes[a];
					count++;
				}
			}
			return browsers;
		}
		/// <summary>
		/// 
		/// </summary>
		/// <param name="child"></param>
		public void RemoveChild(Node child)
		{
			if (child == null)
			{
				return;
			}
			if (child.NameType == nBrowser.NodeType.Browser || child.NameType == nBrowser.NodeType.Gateway)
			{
				Children.Remove(child.Id);
				ChildrenKeys.Remove(child.Id);
			}
			else if (child.NameType == NodeType.DefaultBrowser)
			{
				DefaultChildren.Remove(child.Id);
				DefaultChildrenKeys.Remove(child.Id);
			}
		}
Exemple #4
0
		private Node InitializeTree()
		{
			Node root = new Node();
			//Custom Sorted List, to allow where Multple files in Diff directorys might have the same
			//filename. So still to some degree first come first serve but might be close enough
			//to how microsoft System to match much more closely.
			System.Collections.Generic.SortedList<string, System.Collections.Generic.List<nBrowser.File>> list;
			list = new System.Collections.Generic.SortedList<string, System.Collections.Generic.List<nBrowser.File>>();

			for (int i = 0;i <= Browserfiles.Count - 1;i++)
			{
				if (list.ContainsKey(nbrowserfiles[i].FileName) == false)
				{
					System.Collections.Generic.List<nBrowser.File> l;
					l = new System.Collections.Generic.List<nBrowser.File>();
					list.Add(nbrowserfiles[i].FileName, l);
				}
				list[nbrowserfiles[i].FileName].Add(nbrowserfiles[i]);
			}
			nBrowser.File[] files = new nBrowser.File[Browserfiles.Count];

			int count = 0;
			for (int i = 0;i <= list.Count - 1;i++)
			{
				System.Collections.Generic.List<nBrowser.File> l = list[list.Keys[i]];
				for (int b = 0;b <= l.Count - 1;b++)
				{
					files[count] = l[b];
					count++;
				}
			}

			#region Connect Nodes
			for (int i = 0;i <= Browserfiles.Count - 1;i++)
			{
				for (int a = 0;a <= files[i].Keys.Length - 1;a++)
				{
					Node child = files[i].GetNode(files[i].Keys[a]);
					Node parent = null;
					if (child.ParentId.Length > 0)
					{
						parent = this.GetNode(child.ParentId);
						if (parent == null)
							throw new nBrowser.Exception(String.Format("Parent not found with id = {0}", child.ParentId));
					}
					if (parent == null)
						parent = root;
					parent.AddChild(child);
				}
			}
			#endregion
			
			#region Inject DefaultBrowser Nodes
			for (int i = 0;i <= Browserfiles.Count - 1;i++)
			{
				for (int a = 0;a <= files[i].DefaultKeys.Length - 1;a++)
				{
					Node defaultNode = files[i].GetDefaultNode(files[i].DefaultKeys[a]);
					Node node = this.GetNode(defaultNode.Id);
					if (node == defaultNode) 
					{
						// there is no regular node so the defaultNode is already at
						// the correct spot in the tree.
						continue;
					}
					Node parentNode = this.GetNode(node.ParentId);
					if (parentNode == null)
						parentNode = root;
					// insert the default node between the regular node and it's parent.
					parentNode.RemoveChild(node);
					defaultNode.AddChild(node);
					parentNode.AddChild(defaultNode);
				}
			}
			#endregion

			#region Merge Ref Nodes
			for (int i = 0;i <= Browserfiles.Count - 1;i++)
			{
				foreach (Node refNode in files[i].RefNodes) {
					GetNode(refNode.RefId).MergeFrom(refNode);
				}
			}
			#endregion

			return root;
		}
		/// <summary>
		/// Merge capabilities, captures, markupTextWriters, and adapters from another Node into this Node.
		/// </summary>
		/// <param name="n">node to merge with this node</param>
		public void MergeFrom(Node n)
		{
			if (n.Capabilities != null)
			{
				if (Capabilities == null)
					Capabilities =  new System.Collections.Specialized.NameValueCollection(n.Capabilities.Count);
				foreach (string capName in n.Capabilities)
					Capabilities[capName] = n.Capabilities[capName];
			}
			
			int newLength = 0;
			if (Capture != null)
				newLength += Capture.Length;
			if (n.Capture != null)
				newLength += n.Capture.Length;
			Identification[] newCapture = new Identification[newLength];
			if (Capture != null)
				Array.Copy(Capture, 0, newCapture, 0, Capture.Length);
			if (n.Capture != null)
				Array.Copy(n.Capture, 0, newCapture, (Capture != null ? Capture.Length : 0), n.Capture.Length);
			Capture = newCapture;
			
			if (n.MarkupTextWriterType != null && n.MarkupTextWriterType.Length > 0)
				MarkupTextWriterType = n.MarkupTextWriterType;
			
			if (n.Adapter != null)
			{
				if (Adapter == null)
					Adapter = new System.Collections.Specialized.NameValueCollection();
				foreach (string controlType in n.Adapter)
					Adapter[controlType] = n.Adapter[controlType];
			}
		}