Esempio n. 1
0
        public static void WithDirectoryEntry(ADHelper adHelper, string nativeID, Action <DirectoryEntry> success, Action fail)
        {
            var result = SynchronizeHelper.GetSearchResultByID(adHelper, nativeID);

            if (result != null)
            {
                using (DirectoryEntry ent = result.GetDirectoryEntry())
                {
                    if (ent != null)
                    {
                        if (success != null)
                        {
                            success(ent);
                        }
                    }
                    else
                    {
                        if (fail != null)
                        {
                            fail();
                        }
                    }
                }
            }
            else
            {
                if (fail != null)
                {
                    fail();
                }
            }
        }
Esempio n. 2
0
        private static void DeleteADObject(ObjectModifyType modifyType, IOguObject oguObject, ADObjectWrapper adObject)
        {
            ADHelper adHelper = SynchronizeContext.Current.ADHelper;

            using (DirectoryEntry entry = SynchronizeHelper.GetSearchResultByID(adHelper, adObject.NativeGuid).GetDirectoryEntry())
            {
                entry.ForceBound();
                ObjectSetterHelper.Convert(modifyType, oguObject, entry);
            }
        }
Esempio n. 3
0
        private static void ModifyADObjectProperties(ObjectModifyType modifyType, ModifiedItem item)
        {
            IOguObject      oguObject = item.OguObjectData;
            ADObjectWrapper adObject  = item.ADObjectData;

            using (DirectoryEntry entry = SynchronizeHelper.GetSearchResultByID(SynchronizeContext.Current.ADHelper, adObject.NativeGuid, (ADSchemaType)oguObject.ObjectType).GetDirectoryEntry())
            {
                entry.ForceBound();
                ObjectSetterHelper.Convert(modifyType, oguObject, entry);
            }
        }
Esempio n. 4
0
        private static ADObjectWrapper FindOUObject(IOguObject oguObject)
        {
            ADObjectWrapper adObject = null;
            string          objectGuid;

            if (SynchronizeContext.Current.IDMapper.SCIDMappingDictionary.ContainsKey(oguObject.ID))
            {
                var idMapping = SynchronizeContext.Current.IDMapper.SCIDMappingDictionary[oguObject.ID];
                objectGuid = idMapping.ADObjectGuid;
                adObject   = SynchronizeHelper.GetSearchResultByID(SynchronizeContext.Current.ADHelper, objectGuid, ADSchemaType.Organizations).ToADOjectWrapper();

                if (adObject == null)
                {
                    //这里要删除ID映射
                    if (!SynchronizeContext.Current.IDMapper.DeleteIDMappingDictionary.ContainsKey(oguObject.ID))
                    {
                        SynchronizeContext.Current.IDMapper.DeleteIDMappingDictionary.Add(idMapping);
                    }

                    SynchronizeContext.Current.IDMapper.SCIDMappingDictionary.Remove(c => c.SCObjectID == oguObject.ID);
                }
            }

            if (adObject == null)            //通过ID没找到
            {
                string dn = SynchronizeHelper.GetOguObjectDN(oguObject);
                if (dn != "")
                {
                    adObject = SynchronizeHelper.GetSearchResultByDN(SynchronizeContext.Current.ADHelper, dn, ADSchemaType.Organizations).ToADOjectWrapper();

                    if (adObject != null)
                    {
                        //这里首先要判断是否已被映射过
                        if (SynchronizeContext.Current.IDMapper.ADIDMappingDictionary.ContainsKey(adObject.NativeGuid))
                        {
                            adObject = null;
                        }
                    }
                }
                else
                {
                    //using (DirectoryEntry root = SynchronizeContext.Current.ADHelper.GetRootEntry())
                    //{
                    //    adObject = new ADObjectWrapper() { ObjectType = ADSchemaType.Organizations };
                    //    adObject.Properties["distinguishedName"] = root.Properties["distinguishedName"][0].ToString();
                    //    adObject.Properties["objectGUID"] = root.NativeGuid;
                    //    adObject.Properties["name"] = root.Name;
                    //}
                }
            }

            return(adObject);
        }
Esempio n. 5
0
        public static DirectoryEntry GetDirectoryEntryByID(ADHelper adHelper, string nativeID)
        {
            var result = SynchronizeHelper.GetSearchResultByID(adHelper, nativeID);

            if (result != null)
            {
                return(result.GetDirectoryEntry());
            }
            else
            {
                return(null);
            }
        }
        protected override void ProcessDeleteEntry(ObjectModifyType modifyType, IOguObject srcObject, DirectoryEntry targetObject, string context)
        {
            List <ADObjectWrapper> allChildren = targetObject.FindAllChildrenUser();

            foreach (ADObjectWrapper child in allChildren)
            {
                using (DirectoryEntry subEntry = SynchronizeHelper.GetSearchResultByID(SynchronizeContext.Current.ADHelper, child.NativeGuid).GetDirectoryEntry())
                {
                    subEntry.ForceBound();
                    DisableAccount(subEntry);
                }
            }
        }
Esempio n. 7
0
        private static ADObjectWrapper FindGroupObject(IOguObject oguObject)
        {
            ADObjectWrapper adObject = null;
            string          objectGuid;

            if (SynchronizeContext.Current.IDMapper.SCIDMappingDictionary.ContainsKey(oguObject.ID))
            {
                var idMapping = SynchronizeContext.Current.IDMapper.SCIDMappingDictionary[oguObject.ID];
                objectGuid = idMapping.ADObjectGuid;
                adObject   = SynchronizeHelper.GetSearchResultByID(SynchronizeContext.Current.ADHelper, objectGuid, ADSchemaType.Groups).ToADOjectWrapper();

                if (adObject == null)
                {
                    //这里要删除ID映射
                    if (!SynchronizeContext.Current.IDMapper.DeleteIDMappingDictionary.ContainsKey(oguObject.ID))
                    {
                        SynchronizeContext.Current.IDMapper.DeleteIDMappingDictionary.Add(idMapping);
                    }

                    SynchronizeContext.Current.IDMapper.SCIDMappingDictionary.Remove(c => c.SCObjectID == oguObject.ID);
                }
            }

            if (adObject == null)            //通过ID没找到
            {
                adObject = SynchronizeHelper.GetSearchResultByLogonName(oguObject.Properties["LOGON_NAME"].ToString(), ADSchemaType.Groups).ToADOjectWrapper();

                if (adObject != null)
                {
                    //这里首先要判断是否已被映射过
                    if (SynchronizeContext.Current.IDMapper.ADIDMappingDictionary.ContainsKey(adObject.NativeGuid))
                    {
                        adObject = null;
                    }
                }
            }

            return(adObject);
        }