/// <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 <SAML20> LoadItems(EntityCollection entities) { var samlEnt = entities.Entities .Where(e => e["adx_name"].ToString().StartsWith("Authentication/SAML2/")) .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 samlItems = new List <SAML20>(); foreach (var ent in samlEnt) { var parts = ent.name.Split('/'); var providerName = parts[2]; // see if we have a current item with this fed name var samlItem = samlItems .Where(o => o.Provider == providerName) .FirstOrDefault(); if (samlItem == null) { samlItem = new SAML20() { Provider = providerName }; samlItems.Add(samlItem); } // set the value on the object using helper method ReflectionHelper.SetSiteSettingsValue(samlItem, parts[3], ent.value); } return(samlItems); }