void FinallyDispose()
        {
            DeleteTemporaryFiles();
            Externals.EndRequest();

            // updates session cookie expiration stamp:
            UpdateSessionCookieExpiration();

            this.httpContext = null;
            currentContext   = null;
        }
Exemple #2
0
        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(), ".");
            }

            ScriptContext context = InitApplication(app_context, main_script, relativeSourcePath, sourceRoot);

            try
            {
                context.GuardedCall <object, object>(context.GuardedMain, mainRoutine, true);
                context.GuardedCall <object, object>(context.FinalizeBufferedOutput, null, false);
                context.GuardedCall <object, object>(context.ProcessShutdownCallbacks, null, false);
                context.GuardedCall <object, object>(context.FinalizePhpObjects, null, false);
            }
            finally
            {
                Externals.EndRequest();
            }
        }