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
41 const string Profiles_config = "Profiles.config";
42 const string Profiles_ProfileProviderCollection = "Profiles.ProfileProviderCollection";
43 static ProfileSection config
47 object o = AppDomain.CurrentDomain.GetData (Profiles_config);
49 config = (ProfileSection) WebConfigurationManager.GetSection ("system.web/profile");
50 return (ProfileSection) config;
53 return (ProfileSection) o;
57 AppDomain.CurrentDomain.SetData (Profiles_config, value);
60 static ProfileProviderCollection providersCollection
64 object o = AppDomain.CurrentDomain.GetData (Profiles_ProfileProviderCollection);
65 return (ProfileProviderCollection) o;
69 AppDomain.CurrentDomain.SetData (Profiles_ProfileProviderCollection, value);
73 static ProfileSection config;
74 static ProfileProviderCollection providersCollection;
76 static ProfileManager ()
78 config = (ProfileSection) WebConfigurationManager.GetSection ("system.web/profile");
82 public static int DeleteInactiveProfiles (ProfileAuthenticationOption authenticationOption, DateTime userInactiveSinceDate)
84 return Provider.DeleteInactiveProfiles (authenticationOption, userInactiveSinceDate);
87 public static bool DeleteProfile (string username)
89 return Provider.DeleteProfiles (new string [] { username }) > 0;
92 public static int DeleteProfiles (string[] usernames)
94 return Provider.DeleteProfiles (usernames);
97 public static int DeleteProfiles (ProfileInfoCollection profiles)
99 return Provider.DeleteProfiles (profiles);
102 public static ProfileInfoCollection FindInactiveProfilesByUserName (ProfileAuthenticationOption authenticationOption,
103 string usernameToMatch, DateTime userInactiveSinceDate)
105 int totalRecords = 0;
106 return Provider.FindInactiveProfilesByUserName (authenticationOption, usernameToMatch, userInactiveSinceDate, 0, int.MaxValue, out totalRecords);
109 public static ProfileInfoCollection FindInactiveProfilesByUserName (ProfileAuthenticationOption authenticationOption,
110 string usernameToMatch, DateTime userInactiveSinceDate,
111 int pageIndex, int pageSize, out int totalRecords)
113 return Provider.FindInactiveProfilesByUserName (authenticationOption, usernameToMatch, userInactiveSinceDate, pageIndex, pageSize, out totalRecords);
116 public static ProfileInfoCollection FindProfilesByUserName (ProfileAuthenticationOption authenticationOption, string usernameToMatch)
118 int totalRecords = 0;
119 return Provider.FindProfilesByUserName (authenticationOption, usernameToMatch, 0, int.MaxValue, out totalRecords);
122 public static ProfileInfoCollection FindProfilesByUserName (ProfileAuthenticationOption authenticationOption, string usernameToMatch, int pageIndex, int pageSize, out int totalRecords)
124 return Provider.FindProfilesByUserName (authenticationOption, usernameToMatch, pageIndex, pageSize, out totalRecords);
127 public static ProfileInfoCollection GetAllInactiveProfiles (ProfileAuthenticationOption authenticationOption, DateTime userInactiveSinceDate)
129 int totalRecords = 0;
130 return Provider.GetAllInactiveProfiles (authenticationOption, userInactiveSinceDate, 0, int.MaxValue, out totalRecords);
133 public static ProfileInfoCollection GetAllInactiveProfiles (ProfileAuthenticationOption authenticationOption,
134 DateTime userInactiveSinceDate, int pageIndex, int pageSize,
135 out int totalRecords)
137 return Provider.GetAllInactiveProfiles (authenticationOption, userInactiveSinceDate, pageIndex, pageSize, out totalRecords);
140 public static ProfileInfoCollection GetAllProfiles (ProfileAuthenticationOption authenticationOption)
142 int totalRecords = 0;
143 return Provider.GetAllProfiles (authenticationOption, 0, int.MaxValue, out totalRecords);
146 public static ProfileInfoCollection GetAllProfiles (ProfileAuthenticationOption authenticationOption, int pageIndex, int pageSize, out int totalRecords)
148 return Provider.GetAllProfiles (authenticationOption, pageIndex, pageSize, out totalRecords);
151 public static int GetNumberOfInactiveProfiles (ProfileAuthenticationOption authenticationOption, DateTime userInactiveSinceDate)
153 return Provider.GetNumberOfInactiveProfiles (authenticationOption, userInactiveSinceDate);
156 public static int GetNumberOfProfiles (ProfileAuthenticationOption authenticationOption)
158 int totalRecords = 0;
159 Provider.GetAllProfiles (authenticationOption, 0, 1, out totalRecords);
163 public static string ApplicationName {
165 return Provider.ApplicationName;
168 Provider.ApplicationName = value;
172 public static bool AutomaticSaveEnabled {
174 return config.AutomaticSaveEnabled;
178 public static bool Enabled {
180 return config.Enabled;
184 [MonoTODO ("check AspNetHostingPermissionLevel")]
185 public static ProfileProvider Provider {
187 ProfileProvider p = Providers [config.DefaultProvider];
189 throw new ConfigurationErrorsException ("Provider '" + config.DefaultProvider + "' was not found");
194 public static ProfileProviderCollection Providers {
197 if (providersCollection == null) {
198 ProfileProviderCollection providersCollectionTmp = new ProfileProviderCollection ();
199 ProvidersHelper.InstantiateProviders (config.Providers, providersCollectionTmp, typeof (ProfileProvider));
200 providersCollection = providersCollectionTmp;
202 return providersCollection;
206 static void CheckEnabled ()
209 throw new Exception ("This feature is not enabled. To enable it, add <profile enabled=\"true\"> to your configuration file.");