From e6d513ebd84009a5ae18625a4e5c186b4bdd59f9 Mon Sep 17 00:00:00 2001 From: Michael Giagnocavo Date: Tue, 28 Jul 2009 18:45:47 +0000 Subject: [PATCH] Call entrypoint on scripts so they can perform initialization git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@14399 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- .../mod_managed/managed/ScriptPluginManager.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/mod/languages/mod_managed/managed/ScriptPluginManager.cs b/src/mod/languages/mod_managed/managed/ScriptPluginManager.cs index 7b0192d036..76fb84910c 100644 --- a/src/mod/languages/mod_managed/managed/ScriptPluginManager.cs +++ b/src/mod/languages/mod_managed/managed/ScriptPluginManager.cs @@ -43,6 +43,7 @@ using System.Reflection.Emit; namespace FreeSWITCH { public enum ScriptContextType { + None, App, Api, ApiBackground, @@ -151,6 +152,11 @@ namespace FreeSWITCH { } bool processAssembly(string fileName, Assembly asm) { + // Call the entrypoint once, to initialize apps that need their main called + var entryPoint = getEntryDelegate(asm.EntryPoint); + try { entryPoint(); } catch { } + + // Check for loading var allTypes = asm.GetExportedTypes(); if (!RunLoadNotify(allTypes)) return false; @@ -159,7 +165,6 @@ namespace FreeSWITCH { AddAppPlugins(allTypes); // Add the script executors - var entryPoint = getEntryDelegate(asm.EntryPoint); var name = Path.GetFileName(fileName); var aliases = new List { name }; this.ApiExecutors.Add(new ApiPluginExecutor(name, aliases, () => new ScriptApiWrapper(entryPoint))); @@ -181,6 +186,7 @@ namespace FreeSWITCH { try { entryPoint(); } finally { + Script.contextType = ScriptContextType.None; Script.context = null; } } @@ -191,6 +197,7 @@ namespace FreeSWITCH { try { entryPoint(); } finally { + Script.contextType = ScriptContextType.None; Script.context = null; } } @@ -210,6 +217,7 @@ namespace FreeSWITCH { try { entryPoint(); } finally { + Script.contextType = ScriptContextType.None; Script.context = null; } }