Identification.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #if NET_2_0
  2. /*
  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 owenbrady dot net)
  6. and Dean Brettle (dean at brettle dot 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:
  13. The above copyright notice and this permission notice shall be included in all
  14. copies or substantial portions of the Software.
  15. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  16. INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  17. PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  18. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  19. OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  20. SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  21. */
  22. namespace System.Web.Configuration.nBrowser
  23. {
  24. using System;
  25. using System.Collections.Generic;
  26. using System.Text;
  27. class Identification
  28. {
  29. private bool MatchType = true;
  30. private string MatchName = string.Empty;
  31. private string MatchGroup = string.Empty;
  32. //FxCop will complain that this is assigned to but never used.
  33. //Reason I keep it around is to see the actual regex expresion
  34. //used without having to drill down deep in regex object to find it
  35. private string MatchPattern = string.Empty;
  36. private System.Text.RegularExpressions.Regex RegexPattern;
  37. /// <summary>
  38. /// Sets up Initial Identification Object, So that it is easier debuging
  39. /// and passing Regular expression objects around.
  40. /// </summary>
  41. /// <param name="matchType">True = Match, False = NonMatch</param>
  42. /// <param name="matchGroup">Two Options, capability, header</param>
  43. /// <param name="matchName">Header Name</param>
  44. /// <param name="matchPattern">Regular Expression Pattern</param>
  45. public Identification(bool matchType, string matchGroup, string matchName, string matchPattern)
  46. {
  47. this.MatchType = matchType;
  48. this.MatchGroup = matchGroup;
  49. this.MatchName = matchName;
  50. this.MatchPattern = matchPattern;
  51. RegexPattern = new System.Text.RegularExpressions.Regex(matchPattern);
  52. }
  53. /// <summary>
  54. /// Builds a Match Object from the result of the regular expression
  55. /// </summary>
  56. /// <param name="Header">Header Value which the regular expression will evaluate.</param>
  57. /// <returns>A Match object created from the regular expression and the passed in header.</returns>
  58. public System.Text.RegularExpressions.Match GetMatch(string Header)
  59. {
  60. return RegexPattern.Match(Header == null ? string.Empty : Header);
  61. }
  62. /// <summary>
  63. ///
  64. /// </summary>
  65. public bool IsMatchSuccessful(System.Text.RegularExpressions.Match m)
  66. {
  67. // Return true if a "match" matched successfully or a "nonmatch" didn't match.
  68. return (MatchType == m.Success);
  69. }
  70. /// <summary>
  71. ///
  72. /// </summary>
  73. public string Name
  74. {
  75. get
  76. {
  77. return this.MatchName;
  78. }
  79. }
  80. /// <summary>
  81. ///
  82. /// </summary>
  83. public string Group
  84. {
  85. get
  86. {
  87. return this.MatchGroup;
  88. }
  89. }
  90. public string Pattern
  91. {
  92. get
  93. {
  94. return MatchPattern;
  95. }
  96. }
  97. }
  98. }
  99. #endif