protected override bool ComparePropertyValue(IOguObject srcOguObject, string srcPropertyName, ADObjectWrapper adObject, string targetPropertyName, string context)
		{
			DateTime dtResult = DateTime.MinValue;
			long adAccountExpiresValue = Convert.ToInt64(adObject.Properties[targetPropertyName]);

			try
			{
				if (adAccountExpiresValue != SynchronizeHelper.ACCOUNT_EXPIRES_MAX_VALUE)
				{
					if (adAccountExpiresValue != 0)
					{
						DateTime dt = DateTime.FromFileTime(adAccountExpiresValue);

						//舍弃掉毫秒
						dtResult = new DateTime(dt.Year, dt.Month, dt.Day, dt.Hour, dt.Minute, dt.Second, dt.Millisecond);
					}
				}
			}
			catch (System.ArgumentOutOfRangeException)
			{
				dtResult = DateTime.MaxValue;
			}

			dtResult = SynchronizeContext.Current.ADHelper.GetUserAccountExpirationDate(dtResult);
			var accountExpiresDate = Convert.ToDateTime(srcOguObject.Properties[srcPropertyName]);

			return accountExpiresDate == dtResult;
		}
        private static void MoveItemToNewPath(IOguObject oguObject, DirectoryEntry targetObject)
        {
            ADHelper adHelper = SynchronizeContext.Current.ADHelper;

            IDMapping mapping   = null;
            var       oguParent = oguObject.Parent;

            if (oguParent != null)
            {
                mapping = SynchronizeContext.Current.IDMapper.GetAdObjectMapping(oguParent.ID, false);
            }

            if (mapping != null)
            {
                using (var adEntry = SynchronizeHelper.GetDirectoryEntryByID(SynchronizeContext.Current.ADHelper, mapping.ADObjectGuid))
                {
                    if (adEntry != null)
                    {
                        try
                        {
                            targetObject.MoveTo(adEntry);
                        }
                        catch (DirectoryServicesCOMException comEx)
                        {
                            switch (comEx.ErrorCode)
                            {
                            case -2147019886:
                                //重名
                                SynchronizeHelper.SolveConflictAboutMove(oguObject, targetObject, adEntry);
                                break;

                            case -2147016656:
                                Trace.WriteLine("修改对象属性后,移动对象说对象不存在??被移动的对象:" + oguObject.Name);
                                throw;

                            default:
                                throw;
                            }
                        }
                    }
                }
            }
            else
            {
                var parentDn = SynchronizeHelper.GetParentObjectDN(oguObject);

                Trace.WriteLine("不可靠的方法被执行,目标不存在时,靠DN来延迟移动。Careful !");
                // 父对象还不存在,这可能是被重命名了
                //SynchronizeContext.Current.DelayActions.Add(new DelayMoveToAction(oguObject, parentDn, targetObject.Guid));

                // 没有这种可能性
                var context = SynchronizeContext.Current;
                context.ExceptionCount++;

                LogHelper.WriteSynchronizeDBLogDetail(SynchronizeContext.Current.SynchronizeID, "移动对象", oguObject.ID, oguObject.Name,
                                                      context.ADHelper.GetPropertyStrValue("objectGuid", targetObject),
                                                      context.ADHelper.GetPropertyStrValue("distinguishedName", targetObject),
                                                      string.Format("父对象:{0}无映射,无法移动。", parentDn));
            }
        }
Exemple #3
0
        protected override void SetPropertyValue(IOguObject srcOguObject, string srcPropertyName, DirectoryEntry entry, string targetPropertyName, string context, SetterContext setterContext)
        {
            entry.InvokeSet(targetPropertyName,
                            new object[] { SynchronizeHelper.GetADAccountExpiresDate(srcOguObject.Properties[srcPropertyName]) });

            TraceItHere(srcOguObject.ObjectType.ToString(), srcPropertyName, entry.Name, targetPropertyName, context, srcOguObject.Properties[srcPropertyName].ToString(), SynchronizeHelper.GetADAccountExpiresDate(srcOguObject.Properties[srcPropertyName]).ToLongTimeString());
        }
Exemple #4
0
        public static void FillResult(this IEnumerable <IOguObject> objs, List <IOguObject> queryResult, UserGraphControlObjectMask listMask,
                                      Func <IOguObject, bool> filter = null, Action <IOguObject, IOguObject> addedAction = null)
        {
            objs.ForEach(obj =>
            {
                if (((int)obj.ObjectType & (int)listMask) != 0)
                {
                    bool canAdd = true;

                    if (filter != null)
                    {
                        canAdd = filter(obj);
                    }

                    if (canAdd)
                    {
                        IOguObject newObj = OguBase.CreateWrapperObject(obj);

                        if (addedAction != null)
                        {
                            addedAction(obj, newObj);
                        }

                        queryResult.Add(newObj);
                    }
                }
            }
                         );
        }
Exemple #5
0
        public override void Fill(IOguObject target, SchemaObjectBase src, SCObjectAndRelation relation)
        {
            base.Fill(target, src, relation);

            if (src.SchemaType != "Users")
            {
                throw new ArgumentException(string.Format("SchemaType不匹配", src), "src");
            }
            var wrapper = target as OGUPermission.IUserPropertyAccessible;

            if (wrapper == null)
            {
                throw new InvalidCastException("工厂创建的对象未实现IUserPropertyAccessible");
            }

            //wrapper.Levels = src.Properties.GetValue<int>("Levels", 0);

            wrapper.Attributes = src.Properties.GetValue <UserAttributesType>("CadreType", UserAttributesType.Unspecified);
            wrapper.Email      = src.Properties.GetValue <string>("Mail", string.Empty);
            wrapper.LogOnName  = src.Properties.GetValue <string>("CodeName", string.Empty);
            wrapper.ObjectType = SchemaType.Users;
            wrapper.Occupation = src.Properties.GetValue <string>("Occupation", string.Empty);
            wrapper.Rank       = src.Properties.GetValue <UserRankType>("UserRank", UserRankType.Unspecified);
            if (relation != null)
            {
                wrapper.IsSideline = !relation.Default;
            }
        }
		public ClientOguUser(IOguObject oguObject)
		{
			oguObject.NullCheck("oguObject");

			this.ID = oguObject.ID;
			this.DisplayName = oguObject.DisplayName;
		}
Exemple #7
0
        private static bool IsChildrenModified(IOguObject oguObject, ADObjectWrapper targetObject)
        {
            ADHelper     adHelper = SynchronizeContext.Current.ADHelper;
            SearchResult result   = SynchronizeHelper.GetSearchResultByDN(adHelper, targetObject.DN, ADSchemaType.Groups);           //当前肯定有改组存在
            ResultPropertyValueCollection adMembers = result.Properties["member"];

            IUser[] oguUsers = ((IGroup)oguObject).Members.Where(u => u.FullPath.StartsWith(SynchronizeContext.Current.StartPath) && u.IsSideline == false).ToArray();


            if (adMembers.Count != oguUsers.Count())
            {
                return(true);
            }

            foreach (var memberDN in adMembers)
            {
                bool exists = false;
                for (int i = oguUsers.Length - 1; i >= 0; i--)
                {
                    if (SynchronizeHelper.AppendNamingContext(SynchronizeHelper.GetOguObjectDN(oguUsers[i])) == memberDN.ToString())
                    {
                        exists = true;
                        break;
                    }
                }
                if (exists == false)
                {
                    return(true);
                }
            }

            return(false);
        }
Exemple #8
0
 protected void LoadObectjToTreeNode(UserOUGraphControl treeControl, IOguObject oguObj, DeluxeTreeNode newTreeNode, ref bool cancel)
 {
     if (oguObj.ObjectType == SchemaType.Groups)
     {
         cancel = true;
     }
 }
Exemple #9
0
        public ClientOguUser(IOguObject oguObject)
        {
            oguObject.NullCheck("oguObject");

            this.ID          = oguObject.ID;
            this.DisplayName = oguObject.DisplayName;
        }
        /// <summary>
        /// 输出对象的详细信息
        /// </summary>
        /// <param name="obj"></param>
        public static void OutputObjectDetailInfo(IOguObject obj)
        {
            Console.WriteLine("ID={0}", obj.ID);
            Console.WriteLine("SchemaType={0}", obj.ObjectType);
            Console.WriteLine("Name={0}", obj.Name);
            Console.WriteLine("DisplayName={0}", obj.DisplayName);
            Console.WriteLine("FullPath={0}", obj.FullPath);
            Console.WriteLine("Properties:");

            foreach (DictionaryEntry entry in obj.Properties)
            {
                string key   = "null";
                string value = "null";

                if (entry.Key != null)
                {
                    key = entry.Key.ToString();
                }

                if (entry.Value != null)
                {
                    value = entry.Value.ToString();
                }

                Console.WriteLine("Key={0}, Value={1}", key, value);
            }

            Console.WriteLine();
        }
        protected override bool ComparePropertyValue(IOguObject srcOguObject, string srcPropertyName, ADObjectWrapper adObject, string targetPropertyName, string context)
        {
            DateTime dtResult = DateTime.MinValue;
            long     adAccountExpiresValue = Convert.ToInt64(adObject.Properties[targetPropertyName]);

            try
            {
                if (adAccountExpiresValue != SynchronizeHelper.ACCOUNT_EXPIRES_MAX_VALUE)
                {
                    if (adAccountExpiresValue != 0)
                    {
                        DateTime dt = DateTime.FromFileTime(adAccountExpiresValue);

                        //舍弃掉毫秒
                        dtResult = new DateTime(dt.Year, dt.Month, dt.Day, dt.Hour, dt.Minute, dt.Second, dt.Millisecond);
                    }
                }
            }
            catch (System.ArgumentOutOfRangeException)
            {
                dtResult = DateTime.MaxValue;
            }

            dtResult = SynchronizeContext.Current.ADHelper.GetUserAccountExpirationDate(dtResult);
            var accountExpiresDate = Convert.ToDateTime(srcOguObject.Properties[srcPropertyName]);

            return(accountExpiresDate == dtResult);
        }
Exemple #12
0
        public static IOguObject CreateWrapperObject(string id, SchemaType type)
        {
            IOguObject result = null;

            switch (type)
            {
            case SchemaType.Organizations:
                result = new OguOrganization(id);
                break;

            case SchemaType.Users:
                result = new OguUser(id);
                break;

            case SchemaType.Groups:
                result = new OguGroup(id);
                break;

            default:
                ExceptionHelper.TrueThrow(true, string.Format("SchemaType错误{0}", type));
                break;
            }

            return(result);
        }
Exemple #13
0
        public static IOguObject CreateWrapperObject(IOguObject obj)
        {
            IOguObject result = null;

            if (obj is OguBase || obj == null)
            {
                result = obj;
            }
            else
            {
                if (obj is IUser)
                {
                    result = new OguUser((IUser)obj);
                }
                else
                if (obj is IOrganization)
                {
                    result = new OguOrganization((IOrganization)obj);
                }
                else
                if (obj is IGroup)
                {
                    result = new OguGroup((IGroup)obj);
                }
                else
                {
                    ExceptionHelper.TrueThrow(true, "不能生成类型为{0}的对象人员包装类", obj.GetType().Name);
                }
            }

            return(result);
        }
        protected override void SetPropertyValue(IOguObject srcOguObject, string srcPropertyName, DirectoryEntry entry, string targetPropertyName, string context, SetterContext setterContext)
        {
            string srcPropertyValue    = GetNormalizeddSourceValue(srcOguObject, srcPropertyName, context);
            string targetPropertyValue = GetNormalizeddTargetValue(entry, targetPropertyName, context);

            if (srcPropertyValue != targetPropertyValue)
            {
                //entry.CommitChanges();
                try
                {
                    string targetValue = srcOguObject.Properties[srcPropertyName].ToString();
                    entry.Properties[targetPropertyName].Value  = targetValue;
                    entry.Properties["userPrincipalName"].Value = targetValue + (string.IsNullOrEmpty(targetValue) ? string.Empty : context);
                    // entry.CommitChanges();
                }
                catch (DirectoryServicesCOMException ex)
                {
                    if (ex.ErrorCode == -2147019886)
                    {
                        //对象已存在
                        entry.Properties[targetPropertyName].Value = "TMP" + Environment.TickCount.ToString("X");
                        entry.CommitChanges();
                        SynchronizeContext.Current.DelayActions.Add(new DelayRenameCodeNameAction(srcOguObject, srcPropertyName, entry.NativeGuid, targetPropertyName));
                    }
                    else
                    {
                        throw;
                    }
                }
            }
        }
Exemple #15
0
 protected void DefaultProcessRequest(string delegateUserID)
 {
     if (string.IsNullOrEmpty(delegateUserID))
     {
         DefaultProcessRequest();
     }
     else
     {
         WfDelegationCollection delegation   = WfDelegationAdapter.Instance.Load(builder => builder.AppendItem("DESTINATION_USER_ID", delegateUserID));
         WfDelegation           wfDelegation = new WfDelegation();
         foreach (WfDelegation delegation1 in delegation)
         {
             wfDelegation.DestinationUserID   = delegation1.DestinationUserID;
             wfDelegation.DestinationUserName = delegation1.DestinationUserName;
             wfDelegation.StartTime           = delegation1.StartTime;
             wfDelegation.EndTime             = delegation1.EndTime;
             wfDelegation.SourceUserID        = delegation1.SourceUserID;
             wfDelegation.SourceUserName      = delegation1.SourceUserName;
         }
         if (delegation.Count > 0)
         {
             Data = wfDelegation;
             IOguObject oguObject =
                 OguMechanismFactory.GetMechanism().GetObjects <IOguObject>(SearchOUIDType.Guid, Data.DestinationUserID)[
                     0];
             DelegatedUserInput.SelectedOuUserData.Add(oguObject);
         }
     }
 }
Exemple #16
0
        /// <summary>
        /// 初始化祖先的OUs
        /// </summary>
        /// <param name="currentObj">当前对象</param>
        public void InitAncestorOUs(IOguObject currentObj)
        {
            IOguPropertyAccessible wrapper = (IOguPropertyAccessible)currentObj;

            string parentID = (string)currentObj.Properties["ParentID"];

            Debug.Assert(string.IsNullOrEmpty(parentID) == false);

            Dictionary <string, SCSimpleObjectCollection> parentMap = PC.Adapters.SCSnapshotAdapter.Instance.LoadAllParentsInfo(true, parentID);

            SCSimpleObjectCollection parents = parentMap[parentID];

            List <string> idList = new List <string>(parents.ToIDArray());

            //idList.Add(parentID);

            OguObjectCollection <IOrganization> orgs = this.GetObjects <IOrganization>(SearchOUIDType.Guid, idList.ToArray());

            ((IOguPropertyAccessible)currentObj).Parent = orgs.Find(obj => obj.ID == parentID);
            wrapper = (IOguPropertyAccessible)wrapper.Parent;
            for (int i = parents.Count - 1; i >= 0; i--)
            {
                var org = orgs.Find(obj => obj.ID == parents[i].ID);
                if (org != null && org.DepartmentType != DepartmentTypeDefine.XuNiJiGou)
                {
                    wrapper.Parent = orgs.Find(obj => obj.ID == parents[i].ID);
                    wrapper        = (IOguPropertyAccessible)wrapper.Parent;
                }
            }
        }
		protected override void SetPropertyValue(IOguObject srcOguObject, string srcPropertyName, DirectoryEntry entry, string targetPropertyName, string context, SetterContext setterContext)
		{
			entry.InvokeSet(targetPropertyName,
				new object[] { SynchronizeHelper.GetADAccountExpiresDate(srcOguObject.Properties[srcPropertyName]) });

			TraceItHere(srcOguObject.ObjectType.ToString(), srcPropertyName, entry.Name, targetPropertyName, context, srcOguObject.Properties[srcPropertyName].ToString(), SynchronizeHelper.GetADAccountExpiresDate(srcOguObject.Properties[srcPropertyName]).ToLongTimeString());
		}
Exemple #18
0
        private static OguDataCollection <IUser> DeserializeUsers(IList objs)
        {
            Dictionary <string, IUser> userDict = new Dictionary <string, IUser>();

            for (int i = 0; i < objs.Count; i++)
            {
                IOguObject obj = (IOguObject)objs[i];

                if (obj is IGroup)
                {
                    foreach (IUser user in ((IGroup)obj).Members)
                    {
                        userDict[user.ID] = user;
                    }
                }
                else
                if (obj is IUser)
                {
                    IUser user = (IUser)obj;
                    userDict[user.ID] = user;
                }
            }

            OguDataCollection <IUser> users = new OguDataCollection <IUser>();

            foreach (KeyValuePair <string, IUser> kp in userDict)
            {
                users.Add(kp.Value);
            }

            return(users);
        }
        private void FillObjectToUsers(OguDataCollection <IUser> users, IOguObject obj)
        {
            OguBase wrappedObj = (OguBase)OguBase.CreateWrapperObject(obj);

            wrappedObj.FullPath = obj.FullPath;

            switch (obj.ObjectType)
            {
            case SchemaType.Users:
                if (users.Exists(u => string.Compare(u.ID, obj.ID, true) == 0) == false)
                {
                    users.Add((IUser)wrappedObj);
                }
                break;

            case SchemaType.Groups:
                IGroup group = (IGroup)wrappedObj;
                group.Members.ForEach(u =>
                {
                    if (users.Exists(ul => string.Compare(ul.ID, u.ID, true) == 0) == false)
                    {
                        users.Add(u);
                    }
                });
                break;

            case SchemaType.Organizations:
            case SchemaType.OrganizationsInRole:
                IOrganization dept = (IOrganization)obj;
                dept.Children.ForEach(o => FillObjectToUsers(users, o));
                break;
            }
        }
        private void FillObjectToUsers(OguDataCollection<IUser> users, IOguObject obj)
        {
            OguBase wrappedObj = (OguBase)OguBase.CreateWrapperObject(obj);
            wrappedObj.FullPath = obj.FullPath;

            switch (obj.ObjectType)
            {
                case SchemaType.Users:
                    if (users.Exists(u => string.Compare(u.ID, obj.ID, true) == 0) == false)
                        users.Add((IUser)wrappedObj);
                    break;
                case SchemaType.Groups:
                    IGroup group = (IGroup)wrappedObj;
                    group.Members.ForEach(u =>
                    {
                        if (users.Exists(ul => string.Compare(ul.ID, u.ID, true) == 0) == false)
                            users.Add(u);
                    });
                    break;
                case SchemaType.Organizations:
                case SchemaType.OrganizationsInRole:
                    IOrganization dept = (IOrganization)obj;
                    dept.Children.ForEach(o => FillObjectToUsers(users, o));
                    break;
            }
        }
		private static bool IsChildrenModified(IOguObject oguObject, ADObjectWrapper targetObject)
		{
			ADHelper adHelper = SynchronizeContext.Current.ADHelper;
			SearchResult result = SynchronizeHelper.GetSearchResultByDN(adHelper, targetObject.DN, ADSchemaType.Groups); //当前肯定有改组存在
			ResultPropertyValueCollection adMembers = result.Properties["member"];

			IUser[] oguUsers = ((IGroup)oguObject).Members.Where(u => u.FullPath.StartsWith(SynchronizeContext.Current.StartPath) && u.IsSideline == false).ToArray();


			if (adMembers.Count != oguUsers.Count())
				return true;

			foreach (var memberDN in adMembers)
			{
				bool exists = false;
				for (int i = oguUsers.Length - 1; i >= 0; i--)
				{
					if (SynchronizeHelper.AppendNamingContext(SynchronizeHelper.GetOguObjectDN(oguUsers[i])) == memberDN.ToString())
					{
						exists = true;
						break;
					}
				}
				if (exists == false)
					return true;
			}

			return false;
		}
Exemple #22
0
        private static IList <IOrganization> InitAncestorOUsByParentID(IOguObject current)
        {
            List <IOrganization> result = new List <IOrganization>();

            string parentID = current.Properties.GetValue("PARENT_GUID", string.Empty);

            while (parentID.IsNotEmpty())
            {
                OguObjectCollection <IOrganization> parents =
                    OguMechanismFactory.GetMechanism().GetObjects <IOrganization>(SearchOUIDType.Guid, parentID);

                if (parents.Count > 0)
                {
                    result.Insert(0, parents[0]);
                    current  = parents[0];
                    parentID = current.Properties.GetValue("PARENT_GUID", string.Empty);
                }
                else
                {
                    break;
                }
            }

            return(result);
        }
		protected override void SetPropertyValue(IOguObject srcOguObject, string srcPropertyName, DirectoryEntry entry, string targetPropertyName, string context, SetterContext setterContext)
		{
			string srcPropertyValue = GetNormalizeddSourceValue(srcOguObject, srcPropertyName, context);
			string targetPropertyValue = GetNormalizeddTargetValue(entry, targetPropertyName, context);

			if (srcPropertyValue != targetPropertyValue)
			{
				//entry.CommitChanges();
				try
				{
					entry.Properties[targetPropertyName].Value = srcOguObject.Properties[srcPropertyName];
					// entry.CommitChanges();
				}
				catch (DirectoryServicesCOMException ex)
				{
					if (ex.ErrorCode == -2147019886)
					{
						//对象已存在
						entry.Properties[targetPropertyName].Value = "TMP" + Environment.TickCount.ToString("X");
						entry.CommitChanges();
						SynchronizeContext.Current.DelayActions.Add(new DelayRenameCodeNameAction(srcOguObject, srcPropertyName, entry.NativeGuid, targetPropertyName));
					}
					else
					{
						throw;
					}
				}
			}
		}
Exemple #24
0
        protected override bool ComparePropertyValue(IOguObject srcOguObject, string srcPropertyName, ADObjectWrapper adObject, string targetPropertyName, string context)
        {
            string srcPropertyValue = null;

            if (srcOguObject.Properties[srcPropertyName] != null)
            {
                srcPropertyValue = srcOguObject.Properties[srcPropertyName].ToString();
            }

            string targetPropertyValue = null;

            if (adObject.Properties[targetPropertyName] != null)
            {
                targetPropertyValue = adObject.Properties[targetPropertyName].ToString();
            }

            bool result = false;

            if (srcPropertyValue != null && targetPropertyValue != null)
            {
                result = srcPropertyValue == targetPropertyValue;
            }

            return(result);
        }
		/// <summary>
		/// 输出对象的详细信息
		/// </summary>
		/// <param name="obj"></param>
		public static void OutputObjectDetailInfo(IOguObject obj)
		{
			Console.WriteLine("ID={0}", obj.ID);
			Console.WriteLine("SchemaType={0}", obj.ObjectType);
			Console.WriteLine("Name={0}", obj.Name);
			Console.WriteLine("DisplayName={0}", obj.DisplayName);
			Console.WriteLine("FullPath={0}", obj.FullPath);
			Console.WriteLine("Properties:");

			foreach (DictionaryEntry entry in obj.Properties)
			{
				string key = "null";
				string value = "null";

				if (entry.Key != null)
					key = entry.Key.ToString();

				if (entry.Value != null)
					value = entry.Value.ToString();

				Console.WriteLine("Key={0}, Value={1}", key, value);
			}

			Console.WriteLine();
		}
        protected void InnerGetDataSource(string sPrefix, int iCount, object context, ref IEnumerable result)
        {
            ServiceBrokerContext.Current.Timeout = QueryUserTimeout;

            IOrganization rootOrg = UserOUControlSettings.GetConfig().UserOUControlQuery.GetOrganizationByPath(this.RootPath);
            OguDataCollection <IOguObject> users = QueryChildrenBySelectMask(rootOrg, sPrefix);

            ArrayList arrList = new ArrayList();

            if (this.CanSelectRoot)
            {
                if (rootOrg.DisplayName.IndexOf(sPrefix) == 0)
                {
                    arrList.Add(OguBase.CreateWrapperObject(rootOrg));
                }
            }

            for (int i = 0; i < users.Count; i++)
            {
                //资源类型过滤
                IOguObject oguObject = OguBase.CreateWrapperObject(users[i]);

                if (this.SelectMask == UserControlObjectMask.All || (((int)this.SelectMask & (int)oguObject.ObjectType)) != 0)
                {
                    arrList.Add(oguObject);
                }
            }

            //修饰一下结果
            foreach (OguBase obj in arrList)
            {
                string path = string.Empty;
                if (obj.Parent != null)
                {
                    path = obj.Parent.FullPath;
                }

                if (path.IndexOf(rootOrg.FullPath) == 0)
                {
                    path = path.Substring(rootOrg.FullPath.Length);
                    path = path.Trim('\\');
                }

                if (obj is OguBase)
                {
                    // v-weirf changed : obj must be a OguBase to use Description
                    if (obj is IUser)
                    {
                        ((OguBase)obj).Description = string.Format("{0} {1}", ((IUser)obj).Occupation, path);
                    }
                    else if (obj is OguOrganization)
                    {
                        ((OguBase)obj).Description = path;
                    }
                }
            }

            result = arrList;
        }
        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);
                }
            }
        }
Exemple #28
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="obj"></param>
        protected WfOguObject(IOguObject obj, SchemaType st)
        {
            ExceptionHelper.FalseThrow <ArgumentNullException>(obj != null, "obj");

            this.id         = obj.ID;
            this.baseObject = obj;
            this.objectType = st;
        }
 public void Clear()
 {
     this.activeUser      = null;
     this.passiveUser     = null;
     this.ActiveUserName  = null;
     this.PassiveUserName = null;
     this.Enabled         = false;
 }
			public void Clear()
			{
				this.activeUser = null;
				this.passiveUser = null;
				this.ActiveUserName = null;
				this.PassiveUserName = null;
				this.Enabled = false;
			}
		/// <summary>
		/// 
		/// </summary>
		/// <param name="obj"></param>
		protected WfOguObject(IOguObject obj, SchemaType st)
		{
			ExceptionHelper.FalseThrow<ArgumentNullException>(obj != null, "obj");

			this.id = obj.ID;
			this.baseObject = obj;
			this.objectType = st;
		}
        private void ProcessOrganization(IOrganization organization, ADObjectWrapper adObject)
        {
            SynchronizeContext.Current.ExtendLockTime();
            IList <IOrganization> allOrganizationChildren = GetObjectDetailInfo <IOrganization>(organization.Children);

            SynchronizeContext.Current.ExtendLockTime();
            IList <IUser> allUserChildren = GetUserDetailInfo(organization.Children);

            SynchronizeContext.Current.ExtendLockTime();
            IList <IGroup> allGroupChildren = GetObjectDetailInfo <IGroup>(organization.Children);

            //如果AD中有对应的组织
            if (adObject != null)
            {
                //在AD中找对应的子对象
                List <ADObjectWrapper> allADChildren = SynchronizeHelper.SearchChildren(adObject);

                Trace.WriteLine("检查AD中的子项,共" + allADChildren.Count + "项");

                foreach (ADObjectWrapper child in allADChildren)
                {
                    SynchronizeContext.Current.ExtendLockTime();

                    if (child.Properties.Contains("displayNamePrintable"))
                    {
                        //肯定是群组了
                        if (SynchronizeHelper.PermissionCenterInvolved.Equals(child.Properties["displayNamePrintable"]))
                        {
                            IOguObject subObj = OguObjectFinder.Find(child, organization.Children);

                            if (subObj == null)
                            {
                                //在权限中心的组织下没有找到则删除项
                                SynchronizeContext.Current.PrepareAndAddDeletedItem(subObj, child, ObjectModifyType.Delete);

                                Trace.WriteLineIf(subObj == null, "无对应AD对象 " + child.DN + "的OGU对象,加入删除列表");
                            }
                        }
                    }
                    else
                    {
                        IOguObject subObj = OguObjectFinder.Find(child, organization.Children);

                        if (subObj == null)
                        {
                            //在权限中心的组织下没有找到则删除项
                            SynchronizeContext.Current.PrepareAndAddDeletedItem(subObj, child, ObjectModifyType.Delete);

                            Trace.WriteLineIf(subObj == null, "无对应AD对象 " + child.DN + "的OGU对象,加入删除列表");
                        }
                    }
                }
            }

            allUserChildren.ForEach(child => RecursiveProcess(child));
            allGroupChildren.ForEach(child => RecursiveProcess(child));
            allOrganizationChildren.ForEach(child => RecursiveProcess(child));
        }
Exemple #33
0
        /// <summary>
        /// 获取对象RDN的数组,数组最开始为对象RDN
        /// </summary>
        /// <param name="oguObject"></param>
        /// <returns></returns>
        public static string[] GetOguObjectRdns(IOguObject oguObject)
        {
            if (SynchronizeContext.Current.IsIncluded(oguObject) == false)
            {
                throw new InvalidOperationException("对象不在同步范围中");
            }

            string relativePath = SynchronizeHelper.GetRelativePath(oguObject);

            if (relativePath.Length > 0)
            {
                string[] paths = relativePath.Split('\\');

                if (paths.Length > 0)
                {
                    paths[0] = SynchronizeContext.Current.GetMappedName(paths[0]);                     // 一级目录

                    switch (oguObject.ObjectType)
                    {
                    case SchemaType.Organizations:

                        for (int i = paths.Length - 1; i > 0; i--)
                        {
                            paths[i] = "OU=" + ADHelper.EscapeString(paths[i]);
                        }

                        break;

                    case SchemaType.Users:
                    case SchemaType.Groups:

                        paths[paths.Length - 1] = "CN=" + ADHelper.EscapeString(paths[paths.Length - 1]);

                        for (int i = paths.Length - 2; i > 0; i--)
                        {
                            paths[i] = "OU=" + ADHelper.EscapeString(paths[i]);
                        }
                        break;
                    }
                }

                if (string.IsNullOrEmpty(SynchronizeContext.Current.TargetRootOU) == false)
                {
                    string[] temp = new string[paths.Length + 1];
                    Array.Copy(paths, 0, temp, 1, paths.Length);
                    temp[0] = SynchronizeContext.Current.TargetRootOU;
                    paths   = temp;
                }

                Array.Reverse(paths);

                return(paths);
            }
            else
            {
                return(new string[0]);
            }
        }
        /// <summary>
        /// 转换成简单XML节点
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="element"></param>
        /// <param name="childNodeName"></param>
        public static void ToSimpleXElement(this IOguObject obj, XElement element, string childNodeName)
        {
            element.NullCheck("element");

            if (obj != null)
            {
                ((ISimpleXmlSerializer)obj).ToXElement(element, childNodeName);
            }
        }
Exemple #35
0
        public static string GetOguObjectDN(IOguObject oguObject)
        {
            StringBuilder strResult = new StringBuilder(oguObject.FullPath.Length * 2);

            if (SynchronizeContext.Current.IsIncluded(oguObject) == false)
            {
                throw new InvalidOperationException("对象不在同步范围中");
            }

            string relativePath = SynchronizeHelper.GetRelativePath(oguObject);

            if (relativePath.Length > 0)
            {
                var paths = relativePath.Split('\\');

                if (paths.Length > 0)
                {
                    paths[0] = SynchronizeContext.Current.GetMappedName(paths[0]);                     // 一级目录

                    switch (oguObject.ObjectType)
                    {
                    case SchemaType.Organizations:

                        for (int i = paths.Length - 1; i > 0; i--)
                        {
                            strResult.Append("OU=").Append(ADHelper.EscapeString(paths[i])).Append(",");
                        }

                        strResult.Append(paths[0]);

                        break;

                    case SchemaType.Users:
                    case SchemaType.Groups:

                        string name = "CN=";

                        for (int i = paths.Length - 1; i > 0; i--)
                        {
                            strResult.Append(name).Append(ADHelper.EscapeString(paths[i])).Append(",");
                            name = "OU=";
                        }

                        strResult.Append(paths[0]);

                        break;
                    }
                }
            }

            if (strResult.Length > 0 && string.IsNullOrEmpty(SynchronizeContext.Current.TargetRootOU) == false)
            {
                strResult.Append(",").Append(SynchronizeContext.Current.TargetRootOU);
            }

            return(strResult.ToString());
        }
        private static void FilterObjectToTreeNode(IOguObject obj, DeluxeTreeNode treeNode, UserControlObjectMask listMask, ref bool cancel)
        {
            int mask = (int)obj.ObjectType & (int)listMask;

            if (mask == 0)
            {
                cancel = true;
            }
        }
		public override void AfterObjectUpdated(IOguObject srcOguObject, string srcPropertyName, DirectoryEntry entry, string targetPropertyName, string context, SetterContext setterContext)
		{
			if (DictionaryHelper.GetValue<string, object, bool>(setterContext, "UACPropertySetter_LazySetProperties", false))
			{
				MergeUACValue(srcOguObject, srcPropertyName, entry, targetPropertyName, context);

				setterContext.PropertyChanged = true;
			}
		}
		public override void AfterObjectUpdated(IOguObject srcOguObject, string srcPropertyName, System.DirectoryServices.DirectoryEntry entry, string targetPropertyName, string context, SetterContext setterContext)
		{
			if (DictionaryHelper.GetValue<string, object, bool>(setterContext, "StringCollectionPropertySetter_LazySetProperties", false))
			{
				RefillCollection((string)srcOguObject.Properties[srcPropertyName], entry.Properties[targetPropertyName]);

				setterContext.PropertyChanged = true;
			}
		}
        protected virtual void Fill(IOguObject target, SchemaObjectBase src, SCObjectAndRelation relation, SCSimpleObjectCollection parentsInfo)
        {
            Fill(target, src, relation);

            var wrapper = target as IOguPropertyAccessible;

            if (parentsInfo != null && parentsInfo.Count > 0)
                wrapper.FullPath = parentsInfo.JoinNameToFullPath() + "\\" + wrapper.Name;
        }
		protected override bool ComparePropertyValue(IOguObject srcOguObject, string srcPropertyName, ADObjectWrapper adObject, string targetPropertyName, string context)
		{			
			string targetPropertyValue = null;

			if (adObject.Properties[targetPropertyName] != null)
				targetPropertyValue = adObject.Properties[targetPropertyName].ToString();

			return SynchronizeHelper.AppendNamingContext(SynchronizeHelper.GetOguObjectDN(srcOguObject)) == targetPropertyValue;
		}
		/// <summary>
		/// 
		/// </summary>
		/// <param name="obj"></param>
		public static void OutputObjectInfo(IOguObject obj)
		{
			Console.WriteLine("ID={0}", obj.ID);
			Console.WriteLine("SchemaType={0}", obj.ObjectType);
			Console.WriteLine("Name={0}", obj.Name);
			Console.WriteLine("DisplayName={0}", obj.DisplayName);
			Console.WriteLine("FullPath={0}", obj.FullPath);
			Console.WriteLine();
		}
        public override void AfterObjectUpdated(IOguObject srcOguObject, string srcPropertyName, System.DirectoryServices.DirectoryEntry entry, string targetPropertyName, string context, SetterContext setterContext)
        {
            if (DictionaryHelper.GetValue <string, object, bool>(setterContext, "StringCollectionPropertySetter_LazySetProperties", false))
            {
                RefillCollection((string)srcOguObject.Properties[srcPropertyName], entry.Properties[targetPropertyName]);

                setterContext.PropertyChanged = true;
            }
        }
        public override void AfterObjectUpdated(IOguObject srcOguObject, string srcPropertyName, DirectoryEntry entry, string targetPropertyName, string context, SetterContext setterContext)
        {
            if (DictionaryHelper.GetValue <string, object, bool>(setterContext, "UACPropertySetter_LazySetProperties", false))
            {
                MergeUACValue(srcOguObject, srcPropertyName, entry, targetPropertyName, context);

                setterContext.PropertyChanged = true;
            }
        }
		private static void MoveItemToNewPath(IOguObject oguObject, DirectoryEntry targetObject)
		{
			ADHelper adHelper = SynchronizeContext.Current.ADHelper;

			IDMapping mapping = null;
			var oguParent = oguObject.Parent;
			if (oguParent != null)
			{
				mapping = SynchronizeContext.Current.IDMapper.GetAdObjectMapping(oguParent.ID, false);
			}

			if (mapping != null)
			{
				using (var adEntry = SynchronizeHelper.GetDirectoryEntryByID(SynchronizeContext.Current.ADHelper, mapping.ADObjectGuid))
				{
					if (adEntry != null)
					{
						try
						{
							targetObject.MoveTo(adEntry);
						}
						catch (DirectoryServicesCOMException comEx)
						{
							switch (comEx.ErrorCode)
							{
								case -2147019886:
									//重名
									SynchronizeHelper.SolveConflictAboutMove(oguObject, targetObject, adEntry);
									break;
								case -2147016656:
									Trace.WriteLine("修改对象属性后,移动对象说对象不存在??被移动的对象:" + oguObject.Name);
									throw;
								default:
									throw;
							}
						}
					}
				}
			}
			else
			{
				var parentDn = SynchronizeHelper.GetParentObjectDN(oguObject);

				Trace.WriteLine("不可靠的方法被执行,目标不存在时,靠DN来延迟移动。Careful !");
				// 父对象还不存在,这可能是被重命名了
				//SynchronizeContext.Current.DelayActions.Add(new DelayMoveToAction(oguObject, parentDn, targetObject.Guid));

				// 没有这种可能性
				var context = SynchronizeContext.Current;
				context.ExceptionCount++;

				LogHelper.WriteSynchronizeDBLogDetail(SynchronizeContext.Current.SynchronizeID, "移动对象", oguObject.ID, oguObject.Name,
								 context.ADHelper.GetPropertyStrValue("objectGuid", targetObject),
								 context.ADHelper.GetPropertyStrValue("distinguishedName", targetObject),
								 string.Format("父对象:{0}无映射,无法移动。", parentDn));
			}
		}
 /// <summary>
 ///
 /// </summary>
 /// <param name="obj"></param>
 public static void OutputObjectInfo(IOguObject obj)
 {
     Console.WriteLine("ID={0}", obj.ID);
     Console.WriteLine("SchemaType={0}", obj.ObjectType);
     Console.WriteLine("Name={0}", obj.Name);
     Console.WriteLine("DisplayName={0}", obj.DisplayName);
     Console.WriteLine("FullPath={0}", obj.FullPath);
     Console.WriteLine();
 }
		public override void Convert(ObjectModifyType modifyType, IOguObject srcObject, DirectoryEntry targetObject, string context)
		{
			SetterContext setterContext = new SetterContext();

			ConvertProperties(srcObject, targetObject, setterContext);

			targetObject.CommitChanges();

			DoAfterObjectUpdatedOP(srcObject, targetObject, setterContext);
		}
		private static void DoTheMove(DirectoryEntry targetObject, DirectoryEntry parentEntry, IOguObject oguObj)
		{
			bool fail = false;
			string ldif;
			StringBuilder builder = GetEntryLongNameBuilder(targetObject, out ldif);

			do
			{
				try
				{
					string srcDN;

					try
					{
						srcDN = targetObject.Properties["distinguishedName"].Value as string;
					}
					catch
					{
						srcDN = "无法获取起始路径";
					}

					targetObject.MoveTo(parentEntry, ldif + "=" + ADHelper.EscapeString(builder.ToString()));
					targetObject.CommitChanges();

					try
					{
						LogHelper.WriteSynchronizeDBLogDetail(SynchronizeContext.Current.SynchronizeID, "应用变更: 移到回收站 ",
										oguObj == null ? string.Empty : oguObj.ID,
										oguObj == null ? string.Empty : oguObj.Name,
										targetObject == null ? string.Empty : targetObject.NativeGuid.ToString(),
										targetObject == null ? string.Empty : targetObject.Name, "删除动作,对象的初始可分辨名称为:" + srcDN);
					}
					catch (Exception)
					{
					}


					fail = false;
				}
				catch (DirectoryServicesCOMException comEx)
				{
					switch (comEx.ErrorCode)
					{
						case -2147019886: // 重名
							MakeTimePostfixToBuilderAndTrim(builder);
							fail = true;
							Thread.Sleep(100);
							break;
						default:
							throw;
					}
				}
			} while (fail);
		}
		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;
		}
		protected override void SetPropertyValue(IOguObject srcOguObject, string srcPropertyName, DirectoryEntry entry, string targetPropertyName, string context, SetterContext setterContext)
		{
			string srcPropertyValue = GetNormalizeddSourceValue(srcOguObject, srcPropertyName, context);
			string targetPropertyValue = GetNormalizeddTargetValue(entry, targetPropertyName, context);

			if (srcPropertyValue != targetPropertyValue)
			{
				TraceItHere(srcOguObject.ObjectType.ToString(), srcPropertyName, entry.Name, targetPropertyName, context, srcPropertyValue, targetPropertyValue);
				entry.Properties[targetPropertyName].Value = srcPropertyValue;

				TracePropertyValue(entry, targetPropertyName);
			}
		}
		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);
		}
        // static Dictionary<Type, OguPropertyAdapterBase> adapters;

        // static OguPropertyAdapterBase()
        // {
        //    adapters = new Dictionary<Type, OguPropertyAdapterBase>();
        //    adapters.Add(typeof(IUser), UserPropertyAdapter.Instance);
        //    adapters.Add(typeof(IGroup), GroupPropertyAdapter.Instance);
        //    adapters.Add(typeof(IOrganization), OrganizationPropertyAdapter.Instance);
        //    adapters.Add(typeof(IOrganizationInRole), OrganizationInRolePropertyAdapter.Instance);
        // }

        internal static OguPropertyAdapterBase GetConverter(IOguObject obj)
        {
            //Type[] types = type.GetInterfaces();
            //return adapters[type];
            if (obj is IOrganization)
                return OrganizationPropertyAdapter.Instance;
            else if (obj is IGroup)
                return GroupPropertyAdapter.Instance;
            else if (obj is IUser)
                return UserPropertyAdapter.Instance;
            else
                return null;
        }
		public override void Convert(ObjectModifyType modifyType, IOguObject srcObject, DirectoryEntry targetObject, string context)
		{
			SetterContext setterContext = new SetterContext();

			ConvertProperties(srcObject, targetObject, setterContext);

			targetObject.CommitChanges();

			if (SynchronizeContext.Current.DefaultPassword.IsNotEmpty())
				targetObject.Invoke("SetPassword", SynchronizeContext.Current.DefaultPassword);

			DoAfterObjectUpdatedOP(srcObject, targetObject, setterContext);
		}
		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);
				}
			}
		}
		public override ObjectModifyType Compare(IOguObject srcObject, ADObjectWrapper targetObject)
		{
			ObjectModifyType result = CompareProperties(srcObject, targetObject);

			//if (IsChildrenModified(srcObject, targetObject))
			//    result |= ObjectModifyType.ChildrenModified;

			if (targetObject.Properties.Contains("displayNamePrintable") == false || SynchronizeHelper.PermissionCenterInvolved.Equals(targetObject.Properties["displayNamePrintable"]) == false)
			{
				result |= ObjectModifyType.MissingMarker;
			}

			return result;
		}
		public static ADObjectWrapper Find(IOguObject oguObject, bool keepExists)
		{
			ADObjectWrapper adObject = null;

			switch (oguObject.ObjectType)
			{
				case SchemaType.Organizations:
					adObject = FindOUObject(oguObject);
					break;
				case SchemaType.Users:
					adObject = FindUserObject(oguObject);
					break;
				case SchemaType.Groups:
					adObject = FindGroupObject(oguObject);
					break;
				default:
					throw new Exception("oguObject对象SchemaType不正确");
			}

			if (SynchronizeContext.Current.IDMapper.SCIDMappingDictionary.ContainsKey(oguObject.ID) == false)
			{
				{
					//这里要新增ID映射
					DateTime modifyTime = DateTime.MinValue;

					if (oguObject.Properties["VERSION_START_TIME"] != null)
					{
						DateTime.TryParse(oguObject.Properties["VERSION_START_TIME"].ToString(), out modifyTime);
					}

					var mapping = adObject == null ? null : new IDMapping()
					{
						SCObjectID = oguObject.ID,
						ADObjectGuid = adObject.NativeGuid,
						LastSynchronizedVersionTime = modifyTime
					};

					if (keepExists == false)
					{
						SynchronizeContext.Current.IDMapper.NewIDMappingDictionary[oguObject.ID] = mapping;
					}
					else if (mapping != null)
					{
						SynchronizeContext.Current.IDMapper.SCIDMappingDictionary.AddNotExistsItem(mapping);
					}
				}
			}

			return adObject;
		}
		protected static string GetNormalizeddSourceValue(IOguObject srcOguObject, string srcPropertyName, string context)
		{
			string srcPropertyValue = null;

			if (srcOguObject.Properties[srcPropertyName] != null)
			{
				srcPropertyValue = srcOguObject.Properties[srcPropertyName].ToString();

				if (srcPropertyValue == string.Empty)
					srcPropertyValue = null;
			}

			return srcPropertyValue;
		}
		private static OguAndADObjectComparerBase GetComparer(IOguObject oguObject)
		{
			string schemaTypeName = oguObject.ObjectType.ToString();

			string cacheKey = "OguAndADObjectComparerBase" + "-" + schemaTypeName;

			return (OguAndADObjectComparerBase)ObjectContextCache.Instance.GetOrAddNewValue(cacheKey, (cache, key) =>
			{
				SchemaMappingInfo mappingInfo = PermissionCenterToADSynchronizeSettings.GetConfig().SchemaMappings.GetSchemaMappingInfo(schemaTypeName);

				OguAndADObjectComparerBase comparer = (OguAndADObjectComparerBase)PropertyComparersSettings.GetConfig().ObjectComparers[mappingInfo.ComparerName].CreateInstance();

				cache.Add(cacheKey, comparer);

				return comparer;
			});
		}
		protected override bool ComparePropertyValue(IOguObject srcOguObject, string srcPropertyName, ADObjectWrapper adObject, string targetPropertyName, string context)
		{
			int userAccountControl = Convert.ToInt32(adObject.Properties[targetPropertyName]);

			ADS_USER_FLAG uacFlag = ADS_USER_FLAG.ADS_UF_NONE;

			bool result = true;

			if (Enum.TryParse(context, out uacFlag))
			{
				bool originalFlag = ((userAccountControl & (int)uacFlag) == (int)uacFlag);

				result = originalFlag == (bool)srcOguObject.Properties[srcPropertyName];
			}

			return result;
		}
		private static void MergeUACValue(IOguObject srcOguObject, string srcPropertyName, DirectoryEntry entry, string targetPropertyName, string context)
		{
			int userAccountControl = Convert.ToInt32(entry.Properties[targetPropertyName].Value);

			ADS_USER_FLAG uacFlag = ADS_USER_FLAG.ADS_UF_NONE;

			if (Enum.TryParse(context, out uacFlag))
			{
				bool srcPropertyValue = (bool)srcOguObject.Properties[srcPropertyName];

				if (srcPropertyValue)
					userAccountControl = userAccountControl | (int)uacFlag;
				else
					userAccountControl = userAccountControl & ~(int)(uacFlag);
			}

			entry.Properties[targetPropertyName].Value = userAccountControl;
		}
		protected override void SetPropertyValue(IOguObject srcOguObject, string srcPropertyName, DirectoryEntry entry, string targetPropertyName, string context, SetterContext setterContext)
		{
			int userAccountControl = Convert.ToInt32(entry.Properties[targetPropertyName].Value); // 可能为null

			int result = userAccountControl;

			if (userAccountControl == 0 || entry.IsBounded() == false)
			{
				result = (int)(ADS_USER_FLAG.ADS_UF_NORMAL_ACCOUNT | ADS_USER_FLAG.ADS_UF_PASSWD_NOTREQD);
				entry.Properties[targetPropertyName].Value = result;

				setterContext["UACPropertySetter_LazySetProperties"] = true;
			}
			else
			{
				MergeUACValue(srcOguObject, srcPropertyName, entry, targetPropertyName, context);
			}
		}