Ejemplo n.º 1
0
        /// <summary>
        /// 添加用户和OU_USERS(用户信息扩展表需要操作,现在还没操作)
        /// </summary>
        /// <param name="sr"></param>
        /// <param name="context"></param>
        /// <param name="ts"></param>
        private static void InsertUsersInfoExtend(SearchResult sr, AD2DBTransferContext context)
        {
            ADHelper helper = context.InitialParams.DirectoryHelper;

            //判断是否需要更新电话号码
            string mobile          = helper.GetSearchResultPropertyStrValue("mobile", sr);
            string telephoneNumber = helper.GetSearchResultPropertyStrValue("telephoneNumber", sr);

            //特殊处理手机号
            int num = mobile.IndexOf('/');

            string newmobile = string.Empty;

            if (num != -1)
            {
                newmobile = mobile.Substring(num - 11, 11);
            }
            else if (mobile.Length >= 11)
            {
                newmobile = mobile.Substring(mobile.Length - 11, 11);
            }

            DataTable usersInfoExtendTable = context.ADData.Tables["USERS_INFO_EXTEND"];
            DataRow   dr = usersInfoExtendTable.NewRow();

            dr["ID"]         = helper.GetSearchResultPropertyStrValue("objectGuid", sr);
            dr["MOBILE"]     = newmobile;
            dr["OFFICE_TEL"] = telephoneNumber;
            dr["GENDER"]     = 0;
            dr["NATION"]     = string.Empty;
            dr["IM_ADDRESS"] = helper.GetSearchResultPropertyStrValue("msRTCSIP-PrimaryUserAddress", sr);

            usersInfoExtendTable.Rows.Add(dr);
        }
Ejemplo n.º 2
0
        private static void InsertUser(SearchResult sr, AD2DBTransferContext context)
        {
            ADHelper helper = context.InitialParams.DirectoryHelper;

            string firstName = helper.GetSearchResultPropertyStrValue("givenName", sr);
            string lastName  = helper.GetSearchResultPropertyStrValue("sn", sr);
            string logonName = helper.GetSearchResultPropertyStrValue("samAccountName", sr);
            string pinyin    = logonName;

            DataTable usersTable = context.ADData.Tables["USERS"];
            DataRow   dr         = usersTable.NewRow();

            dr["GUID"] = helper.GetSearchResultPropertyStrValue("objectGuid", sr);

            dr["FIRST_NAME"]    = firstName;
            dr["LAST_NAME"]     = lastName;
            dr["LOGON_NAME"]    = logonName;
            dr["PWD_TYPE_GUID"] = "21545d16-a62f-4a7e-ac2f-beca958e0fdf";
            dr["USER_PWD"]      = "B0-81-DB-E8-5E-1E-C3-FF-C3-D4-E7-D0-22-74-00-CD";       //password "E9-D5-C2-CA-1D-E4-0B-E1-2E-66-CC-57-9D-11-B9-FF";//000000
            dr["RANK_CODE"]     = AD2DBHelper.ConvertUserRankCode(helper.GetSearchResultPropertyStrValue("personalTitle", sr)).ToString();
            dr["POSTURAL"]      = 2;
            dr["PINYIN"]        = pinyin;
            dr["E_MAIL"]        = helper.GetSearchResultPropertyStrValue("mail", sr);

            usersTable.Rows.Add(dr);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 对比AD和DB中的数据,然后更新到OA数据库中
        /// </summary>
        private void CompareADAndDBData(AD2DBTransferContext context)
        {
            //查询对比组织机构、用户、和用户组织机构关系表
            OrginalOguDataOperation ogu = new OrginalOguDataOperation(context);

            ogu.CompareAndModifyData();
            OrginalUsersDataOperation users = new OrginalUsersDataOperation(context);

            users.CompareAndModifyData();
            OrginalOUUsersDataOperation ouusers = new OrginalOUUsersDataOperation(context);

            ouusers.CompareAndModifyData();
            OrginalUserInfoExtendDataOperation userinfo = new OrginalUserInfoExtendDataOperation(context);

            userinfo.CompareAndModifyData();

            using (DbContext ctx = DbContext.GetContext(this.initialParams.AccreditAdminConnectionName))
            {
                DeleteDB(context);                //先删除3个表的信息、然后更新3个表的信息、最后添加三个表的信息。
                UpdateDB(context);
                AddDB(context);
            }

            using (DbContext ctx = DbContext.GetContext(this.initialParams.UserInfoExtend))
            {
                OrginalUserInfoExtendDataOperation userinfoExtend = new OrginalUserInfoExtendDataOperation(context);
                userinfoExtend.DeleteOperation();
                userinfoExtend.UpdateOperation();
                userinfoExtend.AddOperation();
            }
        }
Ejemplo n.º 4
0
		/// <summary>
		/// 找到在一个部门内,原始的ID和排序号之间的关系
		/// </summary>
		/// <param name="parentGuid"></param>
		/// <param name="context"></param>
		/// <returns></returns>
		private static Dictionary<string, string> GetOriginalChildrenGlobalSortDictionary(string parentGuid, AD2DBTransferContext context)
		{
			Dictionary<string, string> sortDict = new Dictionary<string, string>();

			context.OriginalOuUserParentGuidView.FindRows(parentGuid).ForEach(r => sortDict[r["USER_GUID"].ToString()] = r["GLOBAL_SORT"].ToString());
			context.OriginalOguParentGuidView.FindRows(parentGuid).ForEach(r => sortDict[r["GUID"].ToString()] = r["GLOBAL_SORT"].ToString());

			return sortDict;
		}
Ejemplo n.º 5
0
        /// <summary>
        /// 更新ORG的计数器
        /// </summary>
        /// <param name="context"></param>
        /// <param name="ts"></param>
        private static void UpdateParentChildrenCounter(AD2DBTransferContext context)
        {
            DataRowView[] drvs = context.ADOguGuidView.FindRows(context.ParentGuid);

            if (drvs.Length > 0)
            {
                drvs[0]["CHILDREN_COUNTER"] = context.ParentChildrenCount;
            }
        }
Ejemplo n.º 6
0
        private static void FillContext(AD2DBTransferContext context, string parentOU)
        {
            string rootPath = AD2DBHelper.TranslateDNToFullPath(parentOU);

            DataRowView[] drvs = context.ADOguAllPathView.FindRows(rootPath);

            ExceptionHelper.FalseThrow(drvs.Length > 0, "不能在机构人员数据库中找到父对象\"{0}\"", rootPath);

            context.ParentGuid         = drvs[0]["GUID"].ToString();
            context.ParentOriginalSort = drvs[0]["ORIGINAL_SORT"].ToString();

            context.ParentChildrenCount = Convert.ToInt32(drvs[0]["CHILDREN_COUNTER"]);
        }
Ejemplo n.º 7
0
        private static object EnumEntryItemCallBack(SearchResult sr, ADSearchResultParams asrp, object oParams, ref bool bContinue)
        {
            AD2DBTransferContext context = (AD2DBTransferContext)oParams;

            context.InitialParams.OnBeforeProcessADObject(sr, context.InitialParams, ref bContinue);

            if (bContinue)
            {
                string objName  = ADHelper.GetInstance().GetSearchResultPropertyStrValue("name", sr);
                string objClass = AD2DBHelper.TranslateObjectClass(sr.Properties["objectClass"][1].ToString());

                ADHelper helper = ADHelper.GetInstance();

                FillContext(context,
                            ADHelper.GetParentRdnSequence(helper.GetSearchResultPropertyStrValue("distinguishedName", sr)));

                try
                {
                    switch (objClass)
                    {
                    case "ORGANIZATIONS":
                        InsertOrganizations(sr, context);

                        context.OrganizationsConverted++;
                        break;

                    case "USERS":
                        InsertUser(sr, context);
                        InsertOUUser(sr, context);
                        InsertUsersInfoExtend(sr, context);

                        context.UsersConverted++;
                        break;

                    default:
                        break;
                    }

                    UpdateParentChildrenCounter(context);
                }
                catch (System.Exception ex)
                {
                    string strMsg = string.Format("转换对象\"{0}\"出错,{1}", objName, ex.Message + ex.StackTrace);

                    context.InitialParams.Log.Write(strMsg);
                }
            }

            return(null);
        }
        private static void CompareAndUpdateUserExtendData(AD2DBTransferContext context)
        {
            foreach (DataRow row in context.OriginalData.Tables["USERS_INFO_EXTEND"].Rows)
            {
                string userGuid = row["ID"].ToString();

                int index = context.ADUserExtendGuidView.Find(userGuid);

                if (index != -1)
                {
                    CompareAndUpdateUserExtendData(context.ADUserExtendGuidView[index], row);
                }
            }
        }
		private static void CompareAndUpdateUserExtendData(AD2DBTransferContext context)
		{
			foreach (DataRow row in context.OriginalData.Tables["USERS_INFO_EXTEND"].Rows)
			{
				string userGuid = row["ID"].ToString();

				int index = context.ADUserExtendGuidView.Find(userGuid);

				if (index != -1)
				{
					CompareAndUpdateUserExtendData(context.ADUserExtendGuidView[index], row);
				}
			}
		}
		public static void UpdateSort(DataRow dr, AD2DBTransferContext context)
		{
			context.OriginalData.Tables["ORGANIZATIONS"].PrimaryKey = new DataColumn[] { context.OriginalData.Tables["ORGANIZATIONS"].Columns["GUID"] };
			DataRow tempdr = context.OriginalData.Tables["ORGANIZATIONS"].Rows.Find(dr["PARENT_GUID"]);
			int counter = Convert.ToInt32(tempdr["CHILDREN_COUNTER"]) + 1;
			tempdr["CHILDREN_COUNTER"] = counter;

			string innerSort = string.Format("{0:000000}", counter);
			string originalSort = tempdr["ORIGINAL_SORT"].ToString() + innerSort;
			string globalSort = tempdr["GLOBAL_SORT"].ToString() + innerSort;

			dr["ORIGINAL_SORT"] = originalSort;
			dr["GLOBAL_SORT"] = globalSort;
			dr["INNER_SORT"] = innerSort;
		}
Ejemplo n.º 11
0
        private void AddDB(AD2DBTransferContext context)
        {
            OrginalOguDataOperation ogu = new OrginalOguDataOperation(context);

            ogu.AddOperation();
            OrginalUsersDataOperation users = new OrginalUsersDataOperation(context);

            users.AddOperation();
            OrginalOUUsersDataOperation ouusers = new OrginalOUUsersDataOperation(context);

            ouusers.AddOperation();

            this.initialParams.Log.Write(string.Format("ORGANIZATIONS表添加数量是:{0},USERS表添加数量是:{1},OUUSERS表添加数量是:{2}",
                                                       ogu.AddCount.ToString(), users.AddCount.ToString(), ouusers.AddCount.ToString()));
        }
        public static void UpdateSort(DataRow dr, AD2DBTransferContext context)
        {
            context.OriginalData.Tables["ORGANIZATIONS"].PrimaryKey = new DataColumn[] { context.OriginalData.Tables["ORGANIZATIONS"].Columns["GUID"] };
            DataRow tempdr  = context.OriginalData.Tables["ORGANIZATIONS"].Rows.Find(dr["PARENT_GUID"]);
            int     counter = Convert.ToInt32(tempdr["CHILDREN_COUNTER"]) + 1;

            tempdr["CHILDREN_COUNTER"] = counter;

            string innerSort    = string.Format("{0:000000}", counter);
            string originalSort = tempdr["ORIGINAL_SORT"].ToString() + innerSort;
            string globalSort   = tempdr["GLOBAL_SORT"].ToString() + innerSort;

            dr["ORIGINAL_SORT"] = originalSort;
            dr["GLOBAL_SORT"]   = globalSort;
            dr["INNER_SORT"]    = innerSort;
        }
Ejemplo n.º 13
0
        public void ExecuteConvertion(AD2DBTransferContext transferContext)
        {
            ADSearchConditions condition = new ADSearchConditions(SearchScope.OneLevel);

            condition.ADSearchCompleted     += new ADSearchCompletedHandler(condition_ADSearchCompleted);
            condition.SearchCompletedContext = transferContext;

            //condition.Sort = new SortOption("extensionName", SortDirection.Ascending);

            transferContext.InitialParams.DirectoryHelper.ExecuteSearchRecursively(transferContext.InitialParams.Root,
                                                                                   ADSearchConditions.GetFilterByMask(ADSchemaType.Users | ADSchemaType.Organizations | ADSchemaType.Groups),
                                                                                   condition,
                                                                                   new ADSearchRecursivelyDelegate(EnumEntryItemCallBack),
                                                                                   transferContext,
                                                                                   AD2DBHelper.ADObjProperties);
        }
Ejemplo n.º 14
0
		public void ExecuteConvertion(AD2DBTransferContext transferContext)
		{
			ADSearchConditions condition = new ADSearchConditions(SearchScope.OneLevel);

			condition.ADSearchCompleted += new ADSearchCompletedHandler(condition_ADSearchCompleted);
			condition.SearchCompletedContext = transferContext;

			//condition.Sort = new SortOption("extensionName", SortDirection.Ascending);

			transferContext.InitialParams.DirectoryHelper.ExecuteSearchRecursively(transferContext.InitialParams.Root,
					ADSearchConditions.GetFilterByMask(ADSchemaType.Users | ADSchemaType.Organizations | ADSchemaType.Groups),
					condition,
					new ADSearchRecursivelyDelegate(EnumEntryItemCallBack),
					transferContext,
					AD2DBHelper.ADObjProperties);
		}
Ejemplo n.º 15
0
        public void DoConvert()
        {
            this.initialParams.Log.Write("初始化RootOU: " + this.initialParams.Root.Path + "  时间是:" + DateTime.Now.ToString());

            AD2DBTransferContext transferContext = new AD2DBTransferContext(this.initialParams);

            transferContext.InitContext();

            ADDataOperation ado = new ADDataOperation(transferContext);

            ado.ExecuteConvertion(transferContext);

            CompareADAndDBData(transferContext);

            this.initialParams.Log.Write("结束同步,时间是:" + DateTime.Now.ToString());
        }
		private static void CompareAndDeleteAndUpdateOguData(AD2DBTransferContext context)
		{
			foreach (DataRow row in context.OriginalData.Tables["ORGANIZATIONS"].Rows)
			{
				string guid = row["GUID"].ToString();
				int index = context.ADOguGuidView.Find(guid);

				if (index == -1)
				{
					row.Delete();
					DataRowView[] drvs = context.OriginalOuUserParentGuidView.FindRows(guid);

					Array.ForEach(drvs, drv => drv.Row.Delete());
				}
				else
				{
					CompareAndUpdateOguData(context.ADOguGuidView[index], row);
				}
			}
		}
        private static void CompareAndDeleteAndUpdateOguData(AD2DBTransferContext context)
        {
            foreach (DataRow row in context.OriginalData.Tables["ORGANIZATIONS"].Rows)
            {
                string guid  = row["GUID"].ToString();
                int    index = context.ADOguGuidView.Find(guid);

                if (index == -1)
                {
                    row.Delete();
                    DataRowView[] drvs = context.OriginalOuUserParentGuidView.FindRows(guid);

                    Array.ForEach(drvs, drv => drv.Row.Delete());
                }
                else
                {
                    CompareAndUpdateOguData(context.ADOguGuidView[index], row);
                }
            }
        }
		private static void CompareAndAddOguData(DataTable srcTable, DataTable targetTable, DataView compareView, AD2DBTransferContext context)
		{
			//提出要添加的行
			foreach (DataRow dr in srcTable.Rows)
			{
				int index = compareView.Find(dr["GUID"]);

				if (index == -1)
				{
					//添加新纪录
					DataRow newdr = targetTable.NewRow();

					UpdateSort(dr, context);
					AD2DBHelper.CopyDataRow(dr, newdr,
						"GUID", "PARENT_GUID", "OBJ_NAME", "DISPLAY_NAME", "DESCRIPTION", "DESCRIPTION",
						"ALL_PATH_NAME", "ORIGINAL_SORT", "CHILDREN_COUNTER", "GLOBAL_SORT", "RANK_CODE",
						"INNER_SORT", "ORG_TYPE", "ORG_CLASS", "STATUS", "SEARCH_NAME");

					targetTable.Rows.Add(newdr);
				}
			}
		}
Ejemplo n.º 19
0
        private static void condition_ADSearchCompleted(DirectorySearcher searcher, List <SearchResult> resultList, object objContext)
        {
            DirectoryEntry entry = searcher.SearchRoot;

            AD2DBTransferContext context = (AD2DBTransferContext)objContext;
            ADHelper             helper  = context.InitialParams.DirectoryHelper;

            string parentGuid = helper.GetPropertyStrValue("objectGuid", entry);

            Dictionary <string, string> guidGlobalSortDict = GetOriginalChildrenGlobalSortDictionary(parentGuid, context);

            resultList.Sort((sr1, sr2) =>
            {
                string guid1 = helper.GetSearchResultPropertyStrValue("objectGuid", sr1);
                string guid2 = helper.GetSearchResultPropertyStrValue("objectGuid", sr2);

                return(string.Compare(
                           guidGlobalSortDict.GetValue(guid1, "ZZZZZZ"),
                           guidGlobalSortDict.GetValue(guid2, "ZZZZZZ"),
                           true));
            });
        }
Ejemplo n.º 20
0
        private static void InsertOrganizations(SearchResult sr, AD2DBTransferContext context)
        {
            //开始添加AD的比较数据
            ADHelper  helper   = context.InitialParams.DirectoryHelper;
            DataTable oguTable = context.ADData.Tables["ORGANIZATIONS"];

            DataRow dr = oguTable.NewRow();

            dr["GUID"]        = helper.GetSearchResultPropertyStrValue("objectGuid", sr);
            dr["PARENT_GUID"] = context.ParentGuid;

            string name = helper.GetSearchResultPropertyStrValue("name", sr);

            dr["OBJ_NAME"] = name;

            string displayName = helper.GetSearchResultPropertyStrValue("displayName", sr);

            displayName        = string.IsNullOrEmpty(displayName) ? name : displayName;
            dr["DISPLAY_NAME"] = NormalizeName(displayName);

            dr["DESCRIPTION"]   = helper.GetSearchResultPropertyStrValue("description", sr);
            dr["ALL_PATH_NAME"] = AD2DBHelper.TranslateDNToFullPath(helper.GetSearchResultPropertyStrValue("distinguishedName", sr));

            string innerSort    = GetInnerSortAndIncCounter(context);
            string originalSort = context.ParentOriginalSort + innerSort;

            dr["ORIGINAL_SORT"]    = originalSort;
            dr["GLOBAL_SORT"]      = originalSort;
            dr["RANK_CODE"]        = AD2DBHelper.ConvertDepartmentRankCode(helper.GetSearchResultPropertyStrValue("physicalDeliveryOfficeName", sr)).ToString();
            dr["CHILDREN_COUNTER"] = 0;
            dr["INNER_SORT"]       = innerSort;
            dr["ORG_TYPE"]         = (int)AD2DBHelper.TranslateDeptTypeDefine(sr);
            dr["ORG_CLASS"]        = (int)AD2DBHelper.TranslateDeptClass(helper.GetSearchResultPropertyStrValue("c", sr));
            dr["STATUS"]           = 1;
            dr["SEARCH_NAME"]      = name + " " + NormalizeName(displayName);

            oguTable.Rows.Add(dr);
        }
Ejemplo n.º 21
0
		/// <summary>
		/// 添加用户和OU_USERS(用户信息扩展表需要操作,现在还没操作)
		/// </summary>
		/// <param name="sr"></param>
		/// <param name="context"></param>
		/// <param name="ts"></param>
		private static void InsertUsersInfoExtend(SearchResult sr, AD2DBTransferContext context)
		{
			ADHelper helper = context.InitialParams.DirectoryHelper;

			//判断是否需要更新电话号码
			string mobile = helper.GetSearchResultPropertyStrValue("mobile", sr);
			string telephoneNumber = helper.GetSearchResultPropertyStrValue("telephoneNumber", sr);

			//特殊处理手机号
			int num = mobile.IndexOf('/');

			string newmobile = string.Empty;

			if (num != -1)
			{
				newmobile = mobile.Substring(num - 11, 11);
			}
			else if (mobile.Length >= 11)
			{
				newmobile = mobile.Substring(mobile.Length - 11, 11);
			}

			DataTable usersInfoExtendTable = context.ADData.Tables["USERS_INFO_EXTEND"];
			DataRow dr = usersInfoExtendTable.NewRow();

			dr["ID"] = helper.GetSearchResultPropertyStrValue("objectGuid", sr);
			dr["MOBILE"] = newmobile;
			dr["OFFICE_TEL"] = telephoneNumber;
			dr["GENDER"] = 0;
			dr["NATION"] = string.Empty;
			dr["IM_ADDRESS"] = helper.GetSearchResultPropertyStrValue("msRTCSIP-PrimaryUserAddress", sr);

			usersInfoExtendTable.Rows.Add(dr);
		}
		public OrginalOUUsersDataOperation(AD2DBTransferContext ctx)
			: base(ctx)
		{
		}
Ejemplo n.º 23
0
		private static void InsertUser(SearchResult sr, AD2DBTransferContext context)
		{
			ADHelper helper = context.InitialParams.DirectoryHelper;

			string firstName = helper.GetSearchResultPropertyStrValue("givenName", sr);
			string lastName = helper.GetSearchResultPropertyStrValue("sn", sr);
			string logonName = helper.GetSearchResultPropertyStrValue("samAccountName", sr);
			string pinyin = logonName;

			DataTable usersTable = context.ADData.Tables["USERS"];
			DataRow dr = usersTable.NewRow();

			dr["GUID"] = helper.GetSearchResultPropertyStrValue("objectGuid", sr);

			dr["FIRST_NAME"] = firstName;
			dr["LAST_NAME"] = lastName;
			dr["LOGON_NAME"] = logonName;
			dr["PWD_TYPE_GUID"] = "21545d16-a62f-4a7e-ac2f-beca958e0fdf";
			dr["USER_PWD"] = "B0-81-DB-E8-5E-1E-C3-FF-C3-D4-E7-D0-22-74-00-CD";//password "E9-D5-C2-CA-1D-E4-0B-E1-2E-66-CC-57-9D-11-B9-FF";//000000
			dr["RANK_CODE"] = AD2DBHelper.ConvertUserRankCode(helper.GetSearchResultPropertyStrValue("personalTitle", sr)).ToString();
			dr["POSTURAL"] = 2;
			dr["PINYIN"] = pinyin;
			dr["E_MAIL"] = helper.GetSearchResultPropertyStrValue("mail", sr);

			usersTable.Rows.Add(dr);
		}
		public OrginalUserInfoExtendDataOperation(AD2DBTransferContext ctx)
			: base(ctx)
		{
		}
Ejemplo n.º 25
0
        private static void CompareAndDeleteAndUpdateOuUsersData(AD2DBTransferContext context)
        {
            foreach (DataRow row in context.OriginalData.Tables["OU_USERS"].Rows)
            {
                if (row.RowState != DataRowState.Deleted)
                {
                    string userGuid = row["USER_GUID"].ToString();
                    string parentID = row["PARENT_GUID"].ToString();

                    DataRowView[] drvs = context.ADOuUserParentGuidView.FindRows(new string[] { userGuid, parentID });

                    if (drvs.Length != 0)
                    {
                        //在AD中存在,且OU和AD中的相同
                        CompareAndUpdateOuUsersData(drvs[0], row);
                    }
                    else
                    {
                        //在AD中不存在或者OU和AD匹配不上
                        if (context.ADUsersGuidView.FindRows(new string[] { userGuid }).Length > 0)
                        {
                            //在AD中User存在,但是OU不匹配
                            //特殊情况(有后来在数据库维护的兼职情况)改职位是否为兼职(0、主职;1、兼职)
                            int sideline = Convert.ToInt32(row["SIDELINE"]);

                            if (sideline == 0)
                            {
                                row.Delete();
                            }
                            else
                            {
                                int oguIndex = context.ADOguGuidView.Find(row["PARENT_GUID"]);

                                if (oguIndex == -1)
                                {
                                    row.Delete();
                                }
                                else
                                {
                                    //修改这一段,代码,需要在ORIGINAL_SORT后面再加上自己的序号,并且调整"CHILDREN_COUNTER"
                                    DataRowView oguDrv  = context.ADOguGuidView[oguIndex];
                                    string      ogSort  = (string)oguDrv["ORIGINAL_SORT"];
                                    string      newSort = string.Format("{0}{1:000000}", ogSort, oguDrv["CHILDREN_COUNTER"]);

                                    if ((string)row["ORIGINAL_SORT"] != newSort)
                                    {
                                        row["ORIGINAL_SORT"]       = newSort;
                                        row["GLOBAL_SORT"]         = newSort;
                                        oguDrv["CHILDREN_COUNTER"] = (int)oguDrv["CHILDREN_COUNTER"] + 1;
                                    }
                                }
                            }
                        }
                        else
                        {
                            //在AD的User中彻底不存在
                            row.Delete();
                        }
                    }
                }
            }
        }
Ejemplo n.º 26
0
        /// <summary>
        /// 找到在一个部门内,原始的ID和排序号之间的关系
        /// </summary>
        /// <param name="parentGuid"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        private static Dictionary <string, string> GetOriginalChildrenGlobalSortDictionary(string parentGuid, AD2DBTransferContext context)
        {
            Dictionary <string, string> sortDict = new Dictionary <string, string>();

            context.OriginalOuUserParentGuidView.FindRows(parentGuid).ForEach(r => sortDict[r["USER_GUID"].ToString()] = r["GLOBAL_SORT"].ToString());
            context.OriginalOguParentGuidView.FindRows(parentGuid).ForEach(r => sortDict[r["GUID"].ToString()]         = r["GLOBAL_SORT"].ToString());

            return(sortDict);
        }
Ejemplo n.º 27
0
		/// <summary>
		/// 更新ORG的计数器
		/// </summary>
		/// <param name="context"></param>
		/// <param name="ts"></param>
		private static void UpdateParentChildrenCounter(AD2DBTransferContext context)
		{
			DataRowView[] drvs = context.ADOguGuidView.FindRows(context.ParentGuid);

			if (drvs.Length > 0)
				drvs[0]["CHILDREN_COUNTER"] = context.ParentChildrenCount;
		}
Ejemplo n.º 28
0
		private static string GetInnerSortAndIncCounter(AD2DBTransferContext context)
		{
			return string.Format("{0:000000}", context.ParentChildrenCount++);
		}
Ejemplo n.º 29
0
		private static void FillContext(AD2DBTransferContext context, string parentOU)
		{
			string rootPath = AD2DBHelper.TranslateDNToFullPath(parentOU);

			DataRowView[] drvs = context.ADOguAllPathView.FindRows(rootPath);

			ExceptionHelper.FalseThrow(drvs.Length > 0, "不能在机构人员数据库中找到父对象\"{0}\"", rootPath);

			context.ParentGuid = drvs[0]["GUID"].ToString();
			context.ParentOriginalSort = drvs[0]["ORIGINAL_SORT"].ToString();

			context.ParentChildrenCount = Convert.ToInt32(drvs[0]["CHILDREN_COUNTER"]);
		}
 public OriginalDataTableOperationBase(AD2DBTransferContext ctx)
 {
     this.context = ctx;
 }
Ejemplo n.º 31
0
 private static string GetInnerSortAndIncCounter(AD2DBTransferContext context)
 {
     return(string.Format("{0:000000}", context.ParentChildrenCount++));
 }
Ejemplo n.º 32
0
		public ADDataOperation(AD2DBTransferContext ctx)
		{
			this.context = ctx;
		}
		public OriginalDataTableOperationBase(AD2DBTransferContext ctx)
		{
			this.context = ctx;
		}
		private static void CompareAndDeleteAndUpdateOuUsersData(AD2DBTransferContext context)
		{
			foreach (DataRow row in context.OriginalData.Tables["OU_USERS"].Rows)
			{
				if (row.RowState != DataRowState.Deleted)
				{
					string userGuid = row["USER_GUID"].ToString();
					string parentID = row["PARENT_GUID"].ToString();

					DataRowView[] drvs = context.ADOuUserParentGuidView.FindRows(new string[] { userGuid, parentID });

					if (drvs.Length != 0)
					{
						//在AD中存在,且OU和AD中的相同
						CompareAndUpdateOuUsersData(drvs[0], row);
					}
					else
					{
						//在AD中不存在或者OU和AD匹配不上
						if (context.ADUsersGuidView.FindRows(new string[] { userGuid }).Length > 0)
						{
							//在AD中User存在,但是OU不匹配
							//特殊情况(有后来在数据库维护的兼职情况)改职位是否为兼职(0、主职;1、兼职)
							int sideline = Convert.ToInt32(row["SIDELINE"]);

							if (sideline == 0)
							{
								row.Delete();
							}
							else
							{
								int oguIndex = context.ADOguGuidView.Find(row["PARENT_GUID"]);

								if (oguIndex == -1)
								{
									row.Delete();
								}
								else
								{
									//修改这一段,代码,需要在ORIGINAL_SORT后面再加上自己的序号,并且调整"CHILDREN_COUNTER"
									DataRowView oguDrv = context.ADOguGuidView[oguIndex];
									string ogSort = (string)oguDrv["ORIGINAL_SORT"];
									string newSort = string.Format("{0}{1:000000}", ogSort, oguDrv["CHILDREN_COUNTER"]);

									if ((string)row["ORIGINAL_SORT"] != newSort)
									{
										row["ORIGINAL_SORT"] = newSort;
										row["GLOBAL_SORT"] = newSort;
										oguDrv["CHILDREN_COUNTER"] = (int)oguDrv["CHILDREN_COUNTER"] + 1;
									}
								}
							}
						}
						else
						{
							//在AD的User中彻底不存在
							row.Delete();
						}
					}
				}
			}
		}
Ejemplo n.º 35
0
        private static void InsertOUUser(SearchResult sr, AD2DBTransferContext context)
        {
            ADHelper helper = context.InitialParams.DirectoryHelper;

            string logonName = helper.GetSearchResultPropertyStrValue("samAccountName", sr);
            string pinyin    = logonName;

            string displayName = helper.GetSearchResultPropertyStrValue("displayName", sr);

            //by v-zhangbm 20120220 start
            //判断是否需要更新电话号码
            string mobile          = helper.GetSearchResultPropertyStrValue("mobile", sr);
            string telephoneNumber = helper.GetSearchResultPropertyStrValue("telephoneNumber", sr);

            //特殊处理手机号
            int num = mobile.IndexOf('/');

            string newmobile = string.Empty;

            if (num != -1)
            {
                newmobile = mobile.Substring(num - 11, 11);
            }
            else if (mobile.Length >= 11)
            {
                newmobile = mobile.Substring(mobile.Length - 11, 11);
            }

            string email    = helper.GetSearchResultPropertyStrValue("mail", sr);
            string newEmail = string.Empty;

            if (!string.IsNullOrEmpty(email))
            {
                int index = email.IndexOf('@');
                if (index != -1)
                {
                    newEmail = email.Substring(0, index);
                }
            }
            //by v-zhangbm 20120220 end

            if (string.IsNullOrEmpty(displayName))
            {
                string firstName = helper.GetSearchResultPropertyStrValue("givenName", sr);
                string lastName  = helper.GetSearchResultPropertyStrValue("sn", sr);

                displayName = lastName + firstName;                     //DisplayName= givenname + sn
            }

            DataTable ouusersTable = context.ADData.Tables["OU_USERS"];
            DataRow   dr           = ouusersTable.NewRow();

            dr["USER_GUID"]     = helper.GetSearchResultPropertyStrValue("objectGuid", sr);
            dr["PARENT_GUID"]   = context.ParentGuid;
            dr["ALL_PATH_NAME"] = AD2DBHelper.TranslateDNToFullPath(helper.GetSearchResultPropertyStrValue("distinguishedName", sr));
            dr["DISPLAY_NAME"]  = displayName;
            dr["OBJ_NAME"]      = helper.GetSearchResultPropertyStrValue("name", sr);

            if (helper.GetUserAccountPolicy(sr).UserAccountDisabled)
            {
                dr["STATUS"] = 3;
            }
            else
            {
                dr["STATUS"] = 1;
            }

            string innerSort    = GetInnerSortAndIncCounter(context);
            string originalSort = context.ParentOriginalSort + innerSort;

            dr["ORIGINAL_SORT"] = originalSort;
            dr["GLOBAL_SORT"]   = originalSort;
            dr["RANK_NAME"]     = helper.GetSearchResultPropertyStrValue("title", sr);
            dr["DESCRIPTION"]   = helper.GetSearchResultPropertyStrValue("description", sr);
            dr["ATTRIBUTES"]    = (int)AD2DBHelper.TranslateUserAttributes(sr);
            //增加几个搜索条件v-zhangbm 20120220
            dr["SEARCH_NAME"] = displayName + " " + pinyin + " " + logonName + " " + telephoneNumber + " " + newmobile + " " + newEmail;

            ouusersTable.Rows.Add(dr);
        }
		private static void CompareAndAddOuUsersData(DataTable srcTable, DataTable targetTable, DataView compareView, AD2DBTransferContext context)
		{
			//提出要添加的行
			foreach (DataRow dr in srcTable.Rows)
			{
				string userGuid = dr["USER_GUID"].ToString();
				string parentID = dr["PARENT_GUID"].ToString();

				DataRowView[] drv = compareView.FindRows(new string[] { userGuid, parentID });

				if (drv.Length == 0)
				{
					//添加新纪录
					DataRow newdr = targetTable.NewRow();

					UpdateSort(dr, context);

					DataRowView[] sameUsersInfo = context.OriginalOUUserUserGuidView.FindRows(userGuid);

					//将和新插入记录相同GUID的用户都设置为兼职
					Array.ForEach(sameUsersInfo, d => d["SIDELINE"] = 1);

					AD2DBHelper.CopyDataRow(dr, newdr,
						"USER_GUID", "PARENT_GUID", "ALL_PATH_NAME", "DISPLAY_NAME", "OBJ_NAME", "STATUS", "ORIGINAL_SORT",
						"GLOBAL_SORT", "RANK_NAME", "DESCRIPTION", "ATTRIBUTES", "SEARCH_NAME", "INNER_SORT");

					targetTable.Rows.Add(newdr);
				}
			}
		}
Ejemplo n.º 37
0
		private static void InsertOUUser(SearchResult sr, AD2DBTransferContext context)
		{
			ADHelper helper = context.InitialParams.DirectoryHelper;

			string logonName = helper.GetSearchResultPropertyStrValue("samAccountName", sr);
			string pinyin = logonName;

			string displayName = helper.GetSearchResultPropertyStrValue("displayName", sr);

            //by v-zhangbm 20120220 start
            //判断是否需要更新电话号码
            string mobile = helper.GetSearchResultPropertyStrValue("mobile", sr);
            string telephoneNumber = helper.GetSearchResultPropertyStrValue("telephoneNumber", sr);

            //特殊处理手机号
            int num = mobile.IndexOf('/');

            string newmobile = string.Empty;
            if (num != -1)
            {
                newmobile = mobile.Substring(num - 11, 11);
            }
            else if (mobile.Length >= 11)
            {
                newmobile = mobile.Substring(mobile.Length - 11, 11);
            }

            string email = helper.GetSearchResultPropertyStrValue("mail", sr);
            string newEmail = string.Empty;

            if (!string.IsNullOrEmpty(email))
            {
                int index = email.IndexOf('@');
                if (index != -1)
                {
                    newEmail = email.Substring(0, index);
                }
            }
            //by v-zhangbm 20120220 end

			if (string.IsNullOrEmpty(displayName))
			{
				string firstName = helper.GetSearchResultPropertyStrValue("givenName", sr);
				string lastName = helper.GetSearchResultPropertyStrValue("sn", sr);

				displayName = lastName + firstName;	//DisplayName= givenname + sn
			}

			DataTable ouusersTable = context.ADData.Tables["OU_USERS"];
			DataRow dr = ouusersTable.NewRow();

			dr["USER_GUID"] = helper.GetSearchResultPropertyStrValue("objectGuid", sr);
			dr["PARENT_GUID"] = context.ParentGuid;
			dr["ALL_PATH_NAME"] = AD2DBHelper.TranslateDNToFullPath(helper.GetSearchResultPropertyStrValue("distinguishedName", sr));
			dr["DISPLAY_NAME"] = displayName;
			dr["OBJ_NAME"] = helper.GetSearchResultPropertyStrValue("name", sr);

			if (helper.GetUserAccountPolicy(sr).UserAccountDisabled)
				dr["STATUS"] = 3;
			else
				dr["STATUS"] = 1;

			string innerSort = GetInnerSortAndIncCounter(context);
			string originalSort = context.ParentOriginalSort + innerSort;

			dr["ORIGINAL_SORT"] = originalSort;
			dr["GLOBAL_SORT"] = originalSort;
			dr["RANK_NAME"] = helper.GetSearchResultPropertyStrValue("title", sr);
			dr["DESCRIPTION"] = helper.GetSearchResultPropertyStrValue("description", sr);
			dr["ATTRIBUTES"] = (int)AD2DBHelper.TranslateUserAttributes(sr);
            //增加几个搜索条件v-zhangbm 20120220
            dr["SEARCH_NAME"] = displayName + " " + pinyin + " " + logonName + " " + telephoneNumber + " " + newmobile + " " + newEmail;

			ouusersTable.Rows.Add(dr);
		}
Ejemplo n.º 38
0
 public ADDataOperation(AD2DBTransferContext ctx)
 {
     this.context = ctx;
 }
Ejemplo n.º 39
0
        private static void CompareAndAddOuUsersData(DataTable srcTable, DataTable targetTable, DataView compareView, AD2DBTransferContext context)
        {
            //提出要添加的行
            foreach (DataRow dr in srcTable.Rows)
            {
                string userGuid = dr["USER_GUID"].ToString();
                string parentID = dr["PARENT_GUID"].ToString();

                DataRowView[] drv = compareView.FindRows(new string[] { userGuid, parentID });

                if (drv.Length == 0)
                {
                    //添加新纪录
                    DataRow newdr = targetTable.NewRow();

                    UpdateSort(dr, context);

                    DataRowView[] sameUsersInfo = context.OriginalOUUserUserGuidView.FindRows(userGuid);

                    //将和新插入记录相同GUID的用户都设置为兼职
                    Array.ForEach(sameUsersInfo, d => d["SIDELINE"] = 1);

                    AD2DBHelper.CopyDataRow(dr, newdr,
                                            "USER_GUID", "PARENT_GUID", "ALL_PATH_NAME", "DISPLAY_NAME", "OBJ_NAME", "STATUS", "ORIGINAL_SORT",
                                            "GLOBAL_SORT", "RANK_NAME", "DESCRIPTION", "ATTRIBUTES", "SEARCH_NAME", "INNER_SORT");

                    targetTable.Rows.Add(newdr);
                }
            }
        }
 public OrginalOguDataOperation(AD2DBTransferContext ctx)
     : base(ctx)
 {
 }
Ejemplo n.º 41
0
		private static void InsertOrganizations(SearchResult sr, AD2DBTransferContext context)
		{
			//开始添加AD的比较数据
			ADHelper helper = context.InitialParams.DirectoryHelper;
			DataTable oguTable = context.ADData.Tables["ORGANIZATIONS"];

			DataRow dr = oguTable.NewRow();

			dr["GUID"] = helper.GetSearchResultPropertyStrValue("objectGuid", sr);
			dr["PARENT_GUID"] = context.ParentGuid;

			string name = helper.GetSearchResultPropertyStrValue("name", sr);
			dr["OBJ_NAME"] = name;

			string displayName = helper.GetSearchResultPropertyStrValue("displayName", sr);
			displayName = string.IsNullOrEmpty(displayName) ? name : displayName;
			dr["DISPLAY_NAME"] = NormalizeName(displayName);

			dr["DESCRIPTION"] = helper.GetSearchResultPropertyStrValue("description", sr);
			dr["ALL_PATH_NAME"] = AD2DBHelper.TranslateDNToFullPath(helper.GetSearchResultPropertyStrValue("distinguishedName", sr));

			string innerSort = GetInnerSortAndIncCounter(context);
			string originalSort = context.ParentOriginalSort + innerSort;
			dr["ORIGINAL_SORT"] = originalSort;
			dr["GLOBAL_SORT"] = originalSort;
			dr["RANK_CODE"] = AD2DBHelper.ConvertDepartmentRankCode(helper.GetSearchResultPropertyStrValue("physicalDeliveryOfficeName", sr)).ToString();
			dr["CHILDREN_COUNTER"] = 0;
			dr["INNER_SORT"] = innerSort;
			dr["ORG_TYPE"] = (int)AD2DBHelper.TranslateDeptTypeDefine(sr);
			dr["ORG_CLASS"] = (int)AD2DBHelper.TranslateDeptClass(helper.GetSearchResultPropertyStrValue("c", sr));
			dr["STATUS"] = 1;
			dr["SEARCH_NAME"] = name + " " + NormalizeName(displayName);

			oguTable.Rows.Add(dr);
		}
        private static void CompareAndAddOguData(DataTable srcTable, DataTable targetTable, DataView compareView, AD2DBTransferContext context)
        {
            //提出要添加的行
            foreach (DataRow dr in srcTable.Rows)
            {
                int index = compareView.Find(dr["GUID"]);

                if (index == -1)
                {
                    //添加新纪录
                    DataRow newdr = targetTable.NewRow();

                    UpdateSort(dr, context);
                    AD2DBHelper.CopyDataRow(dr, newdr,
                                            "GUID", "PARENT_GUID", "OBJ_NAME", "DISPLAY_NAME", "DESCRIPTION", "DESCRIPTION",
                                            "ALL_PATH_NAME", "ORIGINAL_SORT", "CHILDREN_COUNTER", "GLOBAL_SORT", "RANK_CODE",
                                            "INNER_SORT", "ORG_TYPE", "ORG_CLASS", "STATUS", "SEARCH_NAME");

                    targetTable.Rows.Add(newdr);
                }
            }
        }
 public OrginalUserInfoExtendDataOperation(AD2DBTransferContext ctx)
     : base(ctx)
 {
 }