public ProcessServer(ITaskManager taskManager,
IEnvironment environment,
IRpcProcessConfiguration configuration)
{
Environment = environment;
completionTask = completionHandle.ToTask();
ownsTaskManager = taskManager == null;
if (ownsTaskManager)
{
taskManager = new TaskManager();
try
{
taskManager.Initialize();
}
catch
{
ourContext = new MainThreadSynchronizationContext(cts.Token);
taskManager.Initialize(ourContext);
}
}
else
{
externalCts = CancellationTokenSource.CreateLinkedTokenSource(taskManager.Token);
externalCts.Token.Register(Dispose);
}
TaskManager = taskManager;
if (configuration == null)
{
configuration = new ApplicationConfigurationWrapper(TaskManager, ApplicationConfiguration.instance);
// read the executable path up front so it gets serialized if it needs to, while we're on the main thread
var _ = configuration.ExecutablePath;
}
if (string.IsNullOrEmpty(configuration.AccessToken))
{
configuration.AccessToken = GenerateAccessToken();
}
Configuration = configuration;
localProcessManager = new ProcessManager(Environment);
processManager = new RemoteProcessManager(this, localProcessManager.DefaultProcessEnvironment, cts.Token);
notifications = new ServerNotifications(this);
#if UNITY_EDITOR
UnityEditor.EditorApplication.quitting += ShutdownSync;
#endif
}