private void InitializeScripts()
{
foreach (var type in _scripts.Values)
{
try
{
// Initiate script
var script = Activator.CreateInstance(type) as IScript;
if (!script.Init())
{
Log.Debug("LoadScriptAssembly: Failed to initiate '{0}'.", type.Name);
continue;
}
// Register scripts implementing IDisposable as script to
// dispose on reload.
if (type.GetInterfaces().Contains(typeof(IDisposable)))
_scriptsToDispose.Add(script as IDisposable);
// Run auto loader. This has to be done after Init,
// because of how Load is called from GeneralScript.
if (type.GetInterfaces().Contains(typeof(IAutoLoader)))
(script as IAutoLoader).AutoLoad();
}
catch (Exception ex)
{
Log.Exception(ex, "Error while loading script '{0}' ({1}).", type.Name, ex.Message);
}
}
}