Exemplo n.º 1
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);
        }
Exemplo n.º 2
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);
                }
            }
        }
 private static void CompareAndUpdateUserExtendData(DataRowView drv, DataRow dr)
 {
     //比较并修改原来的记录
     if (CompareUserExtendIsDifferent(drv, dr))
     {
         AD2DBHelper.CopyDataRow(drv.Row, dr,
                                 "MOBILE",
                                 "OFFICE_TEL",
                                 "IM_ADDRESS");
     }
 }
 private static void CompareAndUpdateUsersData(DataRowView drv, DataRow dr)
 {
     //比较并修改原来的记录
     if (CompareUserIsDifferent(drv, dr))
     {
         AD2DBHelper.CopyDataRow(drv.Row, dr,
                                 "LOGON_NAME",
                                 "E_MAIL",
                                 "FIRST_NAME",
                                 "LAST_NAME");
     }
 }
Exemplo n.º 5
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"]);
        }
Exemplo n.º 6
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 CompareAndUpdateOguData(DataRowView drv, DataRow dr)
 {
     //比较并修改原来的记录
     if (CompareOrganizationIsDifferent(drv, dr))
     {
         AD2DBHelper.CopyDataRow(drv.Row, dr,
                                 "PARENT_GUID",
                                 "DISPLAY_NAME",
                                 "OBJ_NAME",
                                 "ALL_PATH_NAME",
                                 "SEARCH_NAME",
                                 "ORIGINAL_SORT",
                                 "CHILDREN_COUNTER",
                                 "GLOBAL_SORT");
     }
 }
Exemplo n.º 8
0
 private static void CompareAndUpdateOuUsersData(DataRowView drv, DataRow dr)
 {
     //比较并修改原来的记录
     if (CompareOuUserIsDifferent(drv, dr))
     {
         AD2DBHelper.CopyDataRow(drv.Row, dr,
                                 "DESCRIPTION",
                                 "DISPLAY_NAME",
                                 "OBJ_NAME",
                                 "ALL_PATH_NAME",
                                 "RANK_NAME",
                                 "SEARCH_NAME",
                                 "STATUS",
                                 "INNER_SORT",
                                 "ORIGINAL_SORT",
                                 "GLOBAL_SORT",
                                 "SIDELINE");
     }
 }
        private static void CompareAndAddUserExtendData(DataTable srcTable, DataTable targetTable, DataView compareView)
        {
            //提出要添加的行
            foreach (DataRow dr in srcTable.Rows)
            {
                int index = compareView.Find(dr["ID"]);

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

                    AD2DBHelper.CopyDataRow(dr, newdr,
                                            "ID", "MOBILE", "OFFICE_TEL", "GENDER", "NATION", "IM_ADDRESS");

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

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

                    AD2DBHelper.CopyDataRow(dr, newdr,
                                            "GUID", "FIRST_NAME", "LAST_NAME", "LOGON_NAME", "PWD_TYPE_GUID", "USER_PWD",
                                            "RANK_CODE", "POSTURAL", "PINYIN", "E_MAIL");

                    targetTable.Rows.Add(newdr);
                }
            }
        }
        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);
                }
            }
        }
Exemplo n.º 12
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);
        }
 /// <summary>
 /// 比较组织表的字段 true 代表不同 false 代表相同
 /// </summary>
 private static bool CompareOrganizationIsDifferent(DataRowView newdrv, DataRow olddr)
 {
     return(AD2DBHelper.CompareDataRowIsDifferent(newdrv, olddr,
                                                  "PARENT_GUID", "DISPLAY_NAME", "OBJ_NAME", "ALL_PATH_NAME", "SEARCH_NAME", "ORIGINAL_SORT", "GLOBAL_SORT", "CHILDREN_COUNTER"));
 }
 private static bool CompareUserExtendIsDifferent(DataRowView newdrv, DataRow olddr)
 {
     return(AD2DBHelper.CompareDataRowIsDifferent(newdrv, olddr,
                                                  "MOBILE", "OFFICE_TEL", "IM_ADDRESS"));
 }
 /// <summary>
 /// 查询用户表的不同
 /// </summary>
 private static bool CompareUserIsDifferent(DataRowView newdrv, DataRow olddr)
 {
     return(AD2DBHelper.CompareDataRowIsDifferent(newdrv, olddr,
                                                  "FIRST_NAME", "LAST_NAME", "LOGON_NAME", "E_MAIL"));
 }
Exemplo n.º 16
0
        public void InitContext()
        {
            using (DbContext context = DbContext.GetContext(this.initialParams.AccreditAdminConnectionName))
            {
                FillData(this.OriginalData, "SELECT * FROM USERS", "USERS", context);
                FillData(this.OriginalData, "SELECT * FROM OU_USERS ORDER BY ALL_PATH_NAME", "OU_USERS", context);
                FillData(this.OriginalData, "SELECT * FROM ORGANIZATIONS ORDER BY ALL_PATH_NAME", "ORGANIZATIONS", context);
            }

            using (DbContext context = DbContext.GetContext(this.initialParams.UserInfoExtend))
            {
                FillData(this.OriginalData, "SELECT * FROM USERS_INFO_EXTEND", "USERS_INFO_EXTEND", context);
            }

            CloneDataSetSchema(OriginalData, ADData);

            InitRootOURow(
                OriginalData.Tables["ORGANIZATIONS"],
                ADData.Tables["ORGANIZATIONS"],
                ADToDBConfigSettings.GetConfig().RootOUName);

            DataRow newRow = InitRootOURow(
                OriginalData.Tables["ORGANIZATIONS"],
                ADData.Tables["ORGANIZATIONS"],
                AD2DBHelper.TranslateDNToFullPath(this.initialParams.Root.Properties["distinguishedName"].Value.ToString()));

            if (newRow != null)
            {
                newRow["CHILDREN_COUNTER"] = 0;
            }

            ADOguAllPathView      = new DataView(ADData.Tables["ORGANIZATIONS"]);
            ADOguAllPathView.Sort = "ALL_PATH_NAME";

            ADOguGuidView      = new DataView(ADData.Tables["ORGANIZATIONS"]);
            ADOguGuidView.Sort = "GUID";

            OriginalOguGuidView      = new DataView(OriginalData.Tables["ORGANIZATIONS"]);
            OriginalOguGuidView.Sort = "GUID";

            OriginalOguParentGuidView      = new DataView(OriginalData.Tables["ORGANIZATIONS"]);
            OriginalOguParentGuidView.Sort = "PARENT_GUID";

            OriginalOuUserParentGuidView      = new DataView(OriginalData.Tables["OU_USERS"]);
            OriginalOuUserParentGuidView.Sort = "PARENT_GUID";

            ADUsersGuidView      = new DataView(ADData.Tables["USERS"]);
            ADUsersGuidView.Sort = "GUID";

            UsersGuidView      = new DataView(OriginalData.Tables["USERS"]);
            UsersGuidView.Sort = "GUID";

            ADOuUserParentGuidView      = new DataView(ADData.Tables["OU_USERS"]);
            ADOuUserParentGuidView.Sort = "USER_GUID,PARENT_GUID";

            ADUserExtendGuidView      = new DataView(ADData.Tables["USERS_INFO_EXTEND"]);
            ADUserExtendGuidView.Sort = "ID";

            OriginalUserExtendGuidView      = new DataView(OriginalData.Tables["USERS_INFO_EXTEND"]);
            OriginalUserExtendGuidView.Sort = "ID";

            OriginalOUUserParentUserGuidView      = new DataView(OriginalData.Tables["OU_USERS"]);
            OriginalOUUserParentUserGuidView.Sort = "USER_GUID,PARENT_GUID";

            OriginalOUUserUserGuidView      = new DataView(OriginalData.Tables["OU_USERS"]);
            OriginalOUUserUserGuidView.Sort = "USER_GUID";
        }
Exemplo n.º 17
0
 private static bool CompareOuUserIsDifferent(DataRowView newdrv, DataRow olddr)
 {
     return(AD2DBHelper.CompareDataRowIsDifferent(newdrv, olddr,
                                                  "RANK_NAME", "DISPLAY_NAME", "OBJ_NAME", "DESCRIPTION", "ALL_PATH_NAME", "SEARCH_NAME", "STATUS", "INNER_SORT", "ORIGINAL_SORT", "GLOBAL_SORT"));
 }
Exemplo n.º 18
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);
        }