Beispiel #1
0
        /// <summary>
        ///     Returns the collection of settings property values for the specified application instance and settings property
        ///     group.
        /// </summary>
        /// <returns>
        ///     A <see cref="T:System.Configuration.SettingsPropertyValueCollection"></see> containing the values for the specified
        ///     settings property group.
        /// </returns>
        /// <param name="context">
        ///     A <see cref="T:System.Configuration.SettingsContext"></see> describing the current application use.
        /// </param>
        /// <param name="collection">
        ///     A <see cref="T:System.Configuration.SettingsPropertyCollection"></see> containing the settings property group whose
        ///     values are to be retrieved.
        /// </param>
        /// <filterpriority>2</filterpriority>
        public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context,
                                                                          SettingsPropertyCollection collection)
        {
            SessionWrapper sessionWrapper = SessionManager.GetSessionWrapper();

            IUserProfileDao profileDao = MemberShipFactory.CreateProfileDao();

            try
            {
                var result = new SettingsPropertyValueCollection();
                Dictionary <string, object> persisteProfileValue = null;
                string       userName     = LoginId(context);
                ProfileValue profileValue = profileDao.FindByLoginId(userName);
                if (profileValue != null)
                {
                    persisteProfileValue = profileValue.Properities;
                }
                foreach (SettingsProperty property in collection)
                {
                    var item = new SettingsPropertyValue(property);
                    if (persisteProfileValue != null && persisteProfileValue.ContainsKey(item.Name))
                    {
                        item.PropertyValue = persisteProfileValue[item.Name];
                    }
                    result.Add(item);
                }
                sessionWrapper.Commit();
                return(result);
            }
            finally
            {
                sessionWrapper.Close();
            }
        }
Beispiel #2
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 #3
0
        /// <summary>
        ///     When overridden in a derived class, returns the number of profiles in which the last activity date occurred on or
        ///     before the specified date.
        /// </summary>
        /// <returns>
        ///     The number of profiles in which the last activity date occurred on or before the specified date.
        /// </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>
        public override int GetNumberOfInactiveProfiles(ProfileAuthenticationOption authenticationOption,
                                                        DateTime userInactiveSinceDate)
        {
            SessionWrapper sessionWrapper = SessionManager.GetSessionWrapper();

            try
            {
                switch (authenticationOption)
                {
                case ProfileAuthenticationOption.Anonymous:
                    return
                        (MemberShipFactory.CreateProfileDao().CountAnonymous(userInactiveSinceDate));

                case ProfileAuthenticationOption.Authenticated:
                    return
                        (MemberShipFactory.CreateProfileDao().CountAuthenticated(
                             userInactiveSinceDate));

                default:
                    return(MemberShipFactory.CreateProfileDao().Count(userInactiveSinceDate));
                }
            }
            finally
            {
                sessionWrapper.Close();
            }
        }
Beispiel #4
0
        /// <summary>
        ///     When overridden in a derived class, deletes profile properties and information for profiles that match the supplied
        ///     list of user names.
        /// </summary>
        /// <returns>
        ///     The number of profiles deleted from the data source.
        /// </returns>
        /// <param name="usernames">A string array of user names for profiles to be deleted.</param>
        public override int DeleteProfiles(string[] usernames)
        {
            SessionWrapper sessionWrapper = SessionManager.GetSessionWrapper();

            try
            {
                return(MemberShipFactory.CreateProfileDao().Delete(usernames));
            }

            finally
            {
                sessionWrapper.Close();
            }
        }
Beispiel #5
0
        /// <summary>
        ///     When overridden in a derived class, deletes profile properties and information for the supplied list of profiles.
        /// </summary>
        /// <returns>
        ///     The number of profiles deleted from the data source.
        /// </returns>
        /// <param name="profiles">
        ///     A <see cref="T:System.Web.Profile.ProfileInfoCollection"></see>  of information about profiles that are to be
        ///     deleted.
        /// </param>
        public override int DeleteProfiles(ProfileInfoCollection profiles)
        {
            SessionWrapper wrapper = SessionManager.GetSessionWrapper();

            try
            {
                var userName = new string[profiles.Count];
                int i        = 0;
                foreach (ProfileInfo info in profiles)
                {
                    userName[i] = info.UserName;
                    i++;
                }
                return(MemberShipFactory.CreateProfileDao().Delete(userName));
            }
            finally
            {
                wrapper.Close();
            }
        }
Beispiel #6
0
        /// <summary>
        ///     When overridden in a derived class, retrieves user profile data for all profiles in the data source.
        /// </summary>
        /// <returns>
        ///     A <see cref="T:System.Web.Profile.ProfileInfoCollection"></see> containing user-profile information for all
        ///     profiles in the data source.
        /// </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="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 GetAllProfiles(ProfileAuthenticationOption authenticationOption,
                                                             int pageIndex, int pageSize, out int totalRecords)
        {
            SessionWrapper sessionWrapper = SessionManager.GetSessionWrapper();

            try
            {
                IList <ProfileValue> users;
                switch (authenticationOption)
                {
                case ProfileAuthenticationOption.Anonymous:
                    users =
                        MemberShipFactory.CreateProfileDao().GetAllAnonymous(pageIndex, pageSize,
                                                                             out totalRecords);
                    break;

                case ProfileAuthenticationOption.Authenticated:
                    users =
                        MemberShipFactory.CreateProfileDao().GetAllAuthenticated(pageIndex,
                                                                                 pageSize,
                                                                                 out totalRecords);
                    break;

                default:
                    users = MemberShipFactory.CreateProfileDao().GetAll(pageIndex, pageSize,
                                                                        out totalRecords);
                    break;
                }
                var result = new ProfileInfoCollection();
                foreach (ProfileValue userProfile in users)
                {
                    result.Add(ToProfileInfo(userProfile));
                }
                return(result);
            }
            finally
            {
                sessionWrapper.Close();
            }
        }
Beispiel #7
0
        /// <summary>
        ///     Sets the values of the specified group of property settings.
        /// </summary>
        /// <param name="context">
        ///     A <see cref="T:System.Configuration.SettingsContext"></see> describing the current application usage.
        /// </param>
        /// <param name="collection">
        ///     A <see cref="T:System.Configuration.SettingsPropertyValueCollection"></see> representing the group of property
        ///     settings to set.
        /// </param>
        /// <filterpriority>2</filterpriority>
        public override void SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection collection)
        {
            SessionWrapper sessionWrapper = SessionManager.GetSessionWrapper();

            try
            {
                string          userName   = LoginId(context);
                IUserProfileDao profileDao = MemberShipFactory.CreateProfileDao();


                ProfileValue profileValue = profileDao.FindByLoginId(userName) ??
                                            new ProfileValue
                {
                    LastActivityDate = DateTime.Now,
                    IsAnonymous      = !userIsAuthenticated(context),
                    LoginId          = userName
                };
                foreach (SettingsPropertyValue settingsPropertyValue in collection)
                {
                    if (profileValue.Properities.ContainsKey(settingsPropertyValue.Name))
                    {
                        profileValue.Properities[settingsPropertyValue.Name] = settingsPropertyValue.PropertyValue;
                    }
                    else
                    {
                        profileValue.Properities.Add(settingsPropertyValue.Name, settingsPropertyValue.PropertyValue);
                    }
                }
                profileDao.SaveOrUpdate(profileValue);
                sessionWrapper.Commit();
            }
            finally
            {
                sessionWrapper.Close();
            }
        }
Beispiel #8
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();
            }
        }