/// <summary> /// Load the entity collection into the structure /// </summary> /// <param name="entities"></param> public void LoadSettings(EntityCollection entities) { // iterate on the records and load the values var props = this.GetType().GetProperties(); #region most properties foreach (var prop in props) { // find the attrib with the name value var attrib = prop .GetCustomAttributes(true) .Where(a => a is SiteSettingsAttribute) .FirstOrDefault() as SiteSettingsAttribute; if (attrib != null) { // get the name from the attribute var name = attrib.NameFormat.ToLower(); // find correct Name from the entity collection var setting = entities.Entities.Where(e => e["adx_name"].ToString().ToLower() == name).FirstOrDefault(); if (setting != null && setting.Attributes.ContainsKey("adx_value")) { var entVal = setting["adx_value"].ToString(); ReflectionHelper.SetSiteSettingsValue(this, prop, attrib, entVal); } } } #endregion #region Open Auth Values // new settings, so MS, FB, LI, all now fall under this collection OpenAuthProviders = OpenAuthProvider.LoadItems(entities, _websiteId).ToArray(); #endregion #region OpenId Connect Values // now add the items back to the prop as an array for the prop grid OpenIdConnectProviders = OpenIdConnect.LoadItems(entities).ToArray(); #endregion #region SAML 2.0 // now add the items back to the prop as an array for the prop grid SAML20Providers = SAML20.LoadItems(entities).ToArray(); #endregion }
/// <summary> /// Helper method to load a collection of items from an Entity List /// </summary> /// <param name="entities"></param> /// <returns></returns> public static List <OpenIdConnect> LoadItems(EntityCollection entities) { var openIdEnt = entities.Entities .Where(e => e["adx_name"].ToString().StartsWith("Authentication/OpenIdConnect/")) .Select(e => new { name = e["adx_name"].ToString(), value = (e.Attributes.ContainsKey("adx_value")) ? e["adx_value"].ToString() : null }); // use new list, dynamic add var items = new List <OpenIdConnect>(); foreach (var ent in openIdEnt) { var parts = ent.name.Split('/'); var fedName = parts[2]; // see if we have a current item with this fed name var openIdItem = items .Where(o => o.FederatedName == fedName) .FirstOrDefault(); if (openIdItem == null) { openIdItem = new OpenIdConnect() { FederatedName = fedName }; items.Add(openIdItem); } // set the value on the object using helper method ReflectionHelper.SetSiteSettingsValue(openIdItem, parts[3], ent.value); } return(items); }