3 Used to determine Browser Capabilities by the Browsers UserAgent String and related
4 Browser supplied Headers.
5 Copyright (C) 2002-Present Owen Brady (Ocean at xvision.com)
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software and associated documentation files (the "Software"), to deal
9 in the Software without restriction, including without limitation the rights
10 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 copies of the Software, and to permit persons to whom the Software is furnished
12 to do so, subject to the following conditions:
14 The above copyright notice and this permission notice shall be included in all
15 copies or substantial portions of the Software.
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
18 INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
19 PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 namespace System.Web.Configuration.nBrowser
27 using System.Collections.Generic;
29 using System.Web.Configuration.nBrowser;
33 private System.Xml.XmlDocument BrowserFile;
34 internal System.Web.Configuration.nBrowser.Node[] Nodes;
35 private System.Collections.Specialized.ListDictionary Lookup;
36 private System.Collections.Specialized.ListDictionary DefaultLookup;
37 internal List<Node> RefNodes;
39 public string FileName
46 private string pFileName = string.Empty;
47 public File(string file)
51 BrowserFile = new System.Xml.XmlDocument();
52 //I can put this in a try /catch but I want
54 BrowserFile.Load(file);
56 this.Load(BrowserFile);
61 /// <param name="file"></param>
62 public File(System.Xml.XmlDocument BrowserFile, string filename)
65 this.Load(BrowserFile);
67 private void Load(System.Xml.XmlDocument BrowserFile)
69 Lookup = new System.Collections.Specialized.ListDictionary();
70 DefaultLookup = new System.Collections.Specialized.ListDictionary();
71 RefNodes = new List<Node>();
72 System.Xml.XmlNode node;
73 //I know this might allocate more nodes then needed but never less.
74 Nodes = new Node[BrowserFile.DocumentElement.ChildNodes.Count];
75 for (int a = 0;a <= BrowserFile.DocumentElement.ChildNodes.Count - 1;a++)
77 node = BrowserFile.DocumentElement.ChildNodes[a];
79 if (node.NodeType == System.Xml.XmlNodeType.Comment)
83 Nodes[a] = new Node(node);
84 Nodes[a].FileName = FileName;
85 if (Nodes[a].NameType != NodeType.DefaultBrowser)
87 //fxcop sugguested this was faster then
88 //Nodes[a].refID != string.Empty
89 if (Nodes[a].RefId.Length > 0)
91 RefNodes.Add(Nodes[a]);
93 else if (Lookup.Contains(Nodes[a].Id) == false)
95 Lookup.Add(Nodes[a].Id, a);
99 throw new nBrowser.Exception("Duplicate ID found \"" + Nodes[a].Id + "\"");
104 //fxcop sugguested this was faster then
105 //Nodes[a].refID != string.Empty
106 if (Nodes[a].RefId.Length > 0)
108 RefNodes.Add(Nodes[a]);
110 else if (DefaultLookup.Contains(Nodes[a].Id) == false)
112 DefaultLookup.Add(Nodes[a].Id, a);
116 throw new nBrowser.Exception("Duplicate ID found \"" + Nodes[a].Id + "\"");
122 /// Returns a Array of strings, which represent the Id Attributes of all the
123 /// Browser/Gatway Nodes
130 string[] k = new string[Lookup.Keys.Count];
132 //This will copy the Keys In Alphabetical Order
133 //Lookup.Keys.CopyTo(k,0);
134 //This Method is ment to copy the Keys in the order
135 //that they were in the xml file.
137 for (int i = 0;i <= Nodes.Length - 1;i++)
139 if (Nodes[i] != null && Nodes[i].NameType != NodeType.DefaultBrowser
140 && Nodes[i].RefId.Length == 0)
150 /// Returns a Array of strings, which represent the Id Attributes of all the
151 /// DefaultBrowser Nodes
153 public string[] DefaultKeys
157 string[] k = new string[DefaultLookup.Keys.Count];
159 //This will copy the Keys In Alphabetical Order
160 //DefaultLookup.Keys.CopyTo(k,0);
161 //This Method is ment to copy the Keys in the order
162 //that they were in the xml file.
164 for (int i = 0;i <= Nodes.Length - 1;i++)
166 if (Nodes[i] != null && Nodes[i].NameType == NodeType.DefaultBrowser)
179 /// <param name="Key"></param>
180 /// <returns></returns>
181 internal Node GetNode(string Key)
183 object o = Lookup[Key];
185 return GetDefaultNode (Key);
186 return Nodes[(int)o];
192 /// <param name="Key"></param>
193 /// <returns></returns>
194 internal Node GetDefaultNode(string Key)
196 object o = DefaultLookup[Key];
199 return Nodes[(int)o];