void InitType (HttpContext context)
{
lock (this_lock) {
if (!needs_init)
return;
try {
string physical_app_path = HttpRuntime.AppDomainAppPath;
string app_file = null;
app_file = Path.Combine (physical_app_path, "Global.asax");
if (!File.Exists (app_file)) {
app_file = Path.Combine (physical_app_path, "global.asax");
if (!File.Exists (app_file))
app_file = null;
}
#if NET_4_0
BuildManager.CallPreStartMethods ();
BuildManager.CompilingTopLevelAssemblies = true;
#endif
AppResourcesCompiler ac = new AppResourcesCompiler (context);
ac.Compile ();
#if WEBSERVICES_DEP
AppWebReferencesCompiler awrc = new AppWebReferencesCompiler ();
awrc.Compile ();
#endif
// Todo: Generate profile properties assembly from Web.config here
AppCodeCompiler acc = new AppCodeCompiler ();
acc.Compile ();
BuildManager.AllowReferencedAssembliesCaching = true;
// Get the default machine *.browser files.
string default_machine_browsers_path = Path.Combine (HttpRuntime.MachineConfigurationDirectory, "Browsers");
default_machine_browsers_files = new string[0];
if (Directory.Exists (default_machine_browsers_path)) {
default_machine_browsers_files
= Directory.GetFiles (default_machine_browsers_path, "*.browser");
}
// Note whether there are any App_Data/Mono_Machine_Browsers/*.browser files. If there
// are we will be using them instead of the default machine *.browser files.
string app_mono_machine_browsers_path = Path.Combine (Path.Combine (physical_app_path, "App_Data"), "Mono_Machine_Browsers");
app_mono_machine_browsers_files = new string[0];
if (Directory.Exists (app_mono_machine_browsers_path)) {
app_mono_machine_browsers_files
= Directory.GetFiles (app_mono_machine_browsers_path, "*.browser");
}
// Note whether there are any App_Browsers/*.browser files. If there
// are we will be using *.browser files for sniffing in addition to browscap.ini
string app_browsers_path = Path.Combine (physical_app_path, "App_Browsers");
app_browsers_files = new string[0];
if (Directory.Exists (app_browsers_path)) {
app_browsers_files = Directory.GetFiles (app_browsers_path, "*.browser");
}
#if NET_4_0
BuildManager.CompilingTopLevelAssemblies = false;
#endif
app_type = BuildManager.GetPrecompiledApplicationType ();
if (app_type == null && app_file != null) {
app_type = BuildManager.GetCompiledType ("~/" + Path.GetFileName (app_file));
if (app_type == null) {
string msg = String.Format ("Error compiling application file ({0}).", app_file);
throw new ApplicationException (msg);
}
} else if (app_type == null) {
app_type = typeof (System.Web.HttpApplication);
app_state = new HttpApplicationState ();
}
WatchLocationForRestart ("?lobal.asax");
#if CODE_DISABLED_UNTIL_SYSTEM_CONFIGURATION_IS_FIXED
// This is the correct behavior, but until
// System.Configuration is fixed to properly reload
// configuration when it is modified on disk, we need to use
// the recursive watchers below.
WatchLocationForRestart ("?eb.?onfig");
#else
// This is to avoid startup delays. Inotify/FAM code looks
// recursively for all subdirectories and adds them to the
// watch set. This can take a lot of time for deep directory
// trees (see bug #490497)
ThreadPool.QueueUserWorkItem (delegate {
try {
WatchLocationForRestart (String.Empty, "?eb.?onfig", true);
} catch (Exception e) {
Console.Error.WriteLine (e);
} }, null);
#endif
needs_init = false;
} catch (Exception) {
if (BuildManager.CodeAssemblies != null)
BuildManager.CodeAssemblies.Clear ();
if (BuildManager.TopLevelAssemblies != null)
BuildManager.TopLevelAssemblies.Clear ();
if (WebConfigurationManager.ExtraAssemblies != null)
WebConfigurationManager.ExtraAssemblies.Clear ();
throw;
}
}
}