public static void RunApplication(Delegate/*!*/ mainRoutine, string relativeSourcePath, string sourceRoot)
{
bool is_pure = mainRoutine is RoutineDelegate;
ApplicationContext app_context = ApplicationContext.Default;
// default culture:
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
// try to preload configuration (to prevent exceptions during InitApplication:
try
{
Configuration.Load(app_context);
}
catch (ConfigurationErrorsException e)
{
Console.WriteLine(e.Message);
return;
}
ApplicationConfiguration app_config = Configuration.Application;
if (is_pure && !app_config.Compiler.LanguageFeaturesSet)
app_config.Compiler.LanguageFeatures = LanguageFeatures.PureModeDefault;
// environment settings; modifies the PATH variable to fix LoadLibrary called by native extensions:
if (EnvironmentUtils.IsDotNetFramework)
{
string path = Environment.GetEnvironmentVariable("PATH");
path = String.Concat(path, Path.PathSeparator, app_config.Paths.ExtNatives);
Environment.SetEnvironmentVariable("PATH", path);
}
Type main_script;
if (is_pure)
{
// loads the calling assembly:
app_context.AssemblyLoader.Load(mainRoutine.Method.Module.Assembly, null);
main_script = null;
}
else
{
main_script = mainRoutine.Method.DeclaringType;
app_context.AssemblyLoader.LoadScriptLibrary(System.Reflection.Assembly.GetEntryAssembly(), ".");
}
using (ScriptContext context = InitApplication(app_context, main_script, relativeSourcePath, sourceRoot))
{
context.GuardedCall<object, object>(context.GuardedMain, mainRoutine, true);
}
}