internal static RidMasterInfo GetRidMasterInfo(IConfigurationSession session)
        {
            bool          useConfigNC = session.UseConfigNC;
            RidMasterInfo result;

            try
            {
                session.UseConfigNC = false;
                RidManagerContainer[] array = session.Find <RidManagerContainer>(null, QueryScope.SubTree, null, null, 1);
                if (array == null || array.Length != 1)
                {
                    throw new RidMasterConfigException(Strings.ErrorCannotRetrieveRidManagerContainer((array == null) ? "0" : array.Length.ToString()));
                }
                session.UseConfigNC = true;
                ADObjectId fsmoRoleOwner = array[0].FsmoRoleOwner;
                if (fsmoRoleOwner == null)
                {
                    throw new RidMasterConfigException(Strings.ErrorEmptyFsmoRoleOwnerAttribute);
                }
                ADServer adserver = session.Read <ADServer>(fsmoRoleOwner.Parent);
                if (adserver == null)
                {
                    throw new RidMasterConfigException(Strings.ErrorCannotRetrieveServer(fsmoRoleOwner.Parent.ToString()));
                }
                string dnsHostName          = adserver.DnsHostName;
                int    fsmoRoleOwnerVersion = SyncDaemonArbitrationConfigHelper.GetFsmoRoleOwnerVersion(array[0].ReplicationAttributeMetadata);
                result = new RidMasterInfo(dnsHostName, fsmoRoleOwnerVersion);
            }
            finally
            {
                session.UseConfigNC = useConfigNC;
            }
            return(result);
        }
Exemple #2
0
 private void RefreshRidMasterInformation()
 {
     if (DateTime.UtcNow - this.lastRidMasterRefreshTime > FullSyncObjectRequestDataProvider.RidMasterRefreshInterval)
     {
         RidMasterInfo ridMasterInfo = SyncDaemonArbitrationConfigHelper.GetRidMasterInfo(this.configurationSession);
         this.configurationSession.DomainController = ridMasterInfo.RidMasterServer;
         this.lastRidMasterRefreshTime = DateTime.UtcNow;
     }
 }
        internal static ArbitrationConfigFromAD GetArbitrationConfigFromAD(string serviceInstanceName)
        {
            IConfigurationSession configurationSession = ForwardSyncDataAccessHelper.CreateSession(true);
            RidMasterInfo         ridMasterInfo        = SyncDaemonArbitrationConfigHelper.GetRidMasterInfo(configurationSession);

            SyncServiceInstance[] array = configurationSession.Find <SyncServiceInstance>(SyncServiceInstance.GetMsoSyncRootContainer(), QueryScope.SubTree, new ComparisonFilter(ComparisonOperator.Equal, ADObjectSchema.Name, serviceInstanceName), null, 1);
            if (array == null || array.Length != 1)
            {
                throw new SyncDaemonArbitrationConfigException(Strings.ErrorCannotRetrieveSyncDaemonArbitrationConfigContainer((array == null) ? "0" : array.Length.ToString()));
            }
            return(new ArbitrationConfigFromAD(array[0], ridMasterInfo));
        }
        protected override void InternalProcessRecord()
        {
            TaskLogger.LogEnter();
            base.InternalProcessRecord();
            string instanceId = this.ServiceInstance.InstanceId;
            ArbitrationConfigFromAD arbitrationConfigFromAD = SyncDaemonArbitrationConfigHelper.GetArbitrationConfigFromAD(instanceId);
            string         path           = string.Format("\\\\{0}", arbitrationConfigFromAD.RidMasterInfo.RidMasterServer);
            string         path2          = Path.Combine(path, SyncDaemonArbitrationConfigHelper.SyncDaemonLeaseShare);
            string         leaseFilePath  = Path.Combine(path2, SyncDaemonArbitrationConfigHelper.GetLeaseFileName(instanceId));
            Guid           guid           = LocalSiteCache.LocalSite.Guid;
            LeaseFileEntry leaseFileEntry = new LeaseFileEntry(SyncDaemonArbitrationConfigHelper.ServerNameForFakeLock, Guid.NewGuid().ToString("N"), arbitrationConfigFromAD.RidMasterInfo.RidMasterVersionFromAD, new DateTime(DateTime.UtcNow.Ticks + new TimeSpan(0, 0, arbitrationConfigFromAD.SyncDaemonArbitrationConfig.PassiveInstanceSleepInterval).Ticks, DateTimeKind.Utc), guid);

            try
            {
                this.WriteLeaseFileEntry(leaseFilePath, leaseFileEntry);
            }
            catch (IOException)
            {
                Thread.Sleep(1000);
                this.WriteLeaseFileEntry(leaseFilePath, leaseFileEntry);
            }
            TaskLogger.LogExit();
        }