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;
35 namespace System.Web.Profile
37 public static class ProfileManager
40 const string Profiles_config = "Profiles.config";
41 const string Profiles_ProfileProviderCollection = "Profiles.ProfileProviderCollection";
42 private static ProfileSection config
46 object o = AppDomain.CurrentDomain.GetData (Profiles_config);
48 config = (ProfileSection) WebConfigurationManager.GetSection ("system.web/profile");
49 return (ProfileSection) config;
52 return (ProfileSection) o;
56 AppDomain.CurrentDomain.SetData (Profiles_config, value);
59 private static ProfileProviderCollection providersCollection
63 object o = AppDomain.CurrentDomain.GetData (Profiles_ProfileProviderCollection);
64 return (ProfileProviderCollection) o;
68 AppDomain.CurrentDomain.SetData (Profiles_ProfileProviderCollection, value);
72 private static ProfileSection config;
73 private static ProfileProviderCollection providersCollection;
75 static ProfileManager ()
77 config = (ProfileSection) WebConfigurationManager.GetSection ("system.web/profile");
81 public static int DeleteInactiveProfiles (ProfileAuthenticationOption authenticationOption, DateTime userInactiveSinceDate)
83 return Provider.DeleteInactiveProfiles (authenticationOption, userInactiveSinceDate);
86 public static bool DeleteProfile (string username)
88 return Provider.DeleteProfiles (new string [] { username }) > 0;
91 public static int DeleteProfiles (string[] usernames)
93 return Provider.DeleteProfiles (usernames);
96 public static int DeleteProfiles (ProfileInfoCollection profiles)
98 return Provider.DeleteProfiles (profiles);
101 public static ProfileInfoCollection FindInactiveProfilesByUserName (ProfileAuthenticationOption authenticationOption,
102 string usernameToMatch, DateTime userInactiveSinceDate)
104 int totalRecords = 0;
105 return Provider.FindInactiveProfilesByUserName (authenticationOption, usernameToMatch, userInactiveSinceDate, 0, int.MaxValue, out totalRecords);
108 public static ProfileInfoCollection FindInactiveProfilesByUserName (ProfileAuthenticationOption authenticationOption,
109 string usernameToMatch, DateTime userInactiveSinceDate,
110 int pageIndex, int pageSize, out int totalRecords)
112 return Provider.FindInactiveProfilesByUserName (authenticationOption, usernameToMatch, userInactiveSinceDate, pageIndex, pageSize, out totalRecords);
115 public static ProfileInfoCollection FindProfilesByUserName (ProfileAuthenticationOption authenticationOption, string usernameToMatch)
117 int totalRecords = 0;
118 return Provider.FindProfilesByUserName (authenticationOption, usernameToMatch, 0, int.MaxValue, out totalRecords);
121 public static ProfileInfoCollection FindProfilesByUserName (ProfileAuthenticationOption authenticationOption, string usernameToMatch, int pageIndex, int pageSize, out int totalRecords)
123 return Provider.FindProfilesByUserName (authenticationOption, usernameToMatch, pageIndex, pageSize, out totalRecords);
126 public static ProfileInfoCollection GetAllInactiveProfiles (ProfileAuthenticationOption authenticationOption, DateTime userInactiveSinceDate)
128 int totalRecords = 0;
129 return Provider.GetAllInactiveProfiles (authenticationOption, userInactiveSinceDate, 0, int.MaxValue, out totalRecords);
132 public static ProfileInfoCollection GetAllInactiveProfiles (ProfileAuthenticationOption authenticationOption,
133 DateTime userInactiveSinceDate, int pageIndex, int pageSize,
134 out int totalRecords)
136 return Provider.GetAllInactiveProfiles (authenticationOption, userInactiveSinceDate, pageIndex, pageSize, out totalRecords);
139 public static ProfileInfoCollection GetAllProfiles (ProfileAuthenticationOption authenticationOption)
141 int totalRecords = 0;
142 return Provider.GetAllProfiles (authenticationOption, 0, int.MaxValue, out totalRecords);
145 public static ProfileInfoCollection GetAllProfiles (ProfileAuthenticationOption authenticationOption, int pageIndex, int pageSize, out int totalRecords)
147 return Provider.GetAllProfiles (authenticationOption, pageIndex, pageSize, out totalRecords);
150 public static int GetNumberOfInactiveProfiles (ProfileAuthenticationOption authenticationOption, DateTime userInactiveSinceDate)
152 return Provider.GetNumberOfInactiveProfiles (authenticationOption, userInactiveSinceDate);
155 public static int GetNumberOfProfiles (ProfileAuthenticationOption authenticationOption)
157 int totalRecords = 0;
158 Provider.GetAllProfiles (authenticationOption, 0, 1, out totalRecords);
162 public static string ApplicationName {
164 return Provider.ApplicationName;
167 Provider.ApplicationName = value;
171 public static bool AutomaticSaveEnabled {
173 return config.AutomaticSaveEnabled;
177 public static bool Enabled {
179 return config.Enabled;
183 [MonoTODO ("check AspNetHostingPermissionLevel")]
184 public static ProfileProvider Provider {
186 ProfileProvider p = Providers [config.DefaultProvider];
188 throw new HttpException ("Provider '" + config.DefaultProvider + "' was not found");
193 public static ProfileProviderCollection Providers {
196 if (providersCollection == null) {
197 providersCollection = new ProfileProviderCollection ();
198 ProvidersHelper.InstantiateProviders (config.Providers, providersCollection, typeof (ProfileProvider));
200 return providersCollection;
204 private static void CheckEnabled ()
207 throw new Exception ("This feature is not enabled. To enable it, add <profile enabled=\"true\"> to your configuration file.");