private void OnInvokeWebServiceCompleted(IAsyncResult ar)
        {
            GetQueueDigestWebServiceImpl.WebServiceRequestAsyncState webServiceRequestAsyncState = (GetQueueDigestWebServiceImpl.WebServiceRequestAsyncState)ar.AsyncState;
            IDiagnosticsAggregationService client    = webServiceRequestAsyncState.Client;
            ADObjectId             serverToConnectTo = webServiceRequestAsyncState.ServerToConnectTo;
            int                    dagIndex          = webServiceRequestAsyncState.DagIndex;
            string                 text                   = null;
            LocalizedString?       localizedString        = null;
            AggregatedViewResponse aggregatedViewResponse = null;

            try
            {
                if (webServiceRequestAsyncState.FailedOnBegin)
                {
                    text = webServiceRequestAsyncState.FailedOnBeginException.ToString();
                }
                else
                {
                    aggregatedViewResponse = client.EndGetAggregatedView(ar);
                }
            }
            catch (FaultException <DiagnosticsAggregationFault> faultException)
            {
                text = string.Format("{0}: {1}", faultException.Detail.ErrorCode, faultException.Detail.Message);
            }
            catch (CommunicationException ex)
            {
                if (GetQueueDigestWebServiceImpl.IsQuotaExceeded(ex))
                {
                    localizedString = new LocalizedString?(Strings.GetQueueDigestQuotaExceeded(serverToConnectTo.Name));
                }
                text = ex.ToString();
            }
            catch (TimeoutException ex2)
            {
                text = ex2.ToString();
            }
            finally
            {
                this.cmdlet.DisposeWebServiceClient(client);
            }
            bool flag = false;

            lock (this)
            {
                if (!webServiceRequestAsyncState.IsConnectingToDag || this.pendingRequestsToDag[dagIndex] != 0)
                {
                    if (aggregatedViewResponse != null)
                    {
                        this.aggregator.AddAggregatedQueues(aggregatedViewResponse.QueueAggregatedViewResponse.AggregatedQueues);
                        if (this.cmdlet.IsVerbose)
                        {
                            foreach (ServerSnapshotStatus serverSnapshotStatus in aggregatedViewResponse.SnapshotStatusOfServers)
                            {
                                this.verboseMessages.Add(new LocalizedString(string.Format("{0}: {1}", serverToConnectTo.Name, serverSnapshotStatus.ToString())));
                            }
                        }
                        if (webServiceRequestAsyncState.IsConnectingToDag)
                        {
                            this.pendingRequestsToDag[dagIndex] = 0;
                        }
                    }
                    else if (webServiceRequestAsyncState.IsConnectingToDag)
                    {
                        this.pendingRequestsToDag[dagIndex]--;
                        if (this.pendingRequestsToDag[dagIndex] > 0)
                        {
                            flag = true;
                        }
                        else
                        {
                            this.failedToConnectDags.Add(serverToConnectTo.Name);
                        }
                    }
                    else
                    {
                        this.failedToConnectServers.Add(serverToConnectTo.Name);
                    }
                    if (text != null)
                    {
                        this.debugMessages.Add(new LocalizedString(string.Format("{0}: {1}", serverToConnectTo.Name, text)));
                    }
                    if (localizedString != null)
                    {
                        this.warningMessages.Add(localizedString.Value);
                    }
                    if (!flag)
                    {
                        this.webServiceRequestsPending--;
                    }
                    if (this.webServiceRequestsPending == 0)
                    {
                        this.webServiceRequestsDone.Set();
                    }
                }
            }
        }
        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));
            }
        }