Esempio n. 1
0
        public void Initialize(Session session, IInteractionSelector interactionSelector)
        {
            using (Trace.Main.scope())
            {
                try
                {
                    Trace.Main.always("Initializing VidyoPanelViewModel");

                    // Set things
                    if (_session == null)
                    {
                        // Only do these things the first time around
                        _session = session;
                        _session.ConnectionStateChanged += SessionOnConnectionStateChanged;
                    }

                    _interactionSelector = interactionSelector;

                    _customNotification = new CustomNotification(_session);
                    MyInteractions      = new InteractionQueue(InteractionsManager.GetInstance(_session),
                                                               new QueueId(QueueType.User, _session.UserId));

                    // Watch queue
                    MyInteractions.InteractionAdded   += MyInteractionsOnInteractionAdded;
                    MyInteractions.InteractionChanged += MyInteractionsOnInteractionChanged;
                    MyInteractions.InteractionRemoved += MyInteractionsOnInteractionRemoved;
                    MyInteractions.StartWatching(_watchedAttrs.ToArray());

                    // Watch for custom notifications
                    _customNotification.CustomNotificationReceived += OnCustomNotificationReceived;
                    WatchCustomNotifications();

                    // Get the Vidyo service client base URL
                    SendCustomNotification(CustomMessageType.ApplicationRequest, VidyoServiceClientBaseUrlRequestOid,
                                           VidyoServiceClientBaseUrlRequestEid, _session.UserId.ToLower());

                    // Let everyone know we're ready
                    IsInitialized = true;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                    Trace.Main.exception(ex, ex.Message);
                    //MessageBox.Show(
                    //    "There was an error intializing the Vidyo addin. Please contact your system administrator.",
                    //    "Vidyo Addin - critical error");
                    throw;
                }
            }
        }
        public QueueViewModel(Session session)
        {
            try
            {
                // Initialize objects
                //Interactions = new ObservableCollection<InteractionViewModel>();

                // Set command bindings
                CommandBindings.Add(new CommandBinding(UiCommands.PickUpCommand,
                                                       PickUp_Executed,
                                                       (sender, e) =>
                {
                    e.CanExecute = true;
                    e.Handled    = true;
                }));
                CommandBindings.Add(new CommandBinding(UiCommands.DisconnectCommand,
                                                       Disconnect_Executed,
                                                       (sender, e) =>
                {
                    e.CanExecute = true;
                    e.Handled    = true;
                }));
                CommandBindings.Add(new CommandBinding(UiCommands.MuteCommand,
                                                       Mute_Executed,
                                                       (sender, e) =>
                {
                    e.CanExecute = true;
                    e.Handled    = true;
                }));
                CommandBindings.Add(new CommandBinding(UiCommands.HoldCommand,
                                                       Hold_Executed,
                                                       (sender, e) =>
                {
                    e.CanExecute = true;
                    e.Handled    = true;
                }));
                CommandBindings.Add(new CommandBinding(UiCommands.ConferenceCommand,
                                                       Conference_Executed,
                                                       (sender, e) =>
                {
                    e.CanExecute = true;
                    e.Handled    = true;
                }));
                CommandBindings.Add(new CommandBinding(UiCommands.DialCommand,
                                                       Dial_Executed,
                                                       (sender, e) =>
                {
                    e.CanExecute = true;
                    e.Handled    = true;
                }));

                // Set objects
                _session = session;
                _queue   = new InteractionQueue(InteractionsManager.GetInstance(_session),
                                                new QueueId(QueueType.MyInteractions, _session.UserId));
                _queue.QueueContentsChanged += QueueOnQueueContentsChanged;
                _queue.StartWatching(_queueAttributes);
            }
            catch (Exception ex)
            {
                MainViewModel.Instance.LogMessage(ex);
            }
        }
Esempio n. 3
0
        public ChatBotService()
        {
            using (Trace.Main.scope())
            {
                try
                {
                    var useWindowsAuth = false;

                    // Parse some settings
                    bool.TryParse(ConfigurationManager.AppSettings["CicUseWindowsAuth"], out useWindowsAuth);
                    bool.TryParse(ConfigurationManager.AppSettings["EnableCommands"], out _enableCommands);

                    // Connect IceLib
                    if (useWindowsAuth)
                    {
                        _session.Connect(new SessionSettings(),
                                         new HostSettings(new HostEndpoint(ConfigurationManager.AppSettings["CicServer"])),
                                         new WindowsAuthSettings(),
                                         new StationlessSettings());
                    }
                    else
                    {
                        _session.Connect(new SessionSettings(),
                                         new HostSettings(new HostEndpoint(ConfigurationManager.AppSettings["CicServer"])),
                                         new ICAuthSettings(ConfigurationManager.AppSettings["CicUser"],
                                                            ConfigurationManager.AppSettings["CicPassword"]),
                                         new StationlessSettings());
                    }

                    // Set up bot manager
                    _botManager = new BotManager(new ServiceProviderDelegates
                    {
                        GetAttributeMethod    = GetAttribute,
                        GetAttributesMethod   = GetAttributes,
                        SetAttributeMethod    = SetAttribute,
                        SetAttributesMethod   = SetAttributes,
                        SendChatMessageMethod = SendChatMessage,
                        ReassignChatMethod    = ReassignChat
                    });
                    _botManager.LoadBots();

                    // Watch queues
                    var queueNames = ConfigurationManager.AppSettings["QueueList"].Split(new[] { '|' });
                    foreach (var queueName in queueNames)
                    {
                        try
                        {
                            Console.WriteLine("Watching queue " + queueName);
                            var queue = new InteractionQueue(InteractionsManager.GetInstance(_session),
                                                             new QueueId(QueueType.Workgroup, queueName));
                            queue.QueueContentsChanged += QueueOnQueueContentsChanged;
                            queue.StartWatching(_queueAttributes);
                            _queues.Add(queue);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex);
                            Trace.Main.exception(ex);
                        }
                    }

                    // Make sure we have some queues
                    if (_queues.Count == 0)
                    {
                        throw new Exception("Not watching any queues after initialization!");
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                    Trace.Main.exception(ex);
                    throw;
                }
            }
        }
Esempio n. 4
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);
        }