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; }
public override ProfileInfoCollection FindInactiveProfilesByUserName(ProfileAuthenticationOption authenticationOption, string usernameToMatch, DateTime userInactiveSinceDate, int pageIndex, int pageSize, out int totalRecords) { ProfileInfoCollection infos = new ProfileInfoCollection(); try { User u = NHibernateProviderEntityHelper.GetUser(usernameToMatch); Profile prof = NHibernateProviderEntityHelper.GetProfile(usernameToMatch); infos.Add(new ProfileInfo(u.Name, this.isAnonymous(), u.LastActivityDate, prof.LastActivityDate, prof.PropertyNames.Length + prof.PropertyValuesBinary.Length + prof.PropertyValuesString.Length)); totalRecords = 1; } catch (Exception ex) { throw ExceptionUtil.NewProviderException(this, "FindInactiveProfilesByUserName", ex); } return infos; }
ProfileInfoCollection BuildProfileInfoCollection(DbDataReader reader, out int totalRecords) { ProfileInfoCollection pic = new ProfileInfoCollection(); while (reader.Read()) { ProfileInfo pi = ReadProfileInfo(reader); if (pi != null) { pic.Add(pi); } } totalRecords = 0; if (reader.NextResult()) { if (reader.Read()) { totalRecords = reader.GetInt32(0); } } return(pic); }
private ProfileInfoCollection GetProfileInfo(ProfileAuthenticationOption authenticationOption, string usernameToMatch, object userInactiveSinceDate, int pageIndex, int pageSize, out int totalRecords) { bool isAnonymous = false; var profilesInfoColl = new ProfileInfoCollection(); switch (authenticationOption) { case ProfileAuthenticationOption.Anonymous: isAnonymous = true; break; case ProfileAuthenticationOption.Authenticated: isAnonymous = false; break; default: break; } try { IList<Profiles> profiles = null; //_profileService.GetProfilesByAppplicationNameLastActivityDate(ApplicationName, (DateTime)userInactiveSinceDate, isAnonymous); IList<Profiles> profiles2 = null; if (profiles == null) totalRecords = 0; else if (profiles.Count < 1) totalRecords = 0; else totalRecords = profiles.Count; //IF USER NAME TO MATCH then fileter out those //Membership.FMembershipProvider us = new INCT.FNHProviders.Membership.FMembershipProvider(); //us.g MembershipUserCollection uc = Membership.FindUsersByName(usernameToMatch); if (usernameToMatch != null) { if (totalRecords > 0) { foreach (Profiles p in profiles) { if (IsUserInCollection(uc, usernameToMatch)) profiles2.Add(p); } if (profiles2 == null) profiles2 = profiles; else if (profiles2.Count < 1) profiles2 = profiles; else totalRecords = profiles2.Count; } else profiles2 = profiles; } else profiles2 = profiles; if (totalRecords <= 0) return profilesInfoColl; if (pageSize == 0) return profilesInfoColl; int counter = 0; int startIndex = pageSize * (pageIndex - 1); int endIndex = startIndex + pageSize - 1; foreach (Profiles p in profiles2) { if (counter >= endIndex) break; if (counter >= startIndex) { ProfileInfo pi = GetProfileInfoFromProfile(p); profilesInfoColl.Add(pi); } counter++; } } catch (Exception e) { throw e; } return profilesInfoColl; }
private ProfileInfoCollection GetProfiles( ProfileAuthenticationOption authenticationOption, string usernameToMatch, DateTime userInactiveSinceDate, int pageIndex, int pageSize, out int totalRecords) { List<string> whereClauses = new List<string>(); using (MySqlConnection c = new MySqlConnection(connectionString)) { c.Open(); MySqlCommand cmd = new MySqlCommand( @"SELECT p.*, u.name, u.isAnonymous, u.lastActivityDate, LENGTH(p.stringdata) + LENGTH(p.binarydata) AS profilesize FROM my_aspnet_profiles p JOIN my_aspnet_users u ON u.id = p.userId WHERE u.applicationId = @appId", c); cmd.Parameters.AddWithValue("@appId", app.FetchId(c)); if (usernameToMatch != null) { cmd.CommandText += " AND u.name LIKE @userName"; cmd.Parameters.AddWithValue("@userName", usernameToMatch); } if (userInactiveSinceDate != DateTime.MinValue) { cmd.CommandText += " AND u.lastActivityDate < @lastActivityDate"; cmd.Parameters.AddWithValue("@lastActivityDate", userInactiveSinceDate); } if (authenticationOption == ProfileAuthenticationOption.Anonymous) cmd.CommandText += " AND u.isAnonymous = 1"; else if (authenticationOption == ProfileAuthenticationOption.Authenticated) cmd.CommandText += " AND u.isAnonymous = 0"; cmd.CommandText += String.Format(" LIMIT {0},{1}", pageIndex * pageSize, pageSize); ProfileInfoCollection pic = new ProfileInfoCollection(); using (MySqlDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { ProfileInfo pi = new ProfileInfo( reader.GetString("name"), reader.GetBoolean("isAnonymous"), reader.GetDateTime("lastActivityDate"), reader.GetDateTime("lastUpdatedDate"), reader.GetInt32("profilesize")); pic.Add(pi); } } cmd.CommandText = "SELECT FOUND_ROWS()"; totalRecords = Convert.ToInt32(cmd.ExecuteScalar()); return pic; } }
private ProfileInfoCollection GetProfilesForQuery(SqlParameter[] args, ProfileAuthenticationOption authenticationOption, int pageIndex, int pageSize, out int totalRecords) { ProfileInfoCollection infos2; if (pageIndex < 0) { throw new ArgumentException(System.Web.SR.GetString("PageIndex_bad"), "pageIndex"); } if (pageSize < 1) { throw new ArgumentException(System.Web.SR.GetString("PageSize_bad"), "pageSize"); } long num = ((pageIndex * pageSize) + pageSize) - 1L; if (num > 0x7fffffffL) { throw new ArgumentException(System.Web.SR.GetString("PageIndex_PageSize_bad"), "pageIndex and pageSize"); } try { SqlConnectionHolder connection = null; SqlDataReader reader = null; try { connection = SqlConnectionHelper.GetConnection(this._sqlConnectionString, true); this.CheckSchemaVersion(connection.Connection); SqlCommand command = new SqlCommand("dbo.aspnet_Profile_GetProfiles", connection.Connection) { CommandTimeout = this.CommandTimeout, CommandType = CommandType.StoredProcedure }; command.Parameters.Add(this.CreateInputParam("@ApplicationName", SqlDbType.NVarChar, this.ApplicationName)); command.Parameters.Add(this.CreateInputParam("@ProfileAuthOptions", SqlDbType.Int, (int) authenticationOption)); command.Parameters.Add(this.CreateInputParam("@PageIndex", SqlDbType.Int, pageIndex)); command.Parameters.Add(this.CreateInputParam("@PageSize", SqlDbType.Int, pageSize)); foreach (SqlParameter parameter in args) { command.Parameters.Add(parameter); } reader = command.ExecuteReader(CommandBehavior.SequentialAccess); ProfileInfoCollection infos = new ProfileInfoCollection(); while (reader.Read()) { string username = reader.GetString(0); bool boolean = reader.GetBoolean(1); DateTime lastActivityDate = DateTime.SpecifyKind(reader.GetDateTime(2), DateTimeKind.Utc); DateTime lastUpdatedDate = DateTime.SpecifyKind(reader.GetDateTime(3), DateTimeKind.Utc); int size = reader.GetInt32(4); infos.Add(new ProfileInfo(username, boolean, lastActivityDate, lastUpdatedDate, size)); } totalRecords = infos.Count; if (reader.NextResult() && reader.Read()) { totalRecords = reader.GetInt32(0); } infos2 = infos; } finally { if (reader != null) { reader.Close(); } if (connection != null) { connection.Close(); connection = null; } } } catch { throw; } return infos2; }
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; }
// 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 ProfileInfoCollection GetProfileInfo( ProfileAuthenticationOption authenticationOption, string usernameToMatch, DateTime? userInactiveSinceDate, int pageIndex, int pageSize, out int totalRecords) { totalRecords = 0; ProfileInfoCollection profiles = new ProfileInfoCollection(); // Count profiles only. if (pageSize == 0) return profiles; int counter = 0; int startIndex = pageSize * (pageIndex - 1); int endIndex = startIndex + pageSize - 1; bool? isAnonymous = null; if (authenticationOption == ProfileAuthenticationOption.Anonymous) isAnonymous = true; else if (authenticationOption == ProfileAuthenticationOption.Authenticated) isAnonymous = false; foreach (CustomProfile profile in Accessor.GetProfile( isAnonymous, usernameToMatch, userInactiveSinceDate, _applicationName, out totalRecords)) { if (counter >= startIndex) { ProfileInfo p = new ProfileInfo( profile.UserName, profile.IsAnonymous ?? true, profile.LastActivityDate ?? DateTime.MinValue, profile.LastUpdatedDate ?? DateTime.MinValue, 0); profiles.Add(p); } if (counter >= endIndex) break; counter++; } return profiles; }
/// <summary> /// Retrieves profile information for profiles in which the user name matches the specified user names. /// </summary> /// <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="usernameToMatch">The user name to search for.</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> /// <returns> /// A <see cref="T:System.Web.Profile.ProfileInfoCollection"/> containing user-profile information for profiles where the user name matches the supplied <paramref name="usernameToMatch"/> parameter. /// </returns> public override ProfileInfoCollection FindProfilesByUserName(ProfileAuthenticationOption authenticationOption, string usernameToMatch, int pageIndex, int pageSize, out int totalRecords) { // Validate arguments if (pageIndex < 0) throw new ArgumentOutOfRangeException("pageIndex"); if (pageSize < 1) throw new ArgumentOutOfRangeException("pageSize"); if (authenticationOption == ProfileAuthenticationOption.Anonymous) { // Anonymous profiles not supported totalRecords = 0; return new ProfileInfoCollection(); } using (DataTable dt = new DataTable()) { // Prepare sql command using (SqlConnection db = this.OpenDatabase()) using (SqlCommand cmd = new SqlCommand("", db)) { if (string.IsNullOrEmpty(usernameToMatch)) { cmd.CommandText = this.ExpandCommand("SELECT $UserName AS UserName, $LastUpdate AS LastUpdate FROM $Profiles WHERE $UserName=@UserName ORDER BY $UserName"); } else { cmd.CommandText = this.ExpandCommand("SELECT $UserName AS UserName, $LastUpdate AS LastUpdate FROM $Profiles WHERE $UserName=@UserName ORDER BY $UserName"); cmd.Parameters.Add("@UserName", SqlDbType.VarChar, 100).Value = usernameToMatch; } using (SqlDataAdapter da = new SqlDataAdapter(cmd)) da.Fill(dt); } // Prepare paging ProfileInfoCollection pic = new ProfileInfoCollection(); totalRecords = dt.Rows.Count; int minIndex = pageIndex * pageSize; if (minIndex > totalRecords - 1) return pic; int maxIndex = minIndex + pageSize - 1; if (maxIndex > totalRecords - 1) maxIndex = totalRecords - 1; // Populate collection from data table for (int i = minIndex; i <= maxIndex; i++) { pic.Add(new ProfileInfo(System.Convert.ToString(dt.Rows[i]["UserName"]), false, DateTime.Now, System.Convert.ToDateTime(dt.Rows[i]["LastUpdate"]), 0)); } return pic; } }
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; }
///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// // Private methods ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// private ProfileInfoCollection GetProfilesForQuery(SqlParameter [] args, ProfileAuthenticationOption authenticationOption, int pageIndex, int pageSize, out int totalRecords) { if ( pageIndex < 0 ) throw new ArgumentException(SR.GetString(SR.PageIndex_bad), "pageIndex"); if ( pageSize < 1 ) throw new ArgumentException(SR.GetString(SR.PageSize_bad), "pageSize"); long upperBound = (long)pageIndex * pageSize + pageSize - 1; if ( upperBound > Int32.MaxValue ) { throw new ArgumentException(SR.GetString(SR.PageIndex_PageSize_bad), "pageIndex and pageSize"); } try { SqlConnectionHolder holder = null; SqlDataReader reader = null; try { holder = SqlConnectionHelper.GetConnection(_sqlConnectionString, true); CheckSchemaVersion( holder.Connection ); SqlCommand cmd = new SqlCommand("dbo.aspnet_Profile_GetProfiles", holder.Connection); cmd.CommandTimeout = CommandTimeout; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(CreateInputParam("@ApplicationName", SqlDbType.NVarChar, ApplicationName)); cmd.Parameters.Add(CreateInputParam("@ProfileAuthOptions", SqlDbType.Int, (int) authenticationOption)); cmd.Parameters.Add(CreateInputParam("@PageIndex", SqlDbType.Int, pageIndex)); cmd.Parameters.Add(CreateInputParam("@PageSize", SqlDbType.Int, pageSize)); foreach (SqlParameter arg in args) cmd.Parameters.Add(arg); reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess); ProfileInfoCollection profiles = new ProfileInfoCollection(); while (reader.Read()) { string username; DateTime dtLastActivity, dtLastUpdated; bool isAnon; username = reader.GetString(0); isAnon = reader.GetBoolean(1); dtLastActivity = DateTime.SpecifyKind(reader.GetDateTime(2), DateTimeKind.Utc); dtLastUpdated = DateTime.SpecifyKind(reader.GetDateTime(3), DateTimeKind.Utc); int size = reader.GetInt32(4); profiles.Add(new ProfileInfo(username, isAnon, dtLastActivity, dtLastUpdated, size)); } totalRecords = profiles.Count; if (reader.NextResult()) if (reader.Read()) totalRecords = reader.GetInt32(0); return profiles; } finally { if (reader != null) reader.Close(); if( holder != null ) { holder.Close(); holder = null; } } } catch { throw; } }
/// <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> /// <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="usernameToMatch">The user name to search for.</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"/> value 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> /// <returns> /// A <see cref="T:System.Web.Profile.ProfileInfoCollection"/> containing user profile information for inactive profiles where the user name matches the supplied <paramref name="usernameToMatch"/> parameter. /// </returns> public override ProfileInfoCollection FindInactiveProfilesByUserName(ProfileAuthenticationOption authenticationOption, string usernameToMatch, DateTime userInactiveSinceDate, int pageIndex, int pageSize, out int totalRecords) { ProfileInfoCollection infos = new ProfileInfoCollection(); try { using (var session = Database.Context.CurrentSession) { User u = UserLogic.GetUser(session, usernameToMatch); Profile prof = ProfileLogic.GetProfile(session, usernameToMatch); infos.Add(new ProfileInfo(u.Name, this.isAnonymous(), u.LastActivityDate, prof.LastActivityDate, prof.PropertyNames.Length + prof.PropertyValuesBinary.Length + prof.PropertyValuesString.Length)); totalRecords = 1; } } catch (Exception ex) { throw new ProviderException("Unable to find Inactive Profiles By Username", ex); } return infos; }
/// <summary> /// Creates the profile info collection. /// </summary> /// <param name="profiles">The profiles.</param> /// <returns></returns> protected internal ProfileInfoCollection CreateProfileInfoCollection(IEnumerable<XmlProfile> profiles) { ProfileInfoCollection collection = new ProfileInfoCollection(); foreach (var p in profiles) { int size = p.Names.Length + p.ValuesString.Length + p.ValuesBinary.Length; collection.Add(new ProfileInfo( p.UserName, !p.Authenticated, p.LastUpdated, p.LastUpdated, size)); } return collection; }
/// <summary> /// When overridden in a derived class, retrieves profile information for profiles in which the user name matches the specified user names. /// </summary> /// <returns> /// A <see cref="T:System.Web.Profile.ProfileInfoCollection"/> containing user-profile information for profiles where the user name matches the supplied <paramref name="usernameToMatch"/> parameter. /// </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="usernameToMatch">The user name to search for. /// </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 FindProfilesByUserName(ProfileAuthenticationOption authenticationOption, string usernameToMatch, 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; ProfileList profileList = ProfileList.GetProfileList(usernameToMatch); 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; }
/// <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; ProfileList profileList = ProfileList.NewList(); foreach (var item in ProfileList.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; }
public override ProfileInfoCollection FindProfilesByUserName(ProfileAuthenticationOption authenticationOption, string usernameToMatch, int pageIndex, int pageSize, out int totalRecords) { if(usernameToMatch == null) { throw new ArgumentNullException("usernameToMatch"); } var pic = new ProfileInfoCollection(); var user = GetUserFromUserName(usernameToMatch); totalRecords = 0; if(user != null) { var username = GetUsername(user); pic.Add(new ProfileInfo(username, user.Properties.IsAnonymous, user.Properties.LastActivityDate, user.Properties.LastUpdatedDate, 0)); totalRecords = 1; } return pic; }
///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// // Private methods ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// private ProfileInfoCollection GetProfilesForQuery(SqlParameter [] args, ProfileAuthenticationOption authenticationOption, int pageIndex, int pageSize, out int totalRecords) { if (pageIndex < 0) { throw new ArgumentException(SR.GetString(SR.PageIndex_bad), "pageIndex"); } if (pageSize < 1) { throw new ArgumentException(SR.GetString(SR.PageSize_bad), "pageSize"); } long upperBound = (long)pageIndex * pageSize + pageSize - 1; if (upperBound > Int32.MaxValue) { throw new ArgumentException(SR.GetString(SR.PageIndex_PageSize_bad), "pageIndex and pageSize"); } try { SqlConnectionHolder holder = null; SqlDataReader reader = null; try { holder = SqlConnectionHelper.GetConnection(_sqlConnectionString, true); CheckSchemaVersion(holder.Connection); SqlCommand cmd = new SqlCommand("dbo.aspnet_Profile_GetProfiles", holder.Connection); cmd.CommandTimeout = CommandTimeout; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(CreateInputParam("@ApplicationName", SqlDbType.NVarChar, ApplicationName)); cmd.Parameters.Add(CreateInputParam("@ProfileAuthOptions", SqlDbType.Int, (int)authenticationOption)); cmd.Parameters.Add(CreateInputParam("@PageIndex", SqlDbType.Int, pageIndex)); cmd.Parameters.Add(CreateInputParam("@PageSize", SqlDbType.Int, pageSize)); foreach (SqlParameter arg in args) { cmd.Parameters.Add(arg); } reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess); ProfileInfoCollection profiles = new ProfileInfoCollection(); while (reader.Read()) { string username; DateTime dtLastActivity, dtLastUpdated; bool isAnon; username = reader.GetString(0); isAnon = reader.GetBoolean(1); dtLastActivity = DateTime.SpecifyKind(reader.GetDateTime(2), DateTimeKind.Utc); dtLastUpdated = DateTime.SpecifyKind(reader.GetDateTime(3), DateTimeKind.Utc); int size = reader.GetInt32(4); profiles.Add(new ProfileInfo(username, isAnon, dtLastActivity, dtLastUpdated, size)); } totalRecords = profiles.Count; if (reader.NextResult()) { if (reader.Read()) { totalRecords = reader.GetInt32(0); } } return(profiles); } finally { if (reader != null) { reader.Close(); } if (holder != null) { holder.Close(); holder = null; } } } catch { throw; } }
/// <summary> /// When overridden in a derived class, retrieves user profile data for all profiles in the data source. /// </summary> /// <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="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> /// <returns> /// A <see cref="T:System.Web.Profile.ProfileInfoCollection"/> containing user-profile information for all profiles in the data source. /// </returns> public override ProfileInfoCollection GetAllProfiles(ProfileAuthenticationOption authenticationOption, int pageIndex, int pageSize, out int totalRecords) { using (var session = Database.Context.CurrentSession) { IEnumerable<Profile> _profiles = ProfileLogic.GetAllProfiles(session, pageIndex, pageSize, out totalRecords); ProfileInfoCollection infos = new ProfileInfoCollection(); foreach (Profile prof in _profiles) { User u = prof.User; infos.Add(new ProfileInfo(u.Name, this.isAnonymous(), u.LastActivityDate, prof.LastActivityDate, prof.PropertyNames.Length + prof.PropertyValuesBinary.Length + prof.PropertyValuesString.Length)); } return infos; } }
/// <summary> /// Returns a user's profile /// Currently assumes a single user will match the token. /// </summary> /// <param name="authenticationOption"></param> /// <param name="usernameToMatch"></param> /// <param name="pageIndex"></param> /// <param name="pageSize"></param> /// <param name="totalRecords"></param> /// <returns></returns> public override ProfileInfoCollection FindProfilesByUserName(ProfileAuthenticationOption authenticationOption, string usernameToMatch, int pageIndex, int pageSize, out int totalRecords) { // TODO: Take paging into account // TODO: Take auth option into account totalRecords = 0; ProfileInfoCollection profiles = new ProfileInfoCollection(); GetAttributesRequest request = new GetAttributesRequest().WithDomainName(domain).WithItemName(usernameToMatch); GetAttributesResponse response = client.GetAttributes(request); if (response.GetAttributesResult.Attribute.Count > 0) { ProfileInfo profile = null; List<Attribute> attributes = response.GetAttributesResult.Attribute; MCItem item = new MCItem(); item.Domain = domain; item.ItemName = usernameToMatch; item.Attributes = new Hashtable(); foreach (Attribute attribute in attributes) { item.Attributes.Add(attribute.Name, attribute.Value); } bool Anon = bool.Parse(item.Get("Anon").Replace("", "false")); DateTime LastActivity = DateTime.Parse(item.Get("LastActivity")); DateTime LastUpdated = DateTime.Parse(item.Get("LastUpdated")); profile = new ProfileInfo(item.Id, Anon, LastActivity, LastUpdated, 0); profiles.Add(profile); } totalRecords = profiles.Count; return profiles; }
public override ProfileInfoCollection GetAllProfiles(ProfileAuthenticationOption authenticationOption, int pageIndex, int pageSize, out int totalRecords) { // TODO: Take paging into account // TODO: Take auth option into account totalRecords = 0; ProfileInfoCollection profiles = new ProfileInfoCollection(); SelectRequest request = new SelectRequest().WithSelectExpression("select * from " + domain); SelectResponse response = client.Select(request); if (response.SelectResult.Item.Count > 0) { foreach (Item _item in response.SelectResult.Item) { ProfileInfo profile = null; List<Attribute> attributes = _item.Attribute; MCItem item = new MCItem(); item.Domain = domain; item.ItemName = _item.Name; item.Attributes = new Hashtable(); foreach (Attribute attribute in attributes) { item.Attributes.Add(attribute.Name, attribute.Value); } bool Anon = bool.Parse(item.Get("Anon").Replace("", "false")); DateTime LastActivity = DateTime.Parse(item.Get("LastActivity")); DateTime LastUpdated = DateTime.Parse(item.Get("LastUpdated")); profile = new ProfileInfo(item.Id, Anon, LastActivity, LastUpdated, 0); profiles.Add(profile); } } totalRecords = profiles.Count; return profiles; }
private ProfileInfoCollection GetProfileInfo( ProfileAuthenticationOption authenticationOption , string usernameToMatch, DateTime? userInactiveSinceDate, int pageIndex, int pageSize, out int totalRecords) { bool isAnonymous = authenticationOption == ProfileAuthenticationOption.Anonymous; var q = UnitOfWork.Current.CreateRepository<Profile>() .Where(p => p.ApplicationName == ApplicationName) .Where(p => p.IsAnonymous == isAnonymous); if (usernameToMatch.HasValue()) q = q.Where(p => p.User.UserName.Contains(usernameToMatch)); if (userInactiveSinceDate != null) q = q.Where(p => p.LastActivityDate == userInactiveSinceDate.Value); totalRecords = q.Count(); var profiles = q .Take(pageSize) .Skip(pageSize * pageIndex) .Select(p => new ProfileInfo(p.User.UserName, p.IsAnonymous, p.LastActivityDate, p.LastUpdatedDate, 0)) .ToList(); var items = new ProfileInfoCollection(); foreach (var item in profiles) items.Add(item); return items; }
private ProfileInfoCollection GetProfilesForQuery(string usernameToMatch, DateTime inactiveSinceUtc, ProfileAuthenticationOption auth, int pageIndex, int pageSize, out int totalRecords) { SecUtility.CheckParameter(ref usernameToMatch, true, true, false, Constants.MaxTableUsernameLength, "usernameToMatch"); bool startsWith = false; if (usernameToMatch.Contains('%')) { if (usernameToMatch.IndexOf('%') != usernameToMatch.Length - 1) { throw new ArgumentException("The TableStorageProfileProvider only supports search strings that contain '%' as the last character!"); } usernameToMatch = usernameToMatch.Substring(0, usernameToMatch.Length - 1); startsWith = true; } if (inactiveSinceUtc < Configuration.MinSupportedDateTime) { throw new ArgumentException("DateTime not supported by data source."); } if (pageIndex < 0) { throw new ArgumentException("pageIndex must not be a negative integer."); } if (pageSize < 1) { throw new ArgumentException("pageSize must be a positive integer (strictly larger than zero)."); } long upperBound = (long)pageIndex * pageSize + pageSize - 1; if (upperBound > Int32.MaxValue) { throw new ArgumentException("pageIndex and pageSize too big."); } try { ProfileInfoCollection infoColl = new ProfileInfoCollection(); totalRecords = 0; TableServiceContext context = CreateDataServiceContext(); List<MembershipRow> users = GetUsersInactive(context, usernameToMatch, startsWith, auth, inactiveSinceUtc); // default order is by user name (not by escaped user name as it appears in the key) users.Sort(); int startIndex = pageIndex * pageSize; int endIndex = startIndex + pageSize; int i = 0; bool userMatches = true; MembershipRow user; for (i = startIndex; i < endIndex && i < users.Count && userMatches; i++) { user = users.ElementAt<MembershipRow>(i); if (startsWith && !string.IsNullOrEmpty(usernameToMatch)) { if (!user.UserName.StartsWith(usernameToMatch, StringComparison.Ordinal)) { userMatches = false; continue; } } infoColl.Add(new ProfileInfo(user.UserName, user.IsAnonymous, user.LastActivityDateUtc.ToLocalTime(), user.ProfileLastUpdatedUtc.ToLocalTime(), user.ProfileSize)); } totalRecords = infoColl.Count; return infoColl; } catch (Exception e) { throw new ProviderException("Error accessing the data store.", e); } }
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) { SystemUserEntity userEntity = userBusinessProxy.FindById(prof.UserID); infos.Add(new ProfileInfo(userEntity.UserLoginID, false, userEntity.LastActivityDate, prof.LastUpdatedDate, 2000)); } return infos; }
///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// // Private methods ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// private ProfileInfoCollection GetProfilesForQuery(string sqlQuery, OleDbParameter[] args, 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"); } try { AccessConnectionHolder holder = AccessConnectionHelper.GetConnection(_DatabaseFileName, true); ProfileInfoCollection profiles = new ProfileInfoCollection(); OleDbDataReader reader = null; try { OleDbCommand cmd = new OleDbCommand(sqlQuery, holder.Connection); cmd.Parameters.Add(new OleDbParameter("@AppId", GetApplicationId(holder))); int len = args.Length; for (int iter = 0; iter < len; iter++) cmd.Parameters.Add(args[iter]); reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess); totalRecords = 0; while (reader.Read()) { totalRecords++; if (totalRecords - 1 < lBound || totalRecords - 1 > uBound) continue; string username; DateTime dtLastActivity, dtLastUpdated; bool isAnon; username = reader.GetString(0); isAnon = reader.GetBoolean(1); dtLastActivity = reader.GetDateTime(2); dtLastUpdated = reader.GetDateTime(3); int size = reader.GetInt32(4); profiles.Add(new ProfileInfo(username, isAnon, dtLastActivity, dtLastUpdated, size)); } return profiles; } catch (Exception e) { throw AccessConnectionHelper.GetBetterException(e, holder); } finally { if (reader != null) reader.Close(); holder.Close(); } } catch { throw; } }
// // 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. // /// <summary> /// Gets the profile info. /// </summary> /// <param name="authenticationOption">The authentication option.</param> /// <param name="usernameToMatch">The username to match.</param> /// <param name="userInactiveSinceDate">The user inactive since date.</param> /// <param name="pageIndex">Index of the page.</param> /// <param name="pageSize">Size of the page.</param> /// <param name="totalRecords">The total records.</param> /// <returns></returns> private ProfileInfoCollection GetProfileInfo( ProfileAuthenticationOption authenticationOption, string usernameToMatch, object userInactiveSinceDate, int pageIndex, int pageSize, out int totalRecords) { MongoClient client = new MongoClient(connectionString); MongoServer server = client.GetServer(); // connect to the mongoDB url. MongoDatabase ProviderDB = server.GetDatabase(pMongoProviderDatabaseName, WriteConcern.Acknowledged); MongoCollection<BsonDocument> profiles = ProviderDB.GetCollection(pMongoProviderProfileCollectionName); var query = Query.EQ("ApplicationNameLowerCase", pApplicationName.ToLower()); // If searching for a user name to match, add the command text and parameters. if (!String.IsNullOrWhiteSpace(usernameToMatch)) { query = Query.And(query, Query.EQ("UsernameLowerCase", usernameToMatch.Trim().ToLower())); } // If searching for inactive profiles, // add the command text and parameters. if (userInactiveSinceDate != null) { query = Query.And(query, Query.LT("LastActivityDate", (DateTime)userInactiveSinceDate)); } // If searching for a anonymous or authenticated profiles, // add the command text and parameters. switch (authenticationOption) { case ProfileAuthenticationOption.Anonymous: query = Query.And(query, Query.EQ("IsAnonymous", true)); break; case ProfileAuthenticationOption.Authenticated: query = Query.And(query, Query.EQ("IsAnonymous", false)); break; default: break; } ProfileInfoCollection profilesCollection = new ProfileInfoCollection(); try { // Get the profile count. totalRecords = (int) profiles.Count(query); // No profiles found. if (totalRecords == 0) { return profilesCollection; } // Count profiles only. if (pageSize == 0) { return profilesCollection; } var cursor = profiles.Find(query); cursor.SetFields(new string[] {"Username", "LastActivityDate", "LastUpdatedDate", "IsAnonymous"}); cursor.Skip = Math.Max(0, pageSize * (pageIndex - 1)); cursor.Limit = pageSize; foreach(var profile in cursor) { ProfileInfo p = GetProfileInfoFromReader(profile); profilesCollection.Add(p); } } catch (ApplicationException e) { if (WriteExceptionsToEventLog) { WriteToEventLog(e, "GetProfileInfo"); throw new ProviderException(exceptionMessage, e); } else { throw e; } } return profilesCollection; }
private static ProfileInfoCollection GetProfilesForQuery(string sqlQuery, SQLiteParameter[] args, 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"); } SQLiteConnection cn = GetDBConnectionForProfile(); try { ProfileInfoCollection profiles = new ProfileInfoCollection(); using (SQLiteCommand cmd = cn.CreateCommand()) { cmd.CommandText = sqlQuery; for (int iter = 0; iter < args.Length; iter++) { cmd.Parameters.Add(args[iter]); } if (cn.State == ConnectionState.Closed) cn.Open(); using (SQLiteDataReader dr = cmd.ExecuteReader()) { totalRecords = 0; while (dr.Read()) { totalRecords++; if ((totalRecords - 1 < lBound) || (totalRecords - 1 > uBound)) continue; string username = dr.GetString(0); bool isAnon = dr.GetBoolean(1); DateTime dtLastActivity = dr.GetDateTime(2); DateTime dtLastUpdated = dr.GetDateTime(3); int size = dr.GetInt32(4); profiles.Add(new ProfileInfo(username, isAnon, dtLastActivity, dtLastUpdated, size)); } return profiles; } } } finally { if (!IsTransactionInProgress()) cn.Dispose(); } }
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.GetProfiles(this.ApplicationName, pageIndex, pageSize, userNameToMatch, inactiveSinceDate); // create an instance for the profiles... ProfileInfoCollection profiles = new ProfileInfoCollection(); DataTable allProfilesDT = DB.Current.GetProfiles(this.ApplicationName, pageIndex, pageSize, userNameToMatch, inactiveSinceDate); //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["LastUpdated"]), 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] ); // We get rid of the dataset in the future and added TotalRecords toallProfilesDT as first column if (allProfilesDT.Rows.Count > 0) totalRecords = Convert.ToInt32(allProfilesDT.Rows[0][0]); else totalRecords = 0; return profiles; }
private ProfileInfoCollection GetProfilesForQuery(SqlCeParameter[] args, ProfileAuthenticationOption authenticationOption, int pageIndex, int pageSize, out int totalRecords) { if (pageIndex < 0) throw new ArgumentException("PageIndex must be greater than -1", "pageIndex"); if (pageSize < 1) throw new ArgumentException("PageSize must be greater than 0", "pageSize"); long lowerBound = pageIndex * pageSize; long upperBound = (long)pageSize - 1 + lowerBound; if (upperBound > Int32.MaxValue) { throw new ArgumentException("The combination of pageIndex and pageSize cannot exceed the maximum value of System.Int32.", "pageIndex and pageSize"); } SqlCeDataReader reader = null; totalRecords = 0; try { using (SqlCeConnection conn = new SqlCeConnection(connectionString)) { conn.Open(); using (SqlCeCommand cmd = new SqlCeCommand( @" SELECT aspnet_Users.UserName, aspnet_Users.IsAnonymous, aspnet_Users.LastActivityDate, aspnet_Profile.LastUpdatedDate, DATALENGTH(aspnet_Profile.PropertyNames) + DATALENGTH(aspnet_Profile.PropertyValuesString) + DATALENGTH(aspnet_Profile.PropertyValuesBinary) FROM aspnet_Users, aspnet_Profile WHERE aspnet_Users.UserId = aspnet_Profile.UserId AND ApplicationId = @ApplicationId AND ( @ProfileAuthOptions = 2 OR (@ProfileAuthOptions = 0 AND IsAnonymous = 1) OR (@ProfileAuthOptions = 1 AND IsAnonymous = 0) )" , conn)) { cmd.Parameters.Add(CreateInputParam("@ApplicationId", SqlDbType.UniqueIdentifier, SqlCeMembershipUtils.GetApplicationId(conn.ConnectionString, ApplicationName))); cmd.Parameters.Add(CreateInputParam("@ProfileAuthOptions", SqlDbType.Int, (int)authenticationOption)); cmd.Parameters.Add(CreateInputParam("@PageLowerBound", SqlDbType.Int, lowerBound)); cmd.Parameters.Add(CreateInputParam("@PageSize", SqlDbType.Int, pageSize)); foreach (SqlCeParameter arg in args) { cmd.Parameters.Add(arg); switch (arg.ParameterName) { case "@InactiveSinceDate": cmd.CommandText += " AND (@InactiveSinceDate IS NULL OR aspnet_Users.LastActivityDate <= @InactiveSinceDate)"; break; case "@UserNameToMatch": cmd.CommandText += " AND (@UserNameToMatch IS NULL OR LoweredUserName LIKE LOWER(@UserNameToMatch))"; break; } } // append paging cmd.CommandText += " ORDER BY aspnet_Users.Username OFFSET @PageLowerBound ROWS FETCH NEXT @PageSize ROWS ONLY"; reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess); ProfileInfoCollection profiles = new ProfileInfoCollection(); while (reader.Read()) { string username; DateTime dtLastActivity, dtLastUpdated; bool isAnon; username = reader.GetString(0); isAnon = reader.GetBoolean(1); dtLastActivity = DateTime.SpecifyKind(reader.GetDateTime(2), DateTimeKind.Utc); dtLastUpdated = DateTime.SpecifyKind(reader.GetDateTime(3), DateTimeKind.Utc); int size = reader.GetInt32(4); profiles.Add(new ProfileInfo(username, isAnon, dtLastActivity, dtLastUpdated, size)); } totalRecords = profiles.Count; if (reader.NextResult()) if (reader.Read()) totalRecords = reader.GetInt32(0); return profiles; } } } catch { throw; } }
//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 dal.GetProfileInfo((int)authenticationOption, usernameToMatch, dt, 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; }
///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// // Private methods ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// private ProfileInfoCollection GetProfilesForQuery(SqlParameter[] insertArgs, int pageIndex, int pageSize, StringBuilder insertQuery, out int totalRecords) { if (pageIndex < 0) throw new ArgumentException("pageIndex"); if (pageSize < 1) throw new ArgumentException("pageSize"); long lowerBound = (long)pageIndex * pageSize; long upperBound = lowerBound + pageSize - 1; if (upperBound > Int32.MaxValue) { throw new ArgumentException("pageIndex and pageSize"); } SqlConnection conn = null; SqlDataReader reader = null; SqlCommand cmd = null; try { conn = new SqlConnection(_sqlConnectionString); conn.Open(); StringBuilder cmdStr = new StringBuilder(200); // Create a temp table TO store the select results cmd = new SqlCommand("CREATE TABLE #PageIndexForProfileUsers(IndexId int IDENTITY (0, 1) NOT NULL, UserId uniqueidentifier)", conn); cmd.CommandTimeout = CommandTimeout; cmd.ExecuteNonQuery(); cmd.Dispose(); insertQuery.Append(" ORDER BY UserName"); cmd = new SqlCommand(insertQuery.ToString(), conn); cmd.CommandTimeout = CommandTimeout; if (insertArgs != null) { foreach (SqlParameter arg in insertArgs) cmd.Parameters.Add(arg); } cmd.ExecuteNonQuery(); cmd.Dispose(); cmdStr = new StringBuilder(200); cmdStr.Append("SELECT u.UserName, u.IsAnonymous, u.LastActivityDate, p.LastUpdatedDate FROM vw_aspnet_Users u, ").Append(_table); cmdStr.Append(" p, #PageIndexForProfileUsers i WHERE u.UserId = p.UserId AND p.UserId = i.UserId AND i.IndexId >= "); cmdStr.Append(lowerBound).Append(" AND i.IndexId <= ").Append(upperBound); cmd = new SqlCommand(cmdStr.ToString(), conn); cmd.CommandTimeout = CommandTimeout; reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess); ProfileInfoCollection profiles = new ProfileInfoCollection(); while (reader.Read()) { string username; DateTime dtLastActivity, dtLastUpdated = DateTime.UtcNow; bool isAnon; username = reader.GetString(0); isAnon = reader.GetBoolean(1); dtLastActivity = DateTime.SpecifyKind(reader.GetDateTime(2), DateTimeKind.Utc); dtLastUpdated = DateTime.SpecifyKind(reader.GetDateTime(3), DateTimeKind.Utc); profiles.Add(new ProfileInfo(username, isAnon, dtLastActivity, dtLastUpdated, 0)); } totalRecords = profiles.Count; if (reader != null) { reader.Close(); reader = null; } cmd.Dispose(); // Cleanup, REVIEW: should move to finally? cmd = new SqlCommand("DROP TABLE #PageIndexForProfileUsers", conn); cmd.ExecuteNonQuery(); return profiles; } catch (Exception ex) { throw ex; } finally { if (reader != null) reader.Close(); if (cmd != null) cmd.Dispose(); if (conn != null) { conn.Close(); conn = null; } } }
//////////////////////////////////////////////////////// // Private Methods // //----------------------------------------------------// //////////////////////////////////////////////////////// // Get Profiles for Query // //----------------------------------------------------// private ProfileInfoCollection GetProfilesForQuery(string sqlQuery, SqliteParameter[] args, 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"); } SqliteConnection holder = new SqliteConnection(_connectionString); ProfileInfoCollection profiles = new ProfileInfoCollection(); SqliteDataReader reader = null; holder.Open(); SqliteCommand cmd = new SqliteCommand(sqlQuery, holder); int len = args.Length; for (int iter = 0; iter < len; iter++) reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess); if (len == 0) { reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess); } totalRecords = 0; while (reader.Read()) { totalRecords++; if (totalRecords - 1 < lBound || totalRecords - 1 > uBound) continue; string username; DateTime dtLastActivity, dtLastUpdated; bool isAnon; username = reader.GetString(0); //isAnon = reader.GetBoolean(1); isAnon = false; dtLastActivity = DateTime.Now;//reader.GetDateTime(1); dtLastUpdated = DateTime.Now;//reader.GetDateTime(2); int size = reader.GetInt32(3); profiles.Add(new ProfileInfo(username, isAnon, dtLastActivity, dtLastUpdated, size)); } holder.Close(); return profiles; }
ProfileInfoCollection BuildProfileInfoCollection (DbDataReader reader, out int totalRecords) { ProfileInfoCollection pic = new ProfileInfoCollection (); while (reader.Read ()) { ProfileInfo pi = ReadProfileInfo (reader); if (pi != null) pic.Add (pi); } totalRecords = 0; if (reader.NextResult ()) { if (reader.Read ()) totalRecords = reader.GetInt32 (0); } return pic; }
private ProfileInfoCollection GetProfilesForQuery(SqlParameter[] args, ProfileAuthenticationOption authenticationOption, int pageIndex, int pageSize, out int totalRecords) { ProfileInfoCollection infos2; if (pageIndex < 0) { throw new ArgumentException(System.Web.SR.GetString("PageIndex_bad"), "pageIndex"); } if (pageSize < 1) { throw new ArgumentException(System.Web.SR.GetString("PageSize_bad"), "pageSize"); } long num = ((pageIndex * pageSize) + pageSize) - 1L; if (num > 0x7fffffffL) { throw new ArgumentException(System.Web.SR.GetString("PageIndex_PageSize_bad"), "pageIndex and pageSize"); } try { SqlConnectionHolder connection = null; SqlDataReader reader = null; try { connection = SqlConnectionHelper.GetConnection(this._sqlConnectionString, true); this.CheckSchemaVersion(connection.Connection); SqlCommand command = new SqlCommand("dbo.aspnet_Profile_GetProfiles", connection.Connection) { CommandTimeout = this.CommandTimeout, CommandType = CommandType.StoredProcedure }; command.Parameters.Add(this.CreateInputParam("@ApplicationName", SqlDbType.NVarChar, this.ApplicationName)); command.Parameters.Add(this.CreateInputParam("@ProfileAuthOptions", SqlDbType.Int, (int)authenticationOption)); command.Parameters.Add(this.CreateInputParam("@PageIndex", SqlDbType.Int, pageIndex)); command.Parameters.Add(this.CreateInputParam("@PageSize", SqlDbType.Int, pageSize)); foreach (SqlParameter parameter in args) { command.Parameters.Add(parameter); } reader = command.ExecuteReader(CommandBehavior.SequentialAccess); ProfileInfoCollection infos = new ProfileInfoCollection(); while (reader.Read()) { string username = reader.GetString(0); bool boolean = reader.GetBoolean(1); DateTime lastActivityDate = DateTime.SpecifyKind(reader.GetDateTime(2), DateTimeKind.Utc); DateTime lastUpdatedDate = DateTime.SpecifyKind(reader.GetDateTime(3), DateTimeKind.Utc); int size = reader.GetInt32(4); infos.Add(new ProfileInfo(username, boolean, lastActivityDate, lastUpdatedDate, size)); } totalRecords = infos.Count; if (reader.NextResult() && reader.Read()) { totalRecords = reader.GetInt32(0); } infos2 = infos; } finally { if (reader != null) { reader.Close(); } if (connection != null) { connection.Close(); connection = null; } } } catch { throw; } return(infos2); }