/// <summary> /// Gets all users. /// </summary> /// <param name="pageIndex">Index of the page.</param> /// <param name="pageSize">Size of the page.</param> /// <param name="totalRecords">The total records.</param> /// <returns>The users.</returns> public virtual List <CRMUser> GetAllUsers(Microsoft.Xrm.Sdk.Query.PagingInfo pagingInfo, out int totalRecords) { const string GetAllUsersKey = "getAllUsers"; ConditionalLog.Info(String.Format("GetAllUsers({0}, {1}). Started.", pagingInfo.PageNumber, pagingInfo.Count), this, TimerAction.Start, GetAllUsersKey); var users = this.GetAllUsersFromCrm(pagingInfo, out totalRecords); if (totalRecords == -1) { ConditionalLog.Info("GetAllUsers returned more than 5k users. A precise count cannot be determined.", this); totalRecords = 5000; } ConditionalLog.Info(String.Format("GetAllUsers({0}, {1}). Retrieved {2} user(s) from CRM.", pagingInfo.PageNumber, pagingInfo.Count, users.Count), this, TimerAction.Tick, GetAllUsersKey); var result = new Dictionary <string, CRMUser>(); foreach (var user in users) { if (!result.ContainsKey(user.Name)) { result.Add(user.Name, user); this.CacheService.UserCache.Add(user); } } ConditionalLog.Info(String.Format("GetAllUsers({0}, {1}). Finished.", pagingInfo.PageNumber, pagingInfo.Count), this, TimerAction.Stop, GetAllUsersKey); return(result.Values.ToList()); }
protected override List <CRMUser> GetAllUsersFromCrm(Microsoft.Xrm.Sdk.Query.PagingInfo pagingInfo, out int totalRecords) { var pagingInfo2 = new PagingInfo { Count = pagingInfo.Count, PageNumber = pagingInfo.PageNumber, PagingCookie = pagingInfo.PagingCookie }; totalRecords = this.GetUsersNumber(Configuration.Settings.UniqueKeyProperty, string.Empty); var contacts = this.GetContacts(pagingInfo2, "statecode", ConditionOperator.Equal, "Active"); return(contacts.Select(this.ContactToUserConverter.Convert).ToList()); }
///// <summary> ///// Deletes all contact-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"/> values, specifying whether anonymous, authenticated, or both types of profiles are deleted.</param> ///// <param name="userInactiveSinceDate">A <see cref="T:System.DateTime"/> that identifies which contact profiles are considered inactive. If the <see cref="P:System.Web.Profile.ProfileInfo.LastActivityDate"/> value of a contact profile occurs on or before this date and time, the profile is considered inactive.</param> ///// <returns>The number of profiles deleted from the CRM system.</returns> //public override int DeleteInactiveProfiles(ProfileAuthenticationOption authenticationOption, DateTime userInactiveSinceDate) //{ // if (!this.initialized || this.ReadOnly) // { // return 0; // } // int totalUsers; // var profiles = (from user in this.userRepository.GetAllUsers(0, Int32.MaxValue, out totalUsers) // where this.HasProfile(user.Name) && (user.LastActivityDate <= userInactiveSinceDate) // select user.Name).ToArray(); // return this.DeleteProfiles(profiles); //} public override int DeleteInactiveProfiles(ProfileAuthenticationOption authenticationOption, DateTime userInactiveSinceDate) { if (!this.initialized || this.ReadOnly) { return(0); } int totalUsers; var pagingInfo = new Microsoft.Xrm.Sdk.Query.PagingInfo { Count = Int32.MaxValue, PageNumber = 1 }; var profiles = (from user in this.userRepository.GetAllUsers(pagingInfo, out totalUsers) where this.HasProfile(user.Name) && (user.LastActivityDate <= userInactiveSinceDate) select user.Name).ToArray(); return(this.DeleteProfiles(profiles)); }
/// <summary> /// Retrieves contact-profile data from the CRM system for profiles in which the last activity date occurred on or before the specified date. /// </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="userInactiveSinceDate">A <see cref="T:System.DateTime"/> that identifies which contact profiles are considered inactive. If the <see cref="P:System.Web.Profile.ProfileInfo.LastActivityDate"/> of a contact 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 contact-profile information about the inactive profiles. /// </returns> public override ProfileInfoCollection GetAllInactiveProfiles(ProfileAuthenticationOption authenticationOption, DateTime userInactiveSinceDate, int pageIndex, int pageSize, out int totalRecords) { if (!this.initialized) { totalRecords = 0; return(new ProfileInfoCollection()); } var result = new ProfileInfoCollection(); int pageNumber = pageIndex + 1; do { int totalUsers; var pagingInfo = new Microsoft.Xrm.Sdk.Query.PagingInfo { Count = pageSize, PageNumber = pageNumber }; var users = this.userRepository.GetAllUsers(pagingInfo, out totalUsers); foreach (var user in users.Where(user => this.HasProfile(user.Name) && (user.LastActivityDate <= userInactiveSinceDate))) { //Note: profile size should be counted. result.Add(new ProfileInfo(user.Name, false, DateTime.Now, DateTime.Now, 0)); } if (((pageNumber + 1) * pageSize) >= totalUsers) { break; } pageNumber++; }while (result.Count < pageSize); totalRecords = result.Count; return(result); }
///// <summary> ///// Gets a collection of all the users in the data source in pages of data. ///// </summary> ///// <returns>A <see cref="T:System.Web.Security.MembershipUserCollection"/> collection that contains a page of <paramref name="pageSize"/><see cref="T:System.Web.Security.MembershipUser"/> objects beginning at the page specified by <paramref name="pageIndex"/>.</returns> ///// <param name="pageIndex">The index of the page of results to return. <paramref name="pageIndex"/> is zero-based.</param> ///// <param name="pageSize">The size of the page of results to return.</param> ///// <param name="totalRecords">The total number of matched users.</param> //public override MembershipUserCollection GetAllUsers(int pageIndex, int pageSize, out int totalRecords) //{ // if (this.initialized) // { // var result = new MembershipUserCollection(); // var crmUsers = this.userRepository.GetAllUsers(pageIndex, pageSize, out totalRecords); // foreach (var crmUser in crmUsers) // { // result.Add(new CRMMembershipUser(this.Name, crmUser)); // } // return result; // } // totalRecords = 0; // return new MembershipUserCollection(); //} public override MembershipUserCollection GetAllUsers(int pageIndex, int pageSize, out int totalRecords) { if (this.initialized) { var pageNumber = pageIndex + 1; var pagingInfo = new Microsoft.Xrm.Sdk.Query.PagingInfo { PageNumber = pageNumber, Count = pageSize }; var result = new MembershipUserCollection(); var crmUsers = this.userRepository.GetAllUsers(pagingInfo, out totalRecords); foreach (var crmUser in crmUsers) { result.Add(new CRMMembershipUser(this.Name, crmUser)); } return(result); } totalRecords = 0; return(new MembershipUserCollection()); }
protected abstract List <CRMUser> GetAllUsersFromCrm(Microsoft.Xrm.Sdk.Query.PagingInfo pagingInfo, out int totalRecords);