public override int DeleteProfiles(ProfileInfoCollection profiles)
 {
     int count = 0;
     foreach (ProfileInfo pi in profiles)
     {
         FileInfo fi = this.GetProfileFile(pi.UserName);
         if (fi != null)
         {
             fi.Delete();
             count++;
         }
     }
     return count;
 }
Exemple #2
0
        /// <summary>
        /// *note method not supported on our custom profile provider, return empty profile
        /// </summary>
        ProfileInfoCollection GetProfileInfo(ProfileAuthenticationOption authenticationOption, string usernameToMatch, object userInactiveSinceDate, int pageIndex, int pageSize, out int totalRecords)
        {
            var profiles = new ProfileInfoCollection();

            profiles.Add(new ProfileInfo(
                             username: "",
                             isAnonymous: false,
                             lastActivityDate: DateTime.MinValue,
                             lastUpdatedDate: DateTime.MinValue,
                             size: 0));

            totalRecords = 0;

            return(profiles);
        }
        private ProfileInfoCollection GetProfiles(ProfileAuthenticationOption authenticationOption, string usernameToMatch, DateTime?userInactiveSinceDate, int pageIndex, int pageSize, out int totalRecords)
        {
            var query = GetQuery(authenticationOption, usernameToMatch, userInactiveSinceDate);

            totalRecords = ( int )this.mongoCollection.Count(query);

            var profileInfoCollection = new ProfileInfoCollection();

            foreach (var bsonDocument in this.mongoCollection.FindAs <BsonDocument>(query).SetSkip(pageIndex * pageSize).SetLimit(pageSize))
            {
                profileInfoCollection.Add(ToProfileInfo(bsonDocument));
            }

            return(profileInfoCollection);
        }
        public override ProfileInfoCollection FindProfilesByUserName(ProfileAuthenticationOption authenticationOption, string usernameToMatch, int pageIndex, int pageSize, out int totalRecords)
        {
            ProfileInfoCollection profiles = new ProfileInfoCollection();
            User u = Bridge.GetUser(usernameToMatch);

            if (u != null)
            {
                totalRecords = 1;
                if (pageIndex == 0 && pageSize > 0)
                {
                    profiles.Add(CreateProfile(u));
                }
            }
            totalRecords = 0;
            return(profiles);
        }
Exemple #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="profiles"></param>
        /// <returns></returns>
        protected internal ProfileInfoCollection CreateProfileInfoCollection(List <XmlProfile> profiles)
        {
            ProfileInfoCollection coll = new ProfileInfoCollection();
            MembershipUser        user;

            foreach (XmlProfile profile in profiles)
            {
                user = Membership.GetUser(profile.UserKey);
                if (user != null)
                {
                    coll.Add(new ProfileInfo(user.UserName, false, user.LastActivityDate, profile.LastUpdated, profile.ValuesBinary.Length));
                }
            }
            ///
            return(coll);
        }
Exemple #6
0
        private ProfileInfoCollection ProfilesToProfileInfoCollection(IEnumerable <Profile> profiles)
        {
            var result = new ProfileInfoCollection();

            foreach (Profile profile in profiles)
            {
                result.Add(new ProfileInfo(
                               profile.Username,
                               profile.IsAnonymous,
                               profile.LastActivityDate,
                               profile.LastUpdatedDate,
                               GetProfileSize(profile.Username)));
            }

            return(result);
        }
        public void DeleteProfiles_DeleteOneExistingProfile_UserDeleted()
        {
            var userRepository = A.Fake <IUserRepository>();
            var user           = A.Fake <IUser>();

            A.CallTo(() => userRepository.GetUserByUserName("username", "njupiter")).Returns(user);
            var profileProvider = GetProfileProvider(userRepository);
            var profiles        = new ProfileInfoCollection();
            var profile         = new ProfileInfo("njupiter\\username", false, DateTime.Now, DateTime.Now, 0);

            profiles.Add(profile);
            var count = profileProvider.DeleteProfiles(profiles);

            Assert.AreEqual(1, count);
            A.CallTo(() => userRepository.DeleteUser(user)).MustHaveHappened(Repeated.Exactly.Once);
        }
        public override ProfileInfoCollection GetAllProfiles(ProfileAuthenticationOption authenticationOption, int pageIndex, int pageSize, out int totalRecords)
        {
            ProfileInfoCollection profiles = new ProfileInfoCollection();
            UserList users = Bridge.GetUserContainer(false);

            if (users != null)
            {
                totalRecords = users.Children.Count;
                foreach (User u in users.GetChildren(new Collections.CountFilter(pageIndex * pageSize, pageSize)))
                {
                    profiles.Add(CreateProfile(u));
                }
            }
            totalRecords = 0;
            return(profiles);
        }
        /// <summary>
        /// The get profile as collection.
        /// </summary>
        /// <param name="authenticationOption">
        /// The authentication option.
        /// </param>
        /// <param name="pageIndex">
        /// The page index.
        /// </param>
        /// <param name="pageSize">
        /// The page size.
        /// </param>
        /// <param name="userNameToMatch">
        /// The user name to match.
        /// </param>
        /// <param name="inactiveSinceDate">
        /// The inactive since date.
        /// </param>
        /// <param name="totalRecords">
        /// The total records.
        /// </param>
        /// <returns>
        /// </returns>
        private ProfileInfoCollection GetProfileAsCollection(
            ProfileAuthenticationOption authenticationOption,
            int pageIndex,
            int pageSize,
            object userNameToMatch,
            object inactiveSinceDate,
            out int totalRecords)
        {
            if (authenticationOption == ProfileAuthenticationOption.Anonymous)
            {
                ExceptionReporter.ThrowArgument("PROFILE", "NOANONYMOUS");
            }

            if (pageIndex < 0)
            {
                ExceptionReporter.ThrowArgument("PROFILE", "PAGEINDEXTOOSMALL");
            }

            if (pageSize < 1)
            {
                ExceptionReporter.ThrowArgument("PROFILE", "PAGESIZETOOSMALL");
            }

            // get all the profiles...
            DataSet allProfilesDS = DB.Current.GetProfiles(this.ApplicationName, pageIndex, pageSize, userNameToMatch, inactiveSinceDate);

            // create an instance for the profiles...
            var profiles = new ProfileInfoCollection();

            DataTable allProfilesDT   = allProfilesDS.Tables[0];
            DataTable profilesCountDT = allProfilesDS.Tables[1];

            foreach (DataRow profileRow in allProfilesDT.Rows)
            {
                string   username     = profileRow["Username"].ToString();
                DateTime lastActivity = DateTime.SpecifyKind(Convert.ToDateTime(profileRow["LastActivity"]), DateTimeKind.Utc);
                DateTime lastUpdated  = DateTime.SpecifyKind(Convert.ToDateTime(profileRow["LastUpdatedDate"]), DateTimeKind.Utc);

                profiles.Add(new ProfileInfo(username, false, lastActivity, lastUpdated, 0));
            }

            // get the first record which is the count...
            totalRecords = Convert.ToInt32(profilesCountDT.Rows[0][0]);

            return(profiles);
        }
        public override ProfileInfoCollection FindProfilesByUserName(ProfileAuthenticationOption authenticationOption, string usernameToMatch, int pageIndex, int pageSize, out int totalRecords)
        {
            if (pageIndex < 0)
            {
                throw new ArgumentOutOfRangeException("pageIndex");
            }
            if (pageSize < 1)
            {
                throw new ArgumentOutOfRangeException("pageSize");
            }
            if (authenticationOption == ProfileAuthenticationOption.Anonymous)
            {
                totalRecords = 0;
                return(new ProfileInfoCollection());
            }
            ProfileInfoCollection profiles = new ProfileInfoCollection();

            totalRecords = 0;

            using (SqlConnection cn = this.OpenConnection())
            {
                SqlCommand cmd = new SqlCommand(this.ExpandCommand(SQL_FindProfilesByUserName), cn);
                cmd.Parameters.Add("@Criteria", SqlDbType.VarChar, CustomMembershipProvider.UserNameSize).Value = PrepareCriteria(usernameToMatch);
                cmd.Parameters.Add("@PageIndex", SqlDbType.Int).Value = pageIndex;
                cmd.Parameters.Add("@PageSize", SqlDbType.Int).Value  = pageSize;
                SqlParameter totalRecordsParameter = new SqlParameter("@TotalRecords", SqlDbType.Int);
                totalRecordsParameter.Direction = ParameterDirection.Output;
                cmd.Parameters.Add(totalRecordsParameter);

                using (SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection))
                {
                    while (reader.Read())
                    {
                        profiles.Add(new ProfileInfo(Convert.ToString(reader["EmailAddress"]), false, DateTime.Now, Convert.ToDateTime(reader["LastUpdateDate"]), 0));
                    }
                }

                if (totalRecordsParameter.Value != DBNull.Value)
                {
                    totalRecords = Convert.ToInt32(totalRecordsParameter.Value);
                }
            }

            return(profiles);
        }
Exemple #11
0
        private static ProfileInfoCollection GetProfilesForCommand(DbCommand selectCommand, int pageIndex, int pageSize, out int totalRecords)
        {
            if (pageIndex < 0)
            {
                throw new ArgumentException("Page index must be non-negative", "pageIndex");
            }
            if (pageSize < 1)
            {
                throw new ArgumentException("Page size must be positive", "pageSize");
            }

            long lBound = (long)pageIndex * pageSize;
            long uBound = lBound + pageSize - 1;

            if (uBound > System.Int32.MaxValue)
            {
                throw new ArgumentException("pageIndex*pageSize too large");
            }

            Database database = Token.Instance.Database;
            ProfileInfoCollection profiles = new ProfileInfoCollection();

            using (IDataReader reader = database.ExecuteReader(selectCommand))
            {
                totalRecords = 0;
                while (reader.Read())
                {
                    totalRecords++;
                    if (totalRecords - 1 < lBound || totalRecords - 1 > uBound)
                    {
                        continue;
                    }

                    string   username       = reader.GetString(0);
                    bool     isAnon         = reader.GetBoolean(1);
                    DateTime dtLastActivity = LocaleHelper.ToLocalTime(reader.GetDateTime(2));
                    DateTime dtLastUpdated  = LocaleHelper.ToLocalTime(reader.GetDateTime(3));
                    int      size           = reader.GetInt32(4);
                    profiles.Add(new ProfileInfo(username, isAnon, dtLastActivity, dtLastUpdated, size));
                }
                reader.Close();
            }

            return(profiles);
        }
Exemple #12
0
        public override int DeleteProfiles(ProfileInfoCollection profiles)
        {
            Condition.Requires(profiles, "profiles").IsNotNull();

            int i;

            using (var db = this.ConnectToDatabase())
            {
                DeleteUserInRoles(db, profiles);
                DeleteOAuthMembership(db, profiles);
                DeleteMembership(db, profiles);
                i =
                    profiles.Cast <ProfileInfo>()
                    .Sum(profile => db.Execute(this.sqlQueryBuilder.DeleteProfile, profile.UserName));
            }

            return(i);
        }
        public static ProfileInfoCollection GetAllInactiveProfiles(
            ProfileAuthenticationOption profileAuthenticationOption, DateTime inactiveSinceDate, int pageIndex,
            int pageSize, out int totalRecords)
        {
            ProfileInfoCollection          infos    = new ProfileInfoCollection();
            List <SystemUserProfileEntity> profiles =
                businessProxy.GetAllInactiveProfiles(profileAuthenticationOption, inactiveSinceDate, pageIndex,
                                                     pageSize, out totalRecords);

            foreach (SystemUserProfileEntity prof in profiles)
            {
                SystemUserWrapper user = SystemUserWrapper.FindById(prof.UserID.UserID);

                infos.Add(new ProfileInfo(user.UserLoginID, false, user.LastActivityDate,
                                          prof.LastUpdatedDate, 2000));
            }
            return(infos);
        }
        public override int DeleteProfiles(ProfileInfoCollection profiles)
        {
            SaveLog("Deleting Profiles by collection");

            int    errorNumber      = 0;
            string errorDescription = null;

            int result = _profileDao.DeleteProfiles(_currentLogin, profiles,
                                                    out errorNumber, out errorDescription);

            if (errorNumber > 0 || !string.IsNullOrEmpty(errorDescription))
            {
                LogManager.WriteWarning(_currentLogin, this, "Error deleting profiles by collection.", errorDescription);
                return(-1);
            }

            return(result);
        }
        public override ProfileInfoCollection GetAllProfiles(ProfileAuthenticationOption authenticationOption, int pageIndex, int pageSize, out int totalRecords)
        {
            ProfileInfoCollection pc = new ProfileInfoCollection();

            totalRecords = 0;

            switch (authenticationOption)
            {
            case ProfileAuthenticationOption.All:
            {
                PageQueryParams pageQueryParams = new PageQueryParams();
                pageQueryParams.PageIndex = pageIndex;
                pageQueryParams.PageSize  = pageSize;

                List <SystemUserWrapper> users = SystemUserWrapper.FindAllByPage(pageQueryParams);

                totalRecords = pageQueryParams.RecordCount;

                foreach (SystemUserWrapper user in users)
                {
                    pc.Add(new ProfileInfo(user.UserLoginID, false, user.LastActivityDate, user.LastLoginDate, 0));
                }

                return(pc);
            };

            case ProfileAuthenticationOption.Anonymous:
            {
                return(pc);
            };

            case ProfileAuthenticationOption.Authenticated:
            {
                List <SystemUserWrapper> users = SystemUserWrapper.FindAuthenticatedUserAll(((pageIndex - 1) * pageSize), pageSize, out totalRecords);
                foreach (SystemUserWrapper user in users)
                {
                    pc.Add(new ProfileInfo(user.UserLoginID, false, user.LastActivityDate, user.LastLoginDate, 0));
                }
                return(pc);
            };

            default: return(pc);
            }
        }
        /// <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"/> containing user-profile information about the inactive profiles.
        /// </returns>
        /// <param name="authenticationOption">One of the <see cref="T:System.Web.Profile.ProfileAuthenticationOption"/> values, specifying whether anonymous, authenticated, or both types of profiles are returned.
        ///                 </param><param name="userInactiveSinceDate">A <see cref="T:System.DateTime"/> that identifies which user profiles are considered inactive. If the <see cref="P:System.Web.Profile.ProfileInfo.LastActivityDate"/>  of a user profile occurs on or before this date and time, the profile is considered inactive.
        ///                 </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><param name="totalRecords">When this method returns, contains the total number of profiles.
        ///                 </param>
        public override ProfileInfoCollection GetAllInactiveProfiles(ProfileAuthenticationOption authenticationOption, DateTime userInactiveSinceDate, int pageIndex, int pageSize, out int totalRecords)
        {
            if (pageIndex < 1 || pageSize < 1)
            {
                throw new ApplicationException(string.Format("{0} page index.", _ERR_INVALID_PARAMETER));
            }

            ProfileInfoCollection profiles = new ProfileInfoCollection();

            int counter    = 0;
            int startIndex = pageSize * (pageIndex - 1);
            int endIndex   = startIndex + pageSize - 1;

            var profileList    = new TList <Profile>();
            var profileService = new ProfileService();

            foreach (var item in profileService.GetAll())
            {
                if (item.LastActivityDate.Value < userInactiveSinceDate)
                {
                    profileList.Add(item);
                }
            }

            totalRecords = profileList.Count;

            foreach (Profile profile in profileList)
            {
                if (counter >= startIndex)
                {
                    profiles.Add(new ProfileInfo(profile.Username, profile.IsAnonymous.Value, profile.LastActivityDate.Value, profile.LastUpdatedDate.Value, 0));
                }

                if (counter >= endIndex)
                {
                    break;
                }

                counter++;
            }

            return(profiles);
        }
Exemple #17
0
        public override int DeleteProfiles(ProfileInfoCollection profiles)
        {
            XElement perfilesXml = new XElement("Perfiles");

            foreach (ProfileInfo profileInfo in profiles)
            {
                perfilesXml.Add(new XElement("Perfil", new XAttribute("Login", profileInfo.UserName)));
            }

            SqlDatabase sqlDatabase = new SqlDatabase(_connectionString);
            DbCommand   dbCommand   = sqlDatabase.GetStoredProcCommand("adm.NlayerSP_EliminarPerfil");

            sqlDatabase.AddInParameter(dbCommand, "Aplicacion", DbType.String, _applicationName);
            sqlDatabase.AddInParameter(dbCommand, "Perfiles", DbType.Xml, perfilesXml.ToString());

            sqlDatabase.ExecuteNonQuery(dbCommand);

            return(profiles.Count);
        }
        public override ProfileInfoCollection FindProfilesByUserName(ProfileAuthenticationOption authenticationOption, string usernameToMatch, int pageIndex, int pageSize, out int totalRecords)
        {
            SaveLog("FindProfilesByUserName");

            int    errorNumber      = 0;
            string errorDescription = string.Empty;


            ProfileInfoCollection list = _profileDao.FindProfilesByUserName(_currentLogin, authenticationOption, usernameToMatch, pageIndex,
                                                                            pageSize, out totalRecords, out errorNumber, out errorDescription);

            if (errorNumber > 0 || !string.IsNullOrEmpty(errorDescription))
            {
                LogManager.WriteWarning(_currentLogin, this, "Error Finding profiles by user name", errorDescription);
                return(null);
            }

            return(list);
        }
Exemple #19
0
        ProfileInfoCollection GetProfiles(ProfileAuthenticationOption authenticationOption, object userInactiveSinceDate, string usernameToMatch, int pageIndex, int pageSize, out int totalRecords)
        {
            ProfileInfoCollection profiles = new ProfileInfoCollection();

            totalRecords = 0;
            DateTime dt = new DateTime(1900, 1, 1);

            if (userInactiveSinceDate != null)
            {
                dt = (DateTime)userInactiveSinceDate;
            }

            if (pageSize == 0)
            {
                totalRecords = Users.GetInactiveUsers(authenticationOption, dt).Count;
                return(profiles);
            }

            int counter    = 0;
            int startIndex = pageSize * (pageIndex - 1);
            int endIndex   = startIndex + pageSize - 1;


            DateTime ld = new DateTime(1900, 1, 1);

            foreach (User profile in Users.GetProfiles(authenticationOption, dt, usernameToMatch, out totalRecords))
            {
                if (counter >= startIndex)
                {
                    ProfileInfo p = new ProfileInfo(profile.UserName, (profile.AccountStatus == AccountStatus.Anonymous ? true : false), profile.LastActiveDate, profile.UpdateTime, 0);
                    profiles.Add(p);
                }

                if (counter >= endIndex)
                {
                    break;
                }

                counter++;
            }

            return(profiles);
        }
Exemple #20
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)
        {
            if (profiles == null)
            {
                throw new ArgumentNullException("profiles");
            }
            if (profiles.Count < 1)
            {
                throw new ArgumentException("Delete Profiles parameter collection was empty");
            }
            string[] textArray1 = new string[profiles.Count];
            int      num1       = 0;

            foreach (ProfileInfo info1 in profiles)
            {
                textArray1[num1++] = info1.UserName;
            }
            return(DeleteProfiles(textArray1));
        }
Exemple #21
0
        /// <summary>Execute subscription job</summary>
        protected virtual string InternalExecute()
        {
            int num1 = 0;
            int num2 = 0;

label_1:
            int totalRecords;
            ProfileInfoCollection allProfiles = ProfileManager.GetAllProfiles(ProfileAuthenticationOption.All, num2++, 1000, out totalRecords);

            if (allProfiles.Count == 0)
            {
                return(string.Format("{0} user profiles were found. {1} subscription e-mails were sent.", (object)totalRecords, (object)num1));
            }
            IEnumerator enumerator = allProfiles.GetEnumerator();

            try
            {
                while (enumerator.MoveNext())
                {
                    EPiServerProfile profile = EPiServerProfile.Get(((ProfileInfo)enumerator.Current).UserName);
                    if (!SubscriptionJob.IsInInterval(profile.SubscriptionInfo.Interval, profile.SubscriptionInfo.LastMessage))
                    {
                        int num3 = this.SendSubscriptions(profile);
                        if (num3 >= 0)
                        {
                            profile.SubscriptionInfo.LastMessage = DateTime.Now;
                            num1 += num3;
                            profile.Save();
                        }
                    }
                }
                goto label_1;
            }
            finally
            {
                IDisposable disposable = enumerator as IDisposable;
                if (disposable != null)
                {
                    disposable.Dispose();
                }
            }
        }
        private void OnSearch()
        {
            bool isAnon = true;

            if (!cbIsAnon.Checked)
            {
                isAnon = false;
            }
            string   sDtime = txtDueDate.Value.Trim();
            DateTime dtime  = DateTime.MinValue;

            if (!string.IsNullOrEmpty(sDtime))
            {
                sDtime = sDtime + " 23:59:59";
                if (!DateTime.TryParse(sDtime, out dtime))
                {
                    WebHelper.MessageBox.Messager(this.Page, lbtnPostBack, "截止日期输入日期格式不正确,请检查", "操作错误", "error");
                    return;
                }
            }

            ProfileAuthenticationOption po = ProfileAuthenticationOption.Anonymous;

            if (!isAnon)
            {
                po = ProfileAuthenticationOption.Authenticated;
            }
            int totalCount = 0;
            ProfileInfoCollection profiles = null;

            if (dtime != DateTime.MinValue)
            {
                profiles = ProfileManager.GetAllInactiveProfiles(po, dtime, AspNetPager1.CurrentPageIndex - 1, AspNetPager1.PageSize, out totalCount);
            }
            else
            {
                profiles = ProfileManager.GetAllProfiles(po, AspNetPager1.CurrentPageIndex - 1, AspNetPager1.PageSize, out totalCount);
            }
            rpData.DataSource = profiles;
            rpData.DataBind();
            AspNetPager1.RecordCount = totalCount;
        }
Exemple #23
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();
            }
        }
        //GetProfileInfo
        //Retrieves a count of profiles and creates a
        //ProfileInfoCollection from the profile data in the
        //database. Called by GetAllProfiles, GetAllInactiveProfiles,
        //FindProfilesByUserName, FindInactiveProfilesByUserName,
        //and GetNumberOfInactiveProfiles.
        //Specifying a pageIndex of 0 retrieves a count of the results only.
        private static ProfileInfoCollection GetProfileInfo(ProfileAuthenticationOption authenticationOption, string usernameToMatch, object userInactiveSinceDate, int pageIndex, int pageSize, out int totalRecords)
        {
            ProfileInfoCollection profiles = new ProfileInfoCollection();

            totalRecords = 0;

            // Count profiles only.
            if (pageSize == 0)
            {
                return(profiles);
            }

            int counter    = 0;
            int startIndex = pageSize * (pageIndex - 1);
            int endIndex   = startIndex + pageSize - 1;

            DateTime dt = new DateTime(1900, 1, 1);

            if (userInactiveSinceDate != null)
            {
                dt = (DateTime)userInactiveSinceDate;
            }

            foreach (CustomProfileInfo profile in s_dal.GetProfileInfo((int)authenticationOption, usernameToMatch, dt, s_applicationName, out totalRecords))
            {
                if (counter >= startIndex)
                {
                    ProfileInfo p = new ProfileInfo(profile.UserName, profile.IsAnonymous, profile.LastActivityDate, profile.LastUpdatedDate, 0);
                    profiles.Add(p);
                }

                if (counter >= endIndex)
                {
                    break;
                }

                counter++;
            }

            return(profiles);
        }
Exemple #25
0
        /// <summary>
        /// When overridden in a derived class, deletes profile properties and information for the supplied list of profiles.
        /// </summary>
        /// <param name="profiles">A <see cref="T:System.Web.Profile.ProfileInfoCollection"></see>  of information about profiles that are to be deleted.</param>
        /// <returns>
        /// The number of profiles deleted from the data source.
        /// </returns>
        public override int DeleteProfiles(ProfileInfoCollection profiles)
        {
            if (profiles == null)
            {
                throw new ArgumentNullException("profiles");
            }

            try
            {
                lock (SyncRoot)
                {
                    foreach (ProfileInfo info in profiles)
                    {
                        this.Store.RemoveByUserName(info.UserName);
                    }
                }
            }
            catch { throw; }
            //
            return(profiles.Count);
        }
Exemple #26
0
        private ProfileInfoCollection GetProfiles(Expression <Func <Entity, bool> > wherePredicate, ProfileAuthenticationOption authenticationOption, int pageIndex, int pageSize, out int totalRecords)
        {
            var profileInfoCollection = new ProfileInfoCollection();

            if (authenticationOption != ProfileAuthenticationOption.All)
            {
                wherePredicate = CreateOrModifyWherePredicate(wherePredicate, authenticationOption);
            }

            var context = CrmConfigurationManager.CreateContext(ContextName);

            var entities = context.CreateQuery(_profileEntityName)
                           .Where(wherePredicate)
                           .OrderBy(entity => entity.GetAttributeValue <string>(_attributeMapUsername))
                           .Skip(pageIndex * pageSize)
                           .Take(pageSize);

            foreach (var entity in entities)
            {
                var username = entity.GetAttributeValue <string>(_attributeMapUsername);

                if (string.IsNullOrEmpty(username))
                {
                    continue;
                }

                profileInfoCollection.Add(
                    new ProfileInfo(
                        username,
                        entity.GetAttributeValue <bool?>(_attributeMapIsAnonymous).GetValueOrDefault(),
                        entity.GetAttributeValue <DateTime?>(_attributeMapLastActivityDate).GetValueOrDefault(),
                        entity.GetAttributeValue <DateTime?>(_attributeMapLastUpdatedDate).GetValueOrDefault(),
                        -1)
                    );
            }

            totalRecords = context.CreateQuery(_profileEntityName).Where(wherePredicate).ToList().Count();

            return(profileInfoCollection);
        }
Exemple #27
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();
            }
        }
Exemple #28
0
        private ProfileInfoCollection QueryProfileInfos(IObjectScope objScope, string oqlQuery, object oqlValue, int pageIndex, int pageSize, out int totalRecords)
        {
            ProfileInfoCollection pic = new ProfileInfoCollection();
            IQuery query = objScope.GetOqlQuery(oqlQuery);

            IQueryResult result;

            if (oqlValue != null)
            {
                result = query.Execute(oqlValue);
            }
            else
            {
                result = query.Execute();
            }

            using (result)
            {
                totalRecords = result.Count;
                int counter    = 0;
                int startIndex = pageSize * pageIndex;
                int endIndex   = startIndex + pageSize - 1;

                foreach (object res in result)
                {
                    if (counter >= startIndex)
                    {
                        EmployeeProfile ep = res as EmployeeProfile;
                        pic.Add(new ProfileInfo(ep.Employee.Name, false, ep.Employee.LastActivityDate, ep.LastUpdatedDate, 0));
                    }
                    if (counter >= endIndex)
                    {
                        break;
                    }
                    counter += 1;
                }
            }
            return(pic);
        }
Exemple #29
0
        /// <summary>
        /// When overridden in a derived class, deletes all user-profile data for profiles in which the last activity date occurred before the specified date.
        /// </summary>
        /// <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 deleted.</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>
        /// <returns>
        /// The number of profiles deleted from the data source.
        /// </returns>
        public override int DeleteInactiveProfiles(ProfileAuthenticationOption authenticationOption, DateTime userInactiveSinceDate)
        {
            int totalRecords = 0;

            try
            {
                lock (SyncRoot)
                {
                    ProfileInfoCollection coll = GetAllInactiveProfiles(authenticationOption, userInactiveSinceDate, 0, int.MaxValue, out totalRecords);
                    foreach (ProfileInfo info in coll)
                    {
                        this.Store.RemoveByUserName(info.UserName);
                    }
                    this.Store.Save();
                }
            }
            catch
            {
                throw;
            }
            return(totalRecords);
        }
Exemple #30
0
        private ProfileInfoCollection ProfileUsersToProfileInfoCollection(IList <ProfileUser> users)
        {
            var profilesCollection = new ProfileInfoCollection();

            foreach (ProfileUser user in users)
            {
                bool isAnonymous;
                if (user.ProfileType == ProfileType.Anonymous)
                {
                    isAnonymous = true;
                }
                else
                {
                    isAnonymous = false;
                }
                var profileInfo = new ProfileInfo(user.Name, isAnonymous, user.LastActivityDate,
                                                  user.LastPropertyChangedDate, -1);
                profilesCollection.Add(profileInfo);
            }

            return(profilesCollection);
        }
Exemple #31
0
        private ProfileInfoCollection BuildProfileInfoCollection(DbDataReader reader, int pageIndex, int pageSize, out int totalRecords)
        {
            int num_read              = 0;
            int num_added             = 0;
            int num_to_skip           = pageIndex * pageSize;
            ProfileInfoCollection pic = new ProfileInfoCollection();

            while (reader.Read())
            {
                if (num_read >= num_to_skip && num_added < pageSize)
                {
                    ProfileInfo pi = ReadProfileInfo(reader);
                    if (pi != null)
                    {
                        pic.Add(pi);
                        num_added++;
                    }
                }
                num_read++;
            }
            totalRecords = num_read;
            return(pic);
        }
    //user made function for the next five functions to use
    private ProfileInfoCollection GetProfile(ProfileAuthenticationOption authenticationOption,
    string usernameToMatch, object userInactiveSinceDate, int pageIndex, int pageSize, out int totalRecords)
    {
        //MAS
        using (OrganizationService service = new OrganizationService(OurConnect()))
        {
            //Retrieve all profiles.

            ConditionExpression appCondition = new ConditionExpression();

            appCondition.AttributeName = consts.appname;
            appCondition.Operator = ConditionOperator.Equal;
            appCondition.Values.Add(_ApplicationName);

            FilterExpression filter = new FilterExpression();
            filter.Conditions.Add(appCondition);

            // If searching for a user name to match, add the command text and parameters.

            if (usernameToMatch != null)
            {
                ConditionExpression usernameCondition = new ConditionExpression();

                usernameCondition.AttributeName = consts.username;
                usernameCondition.Operator = ConditionOperator.Equal;
                usernameCondition.Values.Add(usernameToMatch);

                filter.Conditions.Add(usernameCondition);
            }

            // If searching for inactive profiles,
            // add the command text and parameters.

            if (userInactiveSinceDate != null)
            {
                ConditionExpression lastActivityCondition = new ConditionExpression();

                lastActivityCondition.AttributeName = consts.subject;
                lastActivityCondition.Operator = ConditionOperator.NotBetween;
                lastActivityCondition.Values.Add(userInactiveSinceDate);
                lastActivityCondition.Values.Add(DateTime.Now);

                filter.Conditions.Add(lastActivityCondition);
            }

            // If searching for a anonymous or authenticated profiles,
            // add the command text and parameters.
            ConditionExpression authenticationCondition = new ConditionExpression();

            switch (authenticationOption)
            {
              case ProfileAuthenticationOption.Anonymous:
                authenticationCondition.AttributeName = consts.isanonymous;
                authenticationCondition.Operator = ConditionOperator.Equal;
                authenticationCondition.Values.Add(true);
                break;
              case ProfileAuthenticationOption.Authenticated:
                authenticationCondition.AttributeName = consts.isanonymous;
                authenticationCondition.Operator = ConditionOperator.Equal;
                authenticationCondition.Values.Add(false);
                break;
              default:
                break;
            }

            ProfileInfoCollection profiles = new ProfileInfoCollection();

            try
            {
                QueryExpression query = new QueryExpression(consts.userprofile);

                query.ColumnSet.AddColumn(consts.username);
                query.ColumnSet.AddColumn(consts.isanonymous);
                query.Criteria.AddFilter(filter);

                EntityCollection collection = service.RetrieveMultiple(query);

                totalRecords = collection.Entities.Count;

                if (totalRecords == 0) //No profiles
                    return null;
                else if (pageSize == 0)
                { //Count all profiles
                    for (int i = 0; i < totalRecords; i++)
                    {
                        ProfileInfo p = new ProfileInfo((string)collection.Entities[i][consts.username],
                                                        (bool)collection.Entities[i][consts.isanonymous],
                                                        lastActivity((string)collection.Entities[i][consts.username], String.Empty),
                                                        lastActivity((string)collection.Entities[i][consts.username], "Modified"),
                                                        0);
                        profiles.Add(p);
                    }
                    return profiles;
                }
                else
                { //All other functions
                    var start = pageSize * pageSize;
                    var end = (pageSize * pageSize) + (pageSize - (totalRecords % pageSize));
                    for (int i = start; i < end; i++)
                    {
                        ProfileInfo p = new ProfileInfo((string)collection.Entities[i][consts.username],
                                                        (bool)collection.Entities[i][consts.isanonymous],
                                                        lastActivity((string)collection.Entities[i][consts.username], String.Empty),
                                                        lastActivity((string)collection.Entities[i][consts.username], "Modified"),
                                                        0);
                        profiles.Add(p);
                    }
                    return profiles;
                }
            }

            catch (Exception e)
            {
                throw new Exception("Error in grabbing profiles.", e);//TODO: change exception type
            }
        }
    }
    public override int DeleteProfiles(ProfileInfoCollection profiles)
    {
        //JH
        using (OrganizationService service = new OrganizationService(OurConnect()))
        {
            int deletedProfiles = 0;

            foreach (ProfileInfo p in profiles)
            {
                ConditionExpression usernameCondition = new ConditionExpression();

                usernameCondition.AttributeName = consts.username;
                usernameCondition.Operator = ConditionOperator.Equal;
                usernameCondition.Values.Add(p.UserName);

                FilterExpression filter = new FilterExpression();
                filter.Conditions.Add(usernameCondition);

                QueryExpression query = new QueryExpression(consts.userprofile);
                query.ColumnSet.AddColumn(consts.username);
                query.Criteria.AddFilter(filter);
                EntityCollection collection = service.RetrieveMultiple(query);

                service.Delete(consts.username, collection.Entities[0].Id);
                deletedProfiles++;
            }
            return deletedProfiles;
        }
    }
	public static int DeleteProfiles(ProfileInfoCollection profiles) {}
 // Mangement APIs from ProfileProvider class
 public override int DeleteProfiles(ProfileInfoCollection profiles)
 {
     IProfile dal = Snitz.Membership.Helpers.Factory<IProfile>.Create("Profile");
         dal.TableName = _table;
         return dal.DeleteProfiles(profiles);
 }
    public ProfileInfoCollection FindProfilesByPropertyValue(SettingsProperty property, SearchOperator searchOperator, object value)
    {
        // instantiate an empty ProfileInfoCollection to use it for return
        ProfileInfoCollection pic = new ProfileInfoCollection();

        // try and open the connection and get the results
        try
        {
            // get the connection we're going to use
            using (SqlConnection conn = new SqlConnection(_connectionStringName))
            {

                // instantiate a SettingsPropertyValue from the property
                // to use it to serialize the value for comparison with the database
                SettingsPropertyValue spv = new SettingsPropertyValue(property);
                spv.PropertyValue = value;

                // set common parameters of the aspnet_Profile_FindProfiles stored procedure
                SqlCommand FindProfilesCommand = new SqlCommand("aspnet_Profile_FindProfiles", conn);
                FindProfilesCommand.CommandType = CommandType.StoredProcedure;
                FindProfilesCommand.CommandTimeout = _commandTimeout;
                FindProfilesCommand.Parameters.Add("@ApplicationName", System.Data.SqlDbType.NVarChar, 256).Value = base.ApplicationName;
                FindProfilesCommand.Parameters.Add("@PropertyName", System.Data.SqlDbType.NVarChar, 256).Value = property.Name;
                FindProfilesCommand.Parameters.Add("@OperatorType", System.Data.SqlDbType.Int).Value = (Int32)searchOperator;

                // if the serialized property value is of type string
                // carry on if the size is within allowed limits
                Boolean bTooBig = false;
                if (spv.SerializedValue is String)
                {
                    // if the serialized value is bigger than the PropertyValueString column's length
                    if (((String)spv.SerializedValue).Length > Int32.MaxValue)
                    {
                        bTooBig = true;
                    }
                    else
                    {
                        if (searchOperator == SearchOperator.Contains || searchOperator == SearchOperator.FreeText)
                        {
                            // if the searchOperator is a freetext operator then pass the value unaltered
                            FindProfilesCommand.Parameters.Add("@PropertyValueString",
                                System.Data.SqlDbType.NVarChar, Int32.MaxValue).Value = spv.PropertyValue;
                            FindProfilesCommand.Parameters.Add("@PropertyValueBinary",
                                System.Data.SqlDbType.VarBinary, Int32.MaxValue).Value = DBNull.Value;
                        }
                        else
                        {
                            // otherwise serialise the value before passing it
                            FindProfilesCommand.Parameters.Add("@PropertyValueString",
                                System.Data.SqlDbType.NVarChar, Int32.MaxValue).Value = spv.SerializedValue;
                            FindProfilesCommand.Parameters.Add("@PropertyValueBinary",
                                System.Data.SqlDbType.VarBinary, Int32.MaxValue).Value = DBNull.Value;
                        }

                        // set the parameter @PropertyType to indicate the property is a string
                        FindProfilesCommand.Parameters.Add("@PropertyType", System.Data.SqlDbType.Bit).Value = 0;
                    }
                }
                else
                {
                    if (((SqlBinary)spv.SerializedValue).Length > Int32.MaxValue)
                    {
                        bTooBig = true;
                    }
                    else
                    {
                        if (searchOperator == SearchOperator.Contains || searchOperator == SearchOperator.FreeText)
                        {
                            // if the searchOperator is a freetext operator then pass the value unaltered to the
                            // @PropertyValueString because we are passing a string anyway not a binary
                            FindProfilesCommand.Parameters.Add("@PropertyValueString",
                                System.Data.SqlDbType.NVarChar, Int32.MaxValue).Value = spv.PropertyValue;
                            FindProfilesCommand.Parameters.Add("@PropertyValueBinary",
                                System.Data.SqlDbType.VarBinary, Int32.MaxValue).Value = DBNull.Value;
                        }
                        else
                        {
                            // otherwise just serialise the value and pass it to the @PropertyBinaryValue
                            FindProfilesCommand.Parameters.Add("@PropertyValueString",
                                System.Data.SqlDbType.NVarChar, Int32.MaxValue).Value = DBNull.Value;
                            FindProfilesCommand.Parameters.Add("@PropertyValueBinary",
                                System.Data.SqlDbType.VarBinary, Int32.MaxValue).Value = spv.SerializedValue;
                        }

                        // set the parameter @PropertyType to indicate the property is a binary
                        FindProfilesCommand.Parameters.Add("@PropertyType", System.Data.SqlDbType.Bit).Value = 1;
                    }
                }

                if (bTooBig)
                {
                    // if the size is out of limits throw an exception
                    throw new ProviderException("Property value length is too big.");
                }

                // Open the database
                conn.Open();

                // Get a DataReader for the results we need
                using (SqlDataReader rdr = FindProfilesCommand.ExecuteReader(CommandBehavior.CloseConnection))
                {
                    while (rdr.Read())
                    {
                        // create a ProfileInfo with the data you got back from the current record of the SqlDataReader
                        ProfileInfo pi = new ProfileInfo(rdr.GetString(rdr.GetOrdinal("UserName")),
                            rdr.GetBoolean(rdr.GetOrdinal("IsAnonymous")),
                            DateTime.SpecifyKind(rdr.GetDateTime(rdr.GetOrdinal("LastActivityDate")), DateTimeKind.Utc),
                            DateTime.SpecifyKind(rdr.GetDateTime(rdr.GetOrdinal("LastUpdatedDate")), DateTimeKind.Utc), 0);

                        // add the ProfileInfo you just created to the ProfileInfoCollection that we will return
                        pic.Add(pi);
                    }
                }
            }
        }
        catch (Exception e)
        {
            // if anything went wrong, throw an exception
            throw new ProviderException("An error occured while finding profiles with your search criteria!", e);
        }

        return pic;
    }
 public override ProfileInfoCollection GetAllProfiles(ProfileAuthenticationOption authenticationOption, int pageIndex, int pageSize, out int totalRecords)
 {
     ProfileInfoCollection profiles = new ProfileInfoCollection();
     foreach (FileInfo fi in this.ProfileFiles)
     {
         if (fi != null && fi.Exists == true)
         {
             ProfileInfo profile = new ProfileInfo(this.GetUsernameFromFile(fi.Name), false, fi.LastAccessTime, fi.LastWriteTime, GetProfileSize(fi));
             profiles.Add(profile);
         }
     }
     totalRecords = profiles.Count;
     return profiles;
 }
 public override ProfileInfoCollection FindInactiveProfilesByUserName(ProfileAuthenticationOption authenticationOption, string usernameToMatch, DateTime userInactiveSinceDate, int pageIndex, int pageSize, out int totalRecords)
 {
     ProfileInfoCollection profiles = new ProfileInfoCollection();
     FileInfo fi = this.GetProfileFile(usernameToMatch);
     if (fi != null && fi.Exists == true && fi.LastAccessTime < userInactiveSinceDate)
     {
         ProfileInfo profile = new ProfileInfo(usernameToMatch, false, fi.LastAccessTime, fi.LastWriteTime, GetProfileSize(fi));
         profiles.Add(profile);
     }
     totalRecords = profiles.Count;
     return profiles;
 }
 public override int DeleteProfiles(ProfileInfoCollection profiles)
 {
     throw new Exception("The method or operation is not implemented.");
 }
 public virtual int DeleteProfiles(ProfileInfoCollection profiles)
 {
 }