Exemple #1
0
        private UserSession StoreSession(UserSession newSession)
        {
            if (_teamManager.TryAssignSessionToAgent(newSession))
            {
                _logger.LogInformation($"Assigned new session '{newSession.SessionId}' to agent.");
                return(QueueSession(newSession, SessionStatus.Working));
            }

            var waitingSessionsCount = _sessionQueue.WaitingSessionsCount;

            if (waitingSessionsCount < _teamManager.WaitingCapacity)
            {
                _logger.LogInformation($"Queued new session '{newSession.SessionId}'.");
                return(QueueSession(newSession, SessionStatus.Waiting));
            }

            if (_shiftManager.IsOverflowTeamAvailable())
            {
                // - get the oldest awaiting session from the queue
                // - assign the oldest awaiting to the OverFlowTeam
                // - put incoming session in the queue
                var awaitingSession = _sessionQueue.GetNextWaitingSession(); //reduce queue
                if (awaitingSession != null && _teamManager.TryAssignSessionToOverflowAgent(awaitingSession))
                {
                    _logger.LogInformation($"Overflow. Picked and assigned old session '{awaitingSession.SessionId}' to agent.");
                    _logger.LogInformation($"Overflow. Queued new session '{newSession.SessionId}'.");
                    awaitingSession.Status = SessionStatus.Working;
                    return(QueueSession(newSession, SessionStatus.Waiting));
                }
            }
            _logger.LogInformation($"Refused new session '{newSession.SessionId}'.");
            newSession.Status = SessionStatus.Refused;
            return(newSession);
        }