Welcome to mirror list, hosted at ThFree Co, Russian Federation.

HttpCookieCollection.cs « System.Web « System.Web « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e3918e4a4f0105c4daad1fb0b78b3a22f1cd80cf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// 
// System.Web.HttpCookieCollection
//
// Author:
//   Patrik Torstensson (Patrik.Torstensson@labs2.com)
//   (First impl Bob Smith <bob@thestuff.net>)
//

using System;
using System.Web;
using System.Collections.Specialized;

namespace System.Web {
   public sealed class HttpCookieCollection : NameObjectCollectionBase {
      private HttpCookie [] _AllCookies;
      private string [] _AllKeys;
      
      private HttpResponse _Response;

      internal HttpCookieCollection(HttpResponse Response, bool ReadOnly) : base() {
         _Response = Response;
         IsReadOnly = ReadOnly;
      }

      public HttpCookieCollection() {
      }
      
      public string [] AllKeys {
         get {
            if (null == _AllKeys) {
               _AllKeys = BaseGetAllKeys();
            }

            return _AllKeys;
         }
      }
      
      public HttpCookie this[int index] {
         get {
            return Get(index);
         }
      }
      
      public HttpCookie this[string name] {
         get {
            return Get(name);
         }
      }

      public void Add(HttpCookie cookie) {
         if (null != _Response) {
            _Response.GoingToChangeCookieColl();
         }

         // empy performance cache
         _AllCookies = null;
         _AllKeys = null;

         BaseAdd(cookie.Name, cookie);

         if (null != _Response) {
            _Response.OnCookieAdd(cookie);
         }
      }

      public void Clear() {
         _AllCookies = null;
         _AllKeys = null;
         this.BaseClear();
      }

      public void CopyTo(Array dest, int index) {
         if (null == _AllCookies) {
            _AllCookies = new HttpCookie[Count];

            for (int i = 0; i != Count; i++) {
               _AllCookies[i] = Get(i);
            }
         }

         if (null != _AllCookies) {
            _AllCookies.CopyTo(dest, index);
         }
      }

      public HttpCookie Get(int index) {
         return (HttpCookie) BaseGet(index);
      }

      public HttpCookie Get(string name) {
         HttpCookie oRet = (HttpCookie) BaseGet(name);
         if (null == oRet && _Response != null) {
            _AllCookies = null;
            _AllKeys = null;

            _Response.GoingToChangeCookieColl();
            
            oRet = new HttpCookie(name);
            BaseAdd(name, oRet);

            _Response.OnCookieAdd(oRet);
         }

         return oRet;
      }

      public string GetKey(int index) {
         return this.BaseGetKey(index);
      }

      public void Remove(string name) {
         if (null != _Response) {
            _Response.GoingToChangeCookieColl();
         }

         _AllCookies = null;
         _AllKeys = null;
         this.BaseRemove(name);
         
         if (null != _Response) {
            _Response.ChangedCookieColl();
         }
      }

      public void Set(HttpCookie cookie) {
         if (null != _Response) {
            _Response.GoingToChangeCookieColl();
         }

         _AllCookies = null;
         _AllKeys = null;
         this.BaseSet(cookie.Name, cookie);

         if (null != _Response) {
            _Response.ChangedCookieColl();
         }
      }
   }
}