예제 #1
0
 public bool IsUserExist(string bstrUserName)
 {
     return(UserManager.IsUserExist(bstrUserName));
 }
예제 #2
0
파일: MainWindow.cs 프로젝트: zeus911/tale
        protected void DoSychronizationToRTX(DirectoryEntry entry, string parentId)
        {
            if (parentId == null)
            {
                string rootOuName = entry.Name;
                byte[] bGUID      = entry.Properties["objectGUID"][0] as byte[];
                string id         = BitConverter.ToString(bGUID);
                DoSychronizationToRTX(entry, id);
            }
            else
            {
                foreach (DirectoryEntry subEntry in entry.Children)
                {
                    string entrySchemaClsName = subEntry.SchemaClassName;

                    string[] arr         = subEntry.Name.Split('=');
                    string   categoryStr = arr[0];
                    string   nameStr     = arr[1];
                    string   id          = string.Empty;

                    string         dept_name = nameStr;
                    DirectoryEntry tmp_entry = subEntry.Parent;
                    while (!string.Format("LDAP://{0}", _UsersDomainName).Equals(tmp_entry.Path))
                    {
                        dept_name = tmp_entry.Name.Split('=')[1] + "\\" + dept_name;
                        tmp_entry = tmp_entry.Parent;
                    }

                    if (subEntry.Properties.Contains("objectGUID"))
                    {
                        byte[] bGUID = subEntry.Properties["objectGUID"][0] as byte[];
                        id = BitConverter.ToString(bGUID);
                    }
                    switch (entrySchemaClsName)
                    {
                    case "organizationalUnit":
                        if (!DeptManagerObj.IsDeptExist(dept_name))
                        {
                            if (dept_name.IndexOf("\\") == -1)
                            {
                                DeptManagerObj.AddDept(nameStr, null);
                            }
                            else
                            {
                                DeptManagerObj.AddDept(nameStr, dept_name.Substring(0, dept_name.LastIndexOf("\\")));
                            }
                        }
                        DoSychronizationToRTX(subEntry, id);
                        break;

                    case "user":
                        string accountName     = string.Empty;
                        string telephonenumber = string.Empty;
                        if (subEntry.Properties.Contains("samaccountname"))
                        {
                            accountName = subEntry.Properties["samaccountname"][0].ToString() + "@123u.com";
                            if (subEntry.Properties.Contains("telephonenumber"))
                            {
                                telephonenumber = subEntry.Properties["telephonenumber"][0].ToString();
                            }
                            if (UserManagerObj.IsUserExist(accountName))
                            {
                                UserManagerObj.SetUserBasicInfo(accountName, nameStr, -1, telephonenumber, accountName, null, -1);

                                string      old_depts = DeptManagerObj.GetUserDepts(accountName);
                                XmlDocument xmlDoc    = new XmlDocument();
                                xmlDoc.LoadXml(old_depts);

                                string xpath = "Departments";
                                var    nodes = xmlDoc.SelectNodes(xpath);

                                foreach (XmlNode childrenNode in nodes)
                                {
                                    string old_dept = childrenNode.SelectSingleNode("Department").Attributes["Name"].Value.ToString();
                                    old_dept = old_dept.Substring(0, old_dept.LastIndexOf("\\"));
                                    if (dept_name.Substring(0, dept_name.LastIndexOf("\\")).Equals(old_dept))
                                    {
                                    }
                                    else
                                    {
                                        DeptManagerObj.DelUserFromDept(accountName, old_dept);
                                    }
                                }
                            }
                            else
                            {
                                UserManagerObj.AddUser(accountName, 1);
                                OrgsManagerObj.SetOrgUser(accountName, "江游");
                                UserManagerObj.SetUserBasicInfo(accountName, nameStr, -1, telephonenumber, accountName, null, 1);
                                this.sychronizationResultTxtBox.BeginInvoke(updateSychResult, DateTime.Now.ToString("yy-MM-dd HH:mm:ss") + "| 同步账户:" + accountName + Environment.NewLine);
                            }
                            DeptManagerObj.AddUserToDept(accountName, "", dept_name.Substring(0, dept_name.LastIndexOf("\\")), false);
                        }
                        break;
                    }
                }
            }
        }