/// <summary>
/// Creates a new controller for the given personality.
/// </summary>
/// <param name="p"></param>
/// <returns></returns>
public Controller CreateController(string id, Logger log = null)
{
if (log == null)
log = new Logger("CreateController[" + id + "]");
personControlLock.EnterWriteLock();
try
{
var c = new Controller(this, id);
controllers.Add(c);
// run setups
if (Dirty)
Logger.Log(log, Logger.Level.Error, StringsScripting.Log_VM_Dirty);
else
{
personControlLock.EnterReadLock();
scriptsLock.EnterReadLock();
try
{ runAllSetupOn(c, new StringBuilder()); }
finally
{
scriptsLock.ExitReadLock();
personControlLock.ExitReadLock();
}
}
c.AddFromStartQuery(log);
return c;
}
finally
{ personControlLock.ExitWriteLock(); }
}