private bool TryHostDiagnosticsWebService(bool rehosting, out ServiceHost host) { host = null; Exception ex = null; int diagnosticsAggregationServicePort = DiagnosticsAggregationServicelet.TransportSettings.DiagnosticsAggregationServicePort; try { host = new ServiceHost(typeof(DiagnosticsAggregationServiceImpl), new Uri[0]); string text = string.Format(CultureInfo.InvariantCulture, DiagnosticsAggregationHelper.DiagnosticsAggregationEndpointFormat, new object[] { "localhost", diagnosticsAggregationServicePort }); host.AddServiceEndpoint(typeof(IDiagnosticsAggregationService), DiagnosticsAggregationServicelet.GetTcpBinding(), text); this.AddMetadataEndpointInDebugBuild(host); host.Open(); DiagnosticsAggregationServicelet.Log.Log(DiagnosticsAggregationEvent.Information, string.Format(CultureInfo.InvariantCulture, "listening at {0}", new object[] { text }), new object[0]); } catch (InvalidOperationException ex2) { ex = ex2; } catch (CommunicationException ex3) { ex = ex3; } catch (TimeoutException ex4) { ex = ex4; } finally { if (ex != null && host != null) { WcfUtils.DisposeWcfClientGracefully(host, false); } } if (ex != null) { ExTraceGlobals.DiagnosticsAggregationTracer.TraceError <Exception>(0L, "HostService Failed {0}.", ex); if (rehosting) { DiagnosticsAggregationServicelet.EventLog.LogEvent(MSExchangeDiagnosticsAggregationEventLogConstants.Tuple_DiagnosticsAggregationRehostingFailed, null, new object[] { diagnosticsAggregationServicePort, ex }); } else { DiagnosticsAggregationServicelet.EventLog.LogEvent(MSExchangeDiagnosticsAggregationEventLogConstants.Tuple_DiagnosticsAggregationServiceletLoadFailed, null, new object[] { ex }); } DiagnosticsAggregationServicelet.Log.Log(DiagnosticsAggregationEvent.ServiceletError, ex.ToString(), new object[0]); return(false); } return(true); }
private void RefreshCurrentGroupServerToQueuesMap() { ADNotificationAdapter.TryRunADOperation(new ADOperation(this.RefreshCurrentGroupServers), 2); lock (this) { ADObjectId[] array = new ADObjectId[this.currentGroupServerToQueuesMap.Keys.Count]; this.currentGroupServerToQueuesMap.Keys.CopyTo(array, 0); foreach (ADObjectId adobjectId in array) { if (!this.currentGroupServers.Contains(adobjectId)) { this.currentGroupServerToQueuesMap.Remove(adobjectId); } } } foreach (ADObjectId adobjectId2 in this.currentGroupServers) { string uri = string.Format(CultureInfo.InvariantCulture, DiagnosticsAggregationHelper.DiagnosticsAggregationEndpointFormat, new object[] { adobjectId2.Name, DiagnosticsAggregationServicelet.TransportSettings.DiagnosticsAggregationServicePort }); Exception ex = null; DiagnosticsAggregationServiceClient diagnosticsAggregationServiceClient = null; try { diagnosticsAggregationServiceClient = new DiagnosticsAggregationServiceClient(DiagnosticsAggregationServicelet.GetTcpBinding(), new EndpointAddress(uri)); } catch (UriFormatException ex2) { ex = ex2; } LocalViewRequest localViewRequest = new LocalViewRequest(RequestType.Queues); localViewRequest.QueueLocalViewRequest = new QueueLocalViewRequest(); Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); GroupQueuesDataProvider.GetLocalViewAsyncState asyncState = new GroupQueuesDataProvider.GetLocalViewAsyncState { Client = diagnosticsAggregationServiceClient, Server = adobjectId2, Stopwatch = stopwatch, RequestSessionId = localViewRequest.ClientInformation.SessionId }; try { if (diagnosticsAggregationServiceClient != null) { diagnosticsAggregationServiceClient.BeginGetLocalView(localViewRequest, new AsyncCallback(this.OnGetLocalViewCompleted), asyncState); } } catch (EndpointNotFoundException ex3) { ex = ex3; } catch (InsufficientMemoryException ex4) { ex = ex4; } catch (CommunicationException ex5) { ex = ex5; } catch (TimeoutException ex6) { ex = ex6; } if (ex != null) { WcfUtils.DisposeWcfClientGracefully(diagnosticsAggregationServiceClient, false); stopwatch.Stop(); this.UpdateSnapshotForServer(adobjectId2, localViewRequest.ClientInformation.SessionId, stopwatch.Elapsed, null, ex.Message); if (ex is InsufficientMemoryException) { lock (this) { this.log.Log(DiagnosticsAggregationEvent.OutOfResources, "running out of ephemeral ports, will stop making further web service requests", new object[0]); break; } } } } }