public static MultiValuedProperty <CredentialRecord> Load(Server edgeServer)
        {
            ITopologyConfigurationSession          configurationSession = DirectorySessionFactory.Default.CreateTopologyConfigurationSession(false, ConsistencyMode.PartiallyConsistent, ADSessionSettings.FromRootOrgScopeSet(), 103, "Load", "f:\\15.00.1497\\sources\\dev\\EdgeSync\\src\\Common\\Validation\\CredentialRecord.cs");
            MultiValuedProperty <CredentialRecord> credentialRecords    = new MultiValuedProperty <CredentialRecord>();

            ADNotificationAdapter.TryReadConfigurationPaged <Server>(() => configurationSession.FindAllServersWithVersionNumber(Server.E2007MinVersion), delegate(Server server)
            {
                if (server.IsHubTransportServer && server.EdgeSyncCredentials != null && server.EdgeSyncCredentials.Count != 0)
                {
                    foreach (byte[] data in server.EdgeSyncCredentials)
                    {
                        EdgeSyncCredential edgeSyncCredential = EdgeSyncCredential.DeserializeEdgeSyncCredential(data);
                        if (edgeSyncCredential.EdgeServerFQDN.Equals(edgeServer.Fqdn, StringComparison.OrdinalIgnoreCase))
                        {
                            CredentialRecord credentialRecord     = new CredentialRecord();
                            credentialRecord.TargetEdgeServerFQDN = edgeSyncCredential.EdgeServerFQDN;
                            credentialRecord.ESRAUsername         = edgeSyncCredential.ESRAUsername;
                            credentialRecord.EffectiveDate        = new DateTime(edgeSyncCredential.EffectiveDate).ToLocalTime();
                            credentialRecord.Duration             = new TimeSpan(edgeSyncCredential.Duration);
                            credentialRecord.IsBootStrapAccount   = edgeSyncCredential.IsBootStrapAccount;
                            credentialRecords.Add(credentialRecord);
                        }
                    }
                }
            });
            return(credentialRecords);
        }
        private static bool TryLoadAdObjects <T>(IConfigurationSession session, ADObjectId rootId, out IList <T> objects) where T : ADConfigurationObject, new()
        {
            List <T> results = new List <T>();
            bool     result  = ADNotificationAdapter.TryReadConfigurationPaged <T>(() => session.FindPaged <T>(rootId, QueryScope.SubTree, null, null, ADGenericPagedReader <T> .DefaultPageSize), delegate(T configObject)
            {
                results.Add(configObject);
            });

            objects = results;
            return(result);
        }
        // Token: 0x06000011 RID: 17 RVA: 0x00002A08 File Offset: 0x00000C08
        protected override bool GetBindings(out IPEndPoint[] bindings)
        {
            ExTraceGlobals.ServiceTracer.TraceDebug(0L, "Enter GetBindings");
            List <IPEndPoint> bindingList = new List <IPEndPoint>();

            bindings = null;
            bool flag = true;
            ADOperationResult success = ADOperationResult.Success;

            if (this.receiveConnectorNotificationCookie == null)
            {
                flag = this.RegisterConfigurationChangeHandlers(out success);
            }
            if (flag)
            {
                flag = ADNotificationAdapter.TryReadConfigurationPaged <ReceiveConnector>(delegate()
                {
                    Server server = TransportService.adConfigurationSession.FindLocalServer();
                    return(TransportService.adConfigurationSession.FindPaged <ReceiveConnector>(server.Id, QueryScope.SubTree, null, null, ADGenericPagedReader <ReceiveConnector> .DefaultPageSize));
                }, delegate(ReceiveConnector connector)
                {
                    if (connector.Enabled)
                    {
                        foreach (IPBinding ipbinding in connector.Bindings)
                        {
                            bindingList.Add(new IPEndPoint(ipbinding.Address, ipbinding.Port));
                        }
                    }
                }, 1, out success);
            }
            ExTraceGlobals.SmtpReceiveTracer.TraceError <bool, ADOperationErrorCode>(0L, "AD result: ok={0}, opResult={1}", flag, success.ErrorCode);
            if (flag)
            {
                bindings = bindingList.ToArray();
                this.lastRetrievedBindings = bindings;
                ExTraceGlobals.ServiceTracer.TraceDebug <int>(0L, "New configuration retrieved: {0} bindings", bindings.Length);
                ExTraceGlobals.ServiceTracer.TraceDebug(0L, "Leave GetBindings");
                return(true);
            }
            if (this.lastRetrievedBindings != null)
            {
                ExTraceGlobals.ServiceTracer.TraceDebug(0L, "Failed to retrieve configuration data, ignoring the update and continue with the current configuration");
                TransportService.logger.LogEvent(TransportEventLogConstants.Tuple_ReadConfigReceiveConnectorIgnored, null, new object[0]);
                bindings = this.lastRetrievedBindings;
                return(true);
            }
            this.GenerateConfigFailureEventLog(success.Exception);
            return(false);
        }
Beispiel #4
0
        internal static MserveWebService CreateDefaultMserveWebService(string domainController, bool batchMode, int initialChunkSize)
        {
            ITopologyConfigurationSession rootOrgSession = DirectorySessionFactory.Default.CreateTopologyConfigurationSession(domainController, true, ConsistencyMode.PartiallyConsistent, ADSessionSettings.FromRootOrgScopeSet(), 200, "CreateDefaultMserveWebService", "f:\\15.00.1497\\sources\\dev\\data\\src\\directory\\SystemConfiguration\\EdgeSyncMservConnector.cs");
            EdgeSyncServiceConfig         config         = null;
            string            clientToken       = null;
            ADSite            localSite         = null;
            ADOperationResult adoperationResult = ADNotificationAdapter.TryRunADOperation(delegate()
            {
                localSite = rootOrgSession.GetLocalSite();
                if (localSite == null)
                {
                    throw new TransientException(DirectoryStrings.CannotGetLocalSite);
                }
                config      = rootOrgSession.Read <EdgeSyncServiceConfig>(localSite.Id.GetChildId("EdgeSyncService"));
                clientToken = EdgeSyncMservConnector.GetMserveWebServiceClientTokenFromEndpointConfig(rootOrgSession);
            }, 3);

            if (!adoperationResult.Succeeded)
            {
                throw adoperationResult.Exception;
            }
            if (config == null)
            {
                throw new MserveException(string.Format("No EdgeSync configuration found. Site {0}", localSite.DistinguishedName));
            }
            if (string.IsNullOrEmpty(clientToken))
            {
                throw new InvalidOperationException(string.Format("clientToken from Endpoint configuration is null or empty . Site {0}", localSite.DistinguishedName));
            }
            List <EdgeSyncMservConnector> connectors = new List <EdgeSyncMservConnector>();

            if (!ADNotificationAdapter.TryReadConfigurationPaged <EdgeSyncMservConnector>(() => rootOrgSession.FindPaged <EdgeSyncMservConnector>(config.Id, QueryScope.SubTree, null, null, 0), delegate(EdgeSyncMservConnector connector)
            {
                connectors.Add(connector);
            }, 3, out adoperationResult))
            {
                throw adoperationResult.Exception;
            }
            if (connectors.Count == 0)
            {
                throw new InvalidOperationException(string.Format("No MServ configuration found. Site {0}", localSite.DistinguishedName));
            }
            MserveWebService mserveWebService = new MserveWebService(connectors[0].ProvisionUrl.AbsoluteUri, connectors[0].SettingUrl.AbsoluteUri, connectors[0].RemoteCertificate, clientToken, batchMode);

            mserveWebService.Initialize(initialChunkSize);
            return(mserveWebService);
        }
Beispiel #5
0
        private bool TryLoadTopologies(out Exception e)
        {
            bool result;

            try
            {
                e = null;
                if (Interlocked.Increment(ref this.loadTopologyCount) == 1)
                {
                    ADOperationResult adoperationResult;
                    if (this.localServer == null)
                    {
                        adoperationResult = ADNotificationAdapter.TryRunADOperation(delegate()
                        {
                            this.localServer = this.rootOrgConfigSession.FindLocalServer();
                        }, 3);
                        if (!adoperationResult.Succeeded)
                        {
                            e = adoperationResult.Exception;
                            ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.RpcClientWrapper, ServerManagerLog.EventType.Error, null, string.Format("Failed find local server with Exception {0}", ServerManagerLog.GetExceptionLogString(e, ServerManagerLog.ExceptionLogOption.IncludeStack | ServerManagerLog.ExceptionLogOption.IncludeInnerException)));
                            return(false);
                        }
                        if (this.localServer.ServerSite == null)
                        {
                            ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.RpcClientWrapper, ServerManagerLog.EventType.Error, null, "Local server doesn't have AD site");
                            return(false);
                        }
                        this.localSiteHubsFilter = new AndFilter(new QueryFilter[]
                        {
                            new BitMaskAndFilter(ServerSchema.CurrentServerRole, 32UL),
                            new ComparisonFilter(ComparisonOperator.Equal, ServerSchema.ServerSite, this.localServer.ServerSite)
                        });
                    }
                    List <Server> bridgeheadServers = new List <Server>();
                    if (!ADNotificationAdapter.TryReadConfigurationPaged <Server>(() => this.rootOrgConfigSession.FindPaged <Server>(null, QueryScope.SubTree, this.localSiteHubsFilter, null, 0), delegate(Server server)
                    {
                        ServerVersion a = new ServerVersion(server.VersionNumber);
                        if (ServerVersion.Compare(a, RpcClientWrapper.minRequiredRpcServerVersion) >= 0)
                        {
                            bridgeheadServers.Add(server);
                        }
                    }, out adoperationResult))
                    {
                        e = adoperationResult.Exception;
                        ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.RpcClientWrapper, ServerManagerLog.EventType.Error, null, string.Format("Failed to load topology with exception {0}", ServerManagerLog.GetExceptionLogString(e, ServerManagerLog.ExceptionLogOption.IncludeStack | ServerManagerLog.ExceptionLogOption.IncludeInnerException)));
                        result = false;
                    }
                    else
                    {
                        Interlocked.Exchange <List <Server> >(ref this.localSiteBridgeheadServers, bridgeheadServers);
                        RpcClientWrapper.instance.topologyLastUpdated = DateTime.UtcNow;
                        StringBuilder stringBuilder = new StringBuilder();
                        foreach (Server server2 in bridgeheadServers)
                        {
                            stringBuilder.Append(server2.Name);
                            stringBuilder.Append(",");
                        }
                        ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.RpcClientWrapper, ServerManagerLog.EventType.Success, null, string.Format("Sucessfully load topology with servers {0}", stringBuilder.ToString()));
                        result = true;
                    }
                }
                else
                {
                    result = true;
                }
            }
            finally
            {
                Interlocked.Decrement(ref this.loadTopologyCount);
            }
            return(result);
        }