Пример #1
0
        private void SetInteractionQueue()
        {
            if (InteractionQueue == null)
            {
                InteractionQueue = new InteractionQueue(InteractionsManager.GetInstance(Session),
                                                        new QueueId(QueueType.MyInteractions, Session.UserId));
            }

            InteractionQueue.InteractionAdded             += InteractionQueueInteractionAdded;
            InteractionQueue.InteractionChanged           += InteractionQueueInteractionChanged;
            InteractionQueue.InteractionRemoved           += InteractionQueueInteractionRemoved;
            InteractionQueue.ConferenceInteractionAdded   += InteractionQueueConferenceInteractionAdded;
            InteractionQueue.ConferenceInteractionChanged += InteractionQueueConferenceInteractionChanged;
            InteractionQueue.ConferenceInteractionRemoved += InteractionQueueConferenceInteractionRemoved;

            List <string> RequiredAttributes = new List <string>();

            RequiredAttributes.Add(InteractionAttributeName.CallIdKey.ToString());
            RequiredAttributes.Add(InteractionAttributeName.RemoteName.ToString());
            RequiredAttributes.Add(InteractionAttributeName.RemoteAddress.ToString());
            RequiredAttributes.Add(InteractionAttributeName.State.ToString());
            //RequiredAttributes.Add(InteractionAttributeName.SupervisorRecorders.ToString());
            //RequiredAttributes.Add(InteractionAttributeName.Recorders.ToString());
            RequiredAttributes.Add(InteractionAttributeName.Muted.ToString());
            InteractionQueue.StartWatchingAsync(RequiredAttributes.ToArray(), UpdateInteractionList, null);
        }
        private void StartOrRefreshWatchingInteractions()
        {
            if (_queues == null)
            {
                _queues = new Collection <InteractionQueue>();

                try
                {
                    var workgroups = Repository.Workgroups.Where(w => w.Profiles.Any() && !w.MarkedForDeletion);
                    if (workgroups.Any() && _interactionsManager != null && _interactionsManager.Session != null && _interactionsManager.Session.ConnectionState == ConnectionState.Up)
                    {
                        foreach (var workgroup in workgroups)
                        {
                            try
                            {
                                var interactionQueue = new InteractionQueue(_interactionsManager, new QueueId(QueueType.Workgroup, workgroup.DisplayName));
                                interactionQueue.InteractionAdded += QueueOnInteractionAdded;
                                interactionQueue.StartWatchingAsync(_queueAttributes, Interactions_StartOrRefreshWatchingCompleted, null);
                                _queues.Add(interactionQueue);
                            }
                            catch (Exception e)
                            {
                                _logging.TraceException(e, "WorkgroupInteractions Error");
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    _logging.TraceException(e, "WorkgroupInteractions Error");
                }
            }
            else
            {
                var workgroups = Repository.Workgroups.Where(w => w.Profiles.Any() && !w.MarkedForDeletion).ToList();
                if (workgroups.Any())
                {
                    foreach (var workgroup in workgroups)
                    {
                        var existing = _queues.FirstOrDefault(q => q.QueueId.QueueName == workgroup.DisplayName);
                        if (existing == null)
                        {
                            try
                            {
                                var interactionQueue = new InteractionQueue(_interactionsManager, new QueueId(QueueType.Workgroup, workgroup.DisplayName));
                                interactionQueue.InteractionAdded += QueueOnInteractionAdded;
                                interactionQueue.StartWatchingAsync(_queueAttributes, Interactions_StartOrRefreshWatchingCompleted, null);
                                _queues.Add(interactionQueue);
                            }
                            catch (Exception e)
                            {
                                _logging.TraceException(e, "WorkgroupInteractions Error");
                            }
                        }
                        else
                        {
                            if (workgroup.MarkedForDeletion)
                            {
                                try
                                {
                                    if (existing.IsWatching())
                                    {
                                        existing.StopWatching();
                                    }
                                    _queues.Remove(existing);
                                }
                                catch (Exception e)
                                {
                                    _logging.TraceException(e, "WorkgroupInteractions Error");
                                }
                            }
                        }
                    }
                }
            }
        }