More robust loading; make demo more clear
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@14405 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
e3f4cb6e93
commit
db20243dfe
|
@ -32,7 +32,7 @@
|
|||
// How to test the demo (in the mod/managed directory):
|
||||
// -- Compile to dll for "normal" loading
|
||||
// -- Compile to exe for script EXE loading
|
||||
// -- Rename to demo.csx for dynamic compilation
|
||||
// -- Copy to managed directory for dynamic compilation
|
||||
|
||||
using System;
|
||||
using FreeSWITCH;
|
||||
|
@ -85,7 +85,7 @@ public class LoadDemo : ILoadNotificationPlugin {
|
|||
|
||||
public class ScriptDemo {
|
||||
|
||||
static void Main() {
|
||||
public static void Main() {
|
||||
switch (FreeSWITCH.Script.ContextType) {
|
||||
case ScriptContextType.Api: {
|
||||
var ctx = FreeSWITCH.Script.GetApiContext();
|
|
@ -52,7 +52,7 @@
|
|||
<Compile Include="Loader.cs" />
|
||||
<Compile Include="Extensions.cs" />
|
||||
<Compile Include="Log.cs" />
|
||||
<None Include="Demo.cs" />
|
||||
<None Include="Demo.csx" />
|
||||
<Compile Include="PluginInterfaces.cs" />
|
||||
<Compile Include="PluginManager.cs" />
|
||||
<Compile Include="ScriptPluginManager.cs" />
|
||||
|
|
|
@ -219,15 +219,24 @@ namespace FreeSWITCH {
|
|||
setup.ApplicationName = Path.GetFileName(fileName) + "_" + appDomainCount;
|
||||
var domain = AppDomain.CreateDomain(setup.ApplicationName, null, setup);
|
||||
|
||||
var pm = (PluginManager)domain.CreateInstanceAndUnwrap(pmType.Assembly.FullName, pmType.FullName, null);
|
||||
if (!pm.Load(fileName)) {
|
||||
PluginManager pm;
|
||||
try {
|
||||
pm = (PluginManager)domain.CreateInstanceAndUnwrap(pmType.Assembly.FullName, pmType.FullName, null);
|
||||
if (!pm.Load(fileName)) {
|
||||
AppDomain.Unload(domain);
|
||||
unloadFile(fileName);
|
||||
return;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
// On an exception, we will unload the current file so an old copy doesnt stay active
|
||||
Log.WriteLine(LogLevel.Alert, "Exception loading {0}: {1}", fileName, ex.ToString());
|
||||
AppDomain.Unload(domain);
|
||||
unloadFile(fileName);
|
||||
return;
|
||||
}
|
||||
|
||||
// Update dictionaries atomically
|
||||
lock (loaderLock) {
|
||||
// Update dictionaries atomically
|
||||
unloadFile(fileName);
|
||||
|
||||
var pi = new PluginInfo { FileName = fileName, Domain = domain, Manager = pm };
|
||||
|
@ -279,7 +288,7 @@ namespace FreeSWITCH {
|
|||
AppDomain.Unload(d);
|
||||
Log.WriteLine(LogLevel.Info, "Unloaded {0}, domain {1}.", pi.FileName, friendlyName);
|
||||
} catch (Exception ex) {
|
||||
Log.WriteLine(LogLevel.Critical, "Could not unload {0}, domain {1}: {2}", pi.FileName, friendlyName, ex.ToString());
|
||||
Log.WriteLine(LogLevel.Alert, "Could not unload {0}, domain {1}: {2}", pi.FileName, friendlyName, ex.ToString());
|
||||
}
|
||||
});
|
||||
t.Priority = System.Threading.ThreadPriority.BelowNormal;
|
||||
|
|
Loading…
Reference in New Issue