[System.Web.Extensions] Update default profile and remove old profiles files
[mono.git] / mcs / class / System.Web / System.Web.Caching / CachedRawResponse.cs
1 //
2 // System.Web.Caching.CachedRawResponse
3 //
4 // Author(s):
5 //  Jackson Harper (jackson@ximian.com)
6 //  Marek Habersack <mhabersack@novell.com>
7 //
8 // (C) 2003-2009 Novell, Inc (http://www.novell.com)
9 //
10
11 //
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
19 // 
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
22 // 
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 //
31
32
33 using System;
34 using System.Collections;
35 using System.Collections.Specialized;
36 using System.IO;
37 using System.Text;
38
39 using System.Collections.Generic;
40
41 namespace System.Web.Caching
42 {
43         sealed class CachedRawResponse
44         {
45                 public sealed class DataItem
46                 {
47                         public readonly byte[] Buffer;
48                         public readonly long Length;
49                         public readonly HttpResponseSubstitutionCallback Callback;
50                         
51                         public DataItem (byte[] buffer, long length)
52                         {
53                                 Buffer = buffer;
54                                 Length = length;
55                         }
56
57                         public DataItem (HttpResponseSubstitutionCallback callback) : this (null, 0)
58                         {
59                                 Callback = callback;
60                         }
61                 }
62                 
63                 HttpCachePolicy policy;
64                 CachedVaryBy varyby;
65                 int status_code;
66                 string status_desc;
67                 NameValueCollection headers;
68                 List <DataItem> data;
69
70                 IList Data {
71                         get {
72                                 if (data == null)
73                                         data = new List <DataItem> ();
74
75                                 return data;
76                         }
77                 }
78                 
79                 public CachedRawResponse (HttpCachePolicy policy)
80                 {
81                         this.policy = policy;
82                 }
83
84                 public HttpCachePolicy Policy {
85                         get { return policy; }
86                         set { policy = value; }
87                 }
88
89                 public CachedVaryBy VaryBy {
90                         get { return varyby; }
91                         set { varyby = value; }
92                 }
93                 
94                 public int StatusCode {
95                         get { return status_code; }
96                         set { status_code = value; }
97                 }
98
99                 public string StatusDescription {
100                         get { return status_desc; }
101                         set { status_desc = value; }
102                 }
103
104                 public NameValueCollection Headers {
105                         get { return headers; }
106                 }
107
108                 public void SetHeaders (NameValueCollection headers)
109                 {
110                         this.headers = headers;
111                 }
112
113                 public void SetData (MemoryStream ms)
114                 {
115                         if (ms == null)
116                                 return;
117                         
118                         Data.Add (new DataItem (ms.GetBuffer (), ms.Length));
119                 }
120
121                 public void SetData (HttpResponseSubstitutionCallback callback)
122                 {
123                         if (callback == null)
124                                 return;
125
126                         Data.Add (new DataItem (callback));
127                 }
128                 
129                 public IList GetData ()
130                 {
131                         int count = data != null ? data.Count :0;
132                         if (count == 0)
133                                 return null;
134
135                         return data;
136                 }
137         }
138 }
139