// How to test the demo (in the mod/managed directory):\r
// -- Compile to dll for "normal" loading\r
// -- Compile to exe for script EXE loading\r
-// -- Rename to demo.csx for dynamic compilation\r
+// -- Copy to managed directory for dynamic compilation\r
\r
using System;\r
using FreeSWITCH;\r
\r
public class ScriptDemo {\r
\r
- static void Main() {\r
+ public static void Main() {\r
switch (FreeSWITCH.Script.ContextType) {\r
case ScriptContextType.Api: {\r
var ctx = FreeSWITCH.Script.GetApiContext();\r
<Compile Include="Loader.cs" />\r
<Compile Include="Extensions.cs" />\r
<Compile Include="Log.cs" />\r
- <None Include="Demo.cs" />\r
+ <None Include="Demo.csx" />\r
<Compile Include="PluginInterfaces.cs" />\r
<Compile Include="PluginManager.cs" />\r
<Compile Include="ScriptPluginManager.cs" />\r
setup.ApplicationName = Path.GetFileName(fileName) + "_" + appDomainCount;\r
var domain = AppDomain.CreateDomain(setup.ApplicationName, null, setup);\r
\r
- var pm = (PluginManager)domain.CreateInstanceAndUnwrap(pmType.Assembly.FullName, pmType.FullName, null);\r
- if (!pm.Load(fileName)) {\r
+ PluginManager pm;\r
+ try {\r
+ pm = (PluginManager)domain.CreateInstanceAndUnwrap(pmType.Assembly.FullName, pmType.FullName, null);\r
+ if (!pm.Load(fileName)) {\r
+ AppDomain.Unload(domain);\r
+ unloadFile(fileName);\r
+ return;\r
+ }\r
+ } catch (Exception ex) {\r
+ // On an exception, we will unload the current file so an old copy doesnt stay active\r
+ Log.WriteLine(LogLevel.Alert, "Exception loading {0}: {1}", fileName, ex.ToString());\r
AppDomain.Unload(domain);\r
unloadFile(fileName);\r
return;\r
}\r
\r
+ // Update dictionaries atomically\r
lock (loaderLock) {\r
- // Update dictionaries atomically\r
unloadFile(fileName);\r
\r
var pi = new PluginInfo { FileName = fileName, Domain = domain, Manager = pm };\r
AppDomain.Unload(d);\r
Log.WriteLine(LogLevel.Info, "Unloaded {0}, domain {1}.", pi.FileName, friendlyName);\r
} catch (Exception ex) {\r
- Log.WriteLine(LogLevel.Critical, "Could not unload {0}, domain {1}: {2}", pi.FileName, friendlyName, ex.ToString());\r
+ Log.WriteLine(LogLevel.Alert, "Could not unload {0}, domain {1}: {2}", pi.FileName, friendlyName, ex.ToString());\r
}\r
});\r
t.Priority = System.Threading.ThreadPriority.BelowNormal;\r