// // CircleManager.cs // // Author: // Paul Schneider // // Copyright (c) 2015 GNU GPL // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Lesser General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public License // along with this program. If not, see . using System; using System.Security.Permissions; using System.Configuration; using System.Collections.Specialized; using System.Collections; using System.Reflection; using System.Collections.Generic; using System.Web; using System.Linq; namespace Yavsc.Model.Circles { /// /// Circle manager. /// public class CircleManager { /// /// Initializes a new instance of the class. /// public CircleManager () { } private static CircleProvider defaultProvider=null; /// /// Gets the default provider. /// /// The default provider. public static CircleProvider DefaultProvider { get { if (defaultProvider == null) GetProviderSettings (); return defaultProvider; } } [PermissionSet(SecurityAction.Demand, Name = "FullTrust")] private static void GetProviderSettings() { System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration( ConfigurationUserLevel.None); DataProviderConfigurationSection pSection = config.GetSection("system.web/circleProviders") as DataProviderConfigurationSection; if (pSection == null) throw new ConfigurationErrorsException ("no circleProviders section defined"); ProviderSettingsCollection providerSettings = pSection.Providers; if (pSection.DefaultProvider != null) { var pSetDef = providerSettings [pSection.DefaultProvider]; ConstructorInfo ci = Type.GetType (pSetDef.Type).GetConstructor (Type.EmptyTypes); defaultProvider = ci.Invoke (Type.EmptyTypes) as CircleProvider; defaultProvider.Initialize (pSection.DefaultProvider,pSetDef.Parameters); } } /// /// List the specified user. /// /// User. public static IEnumerable List(string user) { if (user == null) user = HttpContext.Current.User.Identity.Name; return DefaultProvider.List (user); } /// /// Circles the specified user and relation. /// /// User. /// Relation. public static string[] Circles(string relation, string user = null ) { if (user == null) user = HttpContext.Current.User.Identity.Name; return DefaultProvider.Circles (user, relation); } /// /// Lists the available circles. /// /// The available circles. /// User. public static string[] ListAvailableCircles (string user = null ) { if (user == null) user = HttpContext.Current.User.Identity.Name; return DefaultProvider.List (user).Select (x => x.Title).ToArray(); } } }