예제 #1
0
        protected string GetUserStatus()
        {
            var peopleManager = PeopleManager.GetInstance(_session);
            var cache         = new UserStatusList(peopleManager);

            return(cache.GetUserStatus(_session.UserId).StatusMessageDetails.Id);
        }
예제 #2
0
 private void UpdateCurrentUserStatus()
 {
     if (UserStatusList == null)
     {
         UserStatusList = new UserStatusList(PeopleManager);
     }
     UserStatus = UserStatusList.GetUserStatus(PeopleManager.Session.UserId);
     //CurrentStatus = UserStatus.StatusMessageDetails;
     if (!isStatusCallbackSet)
     {
         isStatusCallbackSet = true;
         UserStatusList.WatchedObjectsChanged += UpdateUsersStatus;
         string[] usertowatch = new string[1];
         usertowatch[0] = PeopleManager.Session.UserId;
         UserStatusList.StartWatchingAsync(usertowatch, EmptyCallBack, null);
     }
 }
예제 #3
0
        public static int GetAgentAvailabilityByProfile(int profileId)
        {
            try
            {
                if (UseCachedValue(profileId) || _isResetting)
                {
                    int agentsAvailable;
                    if (_availableAgentsByProfileId.TryGetValue(profileId, out agentsAvailable))
                    {
                        return(agentsAvailable);
                    }
                }
            }
            catch (Exception exception)
            {
                _logging.LogException(exception);
            }

            if (_lastAvailabilityCheckByProfileId.ContainsKey(profileId))
            {
                _lastAvailabilityCheckByProfileId[profileId] = DateTime.Now;
            }
            else
            {
                _lastAvailabilityCheckByProfileId.Add(profileId, DateTime.Now);
            }

            if (ShouldReset())
            {
                ResetWatched();
            }
            var logMessage      = "";
            var availableAgents = 0;

            try
            {
                var repository = new Repository();
                var profile    = repository.Profiles.FirstOrDefault(p => p.ProfileId == profileId);
                if (profile != null && _peopleManager != null && _peopleManager.Session != null && _peopleManager.Session.ConnectionState == ConnectionState.Up)
                {
                    var workgroup = profile.Workgroup;
                    if (workgroup != null)
                    {
                        logMessage += "/~ Checking Availability for: " + workgroup.ConfigId + "~/";

                        var wgUtils = workgroup.Utilizations.ToList();
                        var agents  = workgroup.ActiveMembers;
                        foreach (var agent in agents)
                        {
                            try
                            {
                                logMessage += "/~ Checking Agent: " + agent.ConfigId + "~/";

                                var usl               = new UserStatusList(_peopleManager);
                                var status            = usl.GetUserStatus(agent.ConfigId);
                                var hasRequiredSkills = true;
                                var acdAvailable      = status.LoggedIn && status.StatusMessageDetails.IsAcdStatus;

                                logMessage += "/~ Status: " + status.StatusMessageDetails.MessageText + "~/";
                                logMessage += "/~ Logged In: " + status.LoggedIn + "~/";
                                logMessage += "/~ Is Stale: " + status.IsStale + "~/";
                                logMessage += "/~ Station Count: " + status.Stations.Count + "~/";

                                var agentSkills = agent.Skills;
                                foreach (var skill in profile.Skills)
                                {
                                    if (!agentSkills.Contains(skill))
                                    {
                                        hasRequiredSkills = false;
                                    }
                                }
                                logMessage += "/~ Has Required Skills: " + hasRequiredSkills + "~/";
                                var agentUtils = agent.Utilizations.ToList();
                                var utils      = agentUtils.Any(u => u.MediaType == MediaType.Chat) ? agentUtils : wgUtils;
                                var maxChats   = 1;
                                if (utils != null)
                                {
                                    maxChats = utils.FirstOrDefault(m => m.MediaType == MediaType.Chat).MaxAssignable;
                                }

                                if ((agent.IsLicensedForChat || agent.MediaLevel == 3) && agent.HasActiveClientLicense &&
                                    //agent.ActiveInWorkgroups.Contains(workgroup) && //already finding agents for workgroup above
                                    hasRequiredSkills && utils.Any(u => u.MediaType == MediaType.Chat) && acdAvailable && maxChats > 0)
                                {
                                    logMessage += "/~ Meets base criteria ~/";

                                    var watched    = _queues.FirstOrDefault(q => q.QueueId.QueueName == agent.ConfigId && q.QueueId.QueueType == QueueType.User);
                                    var maxReached = false;
                                    if (((watched != null && !watched.IsWatching()) || watched == null) && _interactionsManager != null)
                                    {
                                        if (watched != null)
                                        {
                                            _queues.Remove(watched);
                                        }
                                        var interactionQueue = new InteractionQueue(_interactionsManager,
                                                                                    new QueueId(QueueType.User, agent.ConfigId));
                                        string[] attributes =
                                        {
                                            InteractionAttributeName.InteractionType,
                                            InteractionAttributeName.State,
                                            InteractionAttributeName.Direction
                                        };
                                        interactionQueue.StartWatching(attributes);
                                        _queues.Add(interactionQueue);
                                        watched = interactionQueue;
                                    }
                                    var interactions = watched.GetContents();

                                    var callUtil     = agentUtils.Any(u => u.MediaType == MediaType.Call) ? agentUtils.FirstOrDefault(u => u.MediaType == MediaType.Call).UtilizationPercent : wgUtils.Any(u => u.MediaType == MediaType.Call) ? wgUtils.FirstOrDefault(u => u.MediaType == MediaType.Call).UtilizationPercent : 0;
                                    var callbackUtil = agentUtils.Any(u => u.MediaType == MediaType.Callback) ? agentUtils.FirstOrDefault(u => u.MediaType == MediaType.Callback).UtilizationPercent : wgUtils.Any(u => u.MediaType == MediaType.Callback) ? wgUtils.FirstOrDefault(u => u.MediaType == MediaType.Callback).UtilizationPercent : 0;
                                    var chatUtil     = agentUtils.Any(u => u.MediaType == MediaType.Chat) ? agentUtils.FirstOrDefault(u => u.MediaType == MediaType.Chat).UtilizationPercent : wgUtils.Any(u => u.MediaType == MediaType.Chat) ? wgUtils.FirstOrDefault(u => u.MediaType == MediaType.Chat).UtilizationPercent : 0;
                                    var emailUtil    = agentUtils.Any(u => u.MediaType == MediaType.Email) ? agentUtils.FirstOrDefault(u => u.MediaType == MediaType.Email).UtilizationPercent : wgUtils.Any(u => u.MediaType == MediaType.Email) ? wgUtils.FirstOrDefault(u => u.MediaType == MediaType.Email).UtilizationPercent : 0;
                                    var genericUtil  = agentUtils.Any(u => u.MediaType == MediaType.Generic) ? agentUtils.FirstOrDefault(u => u.MediaType == MediaType.Generic).UtilizationPercent : wgUtils.Any(u => u.MediaType == MediaType.Generic) ? wgUtils.FirstOrDefault(u => u.MediaType == MediaType.Generic).UtilizationPercent : 0;
                                    var workitemUtil = agentUtils.Any(u => u.MediaType == MediaType.WorkItem) ? agentUtils.FirstOrDefault(u => u.MediaType == MediaType.WorkItem).UtilizationPercent : wgUtils.Any(u => u.MediaType == MediaType.WorkItem) ? wgUtils.FirstOrDefault(u => u.MediaType == MediaType.WorkItem).UtilizationPercent : 0;

                                    var util = chatUtil;
                                    foreach (var interaction in interactions)
                                    {
                                        //Should I be checking for WorkgroupQueue or other identifier in case a non ACD call is connected and the agent is technically unavailable?
                                        var type     = interaction.InteractionType;
                                        var isActive = (interaction.State != InteractionState.ExternalDisconnect &&
                                                        interaction.State != InteractionState.InternalDisconnect &&
                                                        interaction.State != InteractionState.None);
                                        if (type == InteractionType.Chat && isActive)
                                        {
                                            util += chatUtil;
                                            maxChats--;
                                        }
                                        if (type == InteractionType.Call && isActive)
                                        {
                                            util += callUtil;
                                        }
                                        if (type == InteractionType.Callback && isActive)
                                        {
                                            util += callbackUtil;
                                        }
                                        if (type == InteractionType.Email && isActive)
                                        {
                                            util += emailUtil;
                                        }
                                        if (type == InteractionType.Generic && isActive)
                                        {
                                            util += genericUtil;
                                        }
                                        if (type == InteractionType.WorkItem && isActive)
                                        {
                                            util += workitemUtil;
                                        }
                                        if (maxChats < 1 || util > 100)
                                        {
                                            maxReached = true;
                                        }
                                    }
                                    if (!maxReached)
                                    {
                                        logMessage += "/~ Agent " + agent.ConfigId + " is available. ~/";
                                        availableAgents++;
                                    }
                                }
                            }
                            catch (Exception e)
                            {
                                logMessage += "/~" + e.ToString() + "~/";
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                logMessage += "/~" + e.ToString() + "~/";
            }

            logMessage += "/~ Agents Available: " + availableAgents + "~/";

            try
            {
                _logging.LogNote(logMessage);
            }
            catch (Exception)
            {
            }

            if (_availableAgentsByProfileId.ContainsKey(profileId))
            {
                _availableAgentsByProfileId[profileId] = availableAgents;
            }
            else
            {
                _availableAgentsByProfileId.Add(profileId, availableAgents);
            }
            return(availableAgents);
        }