importing messaging-2008 branch to trunk, going on.
[mono.git] / mcs / class / System.Web / System.Web.Configuration_2.0 / CapabilitiesBuild.cs
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 xvision.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
25 namespace System.Web.Configuration
26 {
27         using System;
28         using System.Collections.Generic;
29         using System.Text;
30
31         internal abstract class CapabilitiesBuild : ICapabilitiesProcess
32         {
33                 /// <summary>
34                 /// A list of all headers, that the Browser Detective Code will possibly access.
35                 /// </summary>
36                 System.Collections.ObjectModel.Collection<string> AllPossibleheaders;
37                 /// <summary>
38                 /// 
39                 /// </summary>
40                 /// <param name="list"></param>
41                 /// <returns></returns>
42                 protected abstract System.Collections.ObjectModel.Collection<string> HeaderNames(System.Collections.ObjectModel.Collection<string> list);
43                 /// <summary>
44                 /// 
45                 /// </summary>
46                 /// <param name="userAgent"></param>
47                 /// <param name="initialCapabilities"></param>
48                 /// <returns></returns>
49                 public System.Web.Configuration.CapabilitiesResult Process(string userAgent, System.Collections.IDictionary initialCapabilities)
50                 {
51                         System.Collections.Specialized.NameValueCollection header;
52                         header = new System.Collections.Specialized.NameValueCollection(1);
53                         header.Add("User-Agent", userAgent);
54                         return Process(header, initialCapabilities);
55                 }
56                 /// <summary>
57                 /// 
58                 /// </summary>
59                 /// <param name="request"></param>
60                 /// <param name="initialCapabilities"></param>
61                 /// <returns></returns>
62                 public System.Web.Configuration.CapabilitiesResult Process(System.Web.HttpRequest request, System.Collections.IDictionary initialCapabilities)
63                 {
64                         if (request != null)
65                         {
66                                 return Process(request.Headers, initialCapabilities);
67                         }
68                         else
69                         {
70                                 return Process("", initialCapabilities);
71                         }
72                 }
73                 /// <summary>
74                 /// 
75                 /// </summary>
76                 /// <param name="header"></param>
77                 /// <param name="initialCapabilities"></param>
78                 /// <returns></returns>
79                 public abstract System.Web.Configuration.CapabilitiesResult Process(System.Collections.Specialized.NameValueCollection header, System.Collections.IDictionary initialCapabilities);
80                 /// <summary>
81                 /// Creates a Checksum from the Header values used by the Browser Detection System.
82                 /// </summary>
83                 /// <param name="header">List of Header name/value pairs</param>
84                 /// <returns>checksum value to be used for caching/duplicate checks</returns>
85                 public virtual string HeaderChecksum(System.Collections.Specialized.NameValueCollection header)
86                 {
87                         if (AllPossibleheaders == null)
88                         {
89                                 AllPossibleheaders = this.HeaderNames(new System.Collections.ObjectModel.Collection<string>());
90                         }
91                         System.IO.MemoryStream stream = new System.IO.MemoryStream();
92                         System.IO.StreamWriter writer = new System.IO.StreamWriter(stream, System.Text.Encoding.Default);
93
94                         for (int i = 0;i <= AllPossibleheaders.Count - 1;i++)
95                         {
96                                 if (String.IsNullOrEmpty(header[AllPossibleheaders[i]]) == false)
97                                 {
98                                         writer.WriteLine(header[AllPossibleheaders[i]]);
99                                 }
100                         }
101                         writer.Flush();
102                         byte[] array = stream.ToArray();
103                         writer.Close();
104                         return CapabilitiesChecksum.BuildChecksum(array);
105                 }
106                 /// <summary>
107                 /// Provides a Method to Load the Browser Detection class with a default Data file that is
108                 /// embeded in the dll.
109                 /// </summary>
110                 public abstract void LoadDefaultEmbeddedResource();
111
112                 public virtual string DataFileVersion
113                 {
114                         get
115                         {
116                                 return System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
117                         }
118                 }
119         }
120 }
121 #endif