2005-09-13 Sureshkumar T <tsureshkumar@novell.com>
[mono.git] / mcs / class / corlib / System / AppDomainSetup.cs
1 //
2 // System.AppDomainSetup.cs
3 //
4 // Author:
5 //   Dietmar Maurer (dietmar@ximian.com)
6 //
7 // (C) 2001 Ximian, Inc.  http://www.ximian.com
8 // Copyright (C) 2004-2005 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 using System.IO;
31 using System.Runtime.CompilerServices;
32 using System.Runtime.InteropServices;
33
34 #if NET_2_0
35 using System.Runtime.Hosting;
36 #endif
37
38 namespace System
39 {
40         [Serializable]
41         [ClassInterface (ClassInterfaceType.None)]
42         [MonoTODO ("Fix serialization compatibility with MS.NET")]
43         public sealed class AppDomainSetup : IAppDomainSetup
44         {
45                 string application_base;
46                 string application_name;
47                 string cache_path;
48                 string configuration_file;
49                 string dynamic_base;
50                 string license_file;
51                 string private_bin_path;
52                 string private_bin_path_probe;
53                 string shadow_copy_directories;
54                 string shadow_copy_files;
55                 bool publisher_policy;
56                 private bool path_changed;
57                 private LoaderOptimization loader_optimization;
58                 bool disallow_binding_redirects;
59                 bool disallow_code_downloads;
60 #if NET_2_0
61                 private ActivationArguments _activationArguments;
62 #endif
63
64                 public AppDomainSetup ()
65                 {
66                 }
67
68                 internal AppDomainSetup (AppDomainSetup setup)
69                 {
70                         application_base = setup.application_base;
71                         application_name = setup.application_name;
72                         cache_path = setup.cache_path;
73                         configuration_file = setup.configuration_file;
74                         dynamic_base = setup.dynamic_base;
75                         license_file = setup.license_file;
76                         private_bin_path = setup.private_bin_path;
77                         private_bin_path_probe = setup.private_bin_path_probe;
78                         shadow_copy_directories = setup.shadow_copy_directories;
79                         shadow_copy_files = setup.shadow_copy_files;
80                         publisher_policy = setup.publisher_policy;
81                         path_changed = setup.path_changed;
82                         loader_optimization = setup.loader_optimization;
83                         disallow_binding_redirects = setup.disallow_binding_redirects;
84                         disallow_code_downloads = setup.disallow_code_downloads;
85                 }
86
87 #if NET_2_0
88                 public AppDomainSetup (ActivationArguments activationArguments)
89                 {
90                         _activationArguments = activationArguments;
91                 }
92
93                 [MonoTODO ("LAMESPEC")]
94                 public AppDomainSetup (ActivationContext activationContext)
95                 {
96                         if (activationContext == null)
97                                 throw new ArgumentNullException ("activationContext");
98
99                         // _activationArguments = activationContext.ActivationArguments;
100
101                         // LAMESPEC: beta2 docs says that the context supplies a 
102                         // ActivationArguments object which isn't the case!
103                 }
104 #endif
105
106                 static string GetAppBase (string appBase)
107                 {
108                         if (appBase == null) return null;
109                         int len = appBase.Length;
110                         if (len >= 8 && appBase.ToLower ().StartsWith ("file://")) {
111                                 appBase = appBase.Substring (7);
112                                 if (Path.DirectorySeparatorChar != '/')
113                                         appBase = appBase.Replace ('/', Path.DirectorySeparatorChar);
114
115                         } else if (appBase.IndexOf (':') == -1) {
116                                 appBase = Path.GetFullPath (appBase);
117                         }
118
119                         return appBase;
120                 }
121                 
122                 public string ApplicationBase {
123                         get {
124                                 return application_base;
125                         }
126                         set {
127                                 application_base = GetAppBase (value);
128                         }
129                 }
130
131                 public string ApplicationName {
132                         get {
133                                 return application_name;
134                         }
135                         set {
136                                 application_name = value;
137                         }
138                 }
139
140                 public string CachePath {
141                         get {
142                                 return cache_path;
143                         }
144                         set {
145                                 cache_path = value;
146                         }
147                 }
148
149                 public string ConfigurationFile {
150                         get {
151                                 return configuration_file;
152                         }
153                         set {
154                                 configuration_file = value;
155                         }
156                 }
157
158                 public bool DisallowPublisherPolicy {
159                         get {
160                                 return publisher_policy;
161                         }
162                         set {
163                                 publisher_policy = value;
164                         }
165                 }
166
167                 public string DynamicBase {
168                         get {
169                                 if (dynamic_base == null)
170                                         return null;
171
172                                 if (Path.IsPathRooted (dynamic_base))
173                                         return dynamic_base;
174
175                                 if (ApplicationBase == null)
176                                         throw new MemberAccessException ("The ApplicationBase must be set before retrieving this property.");
177                                 
178                                 return Path.Combine (ApplicationBase, dynamic_base);
179                         }
180                         set {
181                                 if (application_name == null)
182                                         throw new MemberAccessException ("ApplicationName must be set before the DynamicBase can be set.");
183                                 uint id = (uint) application_name.GetHashCode ();
184                                 dynamic_base = Path.Combine (value, id.ToString("x"));
185                         }
186                 }
187
188                 public string LicenseFile {
189                         get {
190                                 return license_file;
191                         }
192                         set {
193                                 license_file = value;
194                         }
195                 }
196
197                 [MonoTODO ("--share-code")]
198                 public LoaderOptimization LoaderOptimization {
199                         get {
200                                 return loader_optimization;
201                         }
202                         set {
203                                 loader_optimization = value;
204                         }
205                 }
206
207                 public string PrivateBinPath {
208                         get {
209                                 return private_bin_path;
210                         }
211                         set {
212                                 private_bin_path = value;
213                                 path_changed = true;
214                         }
215                 }
216
217                 public string PrivateBinPathProbe {
218                         get {
219                                 return private_bin_path_probe;
220                         }
221                         set {
222                                 private_bin_path_probe = value;
223                                 path_changed = true;
224                         }
225                 }
226
227                 public string ShadowCopyDirectories {
228                         get {
229                                 return shadow_copy_directories;
230                         }
231                         set {
232                                 shadow_copy_directories = value;
233                         }
234                 }
235
236                 public string ShadowCopyFiles {
237                         get {
238                                 return shadow_copy_files;
239                         }
240                         set {
241                                 shadow_copy_files = value;
242                         }
243                 }
244
245 #if NET_1_1
246                 public bool DisallowBindingRedirects {
247                         get {
248                                 return disallow_binding_redirects;
249                         }
250                         set {
251                                 disallow_binding_redirects = value;
252                         }
253                 }
254
255                 public bool DisallowCodeDownload {
256                         get {
257                                 return disallow_code_downloads;
258                         }
259                         set {
260                                 disallow_code_downloads = value;
261                         }
262                 }
263 #endif
264
265 #if NET_2_0
266                 public ActivationArguments ActivationArguments {
267                         get { return _activationArguments; }
268                         set { _activationArguments = value; }
269                 }
270 #endif
271         }
272 }