private static ADHelper CreateADHelper() { //初始化域控制器的配置信息 ServerInfoConfigureElement serverSetting = ServerInfoConfigSettings.GetConfig().ServerInfos["dc"]; ServerInfo serverInfo = serverSetting == null ? null : serverSetting.ToServerInfo(); PermissionCenterToADSynchronizeSettings config = PermissionCenterToADSynchronizeSettings.GetConfig(); return(ADHelper.GetInstance(serverInfo)); }
//从配置信息中初始化同步上下文 private void InitContext(string startPath) { SynchronizeContext context = SynchronizeContext.Current; context.SynchronizeResult = ADSynchronizeResult.Correct; //初始化域控制器的配置信息 ServerInfoConfigureElement serverSetting = ServerInfoConfigSettings.GetConfig().ServerInfos["dc"]; ServerInfo serverInfo = serverSetting == null ? null : serverSetting.ToServerInfo(); PermissionCenterToADSynchronizeSettings config = PermissionCenterToADSynchronizeSettings.GetConfig(); context.SourceRootPath = config.SourceRoot; //初始化(权限中心)开始同步的路径和回收站路径 string path = startPath.IsNullOrEmpty() ? config.DefaultStartPath : startPath; if (string.IsNullOrEmpty(path)) { path = context.SourceRootPath; } if (path != context.SourceRootPath && path.StartsWith(context.SourceRootPath + "\\", StringComparison.Ordinal) == false) { throw new System.Configuration.ConfigurationErrorsException("开始同步路径必须位于同步根范围内"); } context.StartPath = path; context.RecycleBinOU = config.RecycleBinOU; //默认用户口令 context.DefaultPassword = config.DefaultPassword; context.TargetRootOU = config.TargetRootOU; context.ADHelper = ADHelper.GetInstance(serverInfo); //初始化权限中心和AD的ID映射关系 context.ExtendLockTime(); context.IDMapper.Initialize(); context.ClearIncludeMappings(); foreach (ObjectMappingElement elem in config.ObjectMappings) { context.AddIncludeMapping(elem.SCObjectName, elem.ADObjectName); } }