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.
32 using System.Web.Configuration;
33 using System.Configuration;
35 namespace System.Web.Profile
37 public static class ProfileManager
39 static ProfileSection config;
40 static ProfileProviderCollection providersCollection;
42 static ProfileManager ()
44 config = (ProfileSection) WebConfigurationManager.GetSection ("system.web/profile");
47 public static int DeleteInactiveProfiles (ProfileAuthenticationOption authenticationOption, DateTime userInactiveSinceDate)
49 return Provider.DeleteInactiveProfiles (authenticationOption, userInactiveSinceDate);
52 public static bool DeleteProfile (string username)
54 return Provider.DeleteProfiles (new string [] { username }) > 0;
57 public static int DeleteProfiles (string[] usernames)
59 return Provider.DeleteProfiles (usernames);
62 public static int DeleteProfiles (ProfileInfoCollection profiles)
64 return Provider.DeleteProfiles (profiles);
67 public static ProfileInfoCollection FindInactiveProfilesByUserName (ProfileAuthenticationOption authenticationOption,
68 string usernameToMatch, DateTime userInactiveSinceDate)
71 return Provider.FindInactiveProfilesByUserName (authenticationOption, usernameToMatch, userInactiveSinceDate, 0, int.MaxValue, out totalRecords);
74 public static ProfileInfoCollection FindInactiveProfilesByUserName (ProfileAuthenticationOption authenticationOption,
75 string usernameToMatch, DateTime userInactiveSinceDate,
76 int pageIndex, int pageSize, out int totalRecords)
78 return Provider.FindInactiveProfilesByUserName (authenticationOption, usernameToMatch, userInactiveSinceDate, pageIndex, pageSize, out totalRecords);
81 public static ProfileInfoCollection FindProfilesByUserName (ProfileAuthenticationOption authenticationOption, string usernameToMatch)
84 return Provider.FindProfilesByUserName (authenticationOption, usernameToMatch, 0, int.MaxValue, out totalRecords);
87 public static ProfileInfoCollection FindProfilesByUserName (ProfileAuthenticationOption authenticationOption, string usernameToMatch, int pageIndex, int pageSize, out int totalRecords)
89 return Provider.FindProfilesByUserName (authenticationOption, usernameToMatch, pageIndex, pageSize, out totalRecords);
92 public static ProfileInfoCollection GetAllInactiveProfiles (ProfileAuthenticationOption authenticationOption, DateTime userInactiveSinceDate)
95 return Provider.GetAllInactiveProfiles (authenticationOption, userInactiveSinceDate, 0, int.MaxValue, out totalRecords);
98 public static ProfileInfoCollection GetAllInactiveProfiles (ProfileAuthenticationOption authenticationOption,
99 DateTime userInactiveSinceDate, int pageIndex, int pageSize,
100 out int totalRecords)
102 return Provider.GetAllInactiveProfiles (authenticationOption, userInactiveSinceDate, pageIndex, pageSize, out totalRecords);
105 public static ProfileInfoCollection GetAllProfiles (ProfileAuthenticationOption authenticationOption)
107 int totalRecords = 0;
108 return Provider.GetAllProfiles (authenticationOption, 0, int.MaxValue, out totalRecords);
111 public static ProfileInfoCollection GetAllProfiles (ProfileAuthenticationOption authenticationOption, int pageIndex, int pageSize, out int totalRecords)
113 return Provider.GetAllProfiles (authenticationOption, pageIndex, pageSize, out totalRecords);
116 public static int GetNumberOfInactiveProfiles (ProfileAuthenticationOption authenticationOption, DateTime userInactiveSinceDate)
118 return Provider.GetNumberOfInactiveProfiles (authenticationOption, userInactiveSinceDate);
121 public static int GetNumberOfProfiles (ProfileAuthenticationOption authenticationOption)
123 int totalRecords = 0;
124 Provider.GetAllProfiles (authenticationOption, 0, 1, out totalRecords);
128 public static string ApplicationName {
130 return Provider.ApplicationName;
133 Provider.ApplicationName = value;
137 public static bool AutomaticSaveEnabled {
139 return config.AutomaticSaveEnabled;
143 public static bool Enabled {
145 return config.Enabled;
149 [MonoTODO ("check AspNetHostingPermissionLevel")]
150 public static ProfileProvider Provider {
152 ProfileProvider p = Providers [config.DefaultProvider];
154 throw new ConfigurationErrorsException ("Provider '" + config.DefaultProvider + "' was not found");
159 public static ProfileProviderCollection Providers {
162 if (providersCollection == null) {
163 ProfileProviderCollection providersCollectionTmp = new ProfileProviderCollection ();
164 ProvidersHelper.InstantiateProviders (config.Providers, providersCollectionTmp, typeof (ProfileProvider));
165 providersCollection = providersCollectionTmp;
167 return providersCollection;
171 static void CheckEnabled ()
174 throw new Exception ("This feature is not enabled. To enable it, add <profile enabled=\"true\"> to your configuration file.");