Exemplo n.º 1
0
        public virtual void Process(UnicornReserializeCompletePipelineArgs args)
        {
            var userPredicate = args.Configuration.Resolve <IUserPredicate>();

            // no predicate = configuration doesn't include any users
            if (userPredicate == null)
            {
                return;
            }

            var dataStore = args.Configuration.Resolve <IUserDataStore>();
            var logger    = args.Configuration.Resolve <ILogger>();

            Assert.IsNotNull(dataStore, $"The IUserDataStore was not registered for the {args.Configuration.Name} configuration.");
            Assert.IsNotNull(logger, $"The ILogger was not registered for the {args.Configuration.Name} configuration.");

            logger.Info(string.Empty);
            logger.Info($"{args.Configuration.Name} users are being reserialized.");

            dataStore.Clear();

            var users = UserManager.GetUsers().Where(user => userPredicate.Includes(user).IsIncluded);

            int userCount = 0;

            foreach (var user in users)
            {
                dataStore.Save(UserSynchronization.BuildSyncUser(Membership.GetUser(user.Name)));
                userCount++;
            }

            logger.Info($"{args.Configuration.Name} users reserialize complete. {userCount} users were reserialized.");
            logger.Info(string.Empty);
        }
        public virtual void UserAlteredOrCreated(string userName)
        {
            var user = User.FromName(userName, false);

            if (_predicate == null || !_predicate.Includes(user).IsIncluded)
            {
                return;
            }

            _dataStore.Save(UserSynchronization.BuildSyncUser(Membership.GetUser(user.Name)));
        }