Esempio n. 1
0
        public ExchangeTopology ReadExchangeTopology(DateTime timestamp, ExchangeTopologyScope topologyScope, bool forceRefresh)
        {
            ExchangeTopology result;

            try
            {
                using (TopologyServiceClient topologyServiceClient = TopologyServiceClient.CreateClient("localhost"))
                {
                    byte[][] exchangeTopology = topologyServiceClient.GetExchangeTopology(timestamp, topologyScope, forceRefresh);
                    if (exchangeTopology == null)
                    {
                        result = null;
                    }
                    else
                    {
                        ExchangeTopologyDiscovery.Simple topology          = ExchangeTopologyDiscovery.Simple.Deserialize(exchangeTopology);
                        ExchangeTopologyDiscovery        topologyDiscovery = ExchangeTopologyDiscovery.Simple.CreateFrom(topology);
                        result = ExchangeTopologyDiscovery.Populate(topologyDiscovery);
                    }
                }
            }
            catch (DataSourceOperationException innerException)
            {
                ServiceDiscoveryPermanentException ex = new ServiceDiscoveryPermanentException(ServerStrings.ExReadExchangeTopologyFailed, innerException);
                ExTraceGlobals.ServiceDiscoveryTracer.TraceError <ServiceDiscoveryPermanentException>(0L, "ExchangeTopologyBridge::ReadExchangeTopology. Read ExchangeTopology failed. Throwing exception: {0}.", ex);
                throw ex;
            }
            catch (Exception ex2)
            {
                if (!(ex2 is CommunicationException) && !(ex2 is TimeoutException) && !(ex2 is InvalidOperationException))
                {
                    throw;
                }
                ServiceDiscoveryTransientException ex3 = new ServiceDiscoveryTransientException(ServerStrings.ExReadExchangeTopologyFailed, ex2);
                ExTraceGlobals.ServiceDiscoveryTracer.TraceError <ServiceDiscoveryTransientException>(0L, "ExchangeTopologyBridge::ReadExchangeTopology. Read ExchangeTopology failed. Throwing exception: {0}.", ex3);
                throw ex3;
            }
            return(result);
        }
        private void PerformTopologyServiceTest(ref TopologyServiceOutcome result, TopologyServiceOperationTypeEnum operationType)
        {
            bool flag = true;

            using (TopologyServiceClient topologyServiceClient = TopologyServiceClient.CreateClient(this.Server.ToString()))
            {
                string               error                = string.Empty;
                StringBuilder        stringBuilder        = new StringBuilder();
                TopologyServiceError topologyServiceError = TopologyServiceError.None;
                Stopwatch            stopwatch            = Stopwatch.StartNew();
                try
                {
                    base.WriteVerbose(Strings.TopologyServiceOperation(operationType.ToString()));
                    IList <TopologyVersion> list;
                    IList <ServerInfo>      serversForRole;
                    switch (operationType)
                    {
                    case TopologyServiceOperationTypeEnum.GetAllTopologyVersions:
                        list = topologyServiceClient.GetAllTopologyVersions();
                        using (IEnumerator <TopologyVersion> enumerator = list.GetEnumerator())
                        {
                            while (enumerator.MoveNext())
                            {
                                TopologyVersion topologyVersion = enumerator.Current;
                                stringBuilder.Append(Strings.ToplogyserviceTopologyVersion(topologyVersion.PartitionFqdn, topologyVersion.Version) + Environment.NewLine);
                            }
                            goto IL_264;
                        }
                        break;

                    case TopologyServiceOperationTypeEnum.GetTopologyVersion:
                        break;

                    case TopologyServiceOperationTypeEnum.SetConfigDC:
                        topologyServiceClient.SetConfigDC(this.PartitionFqdn, this.TargetDomainController);
                        goto IL_264;

                    case TopologyServiceOperationTypeEnum.ReportServerDown:
                        goto IL_13A;

                    case TopologyServiceOperationTypeEnum.GetServersForRole:
                        serversForRole = topologyServiceClient.GetServersForRole(this.PartitionFqdn, new List <string>(), (ADServerRole)this.ADServerRole, 20, false);
                        using (IEnumerator <ServerInfo> enumerator2 = serversForRole.GetEnumerator())
                        {
                            while (enumerator2.MoveNext())
                            {
                                ServerInfo serverInfo = enumerator2.Current;
                                stringBuilder.Append(Strings.TopologyServiceADServerInfo(serverInfo.Fqdn) + Environment.NewLine);
                            }
                            goto IL_264;
                        }
                        goto IL_1DA;

                    case TopologyServiceOperationTypeEnum.Test:
                        goto IL_1DA;

                    default:
                        goto IL_264;
                    }
                    list = topologyServiceClient.GetTopologyVersions(new List <string>
                    {
                        this.PartitionFqdn
                    });
                    using (IEnumerator <TopologyVersion> enumerator3 = list.GetEnumerator())
                    {
                        while (enumerator3.MoveNext())
                        {
                            TopologyVersion topologyVersion2 = enumerator3.Current;
                            stringBuilder.Append(Strings.ToplogyserviceTopologyVersion(topologyVersion2.PartitionFqdn, topologyVersion2.Version) + Environment.NewLine);
                        }
                        goto IL_264;
                    }
IL_13A:
                    topologyServiceClient.ReportServerDown(this.PartitionFqdn, this.TargetDomainController, (ADServerRole)this.ADServerRole);
                    goto IL_264;
IL_1DA:
                    serversForRole = topologyServiceClient.GetServersForRole(this.PartitionFqdn, new List <string>(), (ADServerRole)this.ADServerRole, 20, false);
                    foreach (ServerInfo serverInfo2 in serversForRole)
                    {
                        stringBuilder.Append(Strings.TopologyServiceADServerInfo(serverInfo2.Fqdn) + Environment.NewLine);
                    }
                    if (serversForRole.Count > 0)
                    {
                        flag = true;
                    }
                    else
                    {
                        flag  = false;
                        error = Strings.TopologyServiceNoServersReturned(this.PartitionFqdn);
                    }
                    IL_264 :;
                }
                catch (CommunicationException ex)
                {
                    flag  = false;
                    error = ex.Message;
                    topologyServiceError = TopologyServiceError.CommunicationException;
                }
                catch (Exception ex2)
                {
                    flag  = false;
                    error = ex2.Message;
                    topologyServiceError = TopologyServiceError.OtherException;
                }
                stopwatch.Stop();
                result.Update(flag ? TopologyServiceResultEnum.Success : TopologyServiceResultEnum.Failure, stopwatch.Elapsed, error, stringBuilder.ToString());
                if (this.MonitoringContext)
                {
                    this.monitoringData.Events.Add(new MonitoringEvent(TestTopologyServiceTask.CmdletMonitoringEventSource, (int)((flag ? 1000 : 2000) + this.OperationType), flag ? EventTypeEnumeration.Success : EventTypeEnumeration.Error, flag ? Strings.TopologyServiceSuccess(this.OperationType.ToString()) : (Strings.TopologyServiceFailed(this.OperationType.ToString(), error) + " " + topologyServiceError)));
                }
            }
        }