예제 #1
0
        public override ProfileInfoCollection GetAllProfiles(ProfileAuthenticationOption authenticationOption,
                                                             int pageIndex, int pageSize, out int totalRecords)
        {
            ProfileType?profileType = null;

            if (authenticationOption == ProfileAuthenticationOption.Anonymous)
            {
                profileType = ProfileType.Anonymous;
            }
            else if (authenticationOption == ProfileAuthenticationOption.Authenticated)
            {
                profileType = ProfileType.Authenticated;
            }

            using (var transaction = new TransactionScope(mConfiguration))
            {
                var profileStore = new ProfileUserDataStore(transaction);

                var paging = new PagingInfo(pageSize, pageIndex);
                IList <ProfileUser> users = profileStore.FindByFields(ApplicationName,
                                                                      null, null, profileType, paging);
                totalRecords = (int)paging.RowCount;

                return(ProfileUsersToProfileInfoCollection(users));
            }
        }
예제 #2
0
        public override int GetNumberOfInactiveProfiles(ProfileAuthenticationOption authenticationOption,
                                                        DateTime userInactiveSinceDate)
        {
            ProfileType?profileType = null;

            if (authenticationOption == ProfileAuthenticationOption.Anonymous)
            {
                profileType = ProfileType.Anonymous;
            }
            else if (authenticationOption == ProfileAuthenticationOption.Authenticated)
            {
                profileType = ProfileType.Authenticated;
            }

            using (var transaction = new TransactionScope(mConfiguration))
            {
                var profileStore = new ProfileUserDataStore(transaction);

                IList <ProfileUser> users = profileStore.FindByFields(ApplicationName,
                                                                      null, userInactiveSinceDate, profileType,
                                                                      PagingInfo.All);

                return(users.Count);
            }
        }
예제 #3
0
        public override int DeleteInactiveProfiles(ProfileAuthenticationOption authenticationOption,
                                                   DateTime userInactiveSinceDate)
        {
            ProfileType?profileType = null;

            if (authenticationOption == ProfileAuthenticationOption.Anonymous)
            {
                profileType = ProfileType.Anonymous;
            }
            else if (authenticationOption == ProfileAuthenticationOption.Authenticated)
            {
                profileType = ProfileType.Authenticated;
            }

            int profilesDeleted = 0;

            using (var transaction = new TransactionScope(mConfiguration))
            {
                var profileStore = new ProfileUserDataStore(transaction);

                IList <ProfileUser> users = profileStore.FindByFields(ApplicationName, null, userInactiveSinceDate,
                                                                      profileType, PagingInfo.All);

                profilesDeleted = users.Count;

                foreach (ProfileUser user in users)
                {
                    profileStore.Delete(user.Id);
                }

                transaction.Commit();
            }

            return(profilesDeleted);
        }
예제 #4
0
        private IList <ProfileProperty> GetProperties(string userName)
        {
            if (string.IsNullOrEmpty(userName))
            {
                return(null);
            }

            IList <ProfileProperty> properties;

            using (var transaction = new TransactionScope(mConfiguration))
            {
                var         userStore = new ProfileUserDataStore(transaction);
                ProfileUser user      = userStore.FindByName(ApplicationName, userName);
                if (user == null)
                {
                    return(null);
                }

                var propStore = new ProfilePropertyDataStore(transaction);

                properties = propStore.FindByUser(user);

                //Update the last activity date
                user.LastActivityDate = DateTime.Now;

                transaction.Commit();
            }

            return(properties);
        }
예제 #5
0
        public override void SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection properties)
        {
            var         username = (string)context[CONTEXT_USERNAME];
            ProfileType profileType;

            if ((bool)context[CONTEXT_ISAUTHENTICATED])
            {
                profileType = ProfileType.Authenticated;
            }
            else
            {
                profileType = ProfileType.Anonymous;
            }

            using (var transaction = new TransactionScope(mConfiguration))
            {
                var propStore = new ProfilePropertyDataStore(transaction);
                var userStore = new ProfileUserDataStore(transaction);

                ProfileUser user = userStore.FindByName(ApplicationName, username);
                //Create the user if not exist
                if (user == null)
                {
                    user = new ProfileUser(ApplicationName, username, profileType);
                    userStore.Insert(user);
                }

                bool userChanged = false;

                foreach (SettingsPropertyValue propValue in properties)
                {
                    if (propValue.IsDirty)
                    {
                        if (profileType == ProfileType.Anonymous)
                        {
                            var allowAnonymous = (bool)propValue.Property.Attributes[PROP_ATTRIBUTE_ALLOWANONYMOUS];
                            if (!allowAnonymous)
                            {
                                continue;
                            }
                        }

                        userChanged = true;

                        ChangeProfileProperty(propStore, user, propValue);
                    }
                }

                user.LastActivityDate = DateTime.Now;
                if (userChanged)
                {
                    user.LastPropertyChangedDate = DateTime.Now;
                }

                transaction.Commit();
            }
        }
예제 #6
0
        public override int DeleteProfiles(ProfileInfoCollection profiles)
        {
            int profilesDeleted = 0;

            using (var transaction = new TransactionScope(mConfiguration))
            {
                var profileStore = new ProfileUserDataStore(transaction);

                foreach (ProfileInfo profileInfo in profiles)
                {
                    ProfileUser user = profileStore.FindByName(ApplicationName, profileInfo.UserName);
                    if (user != null)
                    {
                        profileStore.Delete(user.Id);

                        profilesDeleted++;
                    }
                }

                transaction.Commit();
            }

            return(profilesDeleted);
        }
예제 #7
0
        public override int DeleteProfiles(string[] usernames)
        {
            int profilesDeleted = 0;

            using (var transaction = new TransactionScope(mConfiguration))
            {
                var profileStore = new ProfileUserDataStore(transaction);

                foreach (string userName in usernames)
                {
                    IList <ProfileUser> users = profileStore.FindByFields(ApplicationName, userName, null, null,
                                                                          PagingInfo.All);
                    profilesDeleted += users.Count;
                    foreach (ProfileUser user in users)
                    {
                        profileStore.Delete(user.Id);
                    }
                }

                transaction.Commit();
            }

            return(profilesDeleted);
        }