Beispiel #1
0
        public List <User> GetMatchingUsersFromDatabase(string searchString)
        {
            TodoItemRepository repo = new TodoItemRepository();
            var users = repo.Query <User>().Where(u => u.Fullname.ToLower().Contains(searchString.ToLower())).ToList();

            return(users);
        }
        public void DispatcherTimerTick(object sender)
        {
            TodoItemRepository repo = new TodoItemRepository();

            using (var pc = new PrincipalContext(ContextType.Domain, _loginProvider.GetConnectionString()))
            {
                UserPrincipal qbeUser = new UserPrincipal(pc);
                qbeUser.DisplayName = "*";
                PrincipalSearcher srch = new PrincipalSearcher(qbeUser);
                foreach (var found in srch.FindAll())
                {
                    UserPrincipal user = (found as UserPrincipal);
                    if (user != null)
                    {
                        //Infusion hack: remove users that start with ext- or that have - or _ in their username
                        if (/*user.SamAccountName.Contains("-") ||*/ user.SamAccountName.Contains("_"))
                        {
                            continue;
                        }
                        User dbUser = repo.Query <User>().FirstOrDefault(u => u.Username == user.SamAccountName);
                        if (dbUser == null)
                        {
                            dbUser = new DomanUserLoginProvider(_loginProvider.GetConnectionString()).CreateUser(user.SamAccountName);
                            if (!string.IsNullOrEmpty(dbUser.Firstname) && !string.IsNullOrEmpty(dbUser.Lastname) && !string.IsNullOrEmpty(dbUser.Username))
                            {
                                repo.Add <User>(dbUser);
                            }
                        }
                    }
                }
            }
            repo.SaveChanges();
        }
Beispiel #3
0
        public List <User> GetMatchingUsersFromDomain(string searchString)
        {
            try
            {
                List <User>        userList = new List <User>();
                TodoItemRepository repo     = new TodoItemRepository();
                using (var pc = new PrincipalContext(ContextType.Domain, _domain))
                {
                    UserPrincipal qbeUser = new UserPrincipal(pc);
                    qbeUser.DisplayName = string.Format("*{0}*", searchString);
                    PrincipalSearcher srch = new PrincipalSearcher(qbeUser);
                    foreach (var found in srch.FindAll())
                    {
                        UserPrincipal user = (found as UserPrincipal);
                        if (user != null)
                        {
                            //Infusion hack: remove users that start with ext- or that have - or _ in their username
                            if (user.SamAccountName.Contains("-") || user.SamAccountName.Contains("_"))
                            {
                                continue;
                            }
                            User dbUser = repo.Query <User>().FirstOrDefault(u => u.Username == user.SamAccountName);
                            if (dbUser == null)
                            {
                                dbUser = new DomanUserLoginProvider(_domain).CreateUser(user.SamAccountName);
                                if (!string.IsNullOrEmpty(dbUser.Firstname) && !string.IsNullOrEmpty(dbUser.Lastname) && !string.IsNullOrEmpty(dbUser.Username))
                                {
                                    repo.Add <User>(dbUser);
                                }
                            }
                            if (!string.IsNullOrEmpty(dbUser.Firstname) && !string.IsNullOrEmpty(dbUser.Lastname) && !string.IsNullOrEmpty(dbUser.Username))
                            {
                                userList.Add(dbUser);
                            }
                        }
                    }
                }

                repo.SaveChanges();
                return(userList);
            }
            catch (Exception ex)
            {
                Log.Error("Cannot connect to domain", ex);
                return(null);
            }
        }