private void cmbQueues_SelectedIndexChanged(object sender, EventArgs e)
        {
            tvConversations.Nodes.Clear();

            currentQueue = (QueueInfo)((ComboBox)sender).SelectedItem;
            AddLog($"Selected Queue: {currentQueue.Id}, {currentQueue.Name}", true);

            // Get calls from the selected queue
            var conversations = GetCalls(currentQueue);

            AddLog($"Found {conversations.Count} active calls in {currentQueue.Name}");
            foreach (var conversation in conversations)
            {
                var newNode = tvConversations.Nodes.Add($"{conversation.ConversationId} => {DateTime.Now - conversation.ConversationStart}");
                newNode.Tag = conversation.ConversationId;
            }
        }
        private List <AnalyticsConversation> GetCalls(QueueInfo queue)
        {
            AddLog($"Getting calls from queue {queue.Name}");
            var conversations = new List <AnalyticsConversation>();
            var pageNumber    = 1;
            AnalyticsConversationQueryResponse analyticsConversationQueryResponse = null;

            var dateTimeNowISO          = DateTime.UtcNow.ToString("yyyy-MM-ddTHH\\:mm\\:ss.fffZ");
            var dateTimeNowISOMinus1Day = DateTime.UtcNow.AddDays(-7).ToString("yyyy-MM-ddTHH\\:mm\\:ss.fffZ");

            AddLog($"Start Date/Time: {dateTimeNowISOMinus1Day}", true);
            AddLog($"End Date/Time: {dateTimeNowISO}", true);

            do
            {
                var body = new ConversationQuery()
                {
                    Interval            = $"{dateTimeNowISOMinus1Day}/{dateTimeNowISO}",
                    ConversationFilters = new List <AnalyticsQueryFilter>()
                    {
                        new AnalyticsQueryFilter(
                            AnalyticsQueryFilter.TypeEnum.And,
                            new List <AnalyticsQueryClause>()
                        {
                            new AnalyticsQueryClause()
                            {
                                // Should not be disconnected
                                Type       = AnalyticsQueryClause.TypeEnum.And,
                                Predicates = new List <AnalyticsQueryPredicate>()
                                {
                                    new AnalyticsQueryPredicate()
                                    {
                                        Type      = AnalyticsQueryPredicate.TypeEnum.Dimension,
                                        Dimension = AnalyticsQueryPredicate.DimensionEnum.Conversationend,
                                        _Operator = AnalyticsQueryPredicate.OperatorEnum.Notexists
                                    }
                                }
                            }
                        }
                            )
                    },
                    SegmentFilters = new List <AnalyticsQueryFilter>()
                    {
                        new AnalyticsQueryFilter(
                            AnalyticsQueryFilter.TypeEnum.And,
                            new List <AnalyticsQueryClause>()
                        {
                            new AnalyticsQueryClause()
                            {
                                Type       = AnalyticsQueryClause.TypeEnum.And,
                                Predicates = new List <AnalyticsQueryPredicate>()
                                {
                                    // Should be a call
                                    new AnalyticsQueryPredicate()
                                    {
                                        Type      = AnalyticsQueryPredicate.TypeEnum.Dimension,
                                        Dimension = AnalyticsQueryPredicate.DimensionEnum.Mediatype,
                                        _Operator = AnalyticsQueryPredicate.OperatorEnum.Matches,
                                        Value     = "voice"
                                    },
                                    // Should match selected queue
                                    new AnalyticsQueryPredicate()
                                    {
                                        Type      = AnalyticsQueryPredicate.TypeEnum.Dimension,
                                        Dimension = AnalyticsQueryPredicate.DimensionEnum.Queueid,
                                        _Operator = AnalyticsQueryPredicate.OperatorEnum.Matches,
                                        Value     = queue.Id
                                    },
                                    // Should not be finished
                                    new AnalyticsQueryPredicate()
                                    {
                                        Type      = AnalyticsQueryPredicate.TypeEnum.Dimension,
                                        Dimension = AnalyticsQueryPredicate.DimensionEnum.Segmentend,
                                        _Operator = AnalyticsQueryPredicate.OperatorEnum.Notexists
                                    }
                                }
                            }
                        }
                            )
                    },
                    Order   = ConversationQuery.OrderEnum.Asc,
                    OrderBy = ConversationQuery.OrderByEnum.Conversationstart,
                    Paging  = new PagingSpec()
                    {
                        PageSize   = 100,
                        PageNumber = pageNumber++
                    }
                };

                analyticsConversationQueryResponse = analyticsApi.PostAnalyticsConversationsDetailsQuery(body);
                AddLog($"Got response: {analyticsConversationQueryResponse.ToString()}", true);

                if (analyticsConversationQueryResponse.Conversations != null)
                {
                    AddLog($"Got {analyticsConversationQueryResponse.Conversations.Count} conversations", true);
                    foreach (var analyticsConversation in analyticsConversationQueryResponse.Conversations)
                    {
                        conversations.Add(analyticsConversation);
                    }
                }
            } while (analyticsConversationQueryResponse.Conversations != null);

            return(conversations);
        }