2 // System.Web.Profile.ProfileManager.cs
5 // Chris Toshok (toshok@ximian.com)
6 // Vladimir Krasnov (vladimirk@mainsoft.com)
8 // (C) 2005 Novell, Inc (http://www.novell.com)
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 using System.Web.Configuration;
34 using System.Configuration;
36 namespace System.Web.Profile
38 public static class ProfileManager
40 static ProfileSection config;
41 static ProfileProviderCollection providersCollection;
43 static ProfileManager ()
45 config = (ProfileSection) WebConfigurationManager.GetSection ("system.web/profile");
48 public static int DeleteInactiveProfiles (ProfileAuthenticationOption authenticationOption, DateTime userInactiveSinceDate)
50 return Provider.DeleteInactiveProfiles (authenticationOption, userInactiveSinceDate);
53 public static bool DeleteProfile (string username)
55 return Provider.DeleteProfiles (new string [] { username }) > 0;
58 public static int DeleteProfiles (string[] usernames)
60 return Provider.DeleteProfiles (usernames);
63 public static int DeleteProfiles (ProfileInfoCollection profiles)
65 return Provider.DeleteProfiles (profiles);
68 public static ProfileInfoCollection FindInactiveProfilesByUserName (ProfileAuthenticationOption authenticationOption,
69 string usernameToMatch, DateTime userInactiveSinceDate)
72 return Provider.FindInactiveProfilesByUserName (authenticationOption, usernameToMatch, userInactiveSinceDate, 0, int.MaxValue, out totalRecords);
75 public static ProfileInfoCollection FindInactiveProfilesByUserName (ProfileAuthenticationOption authenticationOption,
76 string usernameToMatch, DateTime userInactiveSinceDate,
77 int pageIndex, int pageSize, out int totalRecords)
79 return Provider.FindInactiveProfilesByUserName (authenticationOption, usernameToMatch, userInactiveSinceDate, pageIndex, pageSize, out totalRecords);
82 public static ProfileInfoCollection FindProfilesByUserName (ProfileAuthenticationOption authenticationOption, string usernameToMatch)
85 return Provider.FindProfilesByUserName (authenticationOption, usernameToMatch, 0, int.MaxValue, out totalRecords);
88 public static ProfileInfoCollection FindProfilesByUserName (ProfileAuthenticationOption authenticationOption, string usernameToMatch, int pageIndex, int pageSize, out int totalRecords)
90 return Provider.FindProfilesByUserName (authenticationOption, usernameToMatch, pageIndex, pageSize, out totalRecords);
93 public static ProfileInfoCollection GetAllInactiveProfiles (ProfileAuthenticationOption authenticationOption, DateTime userInactiveSinceDate)
96 return Provider.GetAllInactiveProfiles (authenticationOption, userInactiveSinceDate, 0, int.MaxValue, out totalRecords);
99 public static ProfileInfoCollection GetAllInactiveProfiles (ProfileAuthenticationOption authenticationOption,
100 DateTime userInactiveSinceDate, int pageIndex, int pageSize,
101 out int totalRecords)
103 return Provider.GetAllInactiveProfiles (authenticationOption, userInactiveSinceDate, pageIndex, pageSize, out totalRecords);
106 public static ProfileInfoCollection GetAllProfiles (ProfileAuthenticationOption authenticationOption)
108 int totalRecords = 0;
109 return Provider.GetAllProfiles (authenticationOption, 0, int.MaxValue, out totalRecords);
112 public static ProfileInfoCollection GetAllProfiles (ProfileAuthenticationOption authenticationOption, int pageIndex, int pageSize, out int totalRecords)
114 return Provider.GetAllProfiles (authenticationOption, pageIndex, pageSize, out totalRecords);
117 public static int GetNumberOfInactiveProfiles (ProfileAuthenticationOption authenticationOption, DateTime userInactiveSinceDate)
119 return Provider.GetNumberOfInactiveProfiles (authenticationOption, userInactiveSinceDate);
122 public static int GetNumberOfProfiles (ProfileAuthenticationOption authenticationOption)
124 int totalRecords = 0;
125 Provider.GetAllProfiles (authenticationOption, 0, 1, out totalRecords);
129 public static string ApplicationName {
131 return Provider.ApplicationName;
134 Provider.ApplicationName = value;
138 public static bool AutomaticSaveEnabled {
140 return config.AutomaticSaveEnabled;
144 public static bool Enabled {
146 return config.Enabled;
150 [MonoTODO ("check AspNetHostingPermissionLevel")]
151 public static ProfileProvider Provider {
153 ProfileProvider p = Providers [config.DefaultProvider];
155 throw new ConfigurationErrorsException ("Provider '" + config.DefaultProvider + "' was not found");
160 public static ProfileProviderCollection Providers {
163 if (providersCollection == null) {
164 ProfileProviderCollection providersCollectionTmp = new ProfileProviderCollection ();
165 ProvidersHelper.InstantiateProviders (config.Providers, providersCollectionTmp, typeof (ProfileProvider));
166 providersCollection = providersCollectionTmp;
168 return providersCollection;
172 static void CheckEnabled ()
175 throw new Exception ("This feature is not enabled. To enable it, add <profile enabled=\"true\"> to your configuration file.");