/// <summary> /// Gets the property values relevant to the CRM system from the collection. /// </summary> /// <param name="allPropertyValues">The collection of the property values to filter the CRM relevant property values.</param> /// <returns> /// The collection of the CRM relevant property values. /// </returns> protected virtual SettingsPropertyValueCollection GetRelevantPropertyValues(SettingsPropertyValueCollection allPropertyValues) { var propertyValues = new SettingsPropertyValueCollection(); foreach (SettingsPropertyValue propertyValue in allPropertyValues) { CrmSettingsProperty crmProperty; if (this.GetIfRelevant(propertyValue.Property, out crmProperty)) { var crmPropertyValue = new CrmSettingsPropertyValue(propertyValue, crmProperty); propertyValues.Add(crmPropertyValue); } } return(propertyValues); }
/// <summary> /// Returns the collection of settings property values for the specified application instance and settings property group. /// </summary> /// <param name="context">A <see cref="T:System.Configuration.SettingsContext"/> describing the current application use.</param> /// <param name="collection">A <see cref="T:System.Configuration.SettingsPropertyCollection"/> containing the settings property group whose values are to be retrieved.</param> /// <returns> /// A <see cref="T:System.Configuration.SettingsPropertyValueCollection"/> containing the values for the specified settings property group. /// </returns> /// <exception cref="ProviderException">Couldn't resolve CRM property type</exception> public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection) { if (this.initialized) { var spvc = new SettingsPropertyValueCollection(); var userName = (string)context["UserName"]; if (userName != string.Empty) { if ((!string.IsNullOrEmpty(userName)) && (!userName.Contains("\\"))) { var attributes = new List <string>(); SettingsPropertyCollection relevantProperties = this.GetRelevantProperties(collection); if (relevantProperties.Count > 0) { attributes.AddRange(this.ProcessProperties(relevantProperties, p => (p as CrmSettingsProperty).CrmName)); var propertyValues = this.profileRepository.GetUserProperties(userName, attributes.ToArray()); foreach (CrmSettingsProperty property in relevantProperties) { if (collection[property.Name] == null) { continue; } var crmPropertyValue = new CrmSettingsPropertyValue(collection[property.Name]) { PropertyValue = string.Empty }; collection.Remove(property.Name); crmPropertyValue.PropertyValue = propertyValues.ContainsKey(property.CrmName) ? propertyValues[property.CrmName] : string.Empty; crmPropertyValue.IsDirty = false; spvc.Add(crmPropertyValue); } } } } return(spvc); } return(new SettingsPropertyValueCollection()); }