private void EnsureRootOU(IOrganization startOrg) { if (SynchronizeContext.Current.IsIncluded(startOrg) == false) { throw new InvalidOperationException("同步根不在同步范围内"); } List <string> parentPaths = SynchronizeHelper.GetAllParentPaths(startOrg.FullPath); if (parentPaths.Count > 0) { foreach (string path in parentPaths) { if (path == SynchronizeContext.Current.SourceRootPath) { continue; // 根节点不应该被处理 } var curOrg = OguMechanismFactory.GetMechanism().GetObjects <IOrganization>(SearchOUIDType.FullPath, path).FirstOrDefault(); if (SynchronizeContext.Current.IsIncluded(curOrg)) { ADObjectWrapper adObject = ADObjectFinder.Find(curOrg, true); if (adObject == null) //这里判断找不到的情况,则加到变更列表 { SynchronizeContext.Current.PrepareAndAddModifiedItem(curOrg, adObject, ObjectModifyType.Add); } else //否则需要比较一下路径对不对,有可能按ID找到了,但路径变了 { if (!ObjectComparerHelper.ArePathEqaul(curOrg, adObject)) { SynchronizeContext.Current.PrepareAndAddModifiedItem(curOrg, adObject, ObjectModifyType.PropertyModified); } } } } } }