2008-09-26 Marek Habersack <mhabersack@novell.com>
[mono.git] / mcs / class / System.Web / System.Web.SessionState / SessionConfig.cs
1 //
2 // System.Web.SessionState.SessionConfig
3 //
4 // Authors:
5 //      Gonzalo Paniagua Javier (gonzalo@ximian.com)
6 //
7 // (C) 2003 Ximian, Inc (http://www.ximian.com)
8 // Copyright (C) 2005-2006 Novell, Inc (http://www.novell.com)
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
17 // 
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 // 
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 //
29
30 namespace System.Web.SessionState
31 {
32         class SessionConfig
33         {
34                 internal SessionStateMode Mode;
35                 internal int Timeout; // minutes
36                 internal bool CookieLess;
37                 internal string StateConnectionString;
38                 internal string SqlConnectionString;
39                 internal string StateNetworkTimeout;
40
41                 public SessionConfig (object parent)
42                 {
43                         SessionConfig p = (parent as SessionConfig);
44                         if (p != null) {
45                                 CookieLess = p.CookieLess;
46                                 Mode = p.Mode;
47                                 Timeout = p.Timeout;
48                                 StateConnectionString = p.StateConnectionString;
49                                 SqlConnectionString = p.SqlConnectionString;
50                         } else {
51                                 Mode = SessionStateMode.InProc;
52                                 Timeout = 20;
53                                 StateConnectionString = "127.0.0.1:42424";
54                                 SqlConnectionString = "user id=sa;password=;data source=127.0.0.1";
55                         }
56                 }
57
58                 internal bool SetMode (string value)
59                 {
60                         try {
61                                 Mode = (SessionStateMode) Enum.Parse (typeof (SessionStateMode), value, true);
62                         } catch {
63                                 return false;
64                         }
65
66                         return true;
67                 }
68
69                 internal bool SetCookieLess (string value)
70                 {
71                         if (value == null)
72                                 return false;
73
74                         CookieLess = (0 == String.Compare ("true", value, true));
75                         if (!CookieLess && String.Compare ("false", value, true) != 0)
76                                 return false;
77
78                         return true;
79                 }
80
81                 internal bool SetTimeout (string value)
82                 {
83                         try {
84                                 Timeout = Int32.Parse (value);
85                         } catch {
86                                 return false;
87                         }
88                         
89                         return true;
90                 }
91
92                 internal void SetStateConnectionString (string value)
93                 {
94                         StateConnectionString = value;
95                 }
96
97                 internal void SetSqlConnectionString (string value)
98                 {
99                         SqlConnectionString = value;
100                 }
101
102                 internal void SetStateNetworkTimeout (string value)
103                 {
104                         StateNetworkTimeout = value;
105                 }
106         }
107 }
108