1 /*
2 Used to determine Browser Capabilities by the Browsers UserAgent String and related
3 Browser supplied Headers.
4 Copyright (C) 2002-Present  Owen Brady (Ocean at owenbrady dot net)
5 and Dean Brettle (dean at brettle dot com)
6 
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:
13 
14 The above copyright notice and this permission notice shall be included in all
15 copies or substantial portions of the Software.
16 
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.
23 */
24 namespace System.Web.Configuration.nBrowser
25 {
26 	using System;
27 	using System.Collections.Generic;
28 	using System.Text;
29 
30 	class Identification
31 	{
32 		private bool MatchType = true;
33 		private string MatchName = string.Empty;
34 		private string MatchGroup = string.Empty;
35 		//FxCop will complain that this is assigned to but never used.
36 		//Reason I keep it around is to see the actual regex expresion
37 		//used without having to drill down deep in regex object to find it
38 		private string MatchPattern = string.Empty;
39 		private System.Text.RegularExpressions.Regex RegexPattern;
40 
41 		/// <summary>
42 		/// Sets up Initial Identification Object, So that it is easier debuging
43 		/// and passing Regular expression objects around.
44 		/// </summary>
45 		/// <param name="matchType">True = Match, False = NonMatch</param>
46 		/// <param name="matchGroup">Two Options, capability, header</param>
47 		/// <param name="matchName">Header Name</param>
48 		/// <param name="matchPattern">Regular Expression Pattern</param>
Identification(bool matchType, string matchGroup, string matchName, string matchPattern)49 		public Identification(bool matchType, string matchGroup, string matchName, string matchPattern)
50 		{
51 			this.MatchType = matchType;
52 			this.MatchGroup = matchGroup;
53 			this.MatchName = matchName;
54 			this.MatchPattern = matchPattern;
55 			RegexPattern = new System.Text.RegularExpressions.Regex(matchPattern);
56 		}
57 		/// <summary>
58 		/// Builds a Match Object from the result of the regular expression
59 		/// </summary>
60 		/// <param name="Header">Header Value which the regular expression will evaluate.</param>
61 		/// <returns>A Match object created from the regular expression and the passed in header.</returns>
GetMatch(string Header)62 		public System.Text.RegularExpressions.Match GetMatch(string Header)
63 		{
64 			return RegexPattern.Match(Header == null ? string.Empty : Header);
65 		}
66 		/// <summary>
67 		///
68 		/// </summary>
IsMatchSuccessful(System.Text.RegularExpressions.Match m)69 		public bool IsMatchSuccessful(System.Text.RegularExpressions.Match m)
70 		{
71 			// Return true if a "match" matched successfully or a "nonmatch" didn't match.
72 			return (MatchType == m.Success);
73 		}
74 
75 		/// <summary>
76 		///
77 		/// </summary>
78 		public string Name
79 		{
80 			get
81 			{
82 				return this.MatchName;
83 			}
84 		}
85 		/// <summary>
86 		///
87 		/// </summary>
88 		public string Group
89 		{
90 			get
91 			{
92 				return this.MatchGroup;
93 			}
94 		}
95 		public string Pattern
96 		{
97 			get
98 			{
99 				return MatchPattern;
100 			}
101 		}
102 	}
103 }
104