Example #1
0
        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();
        }
        public async Task <IHttpActionResult> Get(string name)
        {
            Log.Debug("Entering Get(name) in UserController");
            UserFinder  searcher      = new UserFinder(_loginProvider.GetConnectionString());
            List <User> matchingUsers = searcher.GetMatchingUsersFromDatabase(name);

            return(Ok(matchingUsers));
        }