public AggregatedViewResponse GetAggregatedView(AggregatedViewRequest request)
        {
            ExTraceGlobals.DiagnosticsAggregationTracer.TraceFunction <string, string, string>(0L, "GetAggregatedView called. ClientMachineName={0}; ClientProcessName={1}; ClientProcessId={2}", (request.ClientInformation == null) ? string.Empty : request.ClientInformation.ClientMachineName, (request.ClientInformation == null) ? string.Empty : request.ClientInformation.ClientProcessName, (request.ClientInformation == null) ? string.Empty : request.ClientInformation.ClientProcessId.ToString());
            AggregatedViewResponse response = null;

            this.ServiceRequest(delegate
            {
                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();
                this.log.LogOperationFromClient(DiagnosticsAggregationEvent.AggregatedViewRequestReceived, request.ClientInformation, null, "");
                DiagnosticsAggregationServiceImpl.VerifyParameterIsNotNull(request, "request");
                DiagnosticsAggregationServiceImpl.VerifyParameterIsNotNullOrEmpty(request.RequestType, "request.RequestType");
                RequestType requestType;
                bool flag = Enum.TryParse <RequestType>(request.RequestType, out requestType);
                if (!flag || requestType != RequestType.Queues)
                {
                    throw DiagnosticsAggregationServiceImpl.NewUnsupportedParameterFault(request.RequestType, "request.RequestType");
                }
                DiagnosticsAggregationServiceImpl.VerifyParameterIsNotNull(request.QueueAggregatedViewRequest, "request.QueueAggregatedViewRequest");
                IQueueFilter filter;
                if (!QueueFilter.TryParse(request.QueueAggregatedViewRequest.QueueFilter, out filter))
                {
                    throw DiagnosticsAggregationServiceImpl.NewInvalidParameterFault(request.QueueAggregatedViewRequest.QueueFilter, "request.QueueAggregatedViewRequest.QueueFilter");
                }
                DiagnosticsAggregationServiceImpl.VerifyParameterIsNotNullOrEmpty(request.QueueAggregatedViewRequest.GroupByKey, "request.QueueAggregatedViewRequest.GroupByKey");
                QueueDigestGroupBy groupByKey;
                if (!Enum.TryParse <QueueDigestGroupBy>(request.QueueAggregatedViewRequest.GroupByKey, out groupByKey))
                {
                    throw DiagnosticsAggregationServiceImpl.NewUnsupportedParameterFault(request.QueueAggregatedViewRequest.GroupByKey, "request.QueueAggregatedViewRequest.GroupByKey");
                }
                DiagnosticsAggregationServiceImpl.VerifyParameterIsNotNullOrEmpty(request.QueueAggregatedViewRequest.DetailsLevel, "request.QueueAggregatedViewRequest.DetailsLevel");
                DetailsLevel detailsLevel;
                if (!Enum.TryParse <DetailsLevel>(request.QueueAggregatedViewRequest.DetailsLevel, out detailsLevel))
                {
                    throw DiagnosticsAggregationServiceImpl.NewUnsupportedParameterFault(request.QueueAggregatedViewRequest.DetailsLevel, "request.QueueAggregatedViewRequest.DetailsLevel");
                }
                QueueAggregator queueAggregator = new QueueAggregator(groupByKey, detailsLevel, filter, new TimeSpan?(this.GetTimeSpanForQueueDataBeingCurrent()));
                bool flag2 = request.ServersToInclude != null && request.ServersToInclude.Count > 0;
                HashSet <string> hashSet = flag2 ? new HashSet <string>(request.ServersToInclude, StringComparer.InvariantCultureIgnoreCase) : new HashSet <string>();
                IDictionary <ADObjectId, ServerQueuesSnapshot> currentGroupServerToQueuesMap = this.groupQueuesDataProvider.GetCurrentGroupServerToQueuesMap();
                currentGroupServerToQueuesMap.Add(this.localQueuesDataProvider.GetLocalServerId(), this.localQueuesDataProvider.GetLocalServerQueues());
                List <ServerSnapshotStatus> list = new List <ServerSnapshotStatus>();
                foreach (KeyValuePair <ADObjectId, ServerQueuesSnapshot> keyValuePair in currentGroupServerToQueuesMap)
                {
                    ADObjectId key             = keyValuePair.Key;
                    ServerQueuesSnapshot value = keyValuePair.Value;
                    if (!flag2 || hashSet.Contains(key.ToString()))
                    {
                        string message;
                        if (value.IsEmpty())
                        {
                            value.SetAsFailed(DiagnosticsAggregationServiceImpl.NewFault(ErrorCode.LocalQueueDataNotAvailable, value.LastError).Detail.ToString());
                        }
                        else if (this.LocalQueueDataTooOld(value.TimeStampOfQueues, out message))
                        {
                            value.SetAsFailed(DiagnosticsAggregationServiceImpl.NewFault(ErrorCode.LocalQueueDataTooOld, message).Detail.ToString());
                        }
                        else
                        {
                            queueAggregator.AddLocalQueues(value.Queues, value.TimeStampOfQueues);
                        }
                        list.Add(value.GetServerSnapshotStatus());
                    }
                }
                response = new AggregatedViewResponse(list);
                response.QueueAggregatedViewResponse = new QueueAggregatedViewResponse(queueAggregator.GetResultSortedByMessageCount(request.ResultSize));
                stopwatch.Stop();
                this.log.LogOperationFromClient(DiagnosticsAggregationEvent.AggregatedViewResponseSent, request.ClientInformation, new TimeSpan?(stopwatch.Elapsed), "");
            }, "GetAggregatedView", request.ClientInformation);
            return(response);
        }
        private void InvokeWebService(ADObjectId serverToConnectTo, HashSet <ADObjectId> serversToInclude, bool isConnectingToDag, int dagIndex, int portNumber)
        {
            string uri = string.Format(CultureInfo.InvariantCulture, DiagnosticsAggregationHelper.DiagnosticsAggregationEndpointFormat, new object[]
            {
                serverToConnectTo.Name,
                portNumber
            });
            Exception ex = null;
            IDiagnosticsAggregationService diagnosticsAggregationService = null;

            try
            {
                diagnosticsAggregationService = this.cmdlet.CreateWebServiceClient(GetQueueDigestWebServiceImpl.GetWebServiceBinding(this.cmdlet.Timeout), new EndpointAddress(uri));
            }
            catch (UriFormatException ex2)
            {
                ex = ex2;
            }
            List <string> list = new List <string>();

            if (serversToInclude != null && serversToInclude.Count != 0)
            {
                foreach (ADObjectId adobjectId in serversToInclude)
                {
                    list.Add(adobjectId.Name);
                }
            }
            AggregatedViewRequest aggregatedViewRequest = new AggregatedViewRequest(RequestType.Queues, list, uint.MaxValue);

            aggregatedViewRequest.QueueAggregatedViewRequest = new QueueAggregatedViewRequest(this.cmdlet.GroupBy, this.cmdlet.DetailsLevel, this.cmdlet.Filter);
            GetQueueDigestWebServiceImpl.WebServiceRequestAsyncState webServiceRequestAsyncState = new GetQueueDigestWebServiceImpl.WebServiceRequestAsyncState
            {
                Client               = diagnosticsAggregationService,
                ServerToConnectTo    = serverToConnectTo,
                ServersToInclude     = serversToInclude,
                IsConnectingToDag    = isConnectingToDag,
                DagIndex             = dagIndex,
                WebServicePortNumber = portNumber
            };
            try
            {
                if (diagnosticsAggregationService != null)
                {
                    diagnosticsAggregationService.BeginGetAggregatedView(aggregatedViewRequest, new AsyncCallback(this.OnInvokeWebServiceCompleted), webServiceRequestAsyncState);
                }
            }
            catch (EndpointNotFoundException ex3)
            {
                ex = ex3;
            }
            catch (InsufficientMemoryException ex4)
            {
                ex = ex4;
            }
            catch (CommunicationException ex5)
            {
                ex = ex5;
            }
            catch (TimeoutException ex6)
            {
                ex = ex6;
            }
            if (ex != null)
            {
                webServiceRequestAsyncState.FailedOnBegin          = true;
                webServiceRequestAsyncState.FailedOnBeginException = ex;
                ThreadPool.QueueUserWorkItem(new WaitCallback(this.ThreadProcForBeginGetAggregatedViewFailed), new AsyncResult(null, webServiceRequestAsyncState));
            }
        }