public override int DeleteInactiveProfiles(ProfileAuthenticationOption authenticationOption, DateTime userInactiveSinceDate) { ProfileType? profileType = null; if (authenticationOption == ProfileAuthenticationOption.Anonymous) profileType = ProfileType.Anonymous; else if (authenticationOption == ProfileAuthenticationOption.Authenticated) profileType = ProfileType.Authenticated; int profilesDeleted = 0; using (TransactionScope transaction = new TransactionScope(mConfiguration)) { ProfileUserDataStore profileStore = new ProfileUserDataStore(transaction); IList<ProfileUser> users = profileStore.FindByFields(ApplicationName, null, userInactiveSinceDate, profileType, PagingInfo.All); profilesDeleted = users.Count; foreach (ProfileUser user in users) { profileStore.Delete(user.Id); } transaction.Commit(); } return profilesDeleted; }
public override int DeleteProfiles(string[] usernames) { int profilesDeleted = 0; using (TransactionScope transaction = new TransactionScope(mConfiguration)) { ProfileUserDataStore profileStore = new ProfileUserDataStore(transaction); foreach (string userName in usernames) { IList<ProfileUser> users = profileStore.FindByFields(ApplicationName, userName, null, null, PagingInfo.All); profilesDeleted += users.Count; foreach (ProfileUser user in users) { profileStore.Delete(user.Id); } } transaction.Commit(); } return profilesDeleted; }
private IList<ProfileProperty> GetProperties(string userName) { if (string.IsNullOrEmpty(userName)) return null; IList<ProfileProperty> properties; using (TransactionScope transaction = new TransactionScope(mConfiguration)) { ProfileUserDataStore userStore = new ProfileUserDataStore(transaction); ProfileUser user = userStore.FindByName(ApplicationName, userName); if (user == null) return null; ProfilePropertyDataStore propStore = new ProfilePropertyDataStore(transaction); properties = propStore.FindByUser(user); //Update the last activity date user.LastActivityDate = DateTime.Now; transaction.Commit(); } return properties; }
public override void SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection properties) { string username = (string)context[CONTEXT_USERNAME]; ProfileType profileType; if ((bool)context[CONTEXT_ISAUTHENTICATED]) profileType = ProfileType.Authenticated; else profileType = ProfileType.Anonymous; using (TransactionScope transaction = new TransactionScope(mConfiguration)) { ProfilePropertyDataStore propStore = new ProfilePropertyDataStore(transaction); ProfileUserDataStore userStore = new ProfileUserDataStore(transaction); ProfileUser user = userStore.FindByName(ApplicationName, username); //Create the user if not exist if (user == null) { user = new ProfileUser(ApplicationName, username, profileType); userStore.Insert(user); } bool userChanged = false; foreach (SettingsPropertyValue propValue in properties) { if (propValue.IsDirty) { if (profileType == ProfileType.Anonymous) { bool allowAnonymous = (bool)propValue.Property.Attributes[PROP_ATTRIBUTE_ALLOWANONYMOUS]; if (!allowAnonymous) continue; } userChanged = true; ChangeProfileProperty(propStore, user, propValue); } } user.LastActivityDate = DateTime.Now; if (userChanged) user.LastPropertyChangedDate = DateTime.Now; transaction.Commit(); } }
public override int GetNumberOfInactiveProfiles(ProfileAuthenticationOption authenticationOption, DateTime userInactiveSinceDate) { ProfileType? profileType = null; if (authenticationOption == ProfileAuthenticationOption.Anonymous) profileType = ProfileType.Anonymous; else if (authenticationOption == ProfileAuthenticationOption.Authenticated) profileType = ProfileType.Authenticated; using (TransactionScope transaction = new TransactionScope(mConfiguration)) { ProfileUserDataStore profileStore = new ProfileUserDataStore(transaction); IList<ProfileUser> users = profileStore.FindByFields(ApplicationName, null, userInactiveSinceDate, profileType, PagingInfo.All); return users.Count; } }
public override ProfileInfoCollection GetAllProfiles(ProfileAuthenticationOption authenticationOption, int pageIndex, int pageSize, out int totalRecords) { ProfileType? profileType = null; if (authenticationOption == ProfileAuthenticationOption.Anonymous) profileType = ProfileType.Anonymous; else if (authenticationOption == ProfileAuthenticationOption.Authenticated) profileType = ProfileType.Authenticated; using (TransactionScope transaction = new TransactionScope(mConfiguration)) { ProfileUserDataStore profileStore = new ProfileUserDataStore(transaction); PagingInfo paging = new PagingInfo(pageSize, pageIndex); IList<ProfileUser> users = profileStore.FindByFields(ApplicationName, null, null, profileType, paging); totalRecords = (int)paging.RowCount; return ProfileUsersToProfileInfoCollection(users); } }
public override int DeleteProfiles(ProfileInfoCollection profiles) { int profilesDeleted = 0; using (TransactionScope transaction = new TransactionScope(mConfiguration)) { ProfileUserDataStore profileStore = new ProfileUserDataStore(transaction); foreach (ProfileInfo profileInfo in profiles) { ProfileUser user = profileStore.FindByName(ApplicationName, profileInfo.UserName); if (user != null) { profileStore.Delete(user.Id); profilesDeleted++; } } transaction.Commit(); } return profilesDeleted; }