private void RecursiveProcess(IOguObject oguObject)
        {
            if (oguObject != null && SynchronizeContext.Current.IsIncluded(oguObject))
            {
                SynchronizeContext.Current.ExtendLockTime();

                SynchronizeContext.Current.CurrentOguObject = oguObject;

                Debug.WriteLine("递归:OGU对象:" + oguObject.FullPath);

                //AD中是否找到对应的权限中心的对象
                ADObjectWrapper adObject = ADObjectFinder.Find(oguObject);

                if (oguObject.ObjectType == SchemaType.Groups)
                {
                    SynchronizeContext.Current.PrepareGroupToTakeCare(oguObject);                     //需注意的群组
                }

                if (adObject == null)                 //没找到,新增
                {
                    if (SynchronizeContext.Current.IsRealObject(oguObject))
                    {
                        Trace.WriteLine("AD中不存在决定新增" + oguObject.FullPath);
                        SynchronizeContext.Current.PrepareAndAddModifiedItem(oguObject, adObject, ObjectModifyType.Add);
                    }
                    else
                    {
                        Trace.WriteLine("不要新增AD中实际不存在的对象" + oguObject.FullPath);
                    }
                }
                else
                {
                    if (SynchronizeContext.Current.IsRealObject(oguObject))
                    {
                        //比较已经找到的两个对象的差异
                        Trace.Write("AD中存在,比较差异……");
                        //比较差异,也要考虑时间戳是否变化
                        ObjectModifyType compareResult = ObjectComparerHelper.Compare(oguObject, adObject);

                        Trace.WriteLine(compareResult);

                        if (compareResult != ObjectModifyType.None)                         // 修改
                        {
                            SynchronizeContext.Current.PrepareAndAddModifiedItem(oguObject, adObject, compareResult);
                        }
                    }
                    else
                    {
                        Trace.WriteLine("实际不存在,该删掉的对象:" + oguObject.FullPath);
                    }
                }

                if (oguObject.ObjectType == SchemaType.Organizations)
                {
                    //组织要检查是否有删除项,然后递归
                    ProcessOrganization((IOrganization)oguObject, adObject);
                }
            }
        }
        public override void Convert(ObjectModifyType modifyType, IOguObject srcObject, DirectoryEntry targetObject, string context)
        {
            SetterContext setterContext = new SetterContext();

            ConvertProperties(srcObject, targetObject, setterContext);

            targetObject.CommitChanges();

            if (!ObjectComparerHelper.AreParentPathEqaul(srcObject, targetObject))
            {
                MoveItemToNewPath(srcObject, targetObject);
            }

            DoAfterObjectUpdatedOP(srcObject, targetObject, setterContext);
        }
        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);
                            }
                        }
                    }
                }
            }
        }