Building a MVC2 Template, Part 10, Adding a Custom Profile Provider

No Comments

This is the third post on adding custom providers to our MVC2 template project. This post will simply setup the skeleton specifications and code for our own custom profile provider.

Add a class file named ProfileProviderSpecs.cs to the Providers folder in the Nehemiah.Specs project. Here’s our specifications for the custom profile provider.

using Machine.Specifications;
using Nehemiah.Providers;
using System.Web.Security;

namespace Nehemiah.Specs.Providers
{

 [Subject("Profile Provider")]
 public class delete_profiles_by_profile_collection_method
 {
 It should_delete_all_profiles_specified_in_the_collection;
 }

 [Subject("Profile Provider")]
 public class delete_profiles_by_user_method
 {
 It should_delete_all_profiles_for_the_specified_users;
 }

 [Subject("Profile Provider")]
 public class delete_inactive_profiles_method
 {
 It should_;
 }

 [Subject("Profile Provider")]
 public class get_number_of_inactive_profiles_method
 {
 It should_;
 }

 [Subject("Profile Provider")]
 public class get_all_profiles_method
 {
 It should_;
 }

 [Subject("Profile Provider")]
 public class get_all_inactive_profiles_method
 {
 It should_;
 }

 [Subject("Profile Provider")]
 public class find_profiles_by_user_name_profiles_method
 {
 It should_;
 }

 [Subject("Profile Provider")]
 public class find_inactive_profiles_by_user_name_profiles_method
 {
 It should_;
 }

 [Subject("Profile Provider")]
 public class get_property_values_method
 {
 It should_;
 }

 [Subject("Profile Provider")]
 public class set_property_values_method
 {
 It should_;
 }

}


Add a class file named ProfileProvider.cs to the Nehemiah.Providers project. The code for the custom profile provider is below.

using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Web.Profile;

// Refernce URL: http://msdn.microsoft.com/en-us/library/aa479035.aspx

namespace Nehemiah.Providers
{

 public class NehemiahProfileProvider : ProfileProvider
 {
 #region - Properties -

 // The name of the application using the profile provider. ApplicationName is used to scope
 // profile data so that applications can choose whether to share profile data with other
 // applications. This property can be read and written.
 public override string ApplicationName { get; set; }

 #endregion

 #region - Methods -

 public override void Initialize(string name, NameValueCollection config)
 {
 throw new NotImplementedException();
 }

 // Deletes the specified profiles from the data source.
 public override int DeleteProfiles(ProfileInfoCollection profiles)
 {
 throw new NotImplementedException();
 }

 // Deletes the specified users' profiles from the data source.
 public override int DeleteProfiles(string[] usernames)
 {
 throw new NotImplementedException();
 }

 // Deletes all inactive profiles-profiles that haven't been accessed since the specified
 // date-from the data source.
 public override int DeleteInactiveProfiles(ProfileAuthenticationOption authenticationOption, DateTime userInactiveSinceDate)
 {
 throw new NotImplementedException();
 }

 // Returns the number of profiles that haven't been accessed since the specified date.
 public override int GetNumberOfInactiveProfiles(ProfileAuthenticationOption authenticationOption, DateTime userInactiveSinceDate)
 {
 throw new NotImplementedException();
 }

 // Returns a collection of ProfileInfo objects containing administrative information
 // about all profiles, including user names and last activity dates.
 public override ProfileInfoCollection GetAllProfiles(ProfileAuthenticationOption authenticationOption, int pageIndex, int pageSize, out int totalRecords)
 {
 throw new NotImplementedException();
 }

 // Returns a collection of ProfileInfo objects containing administrative information
 // regarding profiles that haven't been accessed since the specified date.
 public override ProfileInfoCollection GetAllInactiveProfiles(ProfileAuthenticationOption authenticationOption, DateTime userInactiveSinceDate, int pageIndex, int pageSize, out int totalRecords)
 {
 throw new NotImplementedException();
 }

 // Returns a collection of ProfileInfo objects containing administrative information
 // regarding profiles whose user names match a specified pattern.
 public override ProfileInfoCollection FindProfilesByUserName(ProfileAuthenticationOption authenticationOption, string usernameToMatch, int pageIndex, int pageSize, out int totalRecords)
 {
 throw new NotImplementedException();
 }

 // Returns a collection of ProfileInfo objects containing administrative information
 // regarding profiles whose user names match a specified pattern and that haven't been accessed since the specified date.
 public override ProfileInfoCollection FindInactiveProfilesByUserName(ProfileAuthenticationOption authenticationOption, string usernameToMatch, DateTime userInactiveSinceDate, int pageIndex, int pageSize, out int totalRecords)
 {
 throw new NotImplementedException();
 }

 // Reads profile property values from the data source and returns them in a
 // SettingsPropertyValueCollection. See GetPropertyValues for details.
 public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection properties)
 {
 throw new NotImplementedException();
 }

 // Writes profile property values to the data source. The values are provided by ASP.NET in a
 // SettingsPropertyValueCollection. See SetPropertyValues for details.
 public override void SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection properties)
 {
 throw new NotImplementedException();
 }

 #endregion

 }   // End Class

}       // End Namespace

Report-html10-01
Rebuild the solution. Viewing the Report.html file should verify we now have 73 specifications and 37 unimplemented specifications. Commit the changes to subversion. Verify with TeamCity that the solution was built without error by opening http://localhost:8080.

References

Shout it


Kick It on DotNetKicks.com
Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)

Leave a Reply

Comment moderation is enabled. Your comment may take some time to appear.