示例#1
0
        public Session CreateSession(IIdentity user, string id, Interpreter interpreter, SecureString password, string profilePath, string commandLineArguments) {
            Session session;

            lock (_sessions) {
                if (_blockedUsers.Contains(user.Name)) {
                    throw new InvalidOperationException(Resources.Error_BlockedByProfileDeletion.FormatInvariant(user.Name));
                }

                var oldUserSessions = GetOrCreateSessionList(user);

                var oldSessions = oldUserSessions.Where(s => s.Id == id).ToArray();
                foreach (var oldSession in oldSessions) {
                    oldUserSessions.Remove(oldSession);
                    Task.Run(() => oldSession.KillHost()).SilenceException<Exception>().DoNotWait();
                    oldSession.State = SessionState.Terminated;
                }

                var userSessions = GetOrCreateSessionList(user);
                session = new Session(this, user, id, interpreter, commandLineArguments, _sessionLogger, _messageLogger);
                session.StateChanged += Session_StateChanged;

                userSessions.Add(session);
            }

            session.StartHost(
                password,
                profilePath,
                _loggingOptions.LogHostOutput ? _hostOutputLogger : null,
                _loggingOptions.LogPackets || _loggingOptions.LogHostOutput ? LogVerbosity.Traffic : LogVerbosity.Minimal);

            return session;
        }