Beispiel #1
0
        /// <summary>
        ///     When overridden in a derived class, retrieves user-profile data from the data source for profiles in which the last
        ///     activity date occurred on or before the specified date.
        /// </summary>
        /// <returns>
        ///     A <see cref="T:System.Web.Profile.ProfileInfoCollection"></see> containing user-profile information about the
        ///     inactive profiles.
        /// </returns>
        /// <param name="authenticationOption">
        ///     One of the <see cref="T:System.Web.Profile.ProfileAuthenticationOption"></see> values, specifying whether
        ///     anonymous, authenticated, or both types of profiles are returned.
        /// </param>
        /// <param name="userInactiveSinceDate">
        ///     A <see cref="T:System.DateTime"></see> that identifies which user profiles are considered inactive. If the
        ///     <see
        ///         cref="P:System.Web.Profile.ProfileInfo.LastActivityDate">
        ///     </see>
        ///     of a user profile occurs on or before this date and time, the profile is considered inactive.
        /// </param>
        /// <param name="totalRecords">When this method returns, contains the total number of profiles.</param>
        /// <param name="pageIndex">The index of the page of results to return.</param>
        /// <param name="pageSize">The size of the page of results to return.</param>
        public override ProfileInfoCollection GetAllInactiveProfiles(ProfileAuthenticationOption authenticationOption,
                                                                     DateTime userInactiveSinceDate, int pageIndex,
                                                                     int pageSize, out int totalRecords)
        {
            SessionWrapper sessionWrapper = SessionManager.GetSessionWrapper();

            try
            {
                var infos = new ProfileInfoCollection();
                IQueryable <ProfileValue> profiles =
                    from profile in
                    MemberShipFactory.Profiles.Take(pageSize).Skip(pageIndex * pageSize)
                    where profile.LastActivityDate < userInactiveSinceDate
                    select profile;
                totalRecords =
                    (from profile in
                     MemberShipFactory.Profiles.Take(pageSize).Skip(pageIndex * pageSize)
                     where profile.LastActivityDate < userInactiveSinceDate
                     select profile).Count();


                foreach (ProfileValue prof in profiles)
                {
                    User u = MemberShipFactory.CreateUserDao().GetByLoginId(prof.LoginId);
                    infos.Add(ToProfileInfo(prof));
                }
                return(infos);
            }
            finally
            {
                sessionWrapper.Close();
            }
        }
Beispiel #2
0
        /// <summary>
        ///     When overridden in a derived class, retrieves profile information for profiles in which
        ///     the last activity date occurred on or before the specified date and the user name matches the specified user name.
        /// </summary>
        /// <returns>
        ///     A <see cref="T:System.Web.Profile.ProfileInfoCollection"></see> containing user profile information for inactive
        ///     profiles where the user name matches the supplied usernameToMatch parameter.
        /// </returns>
        /// <param name="authenticationOption">
        ///     One of the <see cref="T:System.Web.Profile.ProfileAuthenticationOption"></see> values, specifying whether
        ///     anonymous, authenticated, or both types of profiles are returned.
        /// </param>
        /// <param name="userInactiveSinceDate">
        ///     A <see cref="T:System.DateTime"></see> that identifies which user profiles are considered inactive. If the
        ///     <see
        ///         cref="P:System.Web.Profile.ProfileInfo.LastActivityDate">
        ///     </see>
        ///     value of a user profile occurs on or before this date and time, the profile is considered inactive.
        /// </param>
        /// <param name="totalRecords">When this method returns, contains the total number of profiles.</param>
        /// <param name="pageIndex">The index of the page of results to return.</param>
        /// <param name="usernameToMatch">The user name to search for.</param>
        /// <param name="pageSize">The size of the page of results to return.</param>
        public override ProfileInfoCollection FindInactiveProfilesByUserName(
            ProfileAuthenticationOption authenticationOption, string usernameToMatch, DateTime userInactiveSinceDate,
            int pageIndex, int pageSize, out int totalRecords)
        {
            SessionWrapper sessionWrapper = SessionManager.GetSessionWrapper();

            try
            {
                var infos = new ProfileInfoCollection();


                IQueryable <ProfileValue> profiles;
                switch (authenticationOption)
                {
                case ProfileAuthenticationOption.All:
                    profiles = (from pf in MemberShipFactory.Profiles
                                where
                                pf.LastActivityDate < userInactiveSinceDate &&
                                pf.LoginId.StartsWith(usernameToMatch)
                                select pf);

                    totalRecords = (from pf in MemberShipFactory.Profiles
                                    where
                                    pf.LastActivityDate < userInactiveSinceDate &&
                                    pf.LoginId.StartsWith(usernameToMatch)
                                    select pf).Count();
                    break;

                case ProfileAuthenticationOption.Anonymous:
                    profiles = (from pf in MemberShipFactory.Profiles
                                where
                                pf.LastActivityDate < userInactiveSinceDate &&
                                pf.LoginId.StartsWith(usernameToMatch) && pf.IsAnonymous
                                select pf);
                    totalRecords = (from pf in MemberShipFactory.Profiles
                                    where
                                    pf.LastActivityDate < userInactiveSinceDate &&
                                    pf.LoginId.StartsWith(usernameToMatch) && pf.IsAnonymous
                                    select pf).Count();
                    break;

                default:
                    profiles = (from pf in MemberShipFactory.Profiles
                                where
                                pf.LastActivityDate < userInactiveSinceDate &&
                                pf.LoginId.StartsWith(usernameToMatch) && pf.IsAnonymous == false
                                select pf);
                    totalRecords = (from pf in MemberShipFactory.Profiles
                                    where
                                    pf.LastActivityDate < userInactiveSinceDate &&
                                    pf.LoginId.StartsWith(usernameToMatch) && pf.IsAnonymous == false
                                    select pf).Count();
                    break;
                }


                foreach (ProfileValue prof in profiles)
                {
                    User u = MemberShipFactory.CreateUserDao().GetByLoginId(prof.LoginId);
                    infos.Add(new ProfileInfo(u.Name, prof.IsAnonymous, u.Other.LastActivityDate.Value,
                                              prof.LastActivityDate.Value, 30));
                }
                sessionWrapper.Commit();
                return(infos);
            }
            finally
            {
                sessionWrapper.Close();
            }
        }